ChipCenter Questlink
SEARCH CHIPCENTER
Search Type:
Search for:




Knowledge Centers
Product Reviews
Data Sheets
Guides & Experts
News
International
Ask Us
Circuit Cellar Online
App Notes
NetSeminars
Careers
Resources
FAQ
EE Times Network
Electronics Group Sites

BUILDING A PRACTICAL EMBEDDED DEVELOPMENT SYSTEM


Circuit Cellar Online
THE MAGAZINE FOR COMPUTER APPLICATIONS
Circuit Cellar Online offers articles illustrating creative solutions
and unique applications through complete projects, practical
tutorials, and useful design techniques.

BUILDING AN EMBEDDED TIMING SYSTEM

Lessons from the Trenches by Jamie Pollock

Start ý Problem Solving ý EEPROM Programming ý Some Assemblyý ý Interfacing the LCD ý Sources and PDF

SOME ASSEMBLYý

Up to this point we should be able to run our code in RAM using interrupts, and program the EEPROM for testing the final product. Writing code for the 512-byte EEPROM requires the use of assembly language. I use the Motorola free assembler (AS11.EXE available on the Internet).

 

Using assembly language can be frustrating at first, but having complete control of the hardware with compact code is wonderful. I began this project knowing very little assembly language.

At the beginning of the code, the variables need to be cleared. One way to do this is to use a statement like CLR {variable} that takes up a considerable amount of code to clear 39 bytes. Instead, I use a loop relying on the indexed addressing associated with the X register. The code clears the 16-bit D register then begins a loop that stores this value according to where the X register is pointing. Next, the X register is incremented twice and its value is checked against my ending value. This loop can clear as much space as needed with seven statements. The hardware is set up next. In order to use interrupts, there must be a Vector table somewhere telling the controller what to do when an interrupt occurs. Bootstrap mode has the Vector table set up, so I only have to know where each vector points. The Bootstrap code from Motorola lists the Vector table.

The Vector table lists the Timer Output Compare 1 as $00DF. Placing the opcode $7E tells the controller to jump to the location given by the next two bytes. The other two interrupts are programmed similarly. The next part of the initialization is setting the ports for input or output.

Port C and Port F are both cleared before they are set as outputs. These two ports are needed for the LCD. Port C is used as an 8-bit data bus to the LCD and three Port F pins are used for the control pins. The LCD is initialized by software. Five sets of codes are sent to the LCD. These codes determine the options for the LCD controller, like 8-bit data bus and the font. Finally, the interrupt flags are cleared and the CLI opcode is executed. CLI instruction clears the ýIý bit in the Condition Code register. This is enables all masked interrupts.

Masked interrupts can be enabled and disabled through software. Only the interrupts with flags that have been cleared will operate immediately.

Next, we need to talk about the interrupt service routines (ISR). In order to achieve a stable timebase, the use of interrupts is necessary to ensure that the millisecond counter will be updated regardless of what the microcontroller is doing.

The main interrupt is the Timer Output Compare 1 (TOC1). This interrupt compares a 16-bit register to the 16-bit microcontroller clock. If these registers match, the TOC1 ISR is called.

Several things happen inside the TOC1 ISR. The most important thing that happens is the clearing of the TOC1 flag and incrementing the TOC1 register. This example adds 30,000 counts to the TOC1 register. Basically, every 30,000 clock counts the TOC1 ISR is called and the timers are incremented. Next, the individual active timers are incremented and the LCD display is updated. The LCD is updated inside this ISR because I have plenty of time before the next cycle. This arrangement ensures that the display accurately shows the correct time value. If the LCD update was elsewhere, the counter would be able to increment during a write to the LCD.

The next ISR is for the keypad. The keypad uses a special pin called the Pulse Accumulator (PACC). One feature of the PACC is acknowledging pin logic changes on Port A pin 7. This function could have also been done with one of the input capture pins.

The keypad is made by placing a pull-up resistor on each input pin. Port G pins 0ý4 are for the Start/Stop function and Port A pins 0ý4 are for clearing the timers. The switches are then attached to ground. This gives ten switches for control of five timers.

Diodes are placed between each switch and the PACC pin to prevent the switches from interfering with each other. The PACC also has a pull-up resistor.

The keypad can now be operated on an interrupt basis, which is better than the polling method because a key press might slip through the cracks while one of the ISRs is running.

Finally, we need a time-out counter to debounce the switches. TOC2 can be used to prevent one key press from being registered as multiple key presses.

Enabling the TOC2 ISR inside the PACC ISR does this. The TOC2 ISR is called when the timeout has expired. The PACC interrupt flag is then cleared to enable the keypad again. The TOC2 interrupt is not enabled until another key has been pressed.

The controller is entirely run off of interrupts after the initialization is completed. The main routine consists of WAI (wait for interrupt) and a loop back to the same instruction.

PREVIOUSNEXT


Circuit Cellar provides up-to-date information for engineers. Visit www.circuitcellar.com for more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com or subscribe online. ýCircuit Cellar, the Magazine for Computer Applications. Posted with permission.
Click here to get your listing up.

Copyright © 2003 ChipCenter-QuestLink
About ChipCenter-Questlink  Contact Us  Privacy Statement   Advertising Information  FAQ