Programming A PIC: The Program

Your First PIC Program
           Now that the pic has been successfully connected to the host computer, we're going to take a look at the program that we will be programming onto the PIC. It is simple and uses functionality inherint of the Olimex P-40 Dev Board.
           The code below is our first program. It turns Bit 0 of PORTA off and on every 0.3 seconds.

« Begin Code »
/*
Written by: Sascha
Date: 10/13/2007
Purpose & Description: This program turns Bit 0 of PORTA
off and on (0 and 1, 0v and 5v) at 0.3 Second intervals.
For this specific Development Board it will turn the LED
off and on.
*/
#include <p18f452.h>
#include <delays.h>
void main(void){
TRISA = 0x00;
PORTA = 0x00;

    while(1){
        PORTA = 0x01;
        Delay10KTCYx(150);
        PORTA = 0x00;
        Delay10KTCYx(150);
    }
}


« End Code »


           The best thing to do is copy the code above into a notepad document and Save as... main.c
This file will be used later when we want to compile & program the PIC with this code.

Olimex P-40 Development Board
           Below is the schematic of the Development Board used in this tutorial. I altered it a little to draw attention to where the LED is connected. Notice it is connected to Bit 0 of PORTA, aka RA0.

Click To Enlarge:




;