jeudi 4 janvier 2018
my first PIC project
as we know all every embedded system need a software to defign the function of our system . for the PIC we ll use Mikro c for coding and proteus isis for the simulation
the first code we wrote in C is "hello world", today we ll write our mikro c "hello world"
this first code will be about flashing a led . we can use this code also to test our PIC .
we start by a very simple code to make sure that we can write the code correctly and to compile it and loaded it inside the pic.
in this session we ll connect a LED to one of the port pin of pic16F877A and flash it continuously with 1 sec duration .
some software well be needed so i recommand you all to install
- proteus isis 8.0 (link in download page)
- mikroc pro for pic (link in download page)
in this session we ll also know about
digital I/O ports (PORTD) of PIC16F877A
direction control registers, TRISD
special function registers CMCON and ADCON1
software
Open a new project window in mikroC and select Device Name as PIC16F877A. Next assign 4.0 MHz to Device Clock. Go to next and provide the project name and the path of the folder. It is always a good practice to have a separate folder for each project. Create a folder named myfirstpicproj and save the project inside it with a name (say, blink). The mikroC project file has .mccpi extension. The next window is for “Add File to Project “. Leave it blank (there are no files to add to this project) and click next. The next step is to include libraries, select Include All option. Next, click Finish button. You will see a program window with a void main() function already included.
code
// Define LED @ RD1
sbit LED at RD1_bit;
void main() {
ADCON1 = 7;
CMCON = 0x07 ; // Disbale comparators
TRISD.f1= 0; // PORTD All Outputs
do {
LED = 1;
Delay_ms(1000);
LED = 0;
Delay_ms(1000);
} while(1); // Infinite Loop
}
after compiling our code we need to simulate and see the function of our system
first you need to open proteus isis and add all the component (in our case we need crystal, pic16F877A, resistance, LED, and capacitors)
next we route them to get our circuit
double click on PIC to edit it
when this page appear we click on the yellow folder and go to the path where we save our projet and select projectname.hex
enjoy watching your first program :D
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire