how can i delay between the flashing of two LEDs using TMR0 interrupt

Thread Starter

mina123

Joined Jan 1, 2023
1
hi everyone i kept verifying my assembly code and i still didn't get where i made a mistake,if anyone can help or guide me i would be thankful
so essentially the code must make two LEDs blinking using TMR0 interrupt routine to delay between the blinking of the two LEDs

Netwide Assembler:
       LIST   p=16f84

       INCLUDE "p16F84.inc"

       __CONFIG  _CP_OFF & _PWRTE_OFF  & _WDT_OFF


    

comp1         equ 0x0C

comp2         equ 0x0D



       org      0x00

       goto     start

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

       org     0x04

       goto    isr

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

isr

       clrf    TMR0

       bcf     INTCON,GIE

       bcf     INTCON,T0IF

       decfsz  comp1,1

       retfie

       bcf     PORTB,1

       bsf     PORTB,2

       decfsz  comp2,f

       retfie

       bcf     PORTB,2

       retfie

      

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

    

start

       movlw  0x4D

       movwf  comp1

       movlw  0xF

       movwf  comp2

       bsf    STATUS,RP0

       movlw  b'00000000'

       movwf  TRISB

       movlw  b'00000111'

       movwf  OPTION_REG

       movlw  b'10100000'

       movwf  INTCON

       bcf    STATUS,RP0

       clrf   TMR0

       bsf    PORTB,1

       bcf    PORTB,2

      

loop   goto   loop

       END
 
Last edited by a moderator:

trebla

Joined Jun 29, 2019
549
To make LEDs repeatedly blinking at desired intervals you must reload comp1 and comp2 variables after they reached zero. For toggling output pins (for LEDs) you must check port bits state (zero or one) after desired delay and then set it to opposite state:

btfsc PORTB,1
bcf PORTB,1
bsf PORTB, 1

For additional delays use additional variables and literal constants.
 
Top