Hey, im trying to (at first) get some simple RS-232 communications between a computer the pic using the following code:
DEFINE OSC 20
' Setup Hardware for UART
DEFINE HSER_BAUD 9600
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_CLROERR 1
RCIF var PIR1.5
address var byte
sentinal var byte
buffer var byte[30]
init:
Pause 10 'Safe Start Up Delay
ADCON1 = 15 ' All pins are digital
CMCON = 7 ' Turn off comparators
Poke $81,$FF ' Turn off PORT B pull ups
TRISA = %00000000
TRISB = %00000000
TRISC = %10000000
address = %00000100
sentinal = %11111111
HSEROUT ["Activated"]
High PORTB.7
ON Interrupt GOTO inthandle
INTCON = %11000000
PIE1.5 = 1
mainloop:
@ Nop
Goto mainloop
DISABLE
inthandle:
If RCIF Then
HSERIN 100, intreturn, [wait(address),str buffer\30\sentinal]
HSEROUT [str buffer\30]
Low PORTB.7
EndIf
If RCIF Then inthandle
intreturn:
Resume mainloop
ENABLE
So what happens? Upon startup the pic reports 'Activated' and the LED on PORTB.7 lights up... When data is sent to the PIC the LED flickers off and on and sends 'Activated' to the computer, usually once but occasionally several times.
When the 'Low PORTB.7' command is moved before the HSERIN command, incoming data shuts off the LED, but the PIC still restarts. The LED does not reignite after restart.
Why does this happen?
Bookmarks