CK3 Alarm Clock and Thermometer
(C) Lucid Technologies
5
The assembly language source code for the standard CK3 alarm clock is included on the
disk that came with your kit. The source code is well commented and highly modular. If you know
PIC assembly language it should be easy to understand. If you want to learn more about PIC
programming and the free Microchip Assembler (MPASM) consult some of the excellent resources
on the Microchip web site (see Appendix H for the URL).
The source code begins with several blocks of comments and equates. The comments, lines
that begin with a semicolon, are explanatory text that don’t generate any assembly code. Equates
associate understandable names with fixed numeric values. For example the decimal value 103 is
used to set the UART to 2400 baud, this value is given a more understandable name via the equate:
BD2400 equ D'103'
.
The first block, PIC16F87 HARDWARE SETUP, has definitions of the PIC’s I/O pins,
memory addresses, and equates for baud rate settings. The second block, DB1 DISPLAY DATA,
defines the usage of the digits and annunciators on the DB1, and has equates for specific displays.
The third block defines the control and data registers in the DS1305 Real-Time-Clock. The fourth
block defines the PIC I/O pin for the 1-wire interface with the DS18S20 high precision
thermometer. The fifth block is equates for ASCII characters.
The next three blocks are assembler directives, variable definitions and macro definitions.
See the MPASM documentation if you are unfamiliar with any of these concepts.
3.2 Interrupts
The next part of the source code is the interrupt service routine. Only one interrupt is active
in the standard CK3 software, that is the Timer 1 (TMR1) overflow interrupt. The TMR1 prescaler
clocks the 16-bit counter at 500 kHz which produces an overflow interrupt every 131 milliseconds
(7.629 Hz). The interrupt service routine clears the interrupt flag and increments the Timer 1
overflow counter (tmr1ofc) variable.
3.3 Subroutines
The subroutines come next in the source code. The subroutines are well documented and
should be easy to follow for anyone who is familiar with PIC assembly language. The subroutines
are divided into five groups.
1) General Subroutines, such as data conversion; hex to ascii, binary to BCD, delays, etc.
2) UART Subroutines, such as setting baud rates, transmitting and receiving bytes, etc.
3) Synchronous Serial Port Subroutines exchange data with the display, real-time-clock, and
shift register inputs via the SPI.
4) One-wire Bus Subroutines communicate with the DS18S20 thermometer chip. These
routines come from Dallas Semiconductor AN2420 with very little change.
5) Alarm Clock Subroutines to set clock and alarm times, format time data for display, and
generate alarm tones.
3.4 Main Program
The power on reset initialization code begins at the MAIN label. The internal oscillator is
set to 4 MHz, the direction of the I/O ports is set, the TMR1 overflow interrupt is set to 7.629 Hz,
the DB1 display controller and RTC chip are initialized, then the TMR1 overflow interrupt is
enabled.
The label LOOP is the top of the main program loop. The program reads RB6 to see if RTS
Summary of Contents for CK3-1
Page 17: ...CK3 Alarm Clock and Thermometer C Lucid Technologies 17 APPENDIX B CK3 BOARD LAYOUT ...
Page 28: ...CK3 Alarm Clock and Thermometer C Lucid Technologies 28 ...
Page 29: ......
Page 30: ......
Page 31: ......
Page 32: ......
Page 33: ......