Problems concurrently using digital in and digital out on PORTA.
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:
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:
Code:
.============
.Val: 1
.Val: 0
.Val: 1
.Val: 0
.Val: 1
.Val: 0
.Val: 1
.Val: 0
Any idea what's going on?
Digital Outputs 16FXXX dŽont work fine in PBP?...
IŽm a similar problem.
The outputs in a 16f690 controlled by HIGH command dŽont work fine.
This simpy code present the follw voltages in the pins of 16F690 pic.
Code:
inicio:
High PORTC.5
High PORTC.4
High PORTC.3
High PORTC.6
High PORTC.7
High PORTB.7
GOTO inicio
VCC Values:
PORTC.5 = 5V
PORTC.4 = 5V
PORTC.3 = 5V
PORTC.6 = 0.6V
PORTC.7 = 1.8V
PORTB.7 = 5V