6.2. Structure of a C
The following program shows the basic structure of a program in C with the Keil C51 software.
/************************************************* *********
Example structure of a program in C with the Keil C51
and microcontrollers 8051.
Program to flash all the bits of Port 0
with time.
Author: Rafael Aranda
Date: 20-10-2009
Version: 1.0
************************************************** ********/
# Include <reg52.h> / / Include the generic domains of 8052
DelayMs void (unsigned int ms) / / function prototype declaration
/ / Global variable declaration
/ / Main Program
//------------------------------------------------ ----------
void main (void) {
/ / Force initial preparation
P0 = 0, / / Set all bits to 0 P0
/ / Body of the program in an infinite loop
while (1) {
P0 = 0x0FF / / Set all bits to 1 P0
DelayMs (200) / / Delay 200 mS
P0 = 0x00, / / Set all bits to 0 P0
DelayMs (200) / / Delay 200 mS
}
}
/ / Delay function
//------------------------------------------------ ----------
DelayMs void (unsigned int ms) {
/ / Delay in milliseconds for a 11.0592 MHz crystal
unsigned int i;
while (ms) {
i = 115;
while (i> 0) i -;
ms -;
}
}