Two pics communicating via UART
Posted: Mon Oct 18, 2010 8:16 pm
I have not had too much time lately to experiment with any projects, but this is one thing I have been looking into.
I want to create some sort of multiplayer game system where multiple pics can communicate with each other using the inbuilt UART. I have been getting some excellent help once again from the team over at http://www.digital-diy.com
Here is my test circuit: Basically I have two 18f4685 PICs and they are connected by two wires RX and TX on the built in UART.
The image you are seeing is drawn by sending data serially from one pic to the other. So one has the face data stored within it, it then sends the data to the receiving pic which takes care of sending the data to the LED display.
I guess this is just the start - a sort of 'proof of concept' if you will. My ultimate goal is to have two handheld game devices where you can play games such as tetris or connect four or maybe even a game of chasey based around a mario bros game map. The two game devices would connect to each other wirelessly (using the UART) and they would continually send data between each other to let each other know what they are doing. for example if we are playing connect four and player one has just had their turn, we would need to display this data on both player 1's screen and also send that data for display on player 2's screen etc...
I look forward to where this project may be headed. it may be a slow process getting there due to time constraints but we will see!
and lastly, here is the test TX code:
All I am doing in the above code is transmitting the word 'start' the receiver will then wait for this word to come through, it will then acknowledge that it is ready to start by sending back the word 'go' once the transmitter has received this word, it will then start sending the first byte of data. once done, it will do it again another seven times which means the whole graphic will have been sent.
RX code:
This receiver piece of code receives the graphic data and then takes care of drawing it on the display. It waits for the start string to come through, it then sends out the go string and then receives the data that is to follow (one byte at a time) it then sends this byte to the LED cathodes. We then need to activate one row of anodes so I have these connected to PORTA and the last two to PORTE. It will do this a total of eight times which means the full graphic will then be drawn.
I want to create some sort of multiplayer game system where multiple pics can communicate with each other using the inbuilt UART. I have been getting some excellent help once again from the team over at http://www.digital-diy.com
Here is my test circuit: Basically I have two 18f4685 PICs and they are connected by two wires RX and TX on the built in UART.
The image you are seeing is drawn by sending data serially from one pic to the other. So one has the face data stored within it, it then sends the data to the receiving pic which takes care of sending the data to the LED display.
I guess this is just the start - a sort of 'proof of concept' if you will. My ultimate goal is to have two handheld game devices where you can play games such as tetris or connect four or maybe even a game of chasey based around a mario bros game map. The two game devices would connect to each other wirelessly (using the UART) and they would continually send data between each other to let each other know what they are doing. for example if we are playing connect four and player one has just had their turn, we would need to display this data on both player 1's screen and also send that data for display on player 2's screen etc...
I look forward to where this project may be headed. it may be a slow process getting there due to time constraints but we will see!
and lastly, here is the test TX code:
Code: Select all
Device = 18F4685
Clock = 8
Config OSC = IRCIO67
// import library's
Include "usart.bas"
Const green_data(8) As Byte = (%11000011,%10111101,%01010110,%01111010,%01111010,%01010110,%10111101,%11000011)
Dim number As Byte
Dim x As Byte
// Start Of Program...
OSCCON = %01111111
TRISD = %00000000
TRISA = %00000000
number = %10101010
SetBaudrate(br115200)
DelayMS(160)
While true
For x = 0 To 7
USART.Write("start")
USART.WaitForStr("go")
USART.Write(green_data(x))
DelayMS(1)
Next
Wend
RX code:
Code: Select all
Device = 18F4685
Clock = 8
Config OSC = IRCIO67
Include "USART.bas"
Include "SUART.bas"
Include "utils.bas"
Dim green_data As Byte
Dim x As Byte
// Start Of Program...
OSCCON = %01111111
TRISD = %00000000
PORTD = %00000000
TRISA = %00000000
PORTA = %00000000
TRISB = %00000000
PORTB = %00000000
TRISE = %00000000
PORTE = %00000000
SetBaudrate(br115200)
DelayMS(150)
PORTA = %00000000
PORTE = %00000000
While true
For x = 0 To 7
USART.WaitForStr("start")
USART.Write("go")
USART.Read(green_data)
PORTB = green_data
If x < 6 Then
PORTA.bits(x) = 1
ElseIf x = 6 Then
PORTE.bits(0) = 1
ElseIf x = 7 Then
PORTE.bits(1) = 1
EndIf
DelayMS(1)
PORTA = 0
PORTE = 0
Next
Wend