Forum: µC & Digital Electronics Pulsing a pin of the PIC24F04KA201

von Soumojit Bose (Guest)

Rate this post
0 useful
not useful
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.
 * File:   newmainXC16.c
 * Author: Soumojit Bose
 * Created on February 24, 2018, 8:52 PM

#include <p24F04KA201.h>
#define FOSC 32000000
#define FCY (FOSC/2)//This is generally crystal frequency divided by 2
#include <libpic30.h>


/*  *** Configuration Bits Setting  *** */



//void Delay(unsigned int a);
int main()

    TRISBbits.TRISB0 = 0;       /*  Making Pin as output                            */

    LATBbits.LATB0 = 0;         /*  Writing zero to pin 0 of port A                 */

        LATBbits.LATB0 = ~LATBbits.LATB0;   /*  toggling state of PIN zero to one and vice versa    */
        __delay_ms(10); // this is actual delay time in msec 

    return 0;

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?

von Soumojit B. (soumojit_b643)

Attached files:

Rate this post
0 useful
not useful
Also attached here is the Proteus simulation. I have a configuration 
where I am trying to pulse the RB0 pin of the microcontroller. At first, 
I did not have CLKI and CLK0 grounded, assuming that my configuration 
bit settings had taken care of it. The simulation did not work. When I 
have the CLKI and CLKO pins grounded, the simulation works.

Am I looking at this the right way? Are my configuration bits wrong and 
the internal oscillator (32 MHz) is not being used? If so, please help 


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.