Eltronicschool. - When we discuss about the basic of embedded C program, it will show us that the basic of an extension to the standard C programming language with additional features completed like addressing I/O, multiple addressing and fix-point arithmetic and others.
In here, we will show you the example of the basic C embedded C program with circuit based microcontroller 8051 type AT89S52 that popular in basic microcontroller.
Circuit
Description
Accordingly Electronics Hub site that also published this example of basic embedded C program for microcontroller AT89S52 describe that the following image shows the circuit diagram for the example circuit. It contains an 8051 based Microcontroller (AT89S52) along with its basic components (like RESET Circuit, Oscillator Circuit, etc.) and components for blinking LEDs (LEDs and Resistors).
In order to write the Embedded C Program for the above circuit, we will use the Keil C Compiler. This compiler is a part of the Keil µVision IDE. The program is shown below.
#include<reg51.h> // Preprocessor Directive
void delay (int); // Delay Function Declaration
void main(void) // Main Function
{
P1 = 0x00;
/* Making PORT1 pins LOW. All the LEDs are OFF.
(P1 is PORT1, as defined in reg51.h) */
while(1) // infinite loop
{
P1 = 0xFF; // Making PORT1 Pins HIGH i.e. LEDs are ON.
delay(1000);
/* Calling Delay function with Function parameter as 1000.
This will cause a delay of 1000mS i.e. 1 second */
P1 = 0x00; // Making PORT1 Pins LOW i.e. LEDs are OFF.
delay(1000);
}
}
void delay (int d) // Delay Function Definition
{
unsigned int i=0; // Local Variable. Accessible only in this function.
/* This following step is responsible for causing delay of 1000mS (or as per the value entered while calling the delay function) */
for(;d>0;d–)
{
for(i=250;i>0;i – -);
for(i=248;i>0;i – -);
}
}
In here, we will show you the example of the basic C embedded C program with circuit based microcontroller 8051 type AT89S52 that popular in basic microcontroller.
Circuit
Image Courtesy of Electronicshub.org |
Accordingly Electronics Hub site that also published this example of basic embedded C program for microcontroller AT89S52 describe that the following image shows the circuit diagram for the example circuit. It contains an 8051 based Microcontroller (AT89S52) along with its basic components (like RESET Circuit, Oscillator Circuit, etc.) and components for blinking LEDs (LEDs and Resistors).
In order to write the Embedded C Program for the above circuit, we will use the Keil C Compiler. This compiler is a part of the Keil µVision IDE. The program is shown below.
#include<reg51.h> // Preprocessor Directive
void delay (int); // Delay Function Declaration
void main(void) // Main Function
{
P1 = 0x00;
/* Making PORT1 pins LOW. All the LEDs are OFF.
(P1 is PORT1, as defined in reg51.h) */
while(1) // infinite loop
{
P1 = 0xFF; // Making PORT1 Pins HIGH i.e. LEDs are ON.
delay(1000);
/* Calling Delay function with Function parameter as 1000.
This will cause a delay of 1000mS i.e. 1 second */
P1 = 0x00; // Making PORT1 Pins LOW i.e. LEDs are OFF.
delay(1000);
}
}
void delay (int d) // Delay Function Definition
{
unsigned int i=0; // Local Variable. Accessible only in this function.
/* This following step is responsible for causing delay of 1000mS (or as per the value entered while calling the delay function) */
for(;d>0;d–)
{
for(i=250;i>0;i – -);
for(i=248;i>0;i – -);
}
}
0 comments:
Post a Comment
Thank's for your reading in this article, please don't forget to comment.