Issue
138 January 2002
An RF-Controlled
Irrigation System
by
Brian Millier
Start
Controller/Receiver
Encoder/Decoder
The Firmware Time's
Up Sources
& PDF
The
Firmware
One
of the reasons for choosing the AT90S8535 instead of one
of its little brothers, like the ’2313, was to allow me
the luxury of programming the firmware in BASIC. From
past experience, I thought there was not enough space
in the 2-KB flash memory of the ’2313 for an application
such as this using compiled BASIC.
I
wrote the firmware using the MCS Electronics BASCOM-AVR
compiler. It took up more than half, 4800 bytes, of the
8192 bytes of flash program memory, confirming my fears
that it would not have fit into the memory of the smaller
’2313 device. Incidentally, the demo version of the BASCOM-AVR
is available free from MCS Electronics, and is fully functional
apart from the fact that its program size limit is 2 KB.
As
I mentioned earlier, problems I had using Timer2 (designed
for RTC purposes) of the ’8535 prevented me from using
the built-in RTC routines in the BASCOM-AVR. This had
an upside: The RTC routines needed by this application
do not require week, month, or year, so they use less
memory space even though they were coded in BASIC (Note:
The BASCOM intrinsic RTC function is done in assembly
language).
Most
of the firmware takes care of the user interface. An LCD
with four push buttons is easy to build, but takes up
considerable program space to implement a friendly user
interface. There is a routine that allows you to set the
clock to the current time. Another routine enables you
to enter up to six programs. Each program consists of
a time, action (pump on/off), and a Daily or Once-Only
mode. And, a final menu item allows you to turn the pump
on and off immediately from the controller.
The six user-defined programs are stored in EEPROM, so
that they survive a power failure. However, because the
CPU (and therefore the RTC) will stop if the power goes
off, this is a moot point, unless I add a battery backup
for the controller’s CPU.
When
a command comes in from the wireless transmitter, the
valid transmission (VT) line on the decoder will go high,
and its four data output lines will reflect the state
of the four buttons on the keyfob transmitter. The VT
signal is fed into the INT0 interrupt input of the ’8535
(through RC filtering to prevent false triggering). An
interrupt service routine checks the state of the decoder’s
four outputs and turns the pump on or off accordingly.
Although I fitted four buttons into the transmitter and
allowed for all four in the controller, the firmware currently
responds to only two switches—pump on and pump off. I
will likely think of some other device to hook up to this
in the future.