Introduction
The remote terminal consists of:
- LCD: any HD44780
compatible 1 or 2 line dot matrix display
- RS232 interface
- Two push switches
The target device is a Microchip PIC16F871. (visit
www.microchip.com for further information on Micropchip
PICs)
This remote terminal
can be used as an operator interface connected to
a PC or some other computer equipment. A simple menu
system with Yes/No answers via the input switches
could be affected. The applications are endless!
This project was developed
on a Dontronics DT1003 / DT1006. For more information
on Dontronic products visit www.dontronics.com.
Opertation
When SW_1 is pressed send an ASCII '1' out of the
RS232 port, when SW_2 pressed send an ASCII '2' out
of the RS232 port.
A character received
by the RS232 port is interpreted as follows:
Value Action
0x0D Move cursor to start of line 1
0x0A Move cursor to start of line 2
0x0C Erase display
All other characters
are printed to the display.
Buad rate
The baud rate of RS232_1 is set at 1200. This however
may be increased to a maximum of around 4800. Higher
baud rates may cause communications errors since LCD_1
has to carry out its write function in less than one
bit timing of the serial data.
Output File
The builder generates code output to file clcd..c
Testing
A way of testing the simple remote terminal would
be to use a terminal emulator such as Windows HyperTerminal.
Set the emulator to Baud=1200, Data bits=8, Stop bits=2,
Hardware flow control=none, and Comport to the port
you are using.
The connections to the
PC 9-way 'D' are:
PC-Pin2 <- RS232_1-TX_OUT
PC-Pin3 -> RS232_1-RX_IN
PC-Pin5 - RS232-GND
In HyperTerminal when
the return key is pressed the LCD is cleared, any
other key is
printed on the display (not all characters will be
printable). Pressing either of the two push switches
will produce either a '1' or a '2' on the terminal
emulator.
Application code
Below is the application code for this project. To
use it, select and copy (ctr-insert) the below and
past it into a text editor and save as a 'C' file
in your working directory. You may also need to change
the build output path using 'Project | Options'
Note the inclusion of
clcd.c with #include 'clcd.c'
///////////////////////////////////////////////////////////////////////
//// ACLCD.C ////
//// ////
//// Demo application of simple dumb terminal, consisting of ////
//// 2 x Push switchs ////
//// 1 x RS232 Tranceiver ////
//// 1 x LCD dot matrix display 44780 and compatibles ////
//// ////
//// ////
//// This program is an example of how your application code is ////
//// is organised. Note the #include "clcd.c", this include ////
//// file was generated by QuickBuilder and contains all ////
//// driver code. ////
//// ////
//// This demo is intended for a PIC16F871 ////
//// Compiled using CCS 'C' visit www.quickbuilder.co.uk/qb/ccs ////
//// for more information. ////
///////////////////////////////////////////////////////////////////////
#include <16f871.H>
#fuses hs,nowdt,noprotect,put,nowrt,nolvp,nodebug
#case
#define PORTA 5
#define PORTB 6
#define PORTC 7
#define PORTD 8
#define PORTE 9
#define TRISA 0x85
#define TRISB 0x86
#define TRISC 0x87
#define TRISD 0x88
#define TRISE 0x89
#include "clcd.c"
main() {
int c;
// initialise
//
INIT_SUB_CIRCUITS();
setup_adc_ports(NO_ANALOGS);
// show ready
//
printf(LCD_1PUTC, "Ready 1");
LCD_1CURMOVE(0x40);
printf(LCD_1PUTC, "Ready 2");
// main program loop
//
while(1) {
// service rx comms
//
if ( RS232_1INCOMING() ) {
c = RS232_1IN(); // wait for character in
if (c==0x0a) { // line feed ^J
LCD_1CURMOVE(0x40); // move cursor to line 2
} else if (c==0x0d) { // carriage return ^M
LCD_1CURHOME(); // move cursor to line 1
} else if (c==0x0c) { // form feed ^L
LCD_1CLEAR(); // clear display
} else { // none of the above
LCD_1PUTC(c); // print character
}
}
// service user input
//
if ( SW_1PRESSED() ) {
delay_ms(200);
RS232_1OUT('1');
}
if ( SW_2PRESSED() ) {
delay_ms(200);
RS232_1OUT('2');
}
}
}