bbgil
Full Member level 2
Hi. maybe someone can explain why my 16F977a is acting weird. this is a simple asm code. just blink 3 led. but the problem is when there are 3 LED, its not blinking the correct delay (500ms). but when only two, it's correct. what give's? do the amount of led and the power supply have effects on the timing cycle? here's the code.
; Configurations
LIST P=16F877a, W=-302
#include <p16f877a.inc>
__CONFIG 0x3D71 ; HS MODE,WDT OFF, BOREN
BANK_0 EQU 0x00
BANK_1 EQU 0x80
BANK_2 EQU 0x100
BANK_3 EQU 0x180
ORG 0x00
; The program starts here
; When the program starts, RAM Bank 0 is "active"
movlw B'11111000' ; prepare data for TRISB
BANKSEL BANK_1 ; "activate" Bank 1
movwf TRISB ; copy W to TRISB
BANKSEL BANK_0 ; "activate" Bank 0
Loop movlw B'00000111' ; prepare data for PORTB
movwf PORTB ; write W to PORTB
;
call Delay_500ms ; call delay subroutine
movlw B'00000000' ; prepare data for PORTB
movwf PORTB ; write W to PORTB
;
call Delay_500ms ; call delay subroutine
goto Loop ; jump back to Loop
; ****** DELAY SUBROUTINES ******
; ****** SUBROUTINE Delay_500ms ******
Delay_500ms
BANKSEL BANK_3
movlw .50
movwf 0x193
LoDe500
call Delay_10ms
BANKSEL BANK_3
decfsz 0x193, F
goto LoDe500
BANKSEL BANK_0
return
; ****** SUBROUTINE Delay_10ms ******
Delay_10ms
BANKSEL BANK_3
movlw 0xff ; outer counter const
movwf 0x191 ; outer counter
LoDel2 movlw 0x40 ; inner counter const
movwf 0x192 ; inner counter
LoDel1 decfsz 0x192,F
goto LoDel1
decfsz 0x191,F
goto LoDel2
BANKSEL BANK_0
return
; ****** END OF SUBROUTINES ******
END
; Configurations
LIST P=16F877a, W=-302
#include <p16f877a.inc>
__CONFIG 0x3D71 ; HS MODE,WDT OFF, BOREN
BANK_0 EQU 0x00
BANK_1 EQU 0x80
BANK_2 EQU 0x100
BANK_3 EQU 0x180
ORG 0x00
; The program starts here
; When the program starts, RAM Bank 0 is "active"
movlw B'11111000' ; prepare data for TRISB
BANKSEL BANK_1 ; "activate" Bank 1
movwf TRISB ; copy W to TRISB
BANKSEL BANK_0 ; "activate" Bank 0
Loop movlw B'00000111' ; prepare data for PORTB
movwf PORTB ; write W to PORTB
;
call Delay_500ms ; call delay subroutine
movlw B'00000000' ; prepare data for PORTB
movwf PORTB ; write W to PORTB
;
call Delay_500ms ; call delay subroutine
goto Loop ; jump back to Loop
; ****** DELAY SUBROUTINES ******
; ****** SUBROUTINE Delay_500ms ******
Delay_500ms
BANKSEL BANK_3
movlw .50
movwf 0x193
LoDe500
call Delay_10ms
BANKSEL BANK_3
decfsz 0x193, F
goto LoDe500
BANKSEL BANK_0
return
; ****** SUBROUTINE Delay_10ms ******
Delay_10ms
BANKSEL BANK_3
movlw 0xff ; outer counter const
movwf 0x191 ; outer counter
LoDel2 movlw 0x40 ; inner counter const
movwf 0x192 ; inner counter
LoDel1 decfsz 0x192,F
goto LoDel1
decfsz 0x191,F
goto LoDel2
BANKSEL BANK_0
return
; ****** END OF SUBROUTINES ******
END