Here are the 8 different types of codes made on LED controlled by 8-bit microcontroller. It is posted to enhance your programming skills on 8051 as basic skills are developed on LED interfacing with 8051 only.

Try to make your own programs and different method to develop new ways to solve the problems which will enhance your skills more.
1. Blink LED
2. Alternative/ Dancing pattern
3. Curtain effect
4. Counter on LEDs
Interfacing:

Try to make your own programs and different method to develop new ways to solve the problems which will enhance your skills more.
1. Blink LED
#include "REG52.h" #define LED P0 //port defination long int i; void main() { while(1) // infinite loop { LED=0xff; // shows 00000001 for(i=0;i<10000;i++); LED=0x00; for(i=0;i<10000;i++); } }
2. Alternative/ Dancing pattern
#include "REG52.h" #define LED P0 long int i; void main() { while(1) { LED=0xAA; for(i=0;i<4500;i++); LED=0x55; for(i=0;i<4500;i++); } }
3. Curtain effect
#include "REG52.h" int i,j; long int k; void d() // delay function { for(k=0;k<3000;k++); } void main() { while(1) { P0=0x81; //different values on LEDs d(); P0=0xC3; //different values on LEDs d(); P0=0xE7; //different values on LEDs d(); P0=0xFF; //different values on LEDs d(); P0=0xE7; //different values on LEDs d(); P0=0xC3; //different values on LEDs d(); P0=0x81; //different values on LEDs d(); P0=0x00; //different values on LEDs d(); } }
4. Counter on LEDs
#include "REG52.h" #define LED P0 long int j; int k,i; void main() { while(1) { for(k=0;k<5;k++) { for(i=0X01;i<=0X80;i=i<<1) { LED=i; for(i=0;i<50000;i++); } } } }
Comments
Post a Comment