ShortBus
- 11th October 2009, 03:08
I have a switch hooked to PORTA.0 and a LED on PORTA.1 on a PIC16F688. All I am trying to do is read the value of the switch and then set the LED high or low, accordingly. Here is my code:
' PIC16F688
INCLUDE "MODEDEFS.BAS" ' Include Shiftin/out modes
DEFINE OSC 8 ' 8mHz clock
OSCCON = %01110001 ' 8mHz clock
' ======= Set up serial communications
DEFINE HSER_RCSTA 90h 'SPEN=0, CREN=0
DEFINE HSER_TXSTA 24h 'BRGH=0, SYNC=0, TXEN=1
DEFINE HSER_BAUD 19200
DEFINE HSER_CLROERR 1
' =====================================
' ======= Disable unused features & setup IO pins
ANSEL = %00000000 ' everything is digital
ADCON0 = 0 ' disable ADC
CMCON0 = 7 ' no comparators
TRISA = %00000001 ' all but RA0 is output
TRISC = %00100000 ' all outputs on port C except MCLR
' =====================================
' Variables
ALARM VAR PORTC.0
SWITCH VAR PORTA.0
LED VAR PORTA.1
' Intialize
pause 100
hserout ["============", 13, 10]
main:
gosub print_status
pause 1000
goto main
print_status:
hserout ["Val: ", DEC SWITCH, 13, 10]
If switch = 1 then
led = 0
else
LED = 1
endif
return
END
What it's doing instead is toggling the LED on and off:
.============
.Val: 1
.Val: 0
.Val: 1
.Val: 0
.Val: 1
.Val: 0
.Val: 1
.Val: 0
Any idea what's going on?
' PIC16F688
INCLUDE "MODEDEFS.BAS" ' Include Shiftin/out modes
DEFINE OSC 8 ' 8mHz clock
OSCCON = %01110001 ' 8mHz clock
' ======= Set up serial communications
DEFINE HSER_RCSTA 90h 'SPEN=0, CREN=0
DEFINE HSER_TXSTA 24h 'BRGH=0, SYNC=0, TXEN=1
DEFINE HSER_BAUD 19200
DEFINE HSER_CLROERR 1
' =====================================
' ======= Disable unused features & setup IO pins
ANSEL = %00000000 ' everything is digital
ADCON0 = 0 ' disable ADC
CMCON0 = 7 ' no comparators
TRISA = %00000001 ' all but RA0 is output
TRISC = %00100000 ' all outputs on port C except MCLR
' =====================================
' Variables
ALARM VAR PORTC.0
SWITCH VAR PORTA.0
LED VAR PORTA.1
' Intialize
pause 100
hserout ["============", 13, 10]
main:
gosub print_status
pause 1000
goto main
print_status:
hserout ["Val: ", DEC SWITCH, 13, 10]
If switch = 1 then
led = 0
else
LED = 1
endif
return
END
What it's doing instead is toggling the LED on and off:
.============
.Val: 1
.Val: 0
.Val: 1
.Val: 0
.Val: 1
.Val: 0
.Val: 1
.Val: 0
Any idea what's going on?