LED Flashing programming in Embedded C language


Sample code for LED Flashing using delay subroutine.
Following code can be using for 8051 and 8052 ICs like: 89c51, 89c52, 89s51, 89s52, 89c2051.

;==========================================================
 

#include <reg52.h> // special function register declarations #include <stdio.h> // prototype declarations for I/O functions #define LEDPORT P2 void Delay(void); //Function prototype declaration void main (void) { while(1) //End less while so that program never ends { LEDPORT = 0x55; //01010101 binary Delay(); LEDPORT = 0xaa; //10101010 binary Delay(); } } void Delay(void) { int i, j; for(i=0;i<10;i++) { for(j=0;j<10000;j++) { } } }

;==========================================================

Assembly code for LED Flashing

;==========================================================
 

org 0000h jmp start start: mov p1,#FFh call delay mov p1,#00h call delay jmp start delay: mov r0,#10 del2: mov r1,#250 del1: mov r2,#250 djnz r2,$ djnz r1,del1 djnz r0,del2 ret end

;========================================================== LED interfacing program