- #1
SJC1981
- 4
- 1
Hi guys, apparently I've got both a linear and a subroutine programming error in the code below from lines 20-35? Could someone point me in the right direction. I think one might be the 'CALL wait' instruction, which should be 'CALL delay'? Not really sure as new to this, any help would be much appreciated, cheers!
Mentor note:
Here's the original version:
1. ; Slow output binary count is stopped, started
2. ; and reset with push buttons. This version uses a
3. ; subroutine for the delay...
4. ;
5. ; *******************************************************************
6. processor 16f84
7. include <p16f84.inc>
8. __config _RC_OSC & _WDT_OFF & _PWRTE_ON
9. ; Register Label Equates.........
10. porta EQU 05 ; Port A Data Register
11. portb EQU 06 ; Port B Data Register
12. timer EQU 0C ; Spare register for delay
13. ; Input Bit Label Equates..........
14. inres EQU 0 ; ‘Reset’ input button = RA0
15. inrun EQU 1 ; ‘Run’ input button = RA1
16. ; Initialise Port B (Port A defaults to inputs).....
17. MOVLW b’00000000’ ; Port B Data Direction Code
18. TRIS portb ; Load the DDR code into F86
19. GOTO reset
20. ; ‘delay’ subroutine..........
21. delay MOVWF timer ; Copy W to timer register
22. down DECFSZ timer ; Decrement timer register
23. GOTO reset ; and repeat until zero
24. RETURN ; Jump back to main program103
25. ; Start main loop.........
26. reset CLRF portb ; Clear Port B Data
27. start BTFSS porta,inres ; Test RA0 input button is set
28. GOTO reset ; reset Port B if pressed
29. BTFSC porta,inrun ; Test RA1 input button is clear
30. GOTO start ; and run count if pressed
31. INCF portb ; Increment count at Port B
32. MOVLW 0FF ; Delay count literal
33. CALL wait ; Jump to delay subroutine
34. GOTO start ; Repeat main loop always
35. END ; Terminate source code
Code:
; Slow output binary count is stopped, started
; and reset with push buttons. This version uses a
; subroutine for the delay...
;
; *******************************************************************
processor 16f84
include <p16f84.inc>
__config _RC_OSC & _WDT_OFF & _PWRTE_ON
; Register Label Equates.........
porta EQU 05 ; Port A Data Register
portb EQU 06 ; Port B Data Register
timer EQU 0C ; Spare register for delay
; Input Bit Label Equates..........
inres EQU 0 ; ‘Reset’ input button = RA0
inrun EQU 1 ; ‘Run’ input button = RA1
; Initialise Port B (Port A defaults to inputs)......
MOVLW b’00000000’ ; Port B Data Direction Code
TRIS portb ; Load the DDR code into F86
GOTO reset
; ‘delay’ subroutine..........
delay MOVWF timer ; Copy W to timer register
down DECFSZ timer ; Decrement timer register
GOTO reset ; and repeat until zero
RETURN ; Jump back to main program103
; Start main loop.........
reset CLRF portb ; Clear Port B Data
start BTFSS porta,inres ; Test RA0 input button is set
GOTO reset ; reset Port B if pressed
BTFSC porta,inrun ; Test RA1 input button is clear
GOTO start ; and run count if pressed
INCF portb ; Increment count at Port B
MOVLW 0FF ; Delay count literal
CALL wait ; Jump to delay subroutine
GOTO start ; Repeat main loop always
END ; Terminate source code
Mentor note:
Here's the original version:
1. ; Slow output binary count is stopped, started
2. ; and reset with push buttons. This version uses a
3. ; subroutine for the delay...
4. ;
5. ; *******************************************************************
6. processor 16f84
7. include <p16f84.inc>
8. __config _RC_OSC & _WDT_OFF & _PWRTE_ON
9. ; Register Label Equates.........
10. porta EQU 05 ; Port A Data Register
11. portb EQU 06 ; Port B Data Register
12. timer EQU 0C ; Spare register for delay
13. ; Input Bit Label Equates..........
14. inres EQU 0 ; ‘Reset’ input button = RA0
15. inrun EQU 1 ; ‘Run’ input button = RA1
16. ; Initialise Port B (Port A defaults to inputs).....
17. MOVLW b’00000000’ ; Port B Data Direction Code
18. TRIS portb ; Load the DDR code into F86
19. GOTO reset
20. ; ‘delay’ subroutine..........
21. delay MOVWF timer ; Copy W to timer register
22. down DECFSZ timer ; Decrement timer register
23. GOTO reset ; and repeat until zero
24. RETURN ; Jump back to main program103
25. ; Start main loop.........
26. reset CLRF portb ; Clear Port B Data
27. start BTFSS porta,inres ; Test RA0 input button is set
28. GOTO reset ; reset Port B if pressed
29. BTFSC porta,inrun ; Test RA1 input button is clear
30. GOTO start ; and run count if pressed
31. INCF portb ; Increment count at Port B
32. MOVLW 0FF ; Delay count literal
33. CALL wait ; Jump to delay subroutine
34. GOTO start ; Repeat main loop always
35. END ; Terminate source code
Last edited by a moderator: