Tut 15 : Serial data communication

Serial data communication is a communication between microcontroller and other systems like RFID reader, GPS module, GSM module or computer. The communication is done via a RS232 interface. RS232 is a standard for a serial communication interface which allows to send and receive data. With the RS232 interface it is possible to setup a connection between a microcontroller and those units. Sometime the RS232 interface is used for communication between two microcontrollers.
 
 PIC and Computer communication
 
Old computers have their own serial ports (COM), thus the communication will go through these ports. Note that modern PCs don't have a serial port so you need to get a USB to serial converter. They are available at low cost. For serial communication the line used to transmit data is called TX and the line used to receive data is called RX. When sending or recieve commands from a PC to a microcontroller, or vice versa, the informations can be viewed on PC using any hyper termial program. Another way is to send the informations through visual basic.
 Communication blog diagram 
 
 USB to UART converter

PBP Program
'program to send and receive serial data 
 
DEFINE OSC 20
   @ device hs_osc  'jika guna crytal 20Mhz
 
INCLUDE "modedefs.bas"          ' Include serial modes
x VAR Byte(3)
 
loop:                                  
SerIn2 PORTC.7, 84,keyout,[WAIT("A"),STR x\3]    'receive data
SerOut2 PORTC.6,84,[x(0)]     ' Send 1st data
pause 100
SerOut2 PORTC.6,84,[x(1)]     ' Send 2nd data
pause 100
SerOut2 PORTC.6,84,[x(2)]     ' Send 3rd data
pause 100
GoTo loop
End   

No comments:

Post a Comment