Serial Port Complete - Latest Microcontroller projects

(lily) #1
Ports for Embedded Systems

 data_ready_to_send var bit
flow_control_input var PORTB.4
flow_control_output var PORTB.5
serial_in var byte
serial_out var byte


' Configure the flow-control pins as one input and one output.

TRISB.4 = 1
TRISB.5 = 0

' Assert the flow-control output to enable receiving data on the serial port.

flow_control_output = 0
This task loop calls two routines in an endless loop:
loop:
gosub receive_serial_data
gosub transmit_serial_data
GOTO loop
This routine checks for a new received byte on the serial port.
receive_serial_data:

if (PIR1.5 = 1) then

' A byte has arrived at the serial port. Read it.

hserin [serial_in]

' Tell the remote computer to stop sending data.

flow_control_output = 1

' Set serial_out to a character code to send on the serial port.

if ((serial_in > 96) and (serial_in < 123)) then

' The received character code was lower case (a-z).
' Send back the character in upper case.

serial_out = serial_in - 32
Free download pdf