PDA

View Full Version : 16f872. config ports and serin question.



kitcat
- 19th July 2005, 16:35
Hi there.
I want to set up a 16f872 so that all ports are digital. I have had trouble with analogue inputs on a 14 pin package and disabled it with this:
ANSEL = 0
What configuration do I need to make all ports digital i/o/ports.

Secondly. I am sending 2 bytes from a pc and I want to output these two bytes on portb and portc.

Is it ok to simply do this:

serin portb.2,6, mylowbyte
serin portb.2,6, myhihgbyte
portb = mylowbyte
portc = myhighbyte

AM I right in thinking that the pic will sit there doing nothing until it receives a character on the input pin? I am sending two bytes from my pc software every time someone pushes a foot pedal. Is there anything that I should know here/

rhino
- 19th July 2005, 19:31
According to the datasheet......
ADCON1 = 7 ' Set all pins to digital , then use TRIS to set input or output

As for serial output. Look at the manual for serout commands, this should get you what you need.

BobK
- 20th July 2005, 03:03
Hello Kitcat,

On the 16F872 only Port A pins are analog or digital. The ADCON1=7 command sets PortA to all digital. If you are looking for serial operation, any pin on the chip can be used as a serial I/O pin. If you intend to use a hardware serial setup with a RS232 level shifter then you want to use RC.6 for Tx and RC.7 for Rx. I don't mean to sound like a broken record but you should go to microchip.com and download the datasheet on the 16F872 to get all the info you will need to work with this uP.

BobK