PDA

View Full Version : 18f14k22 portb.5 always high using hserout



ozarkshermit
- 4th March 2015, 18:26
Oops - - Should be 18f14k22

Hi

I cannot figure out why, when using HSEROUT, on PORTB.7, PORTB.5 is high
no matter what I try.

Making PORTB = 0 on the first line has no effect either

Actually, when bit 5 on TRISB is set to an input, the port is not
always high then - - that makes sense. Problem is, I need it as an output.

I need to use HSEROUT for my Serial LCD, since I am using interrupts,
and the data is corrupted otherwise.

I am using PBP 2.60A
The manual states on page 93 that "On devices with two serial ports,
HSEROUT will only use the first port."

My circuit board is etched, assembled, and everything works, but I need
to use PORTB.5 as another output.

Here is a simple program to show the problem. When the HSEROUT line
is enabled, PORTB.5 is always high.

If the HSEROUT line is commented out, PORTB.5 works just fine.







DEFINE OSC 16
OSCCON = %11110110 ' 16 MHZ INTERNAL OSCILLATOR

TRISB = %00000000

DEFINE HSER_BAUD 9600 ' FOR 4 LINE BY 20 CHARACTER LCD
' USES PORTB.7 - - DEDICATED HARDWARE SERIAL PORT
DEFINE HSER_TXSTA 20H

HERE:

PAUSE 100

HSEROUT [254,128,"TEST TEST"]

GOTO HERE

''''''''''Cant get much simpler than this . . . .

Archangel
- 5th March 2015, 08:02
There are threads in this forum which have addressed this, worth a search, that said HSERIN idles the input pin at high logic level. To switch it to an i/o port you need to turn it off before you try to use it. Look at pp184 of the data sheet as it addresses RCSTA register.

push goes to shove you might use Debug instead of HSER commands, it's pretty lean for bit bang serial port.

HenrikOlsson
- 5th March 2015, 09:29
When you enable the (E)USART (which HSERIN does of course) it takes control of the TX/RX pins, thus you can't use the as normal I/O.

/Henrik.

ozarkshermit
- 5th March 2015, 14:00
Thanks

I found a "work-around" for this - I needed one output to pulse an LED as a "heart-beat", so I changed that to PORTB.5.
In the program I change TRISB.5 from a 0 to 1 and back to a 0 to flash the LED. Therefore freed up the other output. From what I see it has no other effect on the program.

Ken

Dick Ivers
- 5th March 2015, 14:26
Another approach is to enable/disable the hardware port in your program. For the 16f1826 I use RCSTA.7 = 0 to disable the port when I'm done using it.