PDA

View Full Version : PortA input and outputs



chips123
- 7th June 2010, 03:27
I am using a 16F676 with all of PORTC and PORTA.0 driving a 7 segment display. All is fine if I simply display a digit or count up. I would like to read a dip switch using 4 other bits of PORTA, such as PORTA.1,2,4,5 (.3 is MCLR). I have configured those particular pins as inputs (TRISA) . I am getting strange results. Should I be able to do this? Or are there some possible issues. I have done similar with an LCD, so I would think this should work.

How do I insert code into this message?

Thanks, Scott

mackrackit
- 7th June 2010, 04:07
You will need to add this near the beginning of your code


ANSEL = %00000000
CMCON0 = %00000111

http://www.picbasic.co.uk/forum/showthread.php?t=561

chips123
- 8th June 2010, 02:01
I got it figured out. I needed to get my port bits and ANDING to coorelate correctly. I did have the CMCON and ANSEL set correctly. I am using a rotary binary switch with the common pulled to 5V and the port inputs pulled low w/ 1K resistors. OK, here is the code if anyone wants to peek. I am sure there are better ways, I just needed to know how to read the port. Thanks and take it easy, Scott


CMCON = %00000111
ANSEL = %00000000
TRISA = %00111110
TRISC = %00000000

temp var byte
digit var byte
A var byte
C var byte

PORTA = %00000000
PORTC = %00000000
pause 1000

start: temp = PORTA & %00110110
if temp = 34 then digit = 9
if temp = 32 then digit = 8
if temp = 22 then digit = 7
if temp = 20 then digit = 6
if temp = 18 then digit = 5
if temp = 16 then digit = 4
if temp = 6 then digit = 3
if temp = 4 then digit = 2
if temp = 2 then digit = 1
if temp = 0 then digit = 0

lookup digit,[0,0,1,1,1,1,1,0,1,1],a
lookup digit,[63,6,27,15,38,45,61,7,63,39],c
PORTA = a
PORTC = C
PAUSE 50
goto start

End