Hello people. :-)
I am a beginner in the world of micro-controllers. I have the
PIC24F04KA201 and I have been trying to pulse an LED using the internal
clock of the microcontroller.
Here is the code that I have been using.
1 | /*
|
2 | * File: newmainXC16.c
|
3 | * Author: Soumojit Bose
|
4 | *
|
5 | * Created on February 24, 2018, 8:52 PM
|
6 | */
|
7 |
|
8 | #include <p24F04KA201.h>
|
9 | #define FOSC 32000000
|
10 | #define FCY (FOSC/2)//This is generally crystal frequency divided by 2
|
11 | #include <libpic30.h>
|
12 | #include<xc.h>
|
13 |
|
14 |
|
15 | /******************************************************************************/
|
16 |
|
17 | /* *** Configuration Bits Setting *** */
|
18 |
|
19 | _FGS(GWRP_OFF & GCP_OFF)
|
20 | _FOSCSEL(FNOSC_PRI & IESO_OFF)
|
21 | _FOSC(POSCMOD_HS & OSCIOFNC_ON & POSCFREQ_HS & FCKSM_CSDCMD)
|
22 | _FWDT(WINDIS_OFF & FWDTEN_OFF)
|
23 | _FPOR(BOREN_BOR2 & PWRTEN_OFF & BORV_18V & MCLRE_ON)
|
24 | _FDS(DSWDTEN_OFF)
|
25 |
|
26 | /******************************************************************************/
|
27 | /*
|
28 | *
|
29 | */
|
30 |
|
31 | //void Delay(unsigned int a);
|
32 | int main()
|
33 | {
|
34 |
|
35 |
|
36 | TRISBbits.TRISB0 = 0; /* Making Pin as output */
|
37 |
|
38 | LATBbits.LATB0 = 0; /* Writing zero to pin 0 of port A */
|
39 |
|
40 | while(1)
|
41 | {
|
42 | LATBbits.LATB0 = ~LATBbits.LATB0; /* toggling state of PIN zero to one and vice versa */
|
43 | __delay_ms(10); // this is actual delay time in msec
|
44 | }
|
45 |
|
46 | return 0;
|
47 | }
|
What I do not understand is how to set the OSCCCON bits so that I can
use the internal clock of the PIC24 to do my LED pulsing. Will the
_delay_ms() function work in the same way, if I use an external clock?