creativefla
Newbie level 4
hi today i tried to build a simple program that turns on LED when a button is push, using weak pull-up feature
my program is working under Real PIC simulator but not working on board. my program only works for pin RC2, not RC1 and RC0. for both RC1 and RC0, they always give high value even though i dont press any button. ive skimmed through datasheet so many times yet i couldnt find any answer.
Code:
list F=inhx8m, P=16F688, R=hex, N=0
#include P16F688.INC
__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _BOD_OFF & _IESO_ON & _FCMEN_ON
;definitions ---------------------------
bank0 macro
bcf status, rp1
bcf status, rp0
endm
bank1 macro
bcf status, rp1
bsf status, rp0
endm
bank2 macro
bsf status, rp1
bcf status, rp0
endm
bank3 macro
bsf status, rp1
bsf status, rp0
endm
;#Define ButtonInput PORTA,0;
#Define Switch1 PORTA,0
#Define Switch2 PORTA,1
#Define Switch3 PORTA,2
#Define Output1 PORTC,0
#Define Output2 PORTC,1
#Define Output3 PORTC,2
; RAM preserved ----------------------------------
cblock 0x20
endc
;program memory ------------------------------
org 0x00
goto Init
;Inuterrupt service routine -------------------
org 0x04
;initialisation ----------------------------
Init
bank1
movlw b'01100001'
movwf OSCCON ;set oscillator
clrf ansel
movlw b'00000111'
movwf CMCON0
bank0
;main prog ---------------------------
start
bank1
movlw b'00000111'
movwf TRISA
movlw b'11111000'
movwf TRISC
bank0
bank1
bcf OPTION_REG, NOT_RAPU ;enable pull up resistor for PORTA,
movlw b'00110111'
movwf WPUA
bank0
mainloop
btfss switch3
goto switch_3_is_0
bcf output3
goto check_switch_2
switch_3_is_0
bsf output3
check_switch_2
btfss switch2
goto switch_2_is_0
bcf output2
goto check_switch_1
switch_2_is_0
bsf output2
check_switch_1
btfss switch1
goto switch_1_is_0
bcf output1
goto mainloop
switch_1_is_0
bsf output1
goto mainloop
fins
end
my program is working under Real PIC simulator but not working on board. my program only works for pin RC2, not RC1 and RC0. for both RC1 and RC0, they always give high value even though i dont press any button. ive skimmed through datasheet so many times yet i couldnt find any answer.
Last edited: