PDA

View Full Version : communication between pics



meyou
- 23rd July 2004, 10:49
1 ) I need to design the board that contain the 32 pics and 1 master pic. 32 pics need to send the data/report to master pic. I want to know the best way to do that. can be direct connected to master pic? What type of the communication can be use?

thank you.

Eyal
- 23rd July 2004, 13:54
Originally posted by meyou
1 ) I need to design the board that contain the 32 pics and 1 master pic. 32 pics need to send the data/report to master pic. I want to know the best way to do that. can be direct connected to master pic? What type of the communication can be use?

thank you.

The process:
you can use with the serin serout command.

1-combine oll the slave RX pin together (32)
2-combine oll the slave TX pin together with 32 470R resistor
3-combine the master TX to the slave RX with 470R resistor
4-combine the master RX to the slave TX with 470R resistor

THE RESISTOR IS FOR ERRORS in time you make experiments.
after everything work ok you can get out the 32 470R resistor.



example code that i made before few month
this code refer to 10 slaves with one master

master code:

after the master receive data frome one of the slave
ia transmit the data with tx module.
(pic 16f84)


DEFINE OSC 8 '8Mhz xtal
INCLUDE "MODEDEFS.BAS"
SEND VAR BYTE
key var byte
KEY_CODE VAR BYTE
RKEY_CODE VAR BYTE
A VAR BYTE
B VAR WORD
trisa.0=1

'waite for kbd signal
START:
LOW PORTB.0
A=A+1
IF A=1 THEN
KEY_CODE=$A
GOTO TRANSMIT0
ENDIF
IF A=2 THEN
KEY_CODE=$B
GOTO TRANSMIT1
ENDIF
IF A=3 THEN
KEY_CODE=$C
GOTO TRANSMIT2
ENDIF
IF A=4 THEN
KEY_CODE=$D
GOTO TRANSMIT3
ENDIF
IF A=5 THEN
KEY_CODE=$E
GOTO TRANSMIT4
ENDIF
IF A=6 THEN
KEY_CODE=$AA
GOTO TRANSMIT5
ENDIF
IF A=7 THEN
KEY_CODE=$BB
GOTO TRANSMIT6
ENDIF
IF A=8 THEN
KEY_CODE=$CC
GOTO TRANSMIT7
ENDIF
IF A=9 THEN
KEY_CODE=$DD
GOTO TRANSMIT8
ENDIF
IF A=10 THEN
KEY_CODE=$EE
GOTO TRANSMIT9
ENDIF

GOTO START

TRANSMIT0:
SerOut PORTA.1,N9600,["A9"] 'pic1
GOTO IN
TRANSMIT1:
SerOut PORTA.1,N9600,["B9"] 'pic2
GOTO IN
TRANSMIT2:
SerOut PORTA.1,N9600,["C9"] 'pic3
GOTO IN
TRANSMIT3:
SerOut PORTA.1,N9600,["D9"] 'pic4
GOTO IN
TRANSMIT4:
SerOut PORTA.1,N9600,["E9"] 'pic5
GOTO IN
TRANSMIT5:
SerOut PORTA.1,N9600,["AA"] 'pic6
GOTO IN
TRANSMIT6:
SerOut PORTA.1,N9600,["BB"] 'pic7
GOTO IN
TRANSMIT7:
SerOut PORTA.1,N9600,["CC"] 'pic8
GOTO IN
TRANSMIT8:
SerOut PORTA.1,N9600,["DD"] 'pic9
GOTO IN
TRANSMIT9:
SerOut PORTA.1,N9600,["EE"] 'pic10

IN: 'wait for reply frome the slave
SerIn PORTA.0,N9600,2,WAITE,["ABC"],RKEY_CODE,KEY
WAITE:
IF A=>10 THEN A=0 'send the data to the tx module
if KEY_CODE=RKEY_CODE THEN SEROUT PORTA.2,N2400,["DEF",KEY_CODE,KEY]
KEY=0
RKEY_CODE=0
GOTO START

the slave code:
this pic read several key frome ps2 keyboard
and send the data to the master

(pic16f84)

DEFINE OSC 12 '12Mhz xtal
INCLUDE "MODEDEFS.BAS"
clock_pin var porta.2
data_pin var porta.3
SEND VAR BYTE
key var byte
KEY_CODE VAR BYTE
KEY_CODE=$A
A VAR BYTE
B VAR BYTE
TRISA.0=1
trisa.3=1
trisa.2=1
pause 1000
'waite for kbd signal
start0:
'IF KEY=$F0 THEN B=1
if (data_pin=0)and(clock_pin=0)then go 'waite for signal frome kbd
GOTO START0


'start read data
go:
gosub dealay_0 'delay for clock finish "0" (dealay start bit)
gosub dealay_1 'delay for clock finish "1" (dealay bit 0)
key.bit0=data_pin 'read bit 0
gosub dealay_0 'delay for clock finish "0"
gosub dealay_1 'delay for clock finish "1"
key.bit1=data_pin 'read bit 1
gosub dealay_0
gosub dealay_1
key.bit2=data_pin 'read bit 2
gosub dealay_0
gosub dealay_1
key.bit3=data_pin 'read bit 3
gosub dealay_0
gosub dealay_1
key.bit4=data_pin 'read bit 4
gosub dealay_0
gosub dealay_1
key.bit5=data_pin 'read bit 5
gosub dealay_0
gosub dealay_1
key.bit6=data_pin 'read bit 6
gosub dealay_0
gosub dealay_1
key.bit7=data_pin 'read bit 7
gosub dealay_0
gosub dealay_1
'paritybit.bit0=data_pin
gosub dealay_0
gosub dealay_1 'dealay for stop bit
gosub dealay_0 'dealay for stop bit
'IF B=1 THEN TX
'goto START0

TX:
if (key=$29)or(key=$11)or(key=$14)or(key=$05)or(key=$ 06)or(key=$04)_
or(key=$0C)or(key=$03) then WAITE_PAST
'B=0
GOTO START0

WAITE_PAST:
A=A+1
PAUSEUS 10
IF PORTA.0=1 THEN A=0
IF (A=10)AND(PORTA.0=0) THEN RECIVE
GOTO WAITE_PAST
RECIVE:
SerIn PORTA.0,N9600,["A9"]
PAUSEUS 500
SEROUT PORTA.1,N9600,["ABC",KEY_CODE,KEY]
A=0
PAUSE 100
GOTO START0



dealay_0:
if clock_pin=0 then dealay_0
return

dealay_1:
if clock_pin=1 then dealay_1
return

if you have more question send me email.

mazlan
- 30th July 2004, 07:38
Is there any limited number of pics can be connected to all the tx and rx pin? How about the 230 pics? It's ok?

Eyal
- 30th July 2004, 10:19
Originally posted by mazlan
Is there any limited number of pics can be connected to all the tx and rx pin? How about the 230 pics? It's ok?

yes it is possible
but you need to calculate the time that take to the master pic
to ask all the slave pic if they have a data to send


Eyal

Dwayne
- 30th July 2004, 17:13
Hello Mazlan,

M>>Is there any limited number of pics can be connected to all the tx and rx pin? How about the 230 pics? It's ok?<<

I have a theory...(but haven't checked it out, because of no situation that is needed).

With the Serin command, and the "ID" letters, you should be able to control as many as you want, and communicate back and forth very easily.

For example:
ChipNumber[4] var byte

Loop:
some kind of interupt gosub talk

Goto Loop

Talk
ChipNumber="ZZ00";
Serout Pin1,T2400,ChipNumber,Val.
Serin Pin2,T2400,"ZZ01",Val.
gosub routine
etc. etc. ZZ00 is chip 1 ZZ01 is chip 2 etc...
return
As soon as chip is activated, you can jump to a subroutine
to transfer data with the same principal.

routine:
while Val <> endof transmission
Serin Pin2,"TZZ",Val
do something with Val
end while
return


You can actually have chips talking back and forth to each other similar to a eithernet situation.

Dwayne

mazlan
- 5th August 2004, 03:32
I think it's better to put the switching diode to every communication line for protection.