triplestak
New Member
Hey, I'm new in here and was seeking some advice on a simple program I'm having to write for one of my Electronics classes. It's a basic program written for the PIC16F877A and bit zer0 (SW0) on the switch board (Port B) resets the outputs on Port A and the bit 1 (SW1) starts a count on the LEDs and increments them one value at a time. The code works fine in the MPLAB IDE debugger, but when I send the Hex file to the Control board, the reset button works and the run button only turns on the first bit or the bit zero LED, but it doesn't increment. Here is a copy of the code. Any help would be greatly appreciated...
list p=16f877a ; list directive to define processor
#include <p16f877a.inc> ; processor specific variable definitions
PORTA EQU 005h ;Port A Data Register
PORTB EQU 006h ;Port B Data Register
TIMER EQU 020h ;Spare register for delay
STATUS EQU 003h
TRISA EQU 085h
ADCON1 EQU 09Fh
inres EQU b'00000000' ;'Reset' input button SW0
inrun EQU b'00000001' ;'Run' input button SW1
bcf STATUS,RP0
bcf STATUS,RP1 ;Selects Bank 0
clrf PORTA ; clears port A
bsf STATUS,RP0 ;Selects Bank 1
movlw 006h
movwf ADCON1
movlw b'00000'
movwf TRISA ;Prepares port A for Output
bcf STATUS,RP0
bcf STATUS,RP1 ;Selects Bank 0
clrf PORTA
movlw b'00000' ;Port A Data Direction Code
TRIS PORTA ;Load the DDR code into F86
goto reset
delay movwf TIMER ;is loaded into spare register
down decfsz TIMER ;decrement timer register
goto down ;and repeat until zero then
RETURN ;return to main program
reset clrf PORTA ;Clear Port A Data
start btfsc PORTB,inres ;Test SW0 input button
goto reset ;and reset Port A
btfss PORTB,inrun ;Test SW1 input button
goto start ;and run count if pressed
INCF PORTA ;Increment count at Port A
movlw 002 ;Delay count literal
CALL delay ;Execute delay subroutine
goto start ;Repeat main loop
END ;Terminate source code
list p=16f877a ; list directive to define processor
#include <p16f877a.inc> ; processor specific variable definitions
PORTA EQU 005h ;Port A Data Register
PORTB EQU 006h ;Port B Data Register
TIMER EQU 020h ;Spare register for delay
STATUS EQU 003h
TRISA EQU 085h
ADCON1 EQU 09Fh
inres EQU b'00000000' ;'Reset' input button SW0
inrun EQU b'00000001' ;'Run' input button SW1
bcf STATUS,RP0
bcf STATUS,RP1 ;Selects Bank 0
clrf PORTA ; clears port A
bsf STATUS,RP0 ;Selects Bank 1
movlw 006h
movwf ADCON1
movlw b'00000'
movwf TRISA ;Prepares port A for Output
bcf STATUS,RP0
bcf STATUS,RP1 ;Selects Bank 0
clrf PORTA
movlw b'00000' ;Port A Data Direction Code
TRIS PORTA ;Load the DDR code into F86
goto reset
delay movwf TIMER ;is loaded into spare register
down decfsz TIMER ;decrement timer register
goto down ;and repeat until zero then
RETURN ;return to main program
reset clrf PORTA ;Clear Port A Data
start btfsc PORTB,inres ;Test SW0 input button
goto reset ;and reset Port A
btfss PORTB,inrun ;Test SW1 input button
goto start ;and run count if pressed
INCF PORTA ;Increment count at Port A
movlw 002 ;Delay count literal
CALL delay ;Execute delay subroutine
goto start ;Repeat main loop
END ;Terminate source code