-
Serin Problem 16f819
I have a 16f819 hooked up to a rf ZIGBEE transceiver and had both the serout and serin working a couple of days ago. I have another transceiver hooked up to a laptop and using hyperterminal to communicate with the pic. All of the sudden serin stopped working. I've tried on different pics to no avail. Here is the code that is running on the pic. Is there something I'm overlooking. It's especially frustrating because it worked a few days ago. However, some slight code modifications have been made, but nothing I thought that would affect the serin command. Serout works just fine and I'm getting all the data on hyper terminal
INCLUDE "MODEDEFS.BAS"
'INCLUDE "BS2DEFS.BAS"
@ DEVICE HS_OSC,MCLR_OFF,BOD_OFF
define CHAR_PACING 1000
DEFINE OSC 4
DEFINE SHIFT_PAUSEUS 100
OSCCON=$60
ADCON1=6
SERIN_DATA VAR BYTE
TRISB.0=1
HIGH PORTA.4
begin:
SERIN PORTB.0,T9600,4000,cont,SERIN_DATA
SEROUT PORTB.4,T9600, ["Got the Value: ", SERIN_DATA,13]
IF SERIN_DATA[0]="S" THEN
HIGH PORTA.3
ENDIF
IF SERIN_DATA[0]="F" THEN
LOW PORTA.3
ENDIF
CONT
SEROUT PORTB.4,T9600, ["Still wainting ",13]
goto begin
-
You defined a HS osc... it's suppose to be for a XTAL>4MHZ... but it souldn't be the main problem
OSCCON do nothing here as you're using an external one
You NEVER EVER tell to disable the LVP mode
9600 baud @ 4mhz will NEVER work unless you're using the PIC USART or maybe DEBUG in worst case. There's a BIG warning in the fabulous manual about that.
Code:
DEFINE SHIFT_PAUSEUS 100
is useless
-
This code was taken from larger code. I just wanted to isolate the serin and serout commands. that is why some of the configuration lines are still in the code. What is LVP mode? You say that you cannot run 9600 baud w/ a 4MHz crystal. Would this also apply to serout, because I have had no problems with that at all.
-
Don't use SERIN/SEROUT/SERIN2/SEROUT2 @ 9600 bauds @ 4MHZ. DEBUG may work better. BUT HSERIN/HSEROUT will works a treat... on the right pins.
Use the PicMultiCalc to generate the right HSERIN/HSEROUT DEFINEs
http://www.mister-e.org/pages/utilitiespag.html
LVP mode HAVE TO BE DISABLED.