I have a simple project going to get a toe hold on Pic to Pic serial comm. Trying to keep it simple and going one way com for now.
by pushing button 1 or 2, PIC #1 sends a Binary number (1 or 2) to = "Hello" or "Goodbye" on the PIC #2.
PIC #1's LCD indicates that the messages have been sent to PIC #2.
I believe I have PIC #1 working but PIC #2 is not.
Further, With PIC# 2 running, the LCD on PIC #1 will display then scramble itself up.
<div style="margin:20px; margin-top:5px">
<div class="smallfont" style="margin-bottom:2px">PIC #1 Code:</div>
<pre class="alt2" style="margin:0px; padding:6px; border:1px inset; width:640px; height:300px; overflow:auto"><div dir="ltr" style="text-align:left;">
'_______________Setup PIC 16F870___________________
ADCON0.0=0 'disable analog comparator
TRISA = %00000011 'Setup Port A
define LCD_DREG PORTB ' Set data pin of LCD to
define LCD_DBIT 0 ' PORTB.0-PORTB.3
define LCD_RSREG PORTB ' Set RS bit of LCD to
define LCD_RSBIT 4 ' PORTB.4
define LCD_EREG PORTB ' Set E bit of LCD to
define LCD_EBIT 5 ' PORTB.5
DEFINE HSER_RCSTA 90h
ADCON1=6 'disable analog comparator
SW1 VAR PORTA.0
SW2 VAR PORTA.1
Chkswitch VAR BYTE
'------------Main-----------------------------------
Readpins:
Chkswitch=PORTA & $03
Select case Chkswitch
case 1
Goto Mess1
case 2
goto Mess2
end select
goto readpins
'------------Subroutines----------------------------
Mess1:
Pause 500
Lcdout $fe, 1, "Hello" ' Clear LCD screen
Pause 500
LCDOUT $fe, $c0, "message sent"
Hserout [%00000001]
return
Mess2:
Pause 500
Lcdout $fe, 1, "Goodbye" ' Clear LCD screen
Pause 500
Lcdout $fe, $c0, "message sent"
Hserout [%00000010]
return
End
</div></pre>
</div></div>
I am using 1 pair of Cat 5 cable (10 feet) with no connectors
<div style="margin:20px; margin-top:5px">
<div class="smallfont" style="margin-bottom:2px">PIC #2 Code:</div>
<pre class="alt2" style="margin:0px; padding:6px; border:1px inset; width:640px; height:300px; overflow:auto"><div dir="ltr" style="text-align:left;">
'_______________PIC Setup__________________________
intcon = %11000000 ' enable global and Peripheral interrupt
ADCON1=6 'disable analog comparator
TRISA = %11111111 'Set Port A to inputs
pie1.5 = 1 ' enable interrupt on usart receive
pir1.5 = 0 ' clearing interrupt flags
define LCD_DREG PORTB ' Set data pin of LCD to
define LCD_DBIT 0 ' PORTB.0-PORTB.3
define LCD_RSREG PORTB ' Set RS bit of LCD to
define LCD_RSBIT 4 ' PORTB.4
define LCD_EREG PORTB ' Set E bit of LCD to
define LCD_EBIT 5 ' PORTB.5
Mess VAR PORTA
'____________________Main_________________________ ___
Start:
PicRecieve:
If PIR1.5 = 1 then Pic_serin
Goto PicRecieve
Pic_serin:
Hserin [Mess]
Goto PicRecieve
IncomingM:
Select case Mess
case %00000001
Goto Mess1
case %00000010
goto Mess2
end select
goto incomingM
'___________________Subroutines___________________ ____
Mess1:
Pause 500
LCDOUT $fe, 1, "Hello"
return
Mess2:
Pause 500
LCDOUT $fe, 1, "Goodbye"
return
end
</div></pre>
</div></div>
Pretty new to PICs and programming. I appreciate greatly what I am learning from here.
Thanks for all the help and any you can give.
ChadMan
Bookmarks