In basic C, all programs have atleast one function which is entry point for your application that function is named as "main" function. Similarly in keil, we will have a main function, in which all your application specific work will be defined. Lets move further deep into the working of applications and programs.
When you run your C programs in your PC or computer, you run them as a child program or process to your Operating System so when you exit your programs (exits main function of program) you come back to operating system. Whereas in case of embedded C, you do not have any operating system running in there. So you have to make sure that your program or main file should never exit. This can be done with the help of simple while(1) or for(;;) loop as they are going to run infinitely. Following layout provides a skeleton of Basic C program.
CODE:
void main(){
//Your one time initialization code will come here while(1){ //while 1 loop //This loop will have all your application code //which will run infinitely } } and, for add lets do with practice
we try to make Blink LED on PORT1, Pin 1
CODE:
#include
void main(){ //main function starts unsigned int i; //Initializing Port1 pin1 P1_1 = 0; //Make Pin1 o/p while(1){ //Infinite loop main application //comes here for(i=0;i<1000;i++) ; //delay loop P1_1 = ~P1_1; //complement Port1.1 //this will blink LED connected on Port1.1 } } |
HAVE FUN with MICROCONTROLLER... ^_^
0 comments:
Post a Comment