PDA

View Full Version : Hserin problems



nicjo
- 27th November 2006, 11:16
Hi all,

I guess there's a problem with the code I've written but I cannot see where. I'm trying to rx a character, test it then if OK then drive a port. I've tried all soughts of variations but to no avail.

Help appreciated.

John

Here's the code:

' Initialize USART
TRISA = %11111101 ' port A1 set to out
TRISB = %11110010 ' Set TX (PortB.1) to out
SPBRG = 25 ' Set baud rate to 2400
RCSTA = %10010000 ' Enable serial port and continuous receive
TXSTA = %00100000 ' Enable transmit and asynchronous mode

loop: Gosub charin ' Get a character from serial input, if any
If B1 = 0 Then loop ' No character yet
IF B1 = "A" THEN
HIGH PORTA.1
endif
'IF B1 = "C" THEN LOW PORTA.1
Gosub charout 'this works fine
Goto loop ' Do it forever


' Subroutine to get a character from USART receiver
charin: B1 = 0 ' Preset to no character received
hserin [B1]

Return