■ FIGURE 2. The RCM5450W module and a 50-pin
field for debug (foreground).
whole system. The three PD control bits are named RS,
RW, and E. RS is “Register Select,” RW is “Read/Write”
(1 = read, 0 = write), and E is “Enable.” After initialization
of the module (lcd_init()), to write a character to a specific
location on the display, you put the eight-bit character
on the PA lines, set RS as described in the LCD module’s
interface table, and “blip” the E line (E≤-1 followed by E≤-0).
This functionality is embedded in an lcd_wr_char() routine
in my RPC_LCD.LIB library. Here’s the E bit pulse code
(where EBIT is #define EBIT 2, meaning port D bit 2):
BitWrPortI(PDDR, &PDDRShadow, 1, EBIT);
// LCD E bit = 1
BitWrPortI(PDDR, &PDDRShadow, 0, EBIT);
// LCD E bit = 0
If you can write a character, you can write a string
which is what lcd_wr_str() does in the same library.
details on how that was done.
Wi-Fi Code
C Code Controlling LCD Display
As with relay control, my C code for controlling the
LCD display is based on library routines that I wrote first.
The idea was to hide the grungy details of the LCD
module interface, and make it easy to put text and
numbers anywhere on the LCD display.
The first piece of grunge is that the LCD display can
be very slow. This means you have to poll an LCD’s
module busy bit to see if the display is ready for a new
input. That means reading the busy bit, which requires the
PA port to “turn around” from being all outputs to being
all inputs. Once the busy bit has de-asserted, the PA port
is again changed to outputs, and the character to display
is sent across the PA bits under the control of three PD
bits. A library routine named lcd_busy_wait() accomplishes
all that, and also has a time-out counter so that any
hardware problems with the LCD display can’t hang the
One of the best things about the Rabbit development
environment is the large amount of sample code they
provide. I had no trouble getting the module to connect to
my home network. You will need to change the PRIMARY
STATIC IP to something suitable for your network.
Likewise for the SSID and the KEY0_HEXSTR.
/*
NETWORK CONFIGURATION
*/
#define TCPCONFIG 1
#define _PRIMARY_STATIC_IP “192.168.2.45”
#define _PRIMARY_NETMASK “255.255.255.0”
#define MY_GATEWAY “192.168.2.1”
#define MY_NAMESERVER “192.168.2.1”
#define IFC_WIFI_SSID “ColwellWirelessNetwork”
#define IFC_WIFI_MODE IFPARAM_WIFI_INFRASTRUCTURE
#define IFC_WIFI_REGION IFPARAM_WIFI_REGION_AMERICAS
#define IFC_WIFI_ENCRYPTION IFPARAM_WIFI_ENCR_WEP
#define IFC_WIFI_WEP_KEY0_HEXSTR “1234ABCDEF”
In fact, you might not want to use a static IP, and may
want something stronger than WEP.
Rabbit has examples of DHCP, WAP,
and many other variations. I went
with static IP because it was the
simplest thing I could try, and once it
worked, well … if it ain’t broken,
don’t fix it. To get the radio running,
you do this:
// Initialize the TCP/IP
// stack and HTTP server
// Start network and wait
// for interface to come up
// (or error exit).
sock_init_or_exit(1);
http_init();
■ FIGURE 3. The WFS
chassis with LCD display,
antenna, and power cord.
And the main do-forever loop is as
follows:
■ FIGURE 4.
The power switch
and power supply-chassis ( 24 VAC,
+5V, + 3.3V).
while (1) {
costate {
waitfor (DelayMs(400));
update_outputs
(¤t_zone,
&next_zone);
}
38
February 2011