After setting up starter 8051 board, we will start with simple LED blinking experiment. On this board 4 LED's are connected to higher four bits of PORT 3. We will write the code in Keil Compiler, to setting up Keil compiler for 8051 refer the 8051 Keil Setup tutorial. After generating the hex file refer the tutorial to uploading hex file using nuvoTon.

Hookup

8051 hookup.JPG

Code

#include <reg51.h>
#define LED P3 // LED's are connected to higher bits of P3
void DELAY_ms(unsigned int ms_Count)
{
unsigned int i,j;
for(i=0;i<ms_Count;i++)
{
for(j=0;j<100;j++);
}
}
int main()
{
P3 = (0xf0<<LED); // Configure PORT3.4 to PORT.7 as output
while(1)
{
P3 = (0xf0<<LED); // Turn ON Led's connected to P3
DELAY_ms(1000); // Wait for some time
P3 = (0x00<<LED); // Turn OFF Led connected to P3
DELAY_ms(1000); // Wait for some time
}
return 0;
}

Demo

0Output 2un4ub.gif

Downloads

Download the complete project folder from the below link: https://github.com/ExploreEmbedded/8051_ExploreStarter8051/archive/master.zip


Have a opinion, suggestion , question or feedback about the article let it out here!