I need to have one master pic that communicates to the pc send a command to a slave pic that will read it a/d and send it's reading to the master pic, and the master will read its a/d and send the both together to the pc. I can use a bigger memory pic if i need to, So i need two serials out and one in, and to have the master store the incomming data and send it with it's data to the pc when it gets it. I will have the slave send it's data as ascii to the master.
here is what I got so far:
'Master PIC
Sub Ser_Init
#define baud 833 ;the us delay for 1200 baud rate
#define SerTxHigh Set GPIO.0 on
#define SerTxLow Set GPIO.0 Off
SerTxHigh ;Initial RS232 idle state
#define SerRxHigh GPIO.1 on
#define SerRxLow GPIO.1 off
#define SerTxHigh GPIO.4 on
#define SerTxLow GPIO.4 off
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
sub Bin2ascii(LCDValue )#NR
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
If LCDValue >= 100 Then
LCDValueTemp = LCDValue / 100
SERCEN = LCDValueTemp + 48
Xmit_RS232(SerCen)
LCDValue = LCDValue - LCDValueTemp * 100
end if
IF LCDValueTemp > 0 OR LCDValue >= 10 then
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
Xmit_RS232(Serdec)
LCDValue = LCDValue - LCDValueTemp * 10
end if
SERUN = LCDValue + 48
Xmit_RS232(Serun)
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I need to have one master pic that communicates to the pc send a command to a slave pic that will read it a/d and send it's reading to the master pic, and the master will read its a/d and send the both together to the pc. I can use a bigger memory pic if i need to, So i need two serials out and one in, and to have the master store the incomming data and send it with it's data to the pc when it gets it. I will have the slave send it's data as ascii to the master.
here is what I got so far:
'Master PIC
#chip 12F675, 12 'mhz
#config MCLRE=off, WDT=off
#mem 128 'Chip has 128 bytes
EEADRH = 0
Ser_Init
dim test as Word
dim test1 as word
Dir GPIO.0 out' serial to PC
Dir GPIO.1 in 'serial FROM pic slave
Dir GPIO.2 in 'AD
Dir GPIO.3 In 'AD
Dir GPIO.4 out 'serial TO pic slave
start:
wait 5 m
?
?
?
goto start
sub output
test = ReadAD10(AN2)
Bin2ascii (test_H)
Bin2ascii (test)
test1 = ReadAD10(AN3)
Bin2ascii (test1_H)
Bin2ascii (test1)
end sub
Sub Ser_Init
#define baud 833 ;the us delay for 1200 baud rate
#define SerTxHigh Set GPIO.0 on
#define SerTxLow Set GPIO.0 Off
SerTxHigh ;Initial RS232 idle state
#define SerRxHigh GPIO.1 on
#define SerRxLow GPIO.1 off
#define SerTxHigh GPIO.4 on
#define SerTxLow GPIO.4 off
end sub
sub XMIT_PRINT (PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
XMIT_RS232(PrintData(SysPrintTemp))
next
end sub
Sub XMIT_RS232(Xmit_Byte)#NR
SerTxLow ;Start bit
wait baud us
For cntr = 1 to 8
Rotate Xmit_Byte Right
If Status.C ON Then SerTxHigh
If Status.C Off Then SerTxLow
wait baud us
Next
SerTxHigh ;Stop bit
wait baud us
end sub
sub Bin2ascii(LCDValue )#NR
SERCEN = 0
SERDEC = 0
SERUN = 0
LCDValueTemp = 0
If LCDValue >= 100 Then
LCDValueTemp = LCDValue / 100
SERCEN = LCDValueTemp + 48
Xmit_RS232(SerCen)
LCDValue = LCDValue - LCDValueTemp * 100
end if
IF LCDValueTemp > 0 OR LCDValue >= 10 then
LCDValueTemp = LCDValue / 10
SERDEC = LCDValueTemp + 48
Xmit_RS232(Serdec)
LCDValue = LCDValue - LCDValueTemp * 10
end if
SERUN = LCDValue + 48
Xmit_RS232(Serun)
end sub