89s52 C Program

Only available on StudyMode
  • Download(s) : 430
  • Published : April 20, 2013
Open Document
Text Preview
Simple C program for 89S52
Here is a very simple but complete example program to blink a LED. Actually it is the source code of the example project that we are going to construct in the next part of the tutorial, but for now it is important to concentrate on the programming to summarize the notions discussed above. -------------------------------------------------

#include <REGX52.h>
-------------------------------------------------
#include <math.h>
-------------------------------------------------

-------------------------------------------------
delay(unsigned int y){
-------------------------------------------------
unsigned int i;
-------------------------------------------------
for(i=0;i<y;i++){;}
-------------------------------------------------
}
-------------------------------------------------

-------------------------------------------------
main(){
-------------------------------------------------
while(1){
-------------------------------------------------
delay(30000);
-------------------------------------------------
P1_0 = 0;
-------------------------------------------------
delay(30000);
-------------------------------------------------
P1_0 = 1;
-------------------------------------------------
}
-------------------------------------------------
}
After including basic headers for the SFR definitions of the 8952 microcontroller (REGX52.h) and for mathematical functions (math.h), a function named ‘delay’ is created, which is simple a function to create a delay controlled via the parameter ‘y’. Then comes the main function, with an infinite loop (the condition for that loop to remain will always be...
tracking img