Texas Instruments MSP50C6xx User Manual
Page 335
C– – Efficiency
5-39
Code Development Tools
5.7.1
Real Time Clock Example
The C– – clock works as follows. The Timer2 ISR is set to fire at 1-second
intervals. Inside the ISR a counter is incremented by one each time it fires. An
assembly routine in cmm1.asm (_getSecondsPassed) disables the interrupts,
retrieves the counter, resets it, and turns the interrupts back on. The C– –
program calls getSecondsPassed() whenever it is not busy and uses the
return value to update the clock. This keeps the assembly code to a minimum
and allows all of the calculations to be handled in C– –. The interrupts are
disabled when the counter is being read to prevent possible loss of time.
_getSecondsPassed
rpt2–2 ; interrupt can still fire for 2 cycles
intd
; leaving these out can cause loss of a second
mov a0~, *seconds_passed
zac a0
mov *seconds_passed, a0
inte
mov a0, a0~
ret
The example is divided up into three projects. The first one is a minimal
implementation. It does not have support for speech, LCD, key scanning, or
setting the time. It offers minimum functionality to keep the number of files
small. It is meant to show the basics of a C– – project.
The second project adds speech and key scanning. The speech provides
output and the key scanning is used for input. Adding speech synthesis
increases the number of files in the project dramatically, but the C– – is still
similar. The main changes that relate to C– – are addition of a routine in
cmm1.asm to read buttons on Port D and addition of a routine to speak from
C– –.
The third project adds LCD support. It offers the same speaking abilities as the
third project, but uses an LCD screen for additional output. It also
demonstrates the use of arrays in C– –.
Example 5–1. First Project
The project is of limited use because there is no way to read the time or change
the time without using a scanport. It does provide a good example of a C– –
project that contains a few simple files.
A minimum implementation of the real time clock contains the following files.