PDA

View Full Version : PIC to PIC interupt serial character problems



Wink
- 4th January 2009, 21:47
I started this project a couple of years ago and I was stuck when I put it to the side. I recently brought it back to life and I am still stuck!

Here is the deal: 16F628 w/20mHz OSC sends a "1 2 3 4" with a second between each character cycling over and over while bllinking an LED. The 628 sends the data to a 16F876 w/20mHz OSC on PortC.7 through an interrupt while going through an endless loop.

The problem: The 628 sends the varible "I" which equals (ASCII 1, ASCII 2, ASCII 3, or ASCII 4), but the 876 spits out 103 for the ASCII 1, a 51 for the ASCII 2, a 102 for the ASCII 3, and 25 for a ASCII 4. My Question is why?

Code for the 16F628


@ DEVICE HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF

define OSC 20

CMCON = %00000111 ' Page 56, Comparators Off

CHAROUT VAR PORTB.3
LED VAR PORTB.7
BAUD CON 6
I VAR BYTE


PAUSE 2000

start:
for I = 1 to 4
HIGH LED
PAUSE 500
LOW LED
PAUSE 500
SEROUT2 CHAROUT,16468,[#I] ' N9600
NEXT
GOTO START


and the code for the 16F876


@ DEVICE HS_OSC,LVP_OFF,WDT_OFF,PROTECT_OFF

define OSC 20

INTCON = %01000000 ' Page 22, PEIE=1
PIE1 = %00100000 ' Page 23, RCIE=1
TXSTA = %00100100 ' Page 97, TXEN=1, BRGH=1
RCSTA = %10010000 ' Page 98 , SPEN=1, CREN=1
SPBRG=129 ' Page 100, 9600 BAUD (BRGH = 1)

TRISC = %10000000 ' PortC.7 Input

RCIF VAR PIR1.5 ' Page 24, USART Receive Interrupt Flag bit


CHAR VAR BYTE
X VAR BYTE
FLAG VAR BYTE

BAUD CON 6 ' 9600 Driven Inverted
LCD VAR PORTC.4


on interrupt goto ROUTINE

PAUSE 1000 ' Wait for LCD
SEROUT LCD,BAUD,[12,"Working. . ."] '12=Clear screen and verify working
PAUSE 1000
SEROUT LCD,BAUD,[12] '12=Clear screen

loop:

GOTO loop


disable INTERRUPT
ROUTINE:
RCSTA=%00000000 ' Page 98, Serial port disabled, Disable continuous receive
CHAR = RCREG ' Get character

while RCIF ' Empty RCIF
X = RCREG
wend

SEROUT LCD,BAUD,[12,#CHAR] ' Clear Sceen and display ascii value

RCSTA=%10010000 ' Page 98 , SPEN=1, CREN=1
resume
enable INTERRUPT

Bruce
- 4th January 2009, 22:58
The sending PIC should be using true mode instead of inverted to communicate with the
USART on the receiving end.

Wink
- 4th January 2009, 23:35
Thanks Bruce!! That did the trick.