I have been playing around with a pair of Pic 16f870 chips. I have a project that I'm working on with some goals in mind. I thought I'd post this as an example t other newbies like myself and hopefully get some critique/feedback how to make my coding better for the learning experience from you good people here. I just a begginner with Pics really . Have too many other projects going on most of the time.

My project: 2 Pics each with a 2x16 LCD and 2 buttons communicate with each other using Hserin and Hserout. When either chip sends a comm the other chip responds for confirmation. It's a starting point.

My goal is to put my message strings in EEPROM, increase the number of message strings and access them with a nested menu system that uses 1 or 2 buttons to send messages back and forth.

Pic1
<div id="post_message_11692"><div style="margin:20px; margin-top:5px">
<div class="smallfont" style="margin-bottom:2px">Code:</div>
<pre class="alt2" style="margin:0px; padding:6px; border:1px inset; width:640px; height:250px; overflow:auto">
'_______________Setup PIC1__________________________

DEFINE HSER_CLROERR 1

Init:
TRISB = %00000111 'Setup Port B
PORTB = %00000000 'Clear port B pins
Mess Var Byte 'serial incoming message variable
Chkswitch VAR BYTE 'Button input variable

Lcd:
PAUSE 1000 'Pause for LCD intialization
Lcdout $fe, 1, "B1 sends hello"
Lcdout $fe, $c0, "B2 sends goodbye"
pause 300
Start:
pir1.5 = 0 'clear interrupt flags
If PIR1.5 = 1 then Comroute 'interupt for serial comm
Chkswitch=PORTB & %00000011 'setup pins b0 and b1 for button inputs
Select case Chkswitch
case 1
Goto Mess1
case 2
goto Mess2
end select
Goto Start

Comroute:
Hserin [Mess] 'incoming message routine
Select case Mess
case %00000001
Goto Mess5
case %00000010
goto Mess6
case %00000100
goto mess3
case %00000101
goto mess4
end select
goto comroute
Return

'------------Subroutines----------------------------
Mess1:
Lcdout $fe, 1, "Hello message"
LCDOUT $fe, $c0, "sent to Pic2"
Pause 1000
HSEROUT [%00000001]
goto start
return
Mess2:
Lcdout $fe, 1, "Goodbye message"
Lcdout $fe, $c0, "sent to Pic2"
PAUSE 1000
Hserout [%00000010]
goto start
return
Mess3:
LCDOUT $fe, 1, "Pic2 recieved"
LCDOUT $fe, $c0, "hello message"
Pause 2000
goto lcd
return
Mess4:
LCDOUT $fe, 1, "Pic2 recieved"
LCDOUT $fe, $c0, "goodbye message"
Pause 2000
goto lcd
return
Mess5:
LCDOUT $fe, 1, "Pic2 said"
LCDOUT $fe, $c0, "H E L L O !"
pause 1000
LCDout $fe, 1
HSEROUT [%00000100]
return
Mess6:
LCDOUT $fe, 1, "Pic2 said"
LCDOUT $fe, $c0, "G O O D B Y E !"
pause 1000
LCDout $fe, 1
HSEROUT [%00000101]
return
End
</div></pre>
</div>


Pic2
<div id="post_message_11692"><div style="margin:20px; margin-top:5px">
<div class="smallfont" style="margin-bottom:2px">Code:</div>
<pre class="alt2" style="margin:0px; padding:6px; border:1px inset; width:640px; height:250px; overflow:auto">
'_______________Setup PIC2__________________________

DEFINE HSER_CLROERR 1

Init:
TRISB = %00000111 'Setup Port B
PORTB = %00000000 'Clear port B pins
Mess Var Byte
Chkswitch VAR BYTE

LCD:
PAUSE 1000 'Pause for the LCD to wake
LCDOUT $fe, 1 'Clear the LCD display
Lcdout $fe, 1, "B1 sends hello" ' Clear LCD screen
Lcdout $fe, $c0, "B2 sends goodbye"
Pause 300

Start:
pir1.5 = 0 'clearing interrupt flags
If PIR1.5 = 1 then Comroute 'Interupt for serial comm
Chkswitch=PORTB & %00000011 'sets port B0-B1 as inputs
Select case Chkswitch 'button B1 & B2 input routine
case 1
Goto Mess1
case 2
goto Mess2
end select
Goto Start

Comroute:
Hserin [Mess] 'Incoming to Variable "Mess"
Select case Mess
case %00000001
Goto Mess5
case %00000010
goto Mess6
case %00000100
goto mess3
case %00000101
goto mess4
end select
goto comroute
Return

'______________Message routines___________________
Mess1:
Lcdout $fe, 1, "Hello message"
LCDOUT $fe, $c0, "sent to Pic1"
Pause 1000
HSEROUT [%00000001]
goto start
return
Mess2:
Lcdout $fe, 1, "Goodbye message"
Lcdout $fe, $c0, "sent to Pic1"
PAUSE 1000
Hserout [%00000010]
goto start
return
Mess3:
LCDOUT $fe, 1, "Pic1 recieved"
LCDOUT $fe, $c0, "hello message"
Pause 2000
goto lcd
return
Mess4:
LCDOUT $fe, 1, "Pic1 recieved"
LCDOUT $fe, $c0, "goodbye message"
Pause 2000
goto lcd
return
Mess5:
LCDOUT $fe, 1, "Pic1 said"
LCDOUT $fe, $c0, "H E L L O !"
pause 1000
LCDout $fe, 1
HSEROUT [%00000100]
return
Mess6:
LCDOUT $fe, 1, "Pic1 said"
LCDOUT $fe, $c0, "G O O D B Y E !"
pause 1000
LCDout $fe, 1
HSEROUT [%00000101]
return
End
</div></pre>
</div>

I have it bread boarded and working. Any help or ideas to improve my code would be appreciated greatly. I was also wondering If I could use the serial HX/TX with IR instead of wires possibly? I'm using one pair of a cat5 cable now.