devonsc
Advanced Member level 4

Hi there,
Help needed badly. Mind helping? Please? Thanks in advance. Regarding the following short PIC code:
My intention is to have a toggle switch that will be switched in two positions and the respective LED will light. Say, switch A, LED A and switch B, LED B. When I run the following program, what I observe is the following:
a.) power up the PIC, switch A on, LED A on, LED B off
b.) power up the PIC, switch B on, LED B on, LED A off
c.) power up the PIC, switch A on, LED A on, LED B off but at this moment, if i were to switch the toggle switch into position B, my LED A remains on while LED B remains off instead of LED B on, LED A off
c.) power up the PIC, switch B on, LED B on, LED A off but at this moment, if i were to switch toggle switch into position A, my LED B remains on while LED A remains off when it is suppose to be LED A on, LED B off
Briefly, it seems that it will only work if I were to turn off the PIC and turn ON the PIC again. It seems that I cant refresh the data input from Port C. Mind to comment about this? Thanks in advance...
------------------------------------------------------
LIST P=16F876
#INCLUDE "P16F876.INC"
__CONFIG _CP_OFF & _XT_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF & _BODEN_ON
ERRORLEVEL -306, -302
;MAIN PROGRAM 1 - TEST
;*****************************************************
BSF STATUS,RP0
MOVLW B'11000000' ;SW1,SW2,LED1,LED2,*,PWM,*,*
MOVWF TRISC
BCF STATUS,RP0
AGAIN BTFSS PORTC,7
GOTO NEXT
BCF TRISC,4
BSF TRISC,5
NEXT BTFSS PORTC,6
GOTO AGAIN
BCF TRISC,5
BSF TRISC,4
GOTO AGAIN
;*****************************************************
END
----------------------------------------------------------------------------
Help needed badly. Mind helping? Please? Thanks in advance. Regarding the following short PIC code:
My intention is to have a toggle switch that will be switched in two positions and the respective LED will light. Say, switch A, LED A and switch B, LED B. When I run the following program, what I observe is the following:
a.) power up the PIC, switch A on, LED A on, LED B off
b.) power up the PIC, switch B on, LED B on, LED A off
c.) power up the PIC, switch A on, LED A on, LED B off but at this moment, if i were to switch the toggle switch into position B, my LED A remains on while LED B remains off instead of LED B on, LED A off
c.) power up the PIC, switch B on, LED B on, LED A off but at this moment, if i were to switch toggle switch into position A, my LED B remains on while LED A remains off when it is suppose to be LED A on, LED B off
Briefly, it seems that it will only work if I were to turn off the PIC and turn ON the PIC again. It seems that I cant refresh the data input from Port C. Mind to comment about this? Thanks in advance...
------------------------------------------------------
LIST P=16F876
#INCLUDE "P16F876.INC"
__CONFIG _CP_OFF & _XT_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF & _BODEN_ON
ERRORLEVEL -306, -302
;MAIN PROGRAM 1 - TEST
;*****************************************************
BSF STATUS,RP0
MOVLW B'11000000' ;SW1,SW2,LED1,LED2,*,PWM,*,*
MOVWF TRISC
BCF STATUS,RP0
AGAIN BTFSS PORTC,7
GOTO NEXT
BCF TRISC,4
BSF TRISC,5
NEXT BTFSS PORTC,6
GOTO AGAIN
BCF TRISC,5
BSF TRISC,4
GOTO AGAIN
;*****************************************************
END
----------------------------------------------------------------------------