Wednesday, December 4, 2013

Assembly Code To Blink LEDs


interface one led with 8051


The Delay Generation ASM Routine For Generating Delay

;file: delays.asm
;ALL DELAYS ROUTINES HERE
DELAY_SEG SEGMENT CODE
RSEG DELAY_SEG
;DELAY OF 1MS SUBROUTINE
DELAY1MS:
MOV R7,#250
DJNZ R7,$
MOV R7,#247
DJNZ R7,$
RET
;DELAY OF 100MS SUBROUTINE
DELAY100MS:
MOV R6,#99;1MUS
L1:
ACALL DELAY1MS ;99MS
DJNZ R6,L1;198MUS
MOV R6,#250;1MUS
DJNZ R6,$;500US
MOV R6,#147;1US
DJNZ R6,$;294US
NOP
RET;1US
;DELAY 0F 1SEC SUB ROUTINE
DELAY1S:
MOV R5,#9
L2:
ACALL DELAY100MS
DJNZ R5,L2
MOV R5,#99
L3:
ACALL DELAY1MS
DJNZ R5,L3
MOV R5,#250
DJNZ R5,$
MOV R5,#138
DJNZ R5,$
RET


The Main ASM Routine For Operation

;file:main.asm
;Glow Alternate Leds Connected to A Port 0
$INCLUDE(delays.asm)
cseg at 0
MOV A,#0ffH
MOV A,#055H
MAIN:
MOV P2,A
LCALL DELAY1S
LCALL DELAY1S
XRL A,#0FFH
SJMP MAIN
END
Download Keil Project And Proteous Project For This

Thursday, October 3, 2013

Interface One Led with 8051

Interfacing one Led to 8051 Micro-controller

interface one led with 8051

Description About Interfacing Led to 8051


Led is a simple 1 bit out put device. So we need only one bit(or pin) to operate it.
Led can be configured as active low(i.e Glow when pin is Low ) or It can be configured as
active high(i.e Glow when pin is High).
In above figure it is configured as active low. So For Glowing of led the bit must be 0
and 1 for off the led.

Code for The Above configuration

  #include "./include/reg51.h"  /*contain 8051 specific definition*/
  #include "./include/delays_header.h" /* contain delay generation declaration*/
  /*AS LED IS CONFIGURED AS A NEGATIVE LOGIC DEVICE */
  #define ON 0
  #define OFF 1
  sbit LED1=P0^0;

  void main()
  {
   while(1)/*super loop for embedded application*/
   {
    LED1=ON;
    /*provide some delay so that led in ON state for some time*/
    delay_500_ms();
    LED1=OFF;
    /*provide some delay so that led in OFF state for some time*/
    delay_500_ms();
   }
  }

  

Links For Download Complete keil's Project

The above Link contain single Led as well as 8 leds(full port). Also contain Proteus Simulator Example.