Pages

Monday, September 25, 2017

PIC24FJ64GB002 LED Blink example with CCS C compiler

This small post shows how to simply blink an LED using PIC24FJ64GB002 16-bit microcontroller and CCS C compiler.
Hardware Required:
  • PIC24FJ64GB002 microcontroller
  • AMS1117 3V3 voltage regulator
  • 2 x 10uF polarized capacitor
  • 4 x 0.1uF ceramic capacitor
  • 10K ohm resistor
  • 100 ohm resistor
  • 330 ohm resistor
  • LED
  • 5V source
  • Breadboard
  • Jumper wires
PIC24FJ64GB002 LED Blink example circuit:
PIC24FJ64GB002 LED blink example circuit
The PIC24FJ64GB002 microcontroller works with 3.3V only and supply it we need a 3.3V source or a 5V source and AMS1117 3V3 voltage regulator.
The LED is connected to pin RB0 through 330 ohm resistor.
In this example the PIC24FJ64GB002 microcontroller runs with its internal oscillator.
PIC24FJ64GB002 LED Blink example C code:
The C code below was tested with CCS C compiler version 5.051.
In this example the LED blinks with a frequency of 1Hz (500ms ON and 500ms OFF ==> period = 1s).
// PIC24FJ64GB002 LED blink example CCS C code
// Internal oscillator used @ 8 MHz
// http://ccspicc.blogspot.com/
// electronnote@gmail.com

#include <24FJ64GB002.h>
#fuses FRC NOWDT NOJTAG OSCIO SOSC_IO
#use delay(clock = 8M)
#define LED PIN_B0                          // Led is connected to pin RB0

void main(){
  while(TRUE){
    output_toggle(LED);                     // Toggle led pin status
    delay_ms(500);                          // Wait 500 ms
  }
}