// In Embedded C:
#include <reg51.h>
void delay(unsigned int time)
{
 unsigned int i,j;
 for(i=0;i<time;i++)
  for(j=0;j<0xFF;j++);
}
int main()
{
 P1 = 0x00;
 while(1)
 {
  P1 = ~P1;
  delay(100);
 }
}
// ----------------------------------------------------------------------------
// In Assembly
 org 00h
 ljmp start  ;jump to start on reset
delay:     ;delay routine approx. 1.5 seconds
    mov r3,#0x02
 mov r4,#0x0
 mov r5,#0x0
loop:
 djnz r5, loop
 djnz r4, loop
 djnz r3, loop
 RET
start:
 mov P2, #00h
 acall delay
 mov P2, #0FFh
 acall delay
 sjmp start
 END
Comments
Post a Comment