ETC DRM044

Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Central Heating
Controller using the
MC68HC908LJ12
Reference Design
Designer Reference
Manual
M68HC08
Microcontrollers
DRM044
Rev. 0, 09/2003
MOTOROLA.COM/SEMICONDUCTORS
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Central Heating Controller
using the MC68HC908LJ12
Reference Design
Designer Reference Manual — Rev 0
by:
AT Electronic Embedded Control Consultants
e-business centre
Consett Business Park
Villa Real
Consett
Co. Durham
DH8 6BP
England
Telephone:
Fax:
Email:
Web:
44(0) 1207 693920
44(0) 1207 693920
[email protected]
www.ateecc.com
DRM044 — Rev 0
Central Heating Controller
MOTOROLA
3
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Central Heating Controller
DRM044 — Rev 0
4
MOTOROLA
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
List of Sections
Section 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Freescale Semiconductor, Inc...
Section 2. Design Overview . . . . . . . . . . . . . . . . . . . . . . . 17
Section 3. Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Section 4. Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Appendix A. Software Routines. . . . . . . . . . . . . . . . . . . . 65
Appendix B. Main Circuit Diagram . . . . . . . . . . . . . . . . 157
Appendix C. Main Circuit Bill of Materials . . . . . . . . . . 159
Appendix D. Programming Circuit Diagram . . . . . . . . . 161
Appendix E. Programming Circuit Bill of Materials . . . 163
Appendix F. PCB Details . . . . . . . . . . . . . . . . . . . . . . . . 165
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
List of Sections
For More Information On This Product,
Go to: www.freescale.com
5
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
List of Sections
Central Heating Controller
6
DRM044 — Rev 0
List of Sections
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Table of Contents
Designer Reference Manual — DRM044
Table of Contents
Section 1. Introduction
Freescale Semiconductor, Inc...
Section 2. Design Overview
2.1
Internal Temperature Sensing . . . . . . . . . . . . . . . . . . . . . . . . .18
2.2
Battery Voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
2.3
Keyboard Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.4
Output Drivers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
2.5
LCD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.6
External Temperature Sensor. . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.7
Phase-locked Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.8
Low Voltage Inhibit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Section 3. Hardware
3.1
Phase-locked Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.2
Temperature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.3
User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26
3.4
Climate Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27
3.5
Low Power Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
3.6
Battery Backup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30
Section 4. Software
4.1
Analog to Digital Converter. . . . . . . . . . . . . . . . . . . . . . . . . . . .34
4.2
Serial Communications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
7
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Table of Contents
4.3
Real Time Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
4.4
Phase-lock Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40
4.5
Temperature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.6
User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43
4.7
Climate Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49
4.8
Programming Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .52
4.9
Low Power Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .56
4.10
Battery Backup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59
4.11
On-board Flash Programming . . . . . . . . . . . . . . . . . . . . . . . . .60
Appendix A. Software Routines
A.1
[a2d.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65
A.2
[a2d.h]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
A.3
[Alarm.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
A.4
[Alarm.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73
A.5
[Alarmset.c]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
A.6
[Alarmset.h]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
A.7
[button.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .82
A.8
[button.h]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95
A.9
[Clockset.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
A.10 [Clockset.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
A.11 [Data.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101
A.12 [declared.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
A.13 [define.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
A.14 [Delay.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
A.15 [Delay.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Central Heating Controller
8
DRM044 — Rev 0
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Table of Contents
A.16 [Display.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
A.17 [Display.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
A.18 [extern.h]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117
A.19 [i2c.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
A.20 [i2c.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
A.21 [interrupt.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129
Freescale Semiconductor, Inc...
A.22 [interrupt.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131
A.23 [lj12.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
A.24 [main.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .139
A.25 [operation.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141
A.26 [operation.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .146
A.27 [startup.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .147
A.28 [startup.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .151
A.29 [temperature.c] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
A.30 [temperature.h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .155
Appendix B. Main Circuit Diagram
Appendix C. Main Circuit Bill of Materials
Appendix D. Programming Circuit Diagram
Appendix E. Programming Circuit Bill of Materials
Appendix F. PCB Details
F.1
Component Trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .165
F.2
Component Silk Screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
F.3
Solder Trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
9
Freescale Semiconductor, Inc.
Table of Contents
Solder Silk Screen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .168
Freescale Semiconductor, Inc...
F.4
Central Heating Controller
10
DRM044 — Rev 0
Table of Contents
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
List of Figures
Figure
Freescale Semiconductor, Inc...
1-1
2-1
3-1
3-2
3-3
3-4
3-5
3-6
3-7
4-1
4-2
4-3
4-4
4-5
4-6
4-7
4-8
4-9
Title
The Climate Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16
System Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
The Printed Circuit Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
MC68HC908LJ12 PLL Connections. . . . . . . . . . . . . . . . . . . . .22
Internal Temperature Sensor and Operational Amplifier Circuit
Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
External Temperature Sensor Circuit Diagram (DS1721) . . . .25
Relay Driver Circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Button Simulation Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Supply Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
Software Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
ADC Register Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
Real Time Clock Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
LCD Layout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Segment Labelling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
Button Processing Flow Chart . . . . . . . . . . . . . . . . . . . . . . . . .48
Metroworks Codewarrior Screenshot . . . . . . . . . . . . . . . . . . . . 61
Programming Confirmation. . . . . . . . . . . . . . . . . . . . . . . . . . . .62
During Programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
DRM044 — Rev 0
MOTOROLA
Page
Central Heating Controller
List of Figures
For More Information On This Product,
Go to: www.freescale.com
11
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
List of Figures
Central Heating Controller
12
DRM044 — Rev 0
List of Figures
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
List of Tables
Table
Freescale Semiconductor, Inc...
4-1
4-2
4-3
4-4
4-5
Title
DS1721 Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
PLL Frequency Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
LCD Frequency Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Bit to Segment Correlation – 1st Digit. . . . . . . . . . . . . . . . . . . . 45
Bit to Segment Correlation – 2nd Digit . . . . . . . . . . . . . . . . . . . 45
DRM044 — Rev 0
MOTOROLA
Page
Central Heating Controller
List of Tables
For More Information On This Product,
Go to: www.freescale.com
13
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
List of Tables
Central Heating Controller
14
DRM044 — Rev 0
List of Tables
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — Central Heating Controller
Section 1. Introduction
Freescale Semiconductor, Inc...
This document details the hardware and software design of a functional
time and temperature control system, which combines heating and
cooling algorithms to implement an intelligent climate control system.
The MC68HC908LJ12 has been selected to perform the control
functions, as, in addition to the ample memory size, it contains a
fully-featured real-time clock (RTC) and liquid crystal display (LCD)
driver module, which greatly simplifies the implementation of these
functions.
Emphasis has been placed throughout the design on efficient modes of
operation during periods of mains failure, to demonstrate the low current
consumption of this device when powered by a backup battery.
Two methods of temperature measurement have been used in order to
demonstrate the flexibility of the device. The internal temperature is
detected by an analog sensor, which provides an output voltage
proportional to the temperature. The external temperature is measured
using a 2-wire serial sensor. The resulting data is decoded by the
microcontroller and displayed on the LCD in degrees Celsius.
The internal and external temperature readings are also used in an
algorithm, which may be used to modify the start of an automatic timing
function if desired. This gives the user the opportunity to select a
‘SMART’ mode of operation, whereby the heating or cooling functions
are implemented earlier than the user set-time, depending on the
ambient internal and external temperatures.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Introduction
For More Information On This Product,
Go to: www.freescale.com
15
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Introduction
Figure 1-1. The Climate Controller
During normal operation, the internal temperature is displayed on the
three right-hand digits. Time-of-day (TOD) and day-of-week (DOW) are
displayed in the left-hand digits and chevrons respectively.
A 3 V lithium coin cell is used for backup of time keeping functions.
Central Heating Controller
16
DRM044 — Rev 0
Introduction
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
Section 2. Design Overview
Freescale Semiconductor, Inc...
INTERNAL TEMPERATURE
SENSING
BATTERY VOLTAGE
4 KEYBOARD INPUTS
RELAYS
LEDs
8-DIGIT LCD
EXTERNAL TEMPERATURE
SENSOR
4 KEYBOARD INPUTS
Figure 2-1. System Block Diagram
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Design Overview
For More Information On This Product,
Go to: www.freescale.com
17
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Design Overview
2.1 Internal Temperature Sensing
The voltage supplied by the internal temperature sensor is conditioned
by an operational amplifier and scaled for the input parameters of the
analog to digital converter (ADC). The ADC is then used to read this
temperature value.
2.2 Battery Voltage
To keep the RTC module running during periods of mains supply failure,
a 3 V lithium ‘coin’ cell is used. To minimize current drain from the
battery, all non-essential outputs, i.e., relay drive, temperature
measurement and light-emitting diode (LED) drive signals, are inhibited.
The ADC is used to detect if the battery drops below the microcontroller’s
minimum operating voltage. Under these circumstances, ‘low battery’ is
displayed to the user.
2.3 Keyboard Inputs
All eight of the designated keyboard inputs are connected to buttons.
These buttons are used for the general operation of the controller.
2.4 Output Drivers
Port B is used to activate the two climate control relays and two
indication LEDs.
2.5 LCD
A commercially available LCD has been selected to perform the display
functions. This has eight 7-segment digits, each separated by a decimal
point (period). In addition to the digits, it contains eight
downward-pointing chevrons that are used to indicate weekdays and the
operation of the ‘SMART’ mode (please see 4.7.3 SMART — Intelligent
Temperature Prediction for more information).
Central Heating Controller
18
DRM044 — Rev 0
Design Overview
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Design Overview
External Temperature Sensor
2.6 External Temperature Sensor
This is a 2-wire serial device. This allows the sensor to be placed at
some distance from the controller with no degradation of signal.
2.7 Phase-locked Loop
The phase-locked loop (PLL) feature of the MC68HC908LJ12 enables a
low-cost 32.768 kHz crystal, of the type used extensively in digital
watches, to be used to obtain a bus frequency of 2 MHz.
2.8 Low Voltage Inhibit
The low voltage inhibit (LVI) is used to detect when the mains voltage
fails. The microcontroller then powers down before entering STOP
mode. Depending on feature implementation, current consumption can
be reduced to approximately 30 µA.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Design Overview
For More Information On This Product,
Go to: www.freescale.com
19
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Design Overview
Central Heating Controller
20
DRM044 — Rev 0
Design Overview
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
Freescale Semiconductor, Inc...
Section 3. Hardware
Figure 3-1. The Printed Circuit Board
3.1 Phase-locked Loop
The clock generator module (CGM) generates the system clock signal
CGMXCLK, which operates at the crystal-derived frequency of
32.768 kHz. An internal PLL generates the programmable voltage
controlled oscillator (VCO) frequency clock and thus determines the bus
frequency. A Pierce oscillator configuration is used (Figure 3-2.
MC68HC908LJ12 PLL Connections), which uses four external
components with the crystal connected directly between the crystal
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Hardware
For More Information On This Product,
Go to: www.freescale.com
21
Freescale Semiconductor, Inc.
Hardware
amplifier input pin (OSC1) and the crystal amplifier output pin (OSC2).
The PLL analog power and ground pins VDDA and VSSA are connected
to the same potential as VDD and VSS for correct operation.
A filter network is connected to the external capacitor pin (CGMXFC) to
filter out phase corrections.
Freescale Semiconductor, Inc...
Typical values for the network are shown in Figure 3-2.
MC68HC908LJ12 PLL Connections.
OSC1
OSC2
CGMXFC
10M
VDDA
VDDA
DD
VSSA
VSSA
10k
330k
32.768kHz
33nF
15pF
10nF
100nF
15pF
VSS
VSS
XTAL
OSCILLATOR
PLL FILTER
NETWORK
DECOUPLING
CAPACITOR
Figure 3-2. MC68HC908LJ12 PLL Connections
Central Heating Controller
22
DRM044 — Rev 0
Hardware
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Hardware
Temperature
3.2 Temperature
3.2.1 Analog Temperature Measurement
Freescale Semiconductor, Inc...
The internal temperature sensing is achieved using an LM35. This
device gives an output potential of 10 mV/°C and is available in several
versions, which allow a wide range of temperature ranges to be
measured. The device selected for use in the reference design is an
LM35DZ which has a commercial specification of 0–100°C and an
absolute accuracy of ±1°C.
A 5 Vdc supply is used for normal operation of the MC68HC908LJ12;
this is derived from a mains power source, and the reference for the ADC
is also set to this value.
A maximum internal measurement temperature of 40°C was considered
suitable for the application, and an operational amplifier was used to
scale the sensor output voltage to the necessary 0–5 V. Changing the
scaling factor of the operational amplifier and making the necessary
software changes alters this maximum temperature value.
The amplifier amplification factor is determined as follows:
Output of sensor @ 40°C = 40 • 10 mV = 400 mV
Required amplification at this temperature for full scale (Av):
5 V/0.40 = 12.5
A non-inverting configuration has been used, therefore:
Av = 1+ Ra/Rb
Using preferred resistor values:
Av = 1 + 11.5k /1k = 12.5
Using the nearest preferred value components, Ra consists of 10k
connected in series with 1k2, Rb = 1k. These resistors have a ±1%
tolerance value.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Hardware
For More Information On This Product,
Go to: www.freescale.com
23
Freescale Semiconductor, Inc.
Hardware
VDD
LM35
Vin=10mV/°C
+
Vout = (1+Ra/Rb)Vin
(1+Ra/Rb)Vin
½ 33202
+
½ 33202
-
Ra
VSS
Freescale Semiconductor, Inc...
To A2D input
-
Rb
VSS
Figure 3-3. Internal Temperature Sensor and Operational Amplifier Circuit Diagram
The requirements for the operational amplifier are for single supply,
rail-to-rail operation. A 33202 was selected as a suitable device for the
task. This is a dual op-amp and the 'second' stage is connected as a
non-inverting voltage follower.
If required, the internal LM35 may be replaced with another, mounted
external to the case. A 3-pin connector provides the necessary power,
ground and inputs, whilst a 3-pin, on-board header is used to select one
of the two sensors. A screened cable should be used for the external
analog sensor, although input signal filtering ensures that the sensor
may be mounted several metres from the control unit with no undue
signal degradation.
Central Heating Controller
24
DRM044 — Rev 0
Hardware
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Hardware
Temperature
3.2.2 2-wire, Serial Temperature Sensor
The external sensor is a 2-wire serial data device, type DS1721. This
provides a wide range of temperature measurement and gives a serial
data output, in two's complement format.
Freescale Semiconductor, Inc...
Up to eight devices may be used on the bus, each hard-wired to a unique
address set on three address pins. In this application, only one device is
required, therefore address offset zero is selected by connecting all
three address pins to Vss. The DS1721 acts as a slave on the bus, and
data is requested by and transmitted to the MC68HC908LJ12 via the
SDA line, whilst the clock is generated by the microcontroller on the CLK
line.
A separate 'Thermostat' output is available from this sensor, although
this feature is not used in this design.
A 4-pin Molex KK connector provides the power, ground, clock and data
connections to this device.
+5V
10 k
VSS
SDA
DS1721
100nF
CLK
VDD
A0 A1 A2
Gnd
Figure 3-4. External Temperature Sensor Circuit Diagram (DS1721)
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Hardware
For More Information On This Product,
Go to: www.freescale.com
25
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Hardware
3.3 User Interface
3.3.1 Liquid Crystal Display Driver
To obtain maximum life, together with a wide viewing angle on an LCD,
it is necessary to drive it using an alternating current. The LCD driver
module on the MC68HC908LJ12 contains all the necessary driver
circuitry to make driving a multi-segment LCD very straightforward. The
MC68HC908LJ12 allows three arrangements of frontplane/backplane
configurations:
26 frontplanes x 4 backplanes (104 segments)
27 frontplanes x 3 backplanes (81 segments)
27 frontplanes x 1 backplane (27 segments)
A device with a multiplex ratio of 1/3 was selected for this design, to meet
the display requirements listed, together with those of the LCD driver on
board the MC68HC908LJ12 (see Motorola Technical Data section 16.3).
The part selected for this design is a VARITRONIX VIM838, which has
eight 7-segment digits separated by dots, with a downward pointing
arrow under each digit. The display is a transflective, twisted nematic
type. It is available in a ‘leaded’ format, as used in this design, or a 'zebra
stripe' which would be the preferred option for volume production. The
operating frequency range is 30–85 Hz.
3.3.2 Button Detection
Internal pullup resistors are enabled in software. These resistors have a
nominal value of 28k. They are internally terminated to VSS and are
individually pulled to VDD via the function switches.
Central Heating Controller
26
DRM044 — Rev 0
Hardware
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Hardware
Climate Control
3.4 Climate Control
3.4.1 Heating/Cooling
3.4.1.1 Relay Driver
Freescale Semiconductor, Inc...
Two relays are incorporated to control the output heating/cooling
devices, with uncommitted contact ratings of 3 A @ 230 Vac or 30 Vdc.
It is envisaged that the relays will provide ‘pilot’ control to external
contactors or switching devices, to allow control of much greater
electrical loads.
The relay coils are driven from output ports PB0 and PB1 of the
MC68HC908LJ12 via two bipolar junction transistors (BJT), type BC850.
A 'snubber' diode is incorporated in parallel with each relay coil to
suppress the back emf produced by the relay coil at switch-off.
+12V
Rlim
PTBx
Gnd
Figure 3-5. Relay Driver Circuit
Rlim is included to limit the transistor base drive current from the
microcontroller.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Hardware
For More Information On This Product,
Go to: www.freescale.com
27
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Hardware
3.4.2 Override
If the override button is pressed, a check is done to test whether the
climate control is running. If it is running, then it is deactivated and the
next alarm is loaded into the alarm register.
If a program is not running when the override button is pressed, then two
variables are set to the current time plus one hour. The OverrideCheck()
function then compares the TOD and ‘override time’ variables; when
they match, it deactivates the override and the climate control. If a
scheduled program starts while the override is running, then the override
is disabled and control is passed to the program. See Appendix
A.25[operation.c] — OverrideCheck() and A.7[button.c] —
DecodeButtons() for a more detailed account.
3.5 Low Power Modes
Battery life is of great importance in equipment that may experience
extended periods of mains failure, for example, in installations that are
provided with power from a generator or static inverter. Three possible
modes of operation have been considered in the design, in the event of
mains supply failure.
3.5.1 Low Current Operation
The microcontroller detects the change of state on the input pin, and
performs a ‘low power’ mode shutdown, comprising the switching off of
all relays, LEDs and external sensors, allowing the display to continue
displaying the TOD value. The microcontroller essentially runs in a
‘reduced function’ mode, testing the condition of the power-down input
while in a loop cycle. On restoration of the 5 V power supply, the
microcontroller returns to normal operation. The current consumption at
3 V, under these conditions, was measured at approximately 3 mA. This
may be considered rather high if long periods of power-down are
encountered.
Central Heating Controller
28
DRM044 — Rev 0
Hardware
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Hardware
Low Power Modes
3.5.2 Low Voltage Inhibit — STOP Mode
The LVI module is used to detect when the supply voltage falls below a
value of 4.5 V. It generates an interrupt that is used to invoke STOP
mode. TOD display updating is inhibited, although the RTC timekeeping
functions are maintained and register contents preserved. The message
‘bAtt’ is constantly displayed, to indicate mains failure. The LVI interrupt
is still enabled; therefore, when power is restored, the resultant interrupt
wakes the microcontroller from STOP mode. This returns the program to
normal operation once more. The measured battery current in STOP
mode with the LVI module active was approximately 250µA.
3.5.3 Keyboard Interrupt — STOP Mode
The LVI module is used to detect power loss and to invoke STOP mode,
in a similar manner to that described above, the difference in this case
being that, once the power loss is detected, the LVI module is disabled.
This results in a further power saving, although the interrupt necessary
to waken the microcontroller from STOP mode does not now occur on
restoration of the main supply. To circumvent this problem, a BJT has
been added to the KB13 input. The base of this transistor is supplied with
current, via a series resistor, from the 5 V supply rail. Thus, on
restoration of the supply, the transistor simulates a button press and the
resulting keyboard interrupt wakes the microcontroller and restores
normal operation. On power-up, the base of the transistor is pulled low
via a resistor, supplied from the PD0 pin. PD0 is made an input during
STOP mode, changing to an output low on power-up. The transistor
therefore turns off, allowing the button input to resume its normal
function. This method results in a further reduction in standby current,
which has been measured at approximately 30µA. However, this has the
disadvantage of increasing the hardware count. Provision has been
made on the printed circuit board for the inclusion of this transistor and
its associated drive components.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Hardware
For More Information On This Product,
Go to: www.freescale.com
29
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Hardware
Vsupply
Vmicro
Internal Pullup
Pull-Up
KB13
Event Set Button
PD0
Gnd
Figure 3-6. Button Simulation Circuit
3.6 Battery Backup
Since the LCD current consumption is very low, it is used to give a visual
indication of mains failure by indicating ‘bAtt’. The switch-over between
mains power and battery backup is achieved using two diodes. The
diode connected in series with the battery was selected to be a Schottky
type to minimize the voltage drop and, hence, increase the useful
operating life of the battery.
The diode connected in series with the mains-derived supply is a
standard silicon diode, type LL4148. To negate the effect of the voltage
drop across this diode, a similar device is connected in series with the
common terminal of the IC regulator. The effective output from the
regulator is:
Vsupply
= Vout(nom) + Vdiode = 5.0 + 0.6 = 5.6 V
Vmicro
= Vsupply - Vdiode
= 5.6 - 0.6 = 5.0 V
ADC channel 2 is used to monitor the condition of the battery during
normal operation. The nominal terminal voltage of a new lithium cell is
approximately 3.25 V. The ADC is used to detect when the terminal
Central Heating Controller
30
DRM044 — Rev 0
Hardware
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Hardware
Battery Backup
voltage falls below 2.8 V. When this occurs, the display alternates
between normal TOD and temperature and ‘Lo bAtt’, at 2-second
intervals.
Vdiode
Viin
V
LM78L05
Vsupply
Freescale Semiconductor, Inc...
Vmicro
Schottky Diode
Vdiode
Gnd
Figure 3-7. Supply Circuit
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Hardware
For More Information On This Product,
Go to: www.freescale.com
31
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Hardware
Central Heating Controller
32
DRM044 — Rev 0
Hardware
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
Section 4. Software
MicroStartup
Yes
Yes
LV I Rise
STOP
Power Down
LV I Fall
No
No
Button
Press
Yes
Perform
Button
Action
No
Which
Mode
View Temperature
Ext. and User
Temperature
Display
Program Set
Clock Set
Default
Yes
Program Set
Routine
Clock Set
Routine
Low Battery
No
No
Refresh TOD
Toggle
'Lo Batt'
Heating
Operations
Read
Temperatures
Yes
10ms Sync
Figure 4-1. Software Overview
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
33
Freescale Semiconductor, Inc.
Software
A flowchart of the software is shown in Figure 4-1.
4.1 Analog to Digital Converter
Freescale Semiconductor, Inc...
Figure 4-2 provides a summary of the ADC registers in the
MC68HC908LJ12.
Figure 4-2. ADC Register Summary
The 10-bit ADC data is stored in bits 1, 0 of address $003D (ADRH) and
bits 7–0 of address $003E (ADRL). The data was chosen to be
right-justified to allow simple access to the full ten bits by reading from
address $003D.
The code below shows how both bytes of data can be read as one
sixteen bit variable (a2d_bytes).
a2d_bytes._8bit.hibyte = ADRH.reg;
a2d_bytes._8bit.lobyte = ADRL.reg;
a2d_total += a2d_bytes._16bit;
Central Heating Controller
34
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software
Analog to Digital Converter
The ADC clock register is initialized in MicroStartUp(). The operating
frequency for the ADC lies between 32 kHz and 2 MHz. Therefore, the
bus speed is divided by two to give a 1 MHz clock. The ADC is set to
perform a conversion only when required. The means of initiating a
conversion is to write to the ADC status register. The argument channel
is passed to the routine, which selects the appropriate ADC channel.
Freescale Semiconductor, Inc...
unsigned short int ReadA2D(
{
unsigned short int
union uUNSIGNED_INTEGER
unsigned char
unsigned char channel )
a2d_total;
a2d_bytes;
ii;
for ( a2d_total = 0, ii = 0; ii < A2D_SAMPLE_COUNT; ii++ )
{
ADSCR.reg = 0x00|channel;
// a2d interrupts off, clears COCO bit
while ( !ADSCR.bit.COCO ) ;
// Wait for conversion to complete
a2d_bytes._8bit.hibyte = ADRH.reg; // Read high reg first to latch low reg
a2d_bytes._8bit.lobyte = ADRL.reg; // Now read lo reg
a2d_total += a2d_bytes._16bit;
// Update running total
}
a2d_total /= A2D_SAMPLE_COUNT;
return a2d_total;
}
NOTE:
// Average
// Return averaged result
// ReadA2D()
To obtain stable results, the ADC is read eight times and averaged
before returning a value. This technique greatly reduces the effects of
any external noise or ‘jitter'.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
35
Freescale Semiconductor, Inc.
Software
4.2 Serial Communications
Table 4-1 shows the order in which the master and slave must
communicate with each other. The code had to be arranged so that the
MC68HC908LJ12 talks to the slave and listens when necessary.
Table 4-1. DS1721 Sequence
Freescale Semiconductor, Inc...
LJ12
Mode
TX
TX
RX
TX
RX
TX
TX
RX
TX
RX
TX
TX
RX
RX
TX
RX
NOTE:
DS1721
Mode
RX
RX
TX
RX
TX
RX
RX
TX
RX
TX
RX
RX
TX
TX
RX
TX
Data
START
<address, 0>
ACK
0x51
ACK
START
<address, 0>
ACK
0xAA
ACK
START
<address, 1>
ACK
<1 data byte>
ACK
<1 data byte>
Comments
LJ12 initiates a START condition
LJ12 sends DS1721 address, read = 0
DS1721 generates acknowledge bit
LJ12 sends start convert T protocol
DS1721 generates acknowledge bit
LJ12 initiates a repeated START condition
LJ12 sends DS1721 address, read = 0
DS1721 generates acknowledge bit
LJ12 sends read temperature protocol
DS1721 generates acknowledge bit
LJ12 initiates a repeated START condition
LJ12 sends DS1721 address, read = 1
DS1721 generates acknowledge bit
DS1721 transmits MSB of temperature
LJ12 generates acknowledge bit
DS1721 transmits LSB of temperature
For more information, please refer to the DS1721 data sheet.
A delay function provides an in-line delay while the MC68HC908LJ12
waits for an acknowledge bit or temperature data. The DS1721 operates
at a maximum of 400 kHz; therefore, a delay of 5 µs was chosen to allow
ample time. The main function that performs the above actions is
ExternalTemperatureRead(). The DS1721 has a tolerance of ±1 degree;
therefore, a calibration constant (EXTERNAL_CALIBRATION) exists to
compensate (see Appendix A.19 [i2c.c] —
ExternalTemperatureRead()). The Flash capabilities of the
MC68HC908LJ12 can allow this calibration value to be inserted as part
of the end of line test sequence in a production run, allowing the overall
accuracy of the temperature reading to be improved.
Central Heating Controller
36
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software
Real Time Clock
4.3 Real Time Clock
Freescale Semiconductor, Inc...
The MC68HC908LJ12 has a built in RTC module comprising the
registers shown in Figure 4-3.
Figure 4-3. Real Time Clock Registers
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
37
Freescale Semiconductor, Inc.
Software
Each register rolls over after the appropriate number has been reached.
As shown in Figure 4-3. Real Time Clock Registers, there are also two
alarm registers: minutes and hours. When the RTC hour and minute
registers are equal to the alarm registers, the alarm flag is set and can
generate an interrupt, if desired.
The month, year and chronograph data registers are not used in this
application, but may be incorporated, if more advanced timekeeping
capabilities are required.
Freescale Semiconductor, Inc...
There is a wide range of flags available with their associated interrupts,
ranging from 10 ms to 1 day. However, only the 10 ms interrupt is used
in this application. It is used to synchronize the main loop to 10 ms for
precision in control. Although not used in this application, the 10 ms
synchronization is useful if other types of ‘mains synchronous’ output
switching devices (triacs, for example) are employed (assuming a 50 Hz
mains supply).
///////////////
// 10ms sync //
///////////////
while ( !flags1.bit._10MS ) ;
flags1.bit._10MS = 0;
// Waiting for interrupt
// reset, for next loop iteration
The main program runs for about 2 ms per cycle. However, when the
temperatures are refreshed (every five seconds) the period increases to
about 4 ms per cycle. This is well within the 10 ms interrupt that has
been used, and gives ample time for the loop synchronization to occur.
RTCCR1 controls which interrupts are active and, in this case:
// RTC setup
RTCCR2.reg
= 0x60;
RTCCR1.reg
= 0x40;
RTCCR2.bit.RTCE = 1;
//
//
//
//
rtc off, set for 32.768kHz xtal...
chronograph setup
CHRIE set
...all done, start RTC
RTCCR2 is set up for a 32.768 kHz crystal with the chronograph counter
cleared and enabled. Once both registers are set, the RTC is initiated.
Central Heating Controller
38
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software
Real Time Clock
The TenMsSynchronise() function was set up to toggle variables at
different time intervals based on the 10 ms main loop. Toggles are set
up for 0.25, 0.5 and 1 second intervals (see Appendix A.25
[operation.c] — TenMsSynchronise() for a more detailed account).
void TenMsSynchronise( void )
{
if ( ++_10ms%25
== 0 )
{
_0P25sec
^= 0x01;
Freescale Semiconductor, Inc...
if ( _10ms%50
{
SFLASH
}
== 0 )
^= 0x01;
if ( _10ms%100 == 0 )
{
one_second ^= 0x01;
_5sectick++;
}
if ( _10ms >= 200 )
{
_10ms = 0;
}
}
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
every 0.25s
every 0.5s
every 1.0s
Unsigned char, 256 max
reset for next
TenMsSynchronise()
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
39
Freescale Semiconductor, Inc.
Software
4.4 Phase-lock Loop
A 2 MHz bus speed was chosen to keep current drain as low as possible
while still allowing the maximum main loop cycle time to remain
comfortably inside the 10 ms synchronization.
Table 4-2. PLL Frequency Table
Freescale Semiconductor, Inc...
CGMPCLK (MHz)
8.0
9.8304
10.0
16.0
19.6608
20.0
29.4912
32.0
16.0
8.0
4.0
fBUS (MHz)
2.0
2.5
2.5
4.0
4.9
5.0
7.4
8.0
4.0
2.0
1.0
fRCLK (kHz)
32.768
32.768
32.768
32.768
32.768
32.768
32.768
32.768
32.768
32.768
32.768
R
1
1
1
1
1
1
1
1
1
1
1
N
f5
12c
132
1e9
258
263
384
3d1
1e9
f5
7b
P
0
0
0
0
0
0
0
0
1
2
3
E
0
1
1
1
2
2
2
2
2
2
2
L
d1
80
83
d1
80
82
c0
d0
d0
d0
d0
The code below initializes the PLL at the desired frequency:
void InitialisePLL( void )
{
PBWC.reg
PTCL.reg
PMS
PMRS.reg
PMDS.reg
=
=
=
=
=
0x80;
0x00;
0x00F5;
0xD1;
0x01;
PTCL.bit.PLLON = 1;
//////////////////////////////////
// auto mode
//
// settings here...
//
// as described in...
//
// the MC68HC908LJ12
//
// Rev2.0 data book section
//
// 8.4.6 page 113
//
// turn pll on after settings
//
// 'set'
//
//////////////////////////////////
///////////////////////////////////////////////////
// wait for the required frequency to be reached //
///////////////////////////////////////////////////
ServiceWatchDog();
while ( !PBWC.bit.LOCK );
PTCL.bit.BCS = 1;
}
// pll clock drives CGMOUT
// InitialisePLL()
Central Heating Controller
40
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software
Temperature
4.5 Temperature
All temperatures are updated every five seconds to prevent display jitter,
which is most noticeable with decimal values. In normal mode, the
internal temperature is displayed on the right-hand side of the display.
The function InsideTemperature() is used to calculate this value.
Freescale Semiconductor, Inc...
The ADC is read and stored in a variable. This variable is then
manipulated to correspond to the maximum and minimum temperature
scale. The calculations are shown below:
//////////////////////////////////////////////////////////////////////////////
// The internal temperature calculations:
//
//
//
// The A2D byte is multiplied by 49 to convert it to 10000 * the input
//
// voltage. It is then / by 100 to convert it to 100 * the input voltage.//
//
//
// The result is then * by 41 which is the maximum temperature that can //
// be read by the A2D, and / by 5 which is the maximum input voltage.
//
//
//
// Finally the result is / by 10 to leave it in a manageable form
//
//
//
// eg.
internal temperature = 26.0CA2D function returns 650
//
//
(49 * 650)/100 = 316
(316*41)/50 = 259 (0.33% error)
//
//////////////////////////////////////////////////////////////////////////////
internal_temperature = ( 49 * ReadA2D( CHANNEL0 ))/100;
internal_temperature = ( internal_temperature * 41 )/( 5 * 10 );
NOTE:
The multiples of 10 are used to allow the integers to represent decimal
values.
This calculated internal temperature is then manipulated so that there
are two variables, one stores any multiples of ten and the other stores
the units and decimal values. These are then sent to the
DisplayNumbers() function to be displayed on screen.
This temperature display can also be called before the five seconds
count to refresh the display when in default mode. This is useful when
returning to default mode; otherwise it could take up to five seconds to
display the internal temperature. The refresh variable is set in order to
refresh the display.
When the temperature button is held down, the program runs in
temperature view mode. The external temperature replaces the internal
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
41
Freescale Semiconductor, Inc.
Software
temperature and the last or current user temperature is displayed on the
left-hand side of the screen. The letters ‘P’ and ‘E’ are also displayed to
aid the user in temperature type recognition. While in this mode the user
can manually change the desired temperature for the current override or
climate cycle by using the increment and decrement buttons.
NOTE:
This does not affect the stored program in memory.
Freescale Semiconductor, Inc...
The serial communication returns two bytes of information, the ‘hibyte’
and the ‘lobyte’. Both are in two’s complement form. After conversion,
one is subtracted from the ‘hibyte’. This is because the 0.5 bit is treated
as if it were a one by the DS1721.
NOTE:
For more information, please see the DS1721 data sheet.
The ‘lobyte’ is then converted to a decimal as follows:
////////////////////////////////
// fractional part processing //
////////////////////////////////
dec = 0;
if ( lobyte.byte >= 0x10 )
// is bit 4 or greater, set
{
if ( lobyte.bit.bit7 )
{
dec += 5000;
// 0.5*10000
}
if ( lobyte.bit.bit6 )
{
dec += 2500;
// 0.25*10000
}
if ( lobyte.bit.bit5 )
{
dec += 1250;
// 0.125*10000
}
if ( lobyte.bit.bit4 )
{
dec += 625;
// 0.0625*10000
}
// checking for '0.05' second dec place rounding
if ( dec%1000 >= 500 )
// is remainder >= 0.05
{
dec += 1000;
// 0.1 correction on first decimal
}
// div by 1000 (not 10000) to
dec /= 1000;
// produce integer value for first
// decimal place
Central Heating Controller
42
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software
User Interface
In a similar manner to the methods used in decoding the internal
temperature, the values are manipulated so that they can be sent to the
function DisplayNumber() where they are displayed.
4.6 User Interface
Freescale Semiconductor, Inc...
4.6.1 Liquid Crystal Display Driver
Time
Time of Day
Day
Temperature
Temperaturedisplay
Display
Figure 4-4. LCD Layout
The LCD has a operating frequency range of 30–85 Hz. The 1/3 duty
cycle was selected as the LCD has three backplanes. The 42.7 Hz
frequency was therefore selected as being the optimum choice for a 1/3
duty cycle and a 32.768 kHz crystal.
Table 4-3. LCD Frequency Table
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
43
Freescale Semiconductor, Inc.
Software
For optimum optical performance the fast charge selection is set to a
time period of LCDCLK/64. This value was derived empirically to
achieve a good contrast ratio for the display used.
Freescale Semiconductor, Inc...
/////////////////////
// Display Startup //
/////////////////////
LCDCLK.byte = 0x29;
//
= 00101001;
//
|||||||
//
|||||||___ Base Clock/Frame Rate
//
||||||____
"
"
"
"
//
|||||_____
"
"
"
"
//
||||______ LCD Duty Selection
//
|||_______ "
"
"
//
||________ Fast Charge
//
|_________ "
"
For the LCD control register, the LCD, fast charge and low current
options were all enabled and a high bias voltage was applied to obtain
the optimum viewing angle.
LCDCR.reg
//
//
//
//
//
//
//
//
//
//
= 0xbc;
= 10111100;
||||||||
||||||||___ Contrast Controls
|||||||____
"
"
||||||_____
"
"
|||||______
"
"
||||_______ Low Current
|||________ Fast Charge
||_________ N/A
|__________ LCD Enable (1 = enabled)
At start-up, the segments are lit for one second as a screen test to
confirm that all segments are operational.
Central Heating Controller
44
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software
User Interface
Table 4-4 and Table 4-5 show the relationship between the ‘control’
hexadecimal codes, and the displayed values for the LCD.
Table 4-4. Bit to Segment Correlation – 1st Digit
Freescale Semiconductor, Inc...
Number
0
1
2
3
4
5
6
7
8
9
DP
AN
7
-0
0
0
0
0
0
0
0
0
0
0
0
6
D
1
0
1
1
0
1
1
0
1
0
0
0
5
G
0
0
1
1
1
1
1
0
1
1
0
0
LDAT1
4
3
A
-1
0
0
0
1
0
1
0
0
0
1
0
1
0
1
0
1
0
1
0
0
0
0
0
Hex
2
DP
0
0
0
0
0
0
0
0
0
0
1
0
1
C
1
1
0
1
1
1
1
1
1
1
0
0
0
B
1
1
1
1
1
0
0
1
1
1
0
0
53
03
71
73
23
72
72
13
73
33
04
00
3
-0
0
0
0
0
0
0
0
0
0
0
0
LDAT2
2
1
^
E
0
1
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
1
0
Hex
0
F
1
0
0
0
1
1
1
0
1
1
0
0
3
0
2
0
1
1
3
0
3
1
0
4
Table 4-5. Bit to Segment Correlation – 2nd Digit
Number
0
1
2
3
4
5
6
7
8
9
DP
AN
7
-0
0
0
0
0
0
0
0
0
0
0
0
6
^
0
0
0
0
0
0
0
0
0
0
0
1
5
E
1
0
1
0
0
0
1
0
1
0
0
0
LDAT3
4
3
F
-1
0
0
0
0
0
0
0
1
0
1
0
1
0
0
0
1
0
1
0
0
0
0
0
Hex
2
D
1
0
1
1
0
1
1
0
1
0
0
0
1
G
0
0
1
1
1
1
1
0
1
1
0
0
0
A
1
0
1
1
0
1
1
1
1
1
0
0
35
00
27
07
12
17
37
01
37
13
00
40
7
-0
0
0
0
0
0
0
0
0
0
0
0
LDAT2
6
5
DP C
0
1
0
1
0
0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
0
0
0
Hex
4
B
1
1
1
1
1
0
0
1
1
1
0
0
3
3
1
3
3
2
2
3
3
3
4
0
The tables also allow direct access to individual segments for displaying
a chevron or decimal point; for example:
LDAT1.bit.bit2 = 1;
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
45
Freescale Semiconductor, Inc.
Software
This displays a decimal point on the far right hand digit.
Single
Digit Frontplane
Frontplane
Single Digit
aa
Single
Digit Backplane
Backplane
Single Digit
a
a
f
ee
g
b
f
g
c
ee
BP0 (a,
(a,bbcommoned)
commoned)
BP0
BP1 (c,
(c,f,f,ggcommoned)
commoned)
BP1
ee
Freescale Semiconductor, Inc...
d
b
c
d
FP2 (b,
(b,cccommoned)
commoned)
FP2
BP2 (d,
(d,eecommoned)
commoned)
BP2
FP1 (a,
(a,d,d,ggcommoned)
commoned)
FP1
FP0 (e,
(e,f fcommoned)
commoned)
FP0
Figure 4-5. Segment Labelling
The DisplayNumber() function is used to decode a single integer and
display it in the desired location on screen. The number to be displayed
and the digit location are passed to the function when it is called. Initially,
the function must determine whether the digit number is odd or even so
that it can address the correct registers. This is done by taking the
modulus of 2 from the number and checking for a one or zero. Once this
has been established, the digit variable is altered to accommodate the
non-linear relationship between the variable and the registers, resulting
from each digit occupying one-and-a-half display registers.
if ( digit%2 )
{
switch ( digit )
{
case 1: digit--;break;
case 5: digit++;break;
case 7: digit += 2; break;
}
// odd digit check
// Compensates for 1.5 bytes
// being used per digit
//
After the correct sets of registers are addressed, the numeric variable is
decoded into its hexadecimal code value, which is then placed into the
registers.
Central Heating Controller
46
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software
User Interface
4.6.2 Button Detection
Eight buttons are used in this application. All eight of the designated
keyboard pins (PTA bits 0–3 and PTD bits 4–7) are used for this
purpose. The function ReadButtons() is called every 10 ms to process a
button press. Each button has its own assigned pattern with two
additional patterns for simultaneous button presses in temperature view
mode.
Freescale Semiconductor, Inc...
////////////////////
// button decodes //
////////////////////
#define DEFAULT_BUTTONS
#define BUTTON_1
#define BUTTON_2
#define BUTTON_3
#define BUTTON_4
#define BUTTON_5
#define BUTTON_6
#define BUTTON_7
#define BUTTON_8
#define BUTTON_5_DEC
#define BUTTON_5_INC
0xff
0xfe
0xfd
0xfb
0xf7
0xef
0xdf
0xbf
0x7f
0xed
0xeb
//
//
//
//
//
//
//
//
//
//
//
11111111
11111110
11111101
11111011
11110111
11101111
11011111
10111111
01111111
11101101
11101011
The algorithm used incorporates a button press and a button release
routine. The ability to have an auto-scroll is included; this occurs when a
button is pressed, and remains pressed for the duration of the
de-bounce counter. This condition will occur when performing an
adjustment of any time value. A single press and hold of the increment
or decrement button will cause the auto-scroll to operate. The auto-scroll
feature can be enabled/disabled on any button, as required. The flag that
allows this feature is ‘button_flags.bit.AUTO_SCROLL'. When the flag is
set, the auto-scroll feature is enabled.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
47
Freescale Semiconductor, Inc.
Software
Read Buttons
Freescale Semiconductor, Inc...
button press status
NO BUTTON
PRESS
press detected
BEING
PRESSED
N
Y
RELEASED
button pattern
back to default
N
release counter = 0
N
button pattern
still default
Y
Y
‘button_press_status’ =
BEING_PRESSED
N
pattern has
changed ,but is
not default,
start again.
NO BUTTON
PRESS
original pressed
pattern
Y
N
NO BUTTON
PRESS
BEING
PRESSED
Y
Y
Y
debounced yet
1st decode
N
N
Y
10ms main()
synchronising
point
decode button
auto scroll
enabled
N
Figure 4-6. Button Processing Flow Chart
Central Heating Controller
48
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software
Climate Control
4.7 Climate Control
4.7.1 Heating/Cooling
A ‘Mode' button allows the selection of one of four modes.
•
Automatic — both heating and cooling will be active
•
Heat — only the heating will be active
•
Cool — only the cooling will be active
•
Off — climate control will never be active
The mode of operation is indicated by two LED indicators, which also
serve to indicate heating/cooling activity by flashing at 1 Hz when active.
Relays are used as control devices for the heating and cooling functions.
4.7.2 Override
If the override button is pressed, a check is done to test whether the
climate control is running. If it is running, then it is deactivated and the
next alarm is loaded into the alarm register.
If a program is not running when the override button is pressed, two
variables are set to the current time plus one hour. The OverrideCheck()
function then compares the TOD and ‘override time’ variables. When
they match, it deactivates the override and the climate control. If a
scheduled program starts while the override is running, then the override
is disabled and control is passed to the program. See Appendix A.26
[operation.h] — OverrideCheck() and Appendix A.7 [button.c] —
DecodeButtons() for a more detailed account.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
49
Freescale Semiconductor, Inc.
Software
4.7.3 SMART — Intelligent Temperature Prediction
The ‘SMART’ function allows the controller to modify the user’s
activation times to take account of internal and external temperature
variations. ‘SMART’ mode aims to achieve the user temperature at the
desired time of building occupation. This is independent of external
temperature variations, but is limited by the ‘SMART’ prediction cap.
Freescale Semiconductor, Inc...
When the climate control is activated the user temperature is compared
with the internal temperature. If the internal temperature is below the
hysteresis band (user temperature - one degree), the heating will switch
on, as long as the correct mode is active. If the internal temperature is
above or equal to the user temperature, the cooling will activate provided
that the correct mode is active. See A.25 [operation.c] —
ClimateControl() for a more detailed account.
If the SMART button is pressed, then the SMART chevron will be
displayed. When in SMART mode, an algorithm examines the internal,
external and desired temperatures, one hour prior to the
commencement of the program. A predictive calculation is then
performed, based on the following method:
A percentage of internal temperature to desired temperature is
calculated. The difference of this value from 100% (x) is used
below.
The ratio of internal temperature and external temperature is
taken and multiplied by the previously calculated value, 'x'. This
value is then multiplied by a scaling factor of 3, to enable correct
operation.
Finally this time is subtracted from the programmed 'on time'.
The new calculated 'on time' is then loaded into the alarm register. The
maximum SMART time is capped at 50 minutes to prevent the user's
heating/cooling system from being activated for extended time periods.
The actual SMART algorithm is as follows.
Central Heating Controller
50
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software
Climate Control
// user_temperature;
// Smart calculations, stage 1
if ( smart_time > 1000 )
// For Smart cooling
{
//
smart_time -= 1000;
//
}
//
else
// For Smart heating
{
//
smart_time = 1000 - smart_time;
//
}
//
smart_time = 3 * (( smart_time * internal_temperature ) /
( 100 * external_temperature
));
// Smart calculations, stage 2
Freescale Semiconductor, Inc...
smart_time = ( 1000 * internal_temperature )
NOTE:
The multiples of 10 are used to allow the integers to represent decimal
values. This prevents loss of accuracy in rounding errors.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
51
Freescale Semiconductor, Inc.
Software
4.8 Programming Modes
4.8.1 Clock
Freescale Semiconductor, Inc...
When in 'clock set' mode, the main program branches to the function
Cset(). A switch statement is used to determine which value is being set.
The first case is the 'hour set'. Every 0.25 seconds the hour digits toggle
on/off to indicate the variable, which is being set. The 0.25 second toggle
is used for this purpose, see 4.3 Real Time Clock. On clearing the
display, the minute digits and the chevrons are refreshed, so that they
do not appear to have turned off. If the increment or decrement buttons
are pressed, the ReadButtons() function decodes the button press (see
4.6.2 Button Detection) and alters the hour digit accordingly. As
previously mentioned, the increment and decrement are capable of
auto-scrolling so the user can keep the button pressed and the
corresponding register will scroll round the values. A maximum and
minimum cap is already in place in the RTC registers, however, when the
maximum is reached, the next increment resets the RTC register to zero.
When the minimum is reached, the next decrement sets the register to
its maximum value.
case HOUR_SET:
if ( _0P25sec )
{
SFLASH = 1;
HRClr();
MINClr();
ChevronRefresh();
}
else
{
ClearDisplay();
LDAT10.bit.bit2 = 1;
MINClr();
ChevronRefresh();
}
break;
// For every other 1/4 of a second
// Displays divider decimal point
// Refreshes hour digits
// Refreshes minute digits
// Allows hour digits to flash
// Decimal point remains constant
// Minute digits refreshed
After pressing the ‘clock set’ button, the programming mode switches to
‘minute set’. This function performs in the same manner as the ‘hour set’,
with the exception that the minutes now toggle instead of the hours.
Again, the register ‘rolls over’ when required.
Central Heating Controller
52
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software
Programming Modes
The next program mode is the Day of Week (DOW). The first thing that
is done is to remove all previous chevrons to prevent ‘ghosting’. The
chevron bits can be directly accessed using a ‘bit set’ or ‘bit clear’ (see
4.6.1 Liquid Crystal Display Driver). Again, the 0.25-second toggle is
used to make the chevron flash. The increment and decrement buttons
move the chevron from Monday through Sunday. Sunday is equal to
0x00 in the DOW register so, when Saturday is reached and the
increment button is pressed, the DOW register is reset to zero. Again, a
reverse process is implemented for decrement.
When the clock set button is pressed again, the set mode returns to
default and the main loop no longer branches to the function. There are
no variables to store or manipulate, because the clock set function
changes the RTC registers directly. Whenever the clock set button is
pressed, the RTC second register is reset so that the TOD can be set
precisely, if required.
4.8.2 Climate Control Cycles
Up to four individual on/off time periods may be set at any point in time.
Each period may be set for either a single event up to seven days in
advance, or for multiple timing events at the same time each day. The
daily settings can be made for weekdays, weekends or individual days.
The time setting of a program works in a very similar way to the clock set
but with a few additional modes.
On entering the alarm set mode, the first screen displayed is ‘Pr’ followed
by the number ‘1’ flashing. The increment and decrement buttons can be
used to select a program. The maximum number of programs in this
application is four. Increasing the data structure and the button cap limits
can modify this.
NOTE:
Any new programs must be added to the enum in define.h before the
'NO_PROGRAM' declaration (see Appendix A.13 [define.h]).
The user now has two options. Pressing the ‘Prog’ button will continue
to set a new program. However, pressing the temperature/clear button
will erase the program that is currently flashing from the stored memory.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
53
Freescale Semiconductor, Inc.
Software
Setting the off times equal to the on times does this. The ignore condition
is implemented in Alarm.c (see Appendix A.3 [Alarm.c]).
Freescale Semiconductor, Inc...
After the user has pressed the alarm set button, the DOW selection
mode is activated. The selected program number is then displayed
followed by ‘On’. Once in this mode, the user can press the increment
and decrement buttons in the same way as the DOW mode in clock set.
There are, however, two additional selections. The user can set
programs for individual days, Monday–Friday or Saturday–Sunday. This
gives flexibility to users who may have the same program patterns for the
weekdays but would perhaps prefer the weekends to be different.
The next mode is the ‘On Time’ set. This operates in exactly the same
way as the clock set function, but it is repeated for ‘Off Time’ set also
(see 4.8.1 Clock). Once ‘Off Time’ is activated, the displayed ‘On’
changes to ‘Off’.
After the on and off times are set, the’ final mode is the user temperature
set. A ‘t’ is then displayed instead of ‘Off’ and a default value of ‘20’
flashes next to a ‘c’. Again, increment and decrement change this value,
which has a maximum of 40 and a minimum of 0. The scaling of the
measurement circuitry sets the upper limit. The minimum is set to 0, as
the temperature sensor cannot detect negative values, and it is unlikely
that the building temperature would fall to that value. If the maximum or
minimum is reached, the rollover value is set to a default of 20°C.
At the end of each mode, the data that has just been set is stored into
the ‘program’ structure. The structure stores six different variables:
•
On hour
•
On minute
•
DOW
•
Off hour
•
Off minute
•
Desired temperature
Once the temperature has been set, the ProCheck() function is called to
check if the new program overlaps with any other programs that have
Central Heating Controller
54
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software
Programming Modes
Freescale Semiconductor, Inc...
already been stored. The on and off data is converted into two variables
by multiplying the hours by 60 and then adding the minutes to this value.
These two variables are then checked with the already stored programs,
which are converted into the same format (see Appendix A.5
[Alarmset.c] — ProCheck() for a more detailed account). If an overlap
is found, then ‘Err’ is displayed, followed by the stored program, which
has the conflict, then ‘-’ followed by the new program number that has
been entered. The error screen is displayed for one second. The
program is then cancelled by altering the off times to the ignore
condition. If no error is found then the program continues as normal.
After the ProCheck() function, the Alarm() function is called. The alarm
function is used to load the next scheduled program into the alarm
registers.
When the alarm function is called, a check is done to see if the climate
control is running. If it is, then the corresponding ‘Off time’ is loaded into
the alarm register in preparation for the program ending. Otherwise, a
check is done to determine the next scheduled program. This is done by
checking that the DOW is correct and then converting the on times into
the same format as mentioned previously in ProCheck(). Once the next
on time is loaded into the alarm register, one hour is subtracted and
stored in two separate variables for use in the 'SMART' function (see
4.7.3 SMART — Intelligent Temperature Prediction).
The Alarm function is called when: a new alarm has just been
programmed, an alarm flag is detected, or at the beginning of a new day.
If no programs were active over midnight, the next day’s programs would
not be loaded into the alarm register. For this reason, the last call has
been added. The day flag is checked and, when it is set, as long as a
program is not running, the alarm function is called again. The day flag
is then reset in preparation for the next day.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
55
Freescale Semiconductor, Inc.
Software
4.9 Low Power Modes
4.9.1 Low Current Operation
Freescale Semiconductor, Inc...
Firstly, a measurement of the supply voltage should be taken using
channel 1 of the ADC. A function PowerFailure() is then needed to detect
if the supply voltage has dropped below the desired level. If a reduction
is detected, the MC68HC908LJ12 is prepared for low current operation.
This is done in a very similar way to preparing for STOP mode (see 4.9.2
Low Voltage Inhibit — STOP Mode). The climate control relays and
LEDs are switched off. Ports B and D are then set to be inputs to reduce
any current drain. The ten millisecond interrupt is disabled and the LCD
control register (LCDCR) is modified to decrease the bias voltage for
battery operation. The program then remains in a loop, refreshing the
TOD. Also, ‘Fail’ is displayed on the right-hand side of the display to
show that the supply has failed. The program remains in the loop until
the supply voltage rises again.
void PowerFailure( void )
{
if ( LowPower )
{
PTB.byte = 0x00;
DDRA.reg = 0x00;
DDRB.reg = 0x00;
DDRD.reg = 0x00;
RTCCR1.bit.CHRIE = 0;
SFLASH = 1;
LCDCR.reg
= 0xb0;
while ( !PTA.bit.bit5 )
{
ServiceWatchDog();
HRClr();
MINClr();
LDAT6.byte = 0x33;
LDAT5.byte = 0x03;
LDAT4.byte = 0x33;
LDAT3.byte = 0x30;
LDAT2.byte = 0x03;
LDAT1.byte = 0x40;
}
RTCCR2.bit.CHRCLR = 1;
MicroStartUp();
Alarm();
}
}
// Turn off heating/cooling & LED's
// Set all ports to input
//
//
// Disables RTC 100Hz interrupt
// Decimal point after hour digits
// Adjust LCD to lower power mode
// While in low power mode
// Refresh TOD
//
// Display 'FAIL'
//
//
//
//
//
// Reset chronograph counter
// Reinitialises the micro
// Load next alarm into the register
// PowerFailure()
Central Heating Controller
56
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software
Low Power Modes
When the supply voltage returns, the program runs the same
initialisation routines as the LVI and keyboard methods (see 4.9.2 Low
Voltage Inhibit — STOP Mode). The program then returns to normal
operation.
4.9.2 Low Voltage Inhibit — STOP Mode
Freescale Semiconductor, Inc...
In this application, the LVI is used to detect when the main supply
voltage drops or rises. When a drop in supply voltage is detected, the LVI
module generates an interrupt. Within the interrupt routine, the climate
control relays and LEDs are switched off. Ports B and D are then set to
be inputs to reduce current drain. The LCD is cleared and the control
register (LCDCR) is modified to decrease the bias voltage, so that it can
be read when operating from the low voltage of the battery. ‘bAtt’ is
displayed on the right-hand side of the screen to tell the user that the
controller is now running from the battery.
In addition to the above, the ten millisecond chronograph interrupt must
also be disabled by changing the correct RTC control register
(RTCCR1). Once the above has been completed, the MC68HC908LJ12
is brought into STOP mode by calling the function STOP().
#pragma TRAP_PROC
void LVI_INTERRUPT( void )
{
ServiceWatchDog();
PTB.byte = 0x00;
LVISR.bit.LVIIAK = 1;
// Turn off heating/cooling & LED's
// Resets the interrupt flag
if ( LVISR.bit.LVIOUT )
{
DDRB.reg = 0x00;
DDRD.reg = 0x00;
RTCCR1.bit.CHRIE = 0;
// Set ports to input to reduce...
// current drain
// Disables RTC 100Hz interrupt
ClearDisplay();
LCDCR.reg = 0xb0;
LDAT6.byte = 0x36;
LDAT5.byte = 0x23;
LDAT4.byte = 0x33;
LDAT3.byte = 0x36;
LDAT2.byte = 0x03;
LDAT1.byte = 0x60;
// Adjust LCD to lower power mode
// Displays 'bAtt'
//
//
//
//
//
STOP();
}
else
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
57
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software
{
RTCCR2.bit.CHRCLR = 1;
MicroStartUp();
Alarm();
//
//
//
//
Reset chronograph counter
Return micro to previous state
Load next alarm into the
register.
}
}
NOTE:
// LVI_INTERRUPT()
The LVIOUT flag is used to detect whether the supply voltage has risen
or fallen.
When the supply voltage returns, the LVI issues another interrupt to
bring the MC68HC908LJ12 out of STOP mode. The interrupt routine
then clears the chronograph counter (preventing a ten millisecond
interrupt occurring instantly) and runs the initialization function
MicroStartUp() (see Appendix A.27 [startup.c]). Once the registers of the
MC68HC908LJ12 have been re-initialized, the Alarm() function is called
to allow the next program to be loaded into the alarm register. Normal
operation is then resumed.
4.9.3 Keyboard Interrupt — STOP Mode
If a keyboard interrupt is required to bring the MC68HC908LJ12 out of
STOP mode, then the keyboard interrupts must be initialized before
entering STOP mode (see MC68HC908LJ12 Technical Data, page
367). The LVI module should be used in a similar way to above.
However, the module then must be disabled to save current
consumption. This is done in configuration register one (CONFIG1). By
clearing the LVISTOP bit, the LVI module is automatically disabled
during STOP mode. See below for the LVI interrupt function.
#pragma TRAP_PROC
void LVI_INTERRUPT( void )
{
ServiceWatchDog();
PTB.byte = 0x00;
LVISR.bit.LVIIAK = 1;
// Turn off heating/cooling & LEDs
// Resets the interrupt flag
DDRB.reg = 0x00;
DDRD.reg = 0x00;
RTCCR1.bit.CHRIE = 0;
// Set ports to input to reduce...
// current drain
// Disables RTC 100Hz interrupt
ClearDisplay();
LCDCR.reg = 0xb0;
LDAT6.byte = 0x36;
// Adjust LCD to lower power mode
// Displays 'bAtt'
Central Heating Controller
58
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software
Battery Backup
LDAT5.byte
LDAT4.byte
LDAT3.byte
LDAT2.byte
LDAT1.byte
=
=
=
=
=
0x23;
0x33;
0x36;
0x03;
0x60;
//
//
//
//
//
KBSCR.bit.IMASK = 1;
KBIER.byte
= 0xff;
KBSCR.bit.ACKK = 1;
KBSCR.bit.IMASK = 0;
//
//
//
//
Mask interrupt flag
Enable keyboard interrupts
Clear interrupt flag
Unmask interrupt flag
STOP();
}
// LVI_INTERRUPT()
In addition to the LVI interrupt function, a keyboard interrupt function
must also be added. When a keyboard interrupt is detected, the
MC68HC908LJ12 is brought out of STOP mode and performs the
interrupt routine. This routine must re-initialize the MC68HC908LJ12. An
example routine is shown below.
#pragma TRAP_PROC
void KEYBOARD_INTERRUPT( void )
{
ServiceWatchDog();
KBSCR.bit.IMASK = 1;
KBSCR.bit.ACKK = 1;
// This prevents further interrupts
//
RTCCR2.bit.CHRCLR = 1;
MicroStartUp();
Alarm();
}
// Reinitialises the micro
// Load next alarm into the register
// KEYBOARD_INTERRUPT()
4.10 Battery Backup
Every five seconds, the backup battery voltage is read using channel 2
of the ADC. This value is then accessed in default mode and compared
with a predefined value (see Appendix A.13 [define.h] — LOWBATT). If
the voltage is less than the predefined value then the display toggles
every two seconds between the TOD/internal temperature and ‘Lo bAtt’.
void TimeRefresh( void )
{
if ( BatteryCheck <= LOWBATT && two_second )
{
LDAT12.byte = 0x00;
// Clears unused digit
LDAT11.byte = 0x03;
// Displays 'Lo'
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
59
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software
LDAT10.byte = 0x40;
LDAT9.byte = 0x26;
LDAT8.byte = 0x20;
LDAT7.byte = 0x00;
LDAT6.byte = 0x36;
LDAT5.byte = 0x23;
LDAT4.byte = 0x33;
LDAT3.byte = 0x36;
LDAT2.byte = 0x03;
LDAT1.byte = 0x60;
}
else
{
LDAT6.byte = 0x00;
LDAT5.byte &= 0x0f;
MINClr();
HRClr();
Refresh = 1;
ChevronRefresh();
}
}
//
//
//
// Clears unused digit
// Displays 'bAtt'
//
//
//
//
//
// Removes the 'b'
//
// Refresh TOD display
//
// Refresh internal temperature
// TimeRefresh()
The predefined value is determined as follows:
The minimum recommended voltage for the MC68HC908LJ12 is
3.3 V ± 10%. Therefore ‘Lo bAtt’ should be displayed when the
battery voltage is 2.7 V or less. To convert 2.7 V into ADC counts,
it is divided by the reference voltage (4.8 V) and multiplied by 1024
as the ADC is set at 10-bit resolution. This gives a value of 576
counts.
4.11 On-board Flash Programming
The compiler used for the project was Metroworks Code Warrior IDE
v5.2.1149. The debugging tool that is incorporated into the IDE is very
useful. It allows quick and easy communication with the development kit
for stepping through the code.
Central Heating Controller
60
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Software
On-board Flash Programming
Figure 4-7. Metroworks Codewarrior Screenshot
The debugger also has the option to program the MC68HC908LJ12. The
following method was used for this project. P&E’s programming software
was installed (see Motorola’s data CD–ROM). The target settings were
then changed to the P&E software. To select this, go to the menu
‘component’ —> ‘set target’. Once there, change the target interface to
the ‘P&E target interface’. The P&E software is then loaded. Once
complete, enter programming mode by going to the menu ‘PEDebug’
—> ‘Mode:’ and selecting ‘In-Circuit Debug/Programming’. To load the
project onto the microcontroller, go to ‘PEDebug’ —> ‘load’ and select
the project’s abs file. The screen should now look similar to the screen
shot below.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
61
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Software
Figure 4-8. Programming Confirmation
Click ‘yes’. The program will go through the steps of programming the
microcontroller as shown below.
Central Heating Controller
62
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Software
On-board Flash Programming
Figure 4-9. During Programming
When the programming has completed, the small window will disappear.
Once the program has been set up in this way, microcontrollers can be
programmed using the load command, after they have been connected
to the PC’s serial port. Provision is made on the printed circuit board
(PCB) layout to allow the MC68HC908LJ12 to be programmed ‘in
circuit’. A suitable circuit to interface the device to a PC via an RS232
serial port, is given in Appendix D. Programming Circuit Diagram. This
interface is connected to the main board by means of an IDC header and
ribbon cable.
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software
For More Information On This Product,
Go to: www.freescale.com
63
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Software
Central Heating Controller
64
DRM044 — Rev 0
Software
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
Appendix A. Software Routines
A.1 [a2d.c]
//////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
//////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : a2d.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// a2d routines
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 13/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
#include
"delay.h"
"a2d.h"
//////////////////////////////////////////////////////////////////////////////
// This function returns an averaged analogue value. The averaging is
//
// currently 8, determined by the value of A2D_SAMPLE_COUNT (in a2d.h)
//
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
65
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
//
//
// NOTE: the summing variable 'a2d_total' is 16 bit, this means we can store //
// 32 readings of 0x3ff ie 11 1111 1111. If you want greater averaging then
//
// make 'a2d_total' an unsigned long.
//
//
//
// Argument : analogue channel to read
//
// Returns : averaged analogue result
//
//////////////////////////////////////////////////////////////////////////////
unsigned short int ReadA2D( unsigned char channel )
{
unsigned short int
a2d_total;
union uUNSIGNED_INTEGER a2d_bytes;
unsigned char
ii;
for ( a2d_total = 0, ii = 0; ii < A2D_SAMPLE_COUNT; ii++ )
{
ADSCR.reg = 0x00|channel;
// a2d interrupts off, clears COCO bit
while ( !ADSCR.bit.COCO ) ;
// Wait for conversion to complete
a2d_bytes._8bit.hibyte = ADRH.reg; // Read high reg first to latch low reg
a2d_bytes._8bit.lobyte = ADRL.reg; // Now read lo reg
a2d_total += a2d_bytes._16bit;
// Update running total
}
a2d_total /= A2D_SAMPLE_COUNT;
// Average
return a2d_total;
// Return averaged result
} // ReadA2D()
//----------------------------------------------------------------------------
Central Heating Controller
66
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[a2d.h]
A.2 [a2d.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : a2d.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for 'a2d.c'
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 12/05/00 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__A2D_H_
#define
__A2D_H_
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
CHANNEL0
CHANNEL1
CHANNEL2
CHANNEL3
CHANNEL4
CHANNEL5
A2D_BANDGAP_REF
A2D_VDDA
A2D_VSSA
A2D_OFF
CLEAR_CHANNEL_SEL
A2D_SAMPLE_COUNT
ShutDownA2D()
A2D_STABILISATION
0x00
0x01
0x02
0x03
0x04
0x05
0x06
0x1d
0x1e
0x1f
0xe0
8
(ADSCR.reg = A2D_OFF)
// ADC power off
16// approx 100us == 200 bus cycles @ 2MHz...
// bus speed '16' => 15+(12*16) = 207 bus...
// cycles == 103.5us
////////////////
// prototypes //
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
67
Freescale Semiconductor, Inc.
Software Routines
////////////////
unsigned short intReadA2D( unsigned char );
Freescale Semiconductor, Inc...
#endif
Central Heating Controller
68
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Alarm.c]
A.3 [Alarm.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : Alarm.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Alarm routine
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 27/06/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
#include
<stdio.h>
"Alarm.h"
void Alarm( void )
{
struct sPROG_PARAMS* ptr = NULL;
unsigned char
temp;
if ( PRNumber < NO_PROGRAM
{
ALMR.byte = program[PRNumber].min_off;
ALHR.byte = program[PRNumber].hour_off;
PRNumber = NO_PROGRAM;
PR2
= 1;
}
// If alarm is currently running
// Set off time in alarm register
// Initiate override variable
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
69
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
else
{
for ( ptr = &program[0]; ptr <= &program[3]; ptr++ )
{
temp = ptr->dow;
if ( temp == 8 )
{
if ( 0 < DOWR.byte && DOWR.byte < 6 )
{
temp = DOWR.byte; // Load DOW value for Minute - Fri
}
}
else if ( temp == 9 )
{
if ( DOWR.byte == 0 || DOWR.byte == 6 )
{
temp = DOWR.byte; // Load DOW value for Sat - Sun
}
}
}
OrderCheck(ptr, temp);
// end of 'for'
// Call of function to check...
// the order of the alarms
if ( program[PRNumber].hour_on == 0 )SHour = 23;
else
SHour = program[PRNumber].hour_on - 1;
// Store Alarm hour - 1 for smart
SMin = program[PRNumber].min_on;
// Copy of alarm minute for smart
PR2 = 0;
// Reset override variable
}
} // Alarm()
//------------------------------------------------------------------------------
void OrderCheck( const struct sPROG_PARAMS* ptr, unsigned char dow_check )
{
unsigned short int
stored_total_on;
unsigned short int
stored_total_off;
unsigned short int
alarm_reg_total;
unsigned short int
current_time_total;
if ( dow_check == DOWR.byte )
{
stored_total_on
= (
stored_total_off
= (
alarm_reg_total
= (
current_time_total = (
// Is it the Day of the alarm
60
60
60
60
*
*
*
*
ptr->hour_on )
ptr->hour_off)
ALHR.byte
)
HRR.byte
)
+
+
+
+
ptr->min_on;
ptr->min_off;
ALMR.byte;
MINR.byte;
if ( stored_total_on == stored_total_off )
return;
// If the on time is equal to the off time (clear/ignore condition)
if ( current_time_total < stored_total_on )
{
if ( PRNumber < NO_PROGRAM )
// If a program has already been...
{
// loaded into the alarm register
Central Heating Controller
70
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Alarm.c]
if ( stored_total_on < alarm_reg_total )
{
ALMR.byte = ptr->min_on;
// Set new on time
ALHR.byte = ptr->hour_on;
//
PRNumber = (unsigned char)(ptr - &program[0]);
}
// Store which program is now is the alarm reg.
}
else
{
ALMR.byte = ptr->min_on;
// Set new time
ALHR.byte = ptr->hour_on;
//
PRNumber = (unsigned char)(ptr - &program[0]);
}
// Store which program is now is the alarm reg.
}
}
} // OrderCheck()
//------------------------------------------------------------------------------
void AlarmFlag( void )
{
unsigned char temp;
if ( RTCSR.bit.ALMF )
// If the Alarm flag is set
{
temp = ALHR.reg;
// Clears Alarm flag
if (PRNumber < NO_PROGRAM)
// If alarm is to be activated
{
Active = 1;
// Set heating control variable
user_temperature = program[PRNumber].temperature;
}
// Desired temperature is recalled
else
// If a program has just ended
{
Active = 0;
// Clear heating control variable
PTB.bit.bit0 = 0x00;
// Turn off heating
PTB.bit.bit1 = 0x00;
// Turn off Cooling
}
Alarm();
}
} // AlarmFlag()
//------------------------------------------------------------------------------
void NewDayRefresh( void )
{
unsigned char temp;
if ( RTCSR.bit.DAYF )
{
if ( PRNumber >= NO_PROGRAM )
{
Alarm ();
// If the Day flag is set
// If a program is not running
// Refresh the alarm register
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
71
Freescale Semiconductor, Inc.
Software Routines
}
Freescale Semiconductor, Inc...
temp = DAYR.reg;
// DayFlag reset
}
} // NewDayRefresh()
//----------------------------------------------------------------------------
Central Heating Controller
72
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Alarm.h]
A.4 [Alarm.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : Alarm.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for 'Alarm.c'
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 27/06/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__Alarm_H_
#define
__Alarm_H_
void
void
void
void
NewDayRefresh( void );
OrderCheck( const struct sPROG_PARAMS*, unsigned char );
AlarmFlag( void );
Alarm( void );
#endif
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
73
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
A.5 [Alarmset.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : Alarmset.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Alarm set routines
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 25/06/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
#include
#include
#include
#include
"Display.h"
"button.h"
"Delay.h"
"Alarm.h"
"Alarmset.h"
void ModeAlarmSet( void )
{
switch ( Aset_mode )
{
case PROGRAM_MODE:
Program();
break;
// Branch to the current setting
case WEEK_MODE:
Week();
break;
Central Heating Controller
74
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Alarmset.c]
case WEEKEND_MODE:
Weekend();
break;
case DAILY_MODE:
case DAILY_MODE_REVERSE:
Daily();
break;
case HOUR_MODE:
AlarmHset();
break;
case MINUTE_MODE:
AlarmMset();
break;
case TEMPERATURE_MODE:
AlarmTset();
break;
case PROGRAM_CHECK_MODE:
ProCheck();
set_mode
= MODE_DEFAULT;
Aset_mode
= DEFAULT;
AlarmPRNumber = NO_PROGRAM;
if ( !PR2 )
Alarm ();
// Refresh alarm register
Refresh
= 1;
// Refresh temperature
break;
}
} // ModeAlarmSet()
//------------------------------------------------------------------------------
void Program( void )
{
ClearDisplay();
LDAT12.byte = 0x33;
// Displays "AlarmPRNumber"
LDAT11.byte = 0x12;
//
LDAT10.byte = 0x20;
//
if ( _0P25sec )
// For every other 1/4 of a second
{
LDAT9.byte = 0x00;
// Allows Program Number to Flash
LDAT8.byte &= 0x0f;
//
}
else
DisplayNumber( AlarmPRNumber + 1, 6 );
// Displays Program Number
} // Program()
//------------------------------------------------------------------------------
void Week( void )
{
if ( _0P25sec )
{
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
75
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
LDAT12.bit.bit6
LDAT11.bit.bit2
LDAT9.bit.bit6
LDAT8.bit.bit2
LDAT6.bit.bit6
=
=
=
=
=
1;
1;
1;
1;
1;
// Chevrons are Added, Mon - Fri
//
//
//
//
LDAT12.bit.bit6
LDAT11.bit.bit2
LDAT9.bit.bit6
LDAT8.bit.bit2
LDAT6.bit.bit6
=
=
=
=
=
0;
0;
0;
0;
0;
// Chevrons are Removed, Mon - Fri
//
//
//
//
}
else
{
}
} // end of week
//------------------------------------------------------------------------------
void Weekend( void )
{
if ( _0P25sec )
// For every other 1/4 of a second
{
LDAT5.bit.bit2 = 1;
// Add Chevrons to Sat - Sun
LDAT3.bit.bit6 = 1;
//
}
else
{
LDAT5.bit.bit2 = 0;
// Allows chevrons to flash
LDAT3.bit.bit6 = 0;
//
}
} // end of weekend
//------------------------------------------------------------------------------
void Daily( void )
{
volatile union uPORT*ptr = &LDAT1;
if ( _0P25sec )
{
if ( dow_set == MON || dow_set == WED || dow_set == FRI || dow_set == SUN )
{
// Determins Even Digit
ptr[dow_set].bit.bit6
= 1;
// Adds a Chevron
}
else
ptr[dow_set].bit.bit2 = 1;
// Adds a Chevron
}
else
{
LDAT12.bit.bit6 = 0;
// Clears all chevrons
LDAT11.bit.bit2 = 0;
//
LDAT9.bit.bit6 = 0;
//
LDAT8.bit.bit2 = 0;
//
LDAT6.bit.bit6 = 0;
//
LDAT5.bit.bit2 = 0;
//
Central Heating Controller
76
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Alarmset.c]
LDAT3.bit.bit6 = 0;
//
}
} // end of Daily
//------------------------------------------------------------------------------
void AlarmHset( void )
{
MinAlm();
if ( _0P25sec )
{
LDAT6.byte = 0x00;
LDAT5.byte = 0x00;
LDAT4.byte = 0x00;
}
else
HrAlm();
// Displays minute digits
// For every other 1/4 of a second
// Clears the other digits
//
//
// Display Hour
ChevronRefresh();
} // end of AlarmHset
//------------------------------------------------------------------------------
void AlarmMset( void )
{
HrAlm();
if ( _0P25sec )
{
LDAT3.byte = 0x00;
LDAT2.byte = 0x00;
LDAT1.byte = 0x00;
}
else
MinAlm();
// Displays hour digits
// For every other 1/4 of a second
// Clears the other digits
//
//
// Display Minutes
ChevronRefresh();
} // end of AlarmMset
//-----------------------------------------------------------------------------void AlarmTset( void )
{
if ( _0P25sec )
{
LDAT2.byte &= 0x0f;
LDAT3.byte = 0x00;
LDAT4.byte = 0x00;
LDAT5.byte &= 0xf0;
}
else
TempAlm();
// For every other 1/4 of a second
//
// Temperature Digits are Cleared
//
//
// Display Temperature
ChevronRefresh();
} // end of AlarmTset
//------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// This function checks to see if any of the programs overlap each other. If //
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
77
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
// they do, an error message is displayed with the numbers of the programs
//
// that clash. The latest program is then cancelled/ignored.
//
///////////////////////////////////////////////////////////////////////////////
void ProCheck( void )
{
unsigned short int
temp;
unsigned short int
stored_total_on;
unsigned short int
stored_total_off;
unsigned short int
new_total_on;
unsigned short int
new_total_off;
unsigned char
error = NO_PROGRAM;
unsigned char
stored_program;
new_total_on
= ( 60 *
+
new_total_off = ( 60 *
+
program[AlarmPRNumber].hour_on )
program[AlarmPRNumber].min_on;
program[AlarmPRNumber].hour_off )
program[AlarmPRNumber].min_off;
if ( new_total_on != new_total_off )
{
for ( stored_program = 0; stored_program <= 3; stored_program++ )
{
if ( AlarmPRNumber != stored_program )
{
if ( program[stored_program].dow == 8 )// Mon - Fri
{
if ( program[AlarmPRNumber].dow == 0 ||
// Sun
program[AlarmPRNumber].dow == 6 ||
// Sat
program[AlarmPRNumber].dow == 9 )
// Sat - Sun
{
continue;
// If dow are not equal, skip...
}
// the check
}
if ( program[stored_program].dow == 9 ) //
{
if (( program[AlarmPRNumber].dow > 0
program[AlarmPRNumber].dow < 6 )
program[AlarmPRNumber].dow == 8 )
{
continue;
//
}
//
}
Sat - Sun
&&
||
// DOW > Sunday and ...
// DOW < Saturday or...
// DOW = Mon - Fri
If dow are not equal, skip...
the check
if ( program[AlarmPRNumber].dow == 8 ) // Mon - Fri
{
if ( program[stored_program].dow == 0 ||
// Sun
program[stored_program].dow == 6 )
// Sat
{
continue;
// If dow are not equal, skip...
}
// the check
}
if ( program[AlarmPRNumber].dow == 9 ) // Sat - Sun
Central Heating Controller
78
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Alarmset.c]
{
if ( program[stored_program].dow
program[stored_program].dow
{
continue;
}
}
> 0 &&// DOW > Sunday and ...
< 6 )// DOW < Saturday or...
// If dow are not equal, skip...
// the check
if ( program[AlarmPRNumber].dow < 8 &&
program[stored_program].dow < 8 )
{
if ( program[AlarmPRNumber].dow != program[stored_program].dow )
{
continue;
// If dow are not equal, skip...
}
// the check
}
stored_total_on
= ( 60 * program[stored_program].hour_on )
+ program[stored_program].min_on;
stored_total_off = ( 60 * program[stored_program].hour_off )
+ program[stored_program].min_off;
if ( stored_total_on != stored_total_off )
{
if (( stored_total_on > new_total_on
&&
stored_total_on < new_total_off ) ||
// If the new program starts before the stored but the off time overlaps
(( stored_total_on < new_total_on )
&&
( stored_total_off > new_total_on ) ))
// If the new program starts after the stored but the on time overlaps
{
error = stored_program;
continue;
}
}
}
} // end of 'for'
}
if ( error != NO_PROGRAM )
{
ClearDisplay();
LDAT12.byte
= 0x37;
LDAT11.byte
= 0x02;
LDAT10.byte
= 0x20;
LDAT9.byte
= 0x22;
LDAT4.bit.bit5 = 1;
DisplayNumber( AlarmPRNumber + 1, 4 );
DisplayNumber( error + 1
, 2 );
for ( temp = 0; temp < 1000; temp++ )
{
Delay( _1MS );
ServiceWatchDog();
}
// If an error is present
// Displays "Err"
//
//
//
// Displays "-"
// The program that was entered
// The conflicting program
// 1sec delay to show error message
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
79
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
program[AlarmPRNumber].hour_off = program[AlarmPRNumber].hour_on;
program[AlarmPRNumber].min_off = program[AlarmPRNumber].min_on;
}
// Cancels the program
ClearDisplay();
} // ProCheck()
//------------------------------------------------------------------------------
void HrAlm ( void )
// Hour Alarm Refresh
{
DisplayNumber(( unsigned char )( Hour%10 ), 3 );
// Second Hour Digit
if ( Hour >= 10 )
// If the First Hour Digit != 0
{
DisplayNumber(( unsigned char )( Hour/10 ), 4 );
}
// Displays the First Hour Digit
} // end of HRAlm()
//------------------------------------------------------------------------------
void MinAlm ( void )
// Min Alarm refresh
{
DP = 0;
DisplayNumber(( unsigned char )( Minute%10 ), 1 );
// Second Minute Digit
DisplayNumber(( unsigned char )( Minute/10 ), 2 );
// First Minute Digit
} // end of MINAlm
//------------------------------------------------------------------------------
void TempAlm ( void )
{
DisplayNumber(( unsigned char )( user_temperature%10 ), 2 );
// Second Temperature Digit
if ( user_temperature/10 )
// First Temperature Digit != 0
{
DisplayNumber(( unsigned char )( user_temperature/10 ), 3 );
}
// First Temperature Digit
// Resets the Chevron Variable
} // end of TEMPAlm
//------------------------------------------------------------------------------
Central Heating Controller
80
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Alarmset.h]
A.6 [Alarmset.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : Alarmset.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for 'Alarmset.c'
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 25/06/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__Alarmset_H_
#define
__Alarmset_H_
enum
void
void
void
void
void
void
void
void
void
void
void
void
{ MON_FRI = 0x00, SAT_SUN, SUN, SAT = 0x04, FRI,
THU
= 0x07, WED,
TUE = 0x0a,
MON };
ModeAlarmSet( void );
AlarmTset( void );
AlarmMset( void );
AlarmHset( void );
ProCheck( void );
Weekend( void );
Program( void );
TempAlm( void );
MinAlm( void );
Daily( void );
HrAlm( void );
Week( void );
#endif
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
81
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
A.7 [button.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : button.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Button routine
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 11/07/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
#include
#include
#include
#include
"Alarmset.h"
"Clockset.h"
"Display.h"
"Alarm.h"
"button.h"
////////////////////////////////////////////////////////////////////////////////
// Simple 8 bit (byte) button read
//
//
//
// Arguments: none
//
// returns : none
//
////////////////////////////////////////////////////////////////////////////////
void ReadButtons( void )
{
button_pattern = ( PTD.reg & 0xf0 ) + ( PTA.reg & 0x0f );
Central Heating Controller
82
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[button.c]
///////////////////////////////////////////////////
// any change to the current button press status //
///////////////////////////////////////////////////
switch ( button_press_status )
{
case NO_BUTTON_PRESS:
DefaultButtons();
break;
case BUTTON_PRESSED :
PressedButtons();
break;
case BUTTON_RELEASED:
ReleasedButtons();
break;
}
} // ReadButtons()
//------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
// This function is called from 'ReadButtons()' which is itself called every //
// 'main()' 10ms iteration.
//
//
//
// This function is called if the value of 'button_press_status' is
//
// NO_BUTTON_PRESS. If a press is detected by the variable 'button_pattern'
//
// not being equal to DEFAULT_BUTTONS then 'button_press_status' is assigned //
// to BUTTON_PRESSED. On the next main loop iteration then 'PressedButtons()' //
// will be called from 'ReadButtons()'.
//
//
//
// Arguments : none
//
// Returns
: none
//
////////////////////////////////////////////////////////////////////////////////
void DefaultButtons( void )
{
if ( button_pattern == DEFAULT_BUTTONS )
{
// re-affirmation
pressed_pattern
= DEFAULT_BUTTONS;
button_debounce_counter
= 0;
button_flags.bit.FIRST_PASS = 0;
button_flags.bit.AUTO_REPEAT = 0;
}
else
{
///////////////////////////////////////////////////////////////
// OK, a press detected, this is the first recognition of... //
///////////////////////////////////////////////////////////////
button_press_status = BUTTON_PRESSED;
// state change
pressed_pattern
= button_pattern;
// store for later comparisons
}
} // DefaultButtons()
//------------------------------------------------------------------------------
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
83
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
////////////////////////////////////////////////////////////////////////////////
// To get to this point some button activity has occured. If the button
//
// activity has been stable for DEBOUNCE_COUNTER*10ms then the button press
//
// is accepted and function decoding is performed. If a button is pressed
//
// and kept pressed further decoding will take place if the autoscroll
//
// feature has been enabled for that button. This feature is enabled by the
//
// setting of 'button_flags.bit.AUTO_REPEAT'.
//
//
//
// Arguments : none
//
// Returns
: none
//
////////////////////////////////////////////////////////////////////////////////
void PressedButtons( void )
{
///////////////////////////////////////////////
// No longer pressed, back to pull-up values //
///////////////////////////////////////////////
if ( button_pattern == DEFAULT_BUTTONS )
{
button_press_status
= BUTTON_RELEASED;
button_release_counter = 2;
// initialise 20ms release debounce counter
}
else
{
////////////////////////////////////////////////////
// is the button pattern unchanged from last read //
////////////////////////////////////////////////////
if ( button_pattern == pressed_pattern )
{
// 10ms 'main()' synchronised 'button_debounce_counter' increments here
if ( ++button_debounce_counter >= DEBOUNCE_COUNTER )
{
if ( !button_flags.bit.FIRST_PASS )
// is this the first debounce...
{
// ...of this pattern
button_flags.bit.FIRST_PASS = 1;
// ...yes signal this event
button_flags.bit.AUTO_REPEAT = 0;
// reset autoscroll
DecodeButtons();
// respond to press
}
else
// auto repeat can now occur
{
// if required
///////////////////////////////////////////////////////////////
// same button as for first debounce is still being pressed, //
// after (50-DEBOUNCE_COUNTER)*10ms allow auto repeat.
//
///////////////////////////////////////////////////////////////
if ( button_debounce_counter >= 50 ) // (50-DEBOUNCE_COUNTER)*10ms
{
// before auto repeat mode
button_debounce_counter
= 10; // (50-3)*10ms is the effective
// repeat speed == 470ms,
// approx 2 times per second
if (button_flags.bit.AUTO_REPEAT)// do you require auto scroll...
{
DecodeButtons();
// ...if so keep decoding
}
}
Central Heating Controller
84
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[button.c]
}
}
}
else
{
/////////////////////////////////////////////////////////////////
// pattern is different but something is pressed, start again. //
/////////////////////////////////////////////////////////////////
button_press_status
= NO_BUTTON_PRESS;
pressed_pattern
= DEFAULT_BUTTONS;
button_debounce_counter
= 0;
button_flags.bit.FIRST_PASS = 0;
button_flags.bit.AUTO_REPEAT = 0;
}
}
// end of 'else'
}
// PressedButtons()
//------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// Ok, we think all the buttons are now at their default, initiate a release //
//
//
// Arguments : none
//
// Returns
: none
//
///////////////////////////////////////////////////////////////////////////////
void ReleasedButtons( void )
{
if ( --button_release_counter == 0 )
{
if ( set_mode == MODE_VIEWTEMP)
{
set_mode = MODE_DEFAULT;
Refresh = 1;
ClearDisplay();
}
button_press_status = NO_BUTTON_PRESS;
}
else
{
// checking for noise...
if ( button_pattern
!= DEFAULT_BUTTONS )
{
button_press_status = BUTTON_PRESSED;
// continue as pressed...
}
}
} // ReleasedButtons()
//------------------------------------------------------------------------------
//////////////////////////////////////////////////////
// This function does the physical button decoding. //
//
//
// Arguments: none
//
// returns : none
//
//////////////////////////////////////////////////////
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
85
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
void DecodeButtons( void )
{
unsigned char temp;
switch ( pressed_pattern )
{
case BUTTON_1 :
// Clock Set Button
if ( set_mode == DEFAULT || set_mode == MODE_CLOCKSET )
{
set_mode = MODE_CLOCKSET;
if ( ++Cset_mode > DOW_SET )
{
set_mode = MODE_DEFAULT;
Cset_mode = DEFAULT_SET;
Refresh
= 1;
// Refresh temp and smart chevron
}
else if ( Cset_mode == DOW_SET)
{
MINClr();
// Refresh Min
}
}
SECR.reg = 0x00;
// Resets the second register
break;
case BUTTON_2 :
// Dec Button
Decrement();
if ( Cset_mode == DOW_SET )button_flags.bit.AUTO_REPEAT = 0;
else
button_flags.bit.AUTO_REPEAT = 1;
break;
case BUTTON_3 :
// Inc Button
Increment();
if ( Cset_mode == DOW_SET ) button_flags.bit.AUTO_REPEAT = 0;
else
button_flags.bit.AUTO_REPEAT = 1;
break;
case BUTTON_4 :
// Alarm Set
if ( set_mode == DEFAULT || set_mode == MODE_ALARMSET )
{
set_mode = MODE_ALARMSET;
switch ( Aset_mode )
{
case DEFAULT:
AlarmPRNumber = PROGRAM_1;
Aset_mode
= PROGRAM_MODE;
break;
case PROGRAM_MODE:
onoff = 0;
Aset_mode = WEEK_MODE;
DisplayNumber( AlarmPRNumber + 1, 6 );
break;
// Setting on/off
case WEEK_MODE:
Central Heating Controller
86
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[button.c]
Aset_mode
DW
Hour
Minute
=
=
=
=
HOUR_MODE;
MON_FRI;
program[AlarmPRNumber].hour_on;
program[AlarmPRNumber].min_on;
// Hour set to previous hour
LDAT11.byte &= 0xf0;
LDAT10.byte = 0x00;
LDAT9.byte
= 0x35;
LDAT8.byte
= 0x32;
LDAT7.byte
= 0x22;
// Clears the 7th Digit
//
// Displays "On"
//
//
DisplayNumber( AlarmPRNumber + 1, 8 );
break;
case WEEKEND_MODE:
DW = SAT_SUN;
Aset_mode = HOUR_MODE;
Hour
= program[AlarmPRNumber].hour_on;
Minute
= program[AlarmPRNumber].min_on;
// Hour set to previous hour
LDAT11.byte &= 0xf0;
LDAT10.byte = 0x00;
LDAT9.byte
= 0x35;
LDAT8.byte
= 0x32;
LDAT7.byte
= 0x22;
// Clears the 7th Digit
//
// Displays "On"
//
//
DisplayNumber( AlarmPRNumber + 1, 8 );
break;
case DAILY_MODE:
case DAILY_MODE_REVERSE:
DW = dow_set;
Aset_mode = HOUR_MODE;
Hour
= program[AlarmPRNumber].hour_on;
Minute
= program[AlarmPRNumber].min_on;
// Hour set to previous hour
LDAT11.byte &= 0xf0;
LDAT10.byte = 0x00;
LDAT9.byte
= 0x35;
LDAT8.byte
= 0x32;
LDAT7.byte
= 0x22;
// Clears the 7th Digit
//
// Displays "On"
//
//
DisplayNumber( AlarmPRNumber + 1, 8 );
break;
case HOUR_MODE:
if ( onoff )
// If This is the Second Time This
{
// Function has Been Ran
program[AlarmPRNumber].hour_off = Hour;
// Stores Off Hour
Aset_mode = MINUTE_MODE;
}
else
// If This is the First Time This
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
87
Freescale Semiconductor, Inc.
Software Routines
{
// Function has Been Ran
program[AlarmPRNumber].hour_on = Hour;
// Stores On hour
Aset_mode = MINUTE_MODE;
Minute = program[AlarmPRNumber].min_on;
// Default Minute set to previous
Freescale Semiconductor, Inc...
switch ( DW )
// Stores DOW as different values
{
// Mon-Fri = 0x08, Sat-Sun = 0x09
case MON
: temp = 0x01;break; // Sun = 0x00, Mon = 0x01, etc.
case TUE
: temp = 0x02;break;
case WED
: temp = 0x03;break;
case THU
: temp = 0x04;break;
case FRI
: temp = 0x05; break;
case SAT
: temp = 0x06;break;
case SUN
: temp = 0x00;break;
case SAT_SUN: temp = 0x09; break;
case MON_FRI: temp = 0x08;break;
default
: temp = DOWR.byte;
}
program[AlarmPRNumber].dow = temp;
}
break;
case MINUTE_MODE:
if ( onoff )
// If this is the second time ...
{
// This function has been ran
program[AlarmPRNumber].min_off = Minute;
// Stores Off Minute
Aset_mode
= TEMPERATURE_MODE;
user_temperature = 20;
// Default temperature is set
ClearDisplay();
LDAT11.byte
= 0x03;
// "t" is displayed
LDAT10.byte
= 0x60;
//
LDAT1.byte
= 0x60;
// "c" is displayed
LDAT2.byte
= 0x02;
//
DisplayNumber( AlarmPRNumber + 1, 8 );
ChevronRefresh();
}
else
// If this is the first time ...
{
// This function has been ran
program[AlarmPRNumber].min_on = Minute;
// Stores on minute
onoff = 1;
// Sets Variable to Indicate on Times Have Been set
Aset_mode
= HOUR_MODE;
LDAT11.byte &= 0xf0;
//
LDAT11.byte += 0x03;
// Displays "Off"
LDAT10.byte = 0x53;
//
LDAT9.byte
= 0x33;
//
LDAT8.byte
= 0x03;
//
LDAT7.byte
= 0x30;
//
ChevronRefresh();
}
break;
Central Heating Controller
88
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[button.c]
case TEMPERATURE_MODE:
program[AlarmPRNumber].temperature = user_temperature;
// Stores Temperature
Aset_mode = PROGRAM_CHECK_MODE;
break;
}
}
break;
case BUTTON_5 :
// Temperature/Clear Button
if ( set_mode == MODE_ALARMSET )
{
program[AlarmPRNumber].hour_off = program[AlarmPRNumber].hour_on;
program[AlarmPRNumber].min_off = program[AlarmPRNumber].min_on;
set_mode = MODE_DEFAULT;
Aset_mode = DEFAULT;
AlarmPRNumber = NO_PROGRAM;
Refresh
= 1;
// Refresh temperature
}
else if ( set_mode == DEFAULT )
{
set_mode = MODE_VIEWTEMP;
}
break;
case BUTTON_5_DEC :
// Assigned as decrement for when button_5 being held down
Decrement();
button_flags.bit.AUTO_REPEAT = 1;
break;
case BUTTON_5_INC :
// Assigned as increment for when button_5 being held down
Increment();
button_flags.bit.AUTO_REPEAT = 1;
break;
case BUTTON_6 :
// Override Button
if ( set_mode == DEFAULT )
{
if ( PR2 == 1 || Override == 1 )
// If a program or override is ...
{
// currently running
Override
= 0;
// Reset override
Active
= 0;
// Turn heating/cooling off
PR2
= 0;
// Reset program variable
PTB.bit.bit0 = 0x00;
//
PTB.bit.bit1 = 0x00;
//
Alarm();
// Refresh Alarm Register
}
else
{
if ( HRR.byte >= 23 )
OverrideH = 0;
// Maximum cap for hours
else
OverrideH = HRR.byte + 1;
// Increment to allow override to be on for one hour
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
89
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
OverrideM = MINR.byte;
Override = 1;
Active
= 1;
}
// Store current minutes
// Activate override
// Activate heating/cooling
}
break;
case BUTTON_7 :
if ( set_mode == DEFAULT )
{
smart ^= 0x01;
Refresh = 1;
}
break;
// Smart Button
// Refresh temp and smart chevron
case BUTTON_8 :
// Mode Button
if ( set_mode == DEFAULT )
{
if ( mode++ == OFF )
mode = AUTOMATIC;
}
break;
}
} // DecodeButtons()
//------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
// The <INC> button has been pressed, decide functionality wrt current mode
//
//
//
// Arguments: none
//
// returns : none
//
////////////////////////////////////////////////////////////////////////////////
void Increment( void )
{
volatile union uPORT*ptr = &LDAT1;
switch ( set_mode )
{
case MODE_CLOCKSET:
switch ( Cset_mode )
{
case HOUR_SET:
if ( HRR.byte++ >= 23)
break;
case MINUTE_SET:
if ( MINR.byte++ >= 59)
break;
HRR.byte
= 0;
MINR.byte = 0;
case DOW_SET:
if ( DOWR.byte++ >= 0x06 ) DOWR.byte = 0;
break;
}
break;
Central Heating Controller
90
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[button.c]
case MODE_ALARMSET:
switch ( Aset_mode )
{
case PROGRAM_MODE:
if ( AlarmPRNumber < PROGRAM_4 )
AlarmPRNumber++;
// Resets to Minimum if Maximum Reached
break;
case WEEK_MODE:
Aset_mode = WEEKEND_MODE;
LDAT12.bit.bit6 = 0;
LDAT11.bit.bit2 = 0;
LDAT9.bit.bit6 = 0;
LDAT8.bit.bit2 = 0;
LDAT6.bit.bit6 = 0;
break;
case WEEKEND_MODE:
Aset_mode = DAILY_MODE;
dow_set
= MON;
LDAT5.bit.bit2 = 0;
LDAT3.bit.bit6 = 0;
break;
// Chevrons are Removed, Mon - Fri
//
//
//
//
// Set starting chevron to Mon
// Clears Sat - Sun to allow flash
//
case DAILY_MODE:
case DAILY_MODE_REVERSE:
if ( dow_set == MON || dow_set == WED || dow_set == FRI || dow_set == SUN )
{
// Determins Even Digit
ptr[dow_set].bit.bit6 = 0;
// Adds a Chevron
}
else
// Determins Odd Digit
{
ptr[dow_set].bit.bit2 = 0;
// Adds a Chevron
}
dow_set -= 1;
// DOW is Incrmented
if ( dow_set == 9 || dow_set == 6 || dow_set == 3 )
{
dow_set -= 1;
// Pointer is Incremented further..
}
// due to 1/3 bytes not being used
if ( dow_set == 1 )
{
Aset_mode = WEEK_MODE;
}
break;
case HOUR_MODE:
if ( Hour++ == 23 ) Hour = 0;
break;
// Resets to Minimum
case MINUTE_MODE:
if ( Minute++ == 59 )Minute = 0;// Resets to Minimum
break;
case TEMPERATURE_MODE:
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
91
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
if ( user_temperature++ == 40 )user_temperature = 20;
break;
// Resets to Default
case PROGRAM_CHECK_MODE:
break;
}
break;
case MODE_VIEWTEMP:
if (++user_temperature > 40)
break;
}
user_temperature = 20;
// Maximum cap for temp
} // Increment()
//------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
// The <DEC> button has been pressed, decide functionality wrt current mode
//
//
//
// Arguments: none
//
// returns : none
//
////////////////////////////////////////////////////////////////////////////////
void Decrement( void )
{
volatile union uPORT*ptr = &LDAT1;
switch ( set_mode )
{
case MODE_CLOCKSET:
switch ( Cset_mode )
{
case HOUR_SET:
if ( HRR.byte-- == 0x00 ) HRR.byte = 23;
break;
case MINUTE_SET:
if ( MINR.byte-- == 0x00 ) MINR.byte = 59;
break;
case DOW_SET:
if ( DOWR.byte-- == 0x00 ) DOWR.byte = 0x06;
break;
}
break;
case MODE_ALARMSET:
switch ( Aset_mode )
{
case PROGRAM_MODE:
if ( AlarmPRNumber )
break;
AlarmPRNumber--;// Minimum cap
case WEEK_MODE:
Central Heating Controller
92
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[button.c]
Aset_mode
= DAILY_MODE_REVERSE;
dow_set
= SUN;
LDAT12.bit.bit6 = 0;
LDAT11.bit.bit2 = 0;
LDAT9.bit.bit6 = 0;
LDAT8.bit.bit2 = 0;
LDAT6.bit.bit6 = 0;
break;
case WEEKEND_MODE:
Aset_mode = WEEK_MODE;
LDAT5.bit.bit2 = 0;
LDAT3.bit.bit6 = 0;
break;
// Set starting chevron to Sun
// Chevrons are Removed, Mon - Fri
//
//
//
//
// Clears Sat - Sun
// Chevrons to Flash
case DAILY_MODE:
case DAILY_MODE_REVERSE:
if ( dow_set == MON || dow_set == WED || dow_set == FRI || dow_set == SUN )
{
// Determins Even Digit
ptr[dow_set].bit.bit6 = 0;
// Adds a Chevron
}
else
// Determins Odd Digit
{
ptr[dow_set].bit.bit2 = 0;
// Adds a Chevron
}
dow_set++;
// DOW is Decremented
if ( dow_set == 9 || dow_set == 6 || dow_set == 3 )
{
dow_set++;
// Pointer is Decremented further
}
// due to 1/3 bytes not being used
if (dow_set == 12)
{
Aset_mode = WEEKEND_MODE;
// Next function to be called is weekend
}
break;
case HOUR_MODE:
if ( Hour-- == 0 )
break;
Hour = 23;
case MINUTE_MODE:
if ( Minute-- == 0 ) Minute = 59;
break;
case TEMPERATURE_MODE:
if (user_temperature-- == 0)
break;
// Resets to Maximum
// Resets to Maximum
user_temperature = 20;
// Resets to Default
case PROGRAM_CHECK_MODE:
break;
}
break;
case MODE_VIEWTEMP:
if ( !user_temperature-- )
user_temperature = 20;
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
93
Freescale Semiconductor, Inc.
Software Routines
break;
}
// Resets to Default
Freescale Semiconductor, Inc...
} // Decrement()
//------------------------------------------------------------------------------
Central Heating Controller
94
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[button.h]
A.8 [button.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : button.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for 'button.c'
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 19/06/00 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__BUTTON_H_
#define
__BUTTON_H_
////////////////////
// button decodes //
////////////////////
#define DEFAULT_BUTTONS
#define BUTTON_1
#define BUTTON_2
#define BUTTON_3
#define BUTTON_4
#define BUTTON_5
#define BUTTON_6
#define BUTTON_7
#define BUTTON_8
#define BUTTON_5_DEC
#define BUTTON_5_INC
0xff// 11111111
0xfe// 11111110
0xfd// 11111101
0xfb// 11111011
0xf7// 11110111
0xef// 11101111
0xdf// 11011111
0xbf// 10111111
0x7f// 01111111
0xed // 11101101
0xeb // 11101011
#define DEBOUNCE_COUNTER
3
//////////////////////////
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
95
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
// button_flags defines //
//////////////////////////
#define FIRST_PASS
#define AUTO_REPEAT
bit0
bit1
enum { NO_CHANGE = 0x01, DECREMENT_VALUE, INCREMENT_VALUE };
///////////////////
// button states //
///////////////////
enum { NO_BUTTON_PRESS = 0x01, BUTTON_PRESSED, BUTTON_RELEASED };
enum
{
MODE_DEFAULT = 0x00,
MODE_CLOCKSET,
MODE_ALARMSET,
MODE_VIEWTEMP
};
////////////////
// prototypes //
////////////////
void ReleasedButtons( void );
void PressedButtons( void );
void DefaultButtons( void );
void DecodeButtons( void );
void ReadButtons( void );
void Increment( void );
void Decrement( void );
#endif
Central Heating Controller
96
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Clockset.c]
A.9 [Clockset.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : Clockset.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Clock Setting
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 13/06/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
#include
"Display.h"
"Clockset.h"
void Cset( void )
{
switch ( Cset_mode )
{
case HOUR_SET:
if ( _0P25sec )
{
SFLASH = 1;
HRClr();
MINClr();
ChevronRefresh();
}
else
// For every other 1/4 of a second
// Displays divider decimal point
// Refreshes hour digits
// Refreshes minute digits
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
97
Freescale Semiconductor, Inc.
Software Routines
{
ClearDisplay();
LDAT10.bit.bit2 = 1;
MINClr();
ChevronRefresh();
}
break;
// Allows hour digits to flash
// Decimal point remains constant
// Minute digits refreshed
Freescale Semiconductor, Inc...
case MINUTE_SET:
if ( _0P25sec )
{
SFLASH = 1;
MINClr();
HRClr();
ChevronRefresh();
}
else
{
ClearDisplay();
SFLASH = 1;
HRClr();
ChevronRefresh();
}
break;
case DOW_SET:
LDAT12.bit.bit6
LDAT11.bit.bit2
LDAT9.bit.bit6
LDAT8.bit.bit2
LDAT6.bit.bit6
LDAT5.bit.bit2
LDAT3.bit.bit6
=
=
=
=
=
=
=
// For every other 1/4 of a second
// Displays divider decimal point
// Refreshes hour digits
// Refreshes minute digits
// Allows hour digits to flash
// Decimal point remains constant
// Hour digits refreshed
0;
0;
0;
0;
0;
0;
0;
//
// Clear Chevrons to prevent ghost
//
//
//
//
//
if ( _0P25sec )
{
switch (DOWR.byte)
{
case 0x00:
LDAT3.bit.bit6
break;
// For every other 1/4 of a second
= 1;
case 0x01:
LDAT12.bit.bit6 = 1;
break;
case 0x02:
LDAT11.bit.bit2 = 1;
break;
case 0x03:
LDAT9.bit.bit6 = 1;
break;
// Set Sunday Chevron
// Set Monday Chevron
// Set Tuesday Chevron
// Set Wednesday Chevron
case 0x04:
Central Heating Controller
98
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Clockset.c]
LDAT8.bit.bit2
break;
case 0x05:
LDAT6.bit.bit6
break;
case 0x06:
LDAT5.bit.bit2
break;
}
= 1;
// Set Thursday Chevron
= 1;
// Set Friday Chevron
= 1;
// Set Saturday Chevron
}
break;
}
} // Cset()
//------------------------------------------------------------------------------
void HRClr (void)
// Hour Clock Refresh
{
if ( HRR.byte >=10 )
{
DisplayNumber( (unsigned char)(HRR.byte/10), 8 );
}
else
{
LDAT12.byte = 0x00;
LDAT11.byte &= 0x0f;
}
DP = SFLASH;
DisplayNumber( (unsigned char)(HRR.byte%10), 7 );
DP = 0;
} // HRClr()
//------------------------------------------------------------------------------
void MINClr (void)// Min Clock refresh
{
DP = 0;
DisplayNumber( (unsigned char)(MINR.byte%10), 5 );
DisplayNumber( (unsigned char)(MINR.byte/10), 6 );
} // MINClr()
//------------------------------------------------------------------------------
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
99
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
A.10 [Clockset.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : Clockset.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for 'Clockset.c'
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 06/06/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__Clockset_H_
#define
__Clockset_H_
enum
{ DEFAULT_SET = 0x00, HOUR_SET, MINUTE_SET, DOW_SET };
void MINClr (void);
void HRClr (void);
void Cset (void);
#endif
Central Heating Controller
100
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Data.c]
A.11 [Data.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : Data.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// global data,
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__DECLARED_H_
#include
"declared.h"
#endif
#pragma DATA_SEG __SHORT_SEG _DATA_ZEROPAGE
/////////////////////////////////////////////////////////
// PAGE0 Global variables, range available 0x60 - 0xff //
/////////////////////////////////////////////////////////
uBITS
button_flags;
unsigned char
N2;
unsigned char
DW;
unsigned char
DP;
unsigned char
PR2;
unsigned char
sign;
unsigned char
SMin;
unsigned char
Hour;
unsigned char
mode;
unsigned char
smart;
unsigned char
SHour;
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
101
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
volatile
unsigned
unsigned
unsigned
unsigned
struct
char
_10ms;
char
onoff;
char
Minute;
char
SFLASH;
char
Active;
char
dow_set;
char
Refresh;
char
PRNumber;
char
low_byte;
char
set_mode;
char
_0P25sec;
char
Override;
char
OverrideH;
char
OverrideM;
char
Cset_mode;
char
Aset_mode;
char
_5sectick;
char
one_second;
char
two_second;
char
AlarmPRNumber;
char
button_pattern;
char
pressed_pattern;
char
user_temperature;
char
button_press_status;
char
external_temperature;
char
button_release_counter;
char
button_debounce_counter;
char
external_temperature_decimal;
uBITS
flags1;
short intsmart_time;
short int
stop_counter;
short intBatteryCheck;
short int internal_temperature;
sPROG_PARAMS
program[4];
/////////////////////////////////////////////////////////////
// Global non PAGE0 variables occupying 0x100 to stack top //
/////////////////////////////////////////////////////////////
#pragma DATA_SEG _FAR_RAM
/////////////////////////
// 'const' data ie rom //
/////////////////////////
#pragma CONST_SEG ATEECC_CONST_DATA
Central Heating Controller
102
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[declared.h]
A.12 [declared.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : declared.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// declared data types
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__DECLARED_H_
#define
__DECLARED_H_
//////////////////
// type defines //
//////////////////
typedef union uPORT
uBITS;
typedef unsigned short intUSHORT;
typedef unsigned char
UCHAR;
#pragma MESSAGE DISABLE C1106 // WARNING C1106: Non-standard bitfield type
/////////////////////
// bit/byte access //
/////////////////////
struct sPORT
{
UCHAR bit0 : 1;
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
103
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
UCHAR bit1 :
UCHAR bit2 :
UCHAR bit3 :
UCHAR bit4 :
UCHAR bit5 :
UCHAR bit6 :
UCHAR bit7 :
};
union uPORT
{
UCHAR
UCHAR
struct sPORT
};
1;
1;
1;
1;
1;
1;
1;
byte;
reg;
bit;
//////////////////////
// 16 bit data type //
//////////////////////
struct sUNSIGNED_INTEGER
{
UCHAR
hibyte;
UCHAR
lobyte;
};
union uUNSIGNED_INTEGER
{
USHORT
struct sUNSIGNED_INTEGER _8bit;
};
////////////////////////////
// 16 bit 'bit' data type //
////////////////////////////
struct sUNSIGNED_INTEGER_BIT
{
union uPORT
hibyte;
union uPORT
lobyte;
};
union uUNSIGNED_INTEGER_BIT
{
USHORT
struct sUNSIGNED_INTEGER_BIT _8bit;
};
// 0x12XX
// 0xXX34
_16bit;
// 0x12XX
// 0xXX34
_16bit;
struct sPROG_PARAMS
{
UCHAR
hour_on;
UCHAR
min_on;
UCHAR
dow;
UCHAR
hour_off;
UCHAR
min_off;
UCHAR
temperature;
};
#endif
Central Heating Controller
104
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[define.h]
A.13 [define.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : define.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// global defines
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__DEFINE_H_
#define
__DEFINE_H_
/////////////////
// I/O defines //
/////////////////
#define TIMING_PIN
#define TIMING_PIN_DDR
PTD.bit.bit5
DDRD.bit.bit5
///////////////////////////////
// general numerical defines //
///////////////////////////////
#define _1MS
165
#define _50US
7
#define _100US
16
#define LOWBATT
576
// for debugging
// for debugging
//
//
//
//
//
//
//
//
from delay.c, 15+(12*165)== 1995 bus
cycles == 2000*(1/2.0E6) = 0.9975ms
from delay.c, 15+(12*7)== 99 bus cycles
== 99*(1/2.0E6) = 49.5us
from delay.c, 15+(12*16)==207 bus cycles
== 207*(1/2.0E6) = 103.5us
2.7V is the low battery condition, so...
(2.7/4.8)*1024 == 576.0 counts
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
105
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
#define EXTERNAL_CALIBRATION
enum
enum
enum
-1
// Tolerance of DS1721 is +- 1 degree
{ PROGRAM_1 = 0x00, PROGRAM_2, PROGRAM_3, PROGRAM_4, NO_PROGRAM };
// 0 - 3 are valid programs
{ DEFAULT
= 0x00 ,
PROGRAM_MODE
,
WEEK_MODE
,
WEEKEND_MODE
,
DAILY_MODE
,
DAILY_MODE_REVERSE,
HOUR_MODE
,
MINUTE_MODE
,
TEMPERATURE_MODE ,
PROGRAM_CHECK_MODE
};
{ AUTOMATIC = 0x00, HEAT, COOL, OFF };
////////////////////
// flags1 defines //
////////////////////
#define _10MS
#define _1S
#define TO_BE_ASSIGNED_2
#define TO_BE_ASSIGNED_3
#define TO_BE_ASSIGNED_4
#define TO_BE_ASSIGNED_5
#define TO_BE_ASSIGNED_6
#define TO_BE_ASSIGNED_7
///////////////////
// Assembler 'C' //
///////////////////
#define RSP()
#define SEI()
#define CLI()
#define STOP()
#define WAIT()
#define NOP()
#define ServiceWatchDog()
bit0
bit1
bit2
bit3
bit4
bit5
bit6
bit7
//
//
//
//
//
//
this
this
this
this
this
this
is
is
is
is
is
is
free
free
free
free
free
free
for
for
for
for
for
for
use
use
use
use
use
use
asm rsp
asm sei
asm cli
asm stop
asm wait
asm nop
COPCTL.reg = 0
#endif
Central Heating Controller
106
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Delay.c]
A.14 [Delay.c]
///////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : Delay.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// delay routines
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#include
"delay.h"
////////////////////////////////////////////////////////////////////////////////
// The total delay consists of loading the accumulator with the delay
//
// argument, branching to the delay routine and lastly returning from the
//
// routine, this is shown below:
//
//
//
//
lda
#D
; delay arg sent to function [2] cycles
//
//
jsr
Delay
; branches to this function
[5] cycles
//
//
psha
:
[2] cycles //
// DELAY1:
//
//
nop
:
[1] cycle
//
//
nop
:
[1] cycle
//
//
nop
:
[1] cycle
//
//
nop
:
[1] cycle
//
//
nop
:
[1] cycle
//
//
nop
:
[1] cycle
//
//
tsx
:
[2] cycles
//
//
dbnz
X, *-5
:
[4] cycles
//
//
pulh
:
[2] cycles
//
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
107
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
//
rts
:
[4] cycles
//
//
//
// This gives a total delay of 13+12*D cycles, where D is the arg sent.
//
// With a 2MHZ bus speed, say we require a 1ms delay, then we have:
//
// 1E-3/(1/2E6) = 2000 bus cycles => 2000 = 15 + 12*D, => D = 165.41
//
// approx = 165
//
// 'Delay( 165 )' to get 1ms delay.
//
//
//
// Arguments: 'D' delay value as calculated from 'cyles = 15 + 12D'
//
// Returns : none
//
////////////////////////////////////////////////////////////////////////////////
void Delay( unsigned char delay_value )
{
#asm
DELAY1:
nop
nop
nop
nop
nop
nop
tsx
dbnz delay_value, DELAY1
#endasm
} // Delay()
//------------------------------------------------------------------------------
Central Heating Controller
108
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Delay.h]
A.15 [Delay.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : Delay.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for Delay.c
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/00 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__DELAY_H_
#define
__DELAY_H_
/////////////////////////
// function prototypes //
/////////////////////////
void Delay( unsigned char );
#endif
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
109
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
A.16 [Display.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : Display.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Display Functions
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 06/06/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
#include
#include
"button.h"
"delay.h"
"Display.h"
void InitialDisplay( void )
{
unsigned short int temp;
for ( temp = 0; temp < 1000; temp++ )
{
Delay( _1MS );
ServiceWatchDog();
}
ClearDisplay();
Central Heating Controller
110
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Display.c]
Refresh = 1;
} // Display
//------------------------------------------------------------------------------
void ClearDisplay( void )
{
volatile union uPORT*
ptr = &LDAT1;
for ( ; ptr <= &LDAT12; ptr++ ) ptr->reg = 0x00;
// All Segments Off
} // ClearDisplay
//------------------------------------------------------------------------------
void DisplayNumber( unsigned char N, unsigned char digit )
{
volatile union uPORT*ptr = &LDAT1;
if ( digit%2 )
{
switch ( digit )
{
case 1: digit--;
break;
case 5:digit++;
break;
case 7: digit += 2; break;
}
switch ( N )
{
case 0x00:
ptr[digit].byte
= 0x53;
ptr[(digit + 1)].byte &= 0xf0;
ptr[(digit + 1)].byte += 0x03;
break;
// odd digit check
// Compensates for 1.5 bytes
// being used per digit
//
// '0'
case 0x01:
ptr[digit].byte
= 0x03;
ptr[(digit + 1)].byte &= 0xf0;
break;
// '1'
case 0x02:
ptr[digit].byte
= 0x71;
ptr[(digit + 1)].byte &= 0xf0;
ptr[(digit + 1)].byte += 0x02;
break;
// '2'
case 0x03:
ptr[digit].byte
= 0x73;
ptr[(digit + 1)].byte &= 0xf0;
break;
// '3'
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
111
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
case 0x04:
ptr[digit].byte
= 0x23;
ptr[(digit + 1)].byte &= 0xf0;
ptr[(digit + 1)].byte += 0x01;
break;
// '4'
case 0x05:
ptr[digit].byte
= 0x72;
ptr[(digit + 1)].byte &= 0xf0;
ptr[(digit + 1)].byte += 0x01;
break;
// '5'
case 0x06:
ptr[digit].byte
= 0x72;
ptr[(digit + 1)].byte &= 0xf0;
ptr[(digit + 1)].byte += 0x03;
break;
// '6'
case 0x07:
ptr[digit].byte
= 0x13;
ptr[(digit + 1)].byte &= 0xf0;
break;
// '7'
case 0x08:
ptr[digit].byte
= 0x73;
ptr[(digit + 1)].byte &= 0xf0;
ptr[(digit + 1)].byte += 0x03;
break;
// '8'
case 0x09:
ptr[digit].byte
= 0x33;
ptr[(digit + 1)].byte &= 0xf0;
ptr[(digit + 1)].byte += 0x01;
break;
}
if ( DP )
ptr[digit].bit.bit2
= 1;
}
else
{
switch ( digit )
{
case 2: digit--;
break;
case 6:digit++;
break;
case 8: digit += 2; break;
}
switch (N)
{
case 0x00:
ptr[(digit + 1)].byte = 0x35;
ptr[digit].byte
&= 0x0f;
ptr[digit].byte
+= 0x30;
break;
// '9'
case 0x01:
ptr[(digit + 1)].byte
// Set Decimal Point
// even digit
// Compensates for 1.5 bytes...
// being used per digit
//
// '0'
// '1'
= 0x00;
Central Heating Controller
112
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Display.c]
ptr[digit].byte
ptr[digit].byte
break;
&= 0x0f;
+= 0x30;
case 0x02:
ptr[(digit + 1)].byte = 0x27;
ptr[digit].byte
&= 0x0f;
ptr[digit].byte
+= 0x10;
break;
// '2'
case 0x03:
ptr[(digit + 1)].byte = 0x07;
ptr[digit].byte
&= 0x0f;
ptr[digit].byte
+= 0x30;
break;
// '3'
case 0x04:
ptr[(digit + 1)].byte = 0x12;
ptr[digit].byte
&= 0x0f;
ptr[digit].byte
+= 0x30;
break;
// '4'
case 0x05:
ptr[(digit + 1)].byte = 0x17;
ptr[digit].byte
&= 0x0f;
ptr[digit].byte
+= 0x20;
break;
// '5'
case 0x06:
ptr[(digit + 1)].byte = 0x37;
ptr[digit].byte
&= 0x0f;
ptr[digit].byte
+= 0x20;
break;
// '6'
case 0x07:
ptr[(digit + 1)].byte = 0x01;
ptr[digit].byte
&= 0x0f;
ptr[digit].byte
+= 0x30;
break;
// '7'
case 0x08:
ptr[(digit + 1)].byte = 0x37;
ptr[digit].byte
&= 0x0f;
ptr[digit].byte
+= 0x30;
break;
// '8'
case 0x09:
ptr[(digit + 1)].byte = 0x13;
ptr[digit].byte
&= 0x0f;
ptr[digit].byte
+= 0x30;
break;
}
if ( DP )
ptr[digit].bit.bit6 = 1;
// '9'
// Set Decimal Point
}
} // DisplayNumber()
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
113
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
//------------------------------------------------------------------------------
void ChevronRefresh( void )
{
if ( set_mode == MODE_ALARMSET )
{
switch ( DW )
{
case 0:
LDAT6.bit.bit6 = 1;
LDAT8.bit.bit2 = 1;
LDAT9.bit.bit6 = 1;
LDAT11.bit.bit2 = 1;
LDAT12.bit.bit6 = 1;
break;
case 1:
LDAT3.bit.bit6
LDAT5.bit.bit2
break;
= 1;
= 1;
// If DOW = Mon - Fri
//
// Add Chevrons
//
//
//
// If DOW = Sat - Sun
// Add Chevron
//
case 2:
LDAT3.bit.bit6
break;
= 1;
// If DOW = Sun
// Add Chevron
case 4:
LDAT5.bit.bit2
break;
= 1;
// If DOW = Sat
// Add Chevron
case 5:
LDAT6.bit.bit6
break;
= 1;
// If DOW = Fri
// Add Chevron
case 7:
LDAT8.bit.bit2
break;
= 1;
// If DOW = Thu
// Add Chevron
case 8:
LDAT9.bit.bit6
break;
= 1;
// If DOW = Wed
// Add Chevron
case 10:
LDAT11.bit.bit2 = 1;
break;
// If DOW = Tue
// Add Chevron
case 11:
LDAT12.bit.bit6 = 1;
break;
// If DOW = Mon
// Add Chevron
}
}
else
{
switch ( DOWR.byte )
{
Central Heating Controller
114
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[Display.c]
case 0:
LDAT3.bit.bit6
break;
= 1;
// If DOW = Sun
// Add Chevron
case 1:
LDAT12.bit.bit6 = 1;
break;
// If DOW = Mon
// Add Chevron
case 2:
LDAT11.bit.bit2 = 1;
break;
// If DOW = Tue
// Add Chevron
case 3:
LDAT9.bit.bit6
break;
= 1;
// If DOW = Wed
// Add Chevron
case 4:
LDAT8.bit.bit2
break;
= 1;
// If DOW = Thu
// Add Chevron
case 5:
LDAT6.bit.bit6
break;
= 1;
// If DOW = Fri
// Add Chevron
case 6:
LDAT5.bit.bit2
break;
= 1;
// If DOW = Sat
// Add Chevron
}
}
} // ChevronRefresh()
//------------------------------------------------------------------------------
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
115
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
A.17 [Display.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : Display.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for 'Display.c'
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 06/06/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__Display_H_
#define
__Display_H_
void
void
void
void
InitialDisplay( void );
ChevronRefresh( void );
DisplayNumber( unsigned char, unsigned char );
ClearDisplay( void );
#endif
Central Heating Controller
116
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[extern.h]
A.18 [extern.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : extern.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// 'extern' declarations for global variables declared in 'data.c'
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#define
__EXTERN_H_
#ifndef
#include
#endif
__DECLARED_H_
"declared.h"
#ifndef
#include
#endif
__LJ12_H_
"lj12.h"
#ifndef
#include
#endif
__DEFINE_H_
"define.h"
#pragma DATA_SEG __SHORT_SEG _DATA_ZEROPAGE
////////////////////////////
// PAGE0 Global variables //
////////////////////////////
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
117
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
extern
uBITS
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned
volatile
unsigned
unsigned
unsigned
unsigned
struct
button_flags;
N2;
DW;
DP;
PR2;
sign;
SMin;
Hour;
mode;
smart;
SHour;
_10ms;
onoff;
Minute;
SFLASH;
Active;
dow_set;
Refresh;
PRNumber;
low_byte;
set_mode;
_0P25sec;
Override;
OverrideH;
OverrideM;
Cset_mode;
Aset_mode;
_5sectick;
one_second;
two_second;
AlarmPRNumber;
button_pattern;
pressed_pattern;
user_temperature;
button_press_status;
external_temperature;
button_release_counter;
button_debounce_counter;
external_temperature_decimal;
flags1;
smart_time;
stop_counter;
BatteryCheck;
internal_temperature;
program[4];
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
char
uBITS
short int
short int
short int
short int
sPROG_PARAMS
////////////////////////////////
// Global non PAGE0 variables //
////////////////////////////////
#pragma DATA_SEG _FAR_RAM
/////////////////////////
// 'const' data ie rom //
/////////////////////////
Central Heating Controller
118
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Routines
[extern.h]
#pragma CONST_SEG ATEECC_CONST_DATA
Freescale Semiconductor, Inc...
#endif
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
119
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
A.19 [i2c.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : i2c.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// i2c routines for accessing external temperature
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 17/06/00 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
"i2c.h"
unsigned char WaitForI2CAcknowledge( void )
{
unsigned char
temp = 0;
SET_DATA_TO_OUTPUT;
////////////////////////////////////////////////////////////
// set SDA hi because during the 9th clock the SLAVE will //
// pull the SDA line lo
//
////////////////////////////////////////////////////////////
SET_SDA;
/////////////////////////////////////////////
Central Heating Controller
120
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[i2c.c]
// data line now input so we can see go lo //
/////////////////////////////////////////////
SET_DATA_TO_INPUT;
SetUpAndHoldTimingDelay();
/////////////////////////////////////////////
// SLAVE should pull line lo anytime
//
/////////////////////////////////////////////
SET_SCL;
SetUpAndHoldTimingDelay();
while ( READ_SDA )
{
if ( ++temp >= 250 )
{
SET_DATA_TO_OUTPUT;
SetUpAndHoldTimingDelay();
RESET_SCL;
return 0;
}
}
////////////////////////////
// basic error check here //
////////////////////////////
// back to output
// 9th clock bit complete
SET_DATA_TO_OUTPUT;
// back to output
SetUpAndHoldTimingDelay();
RESET_SCL;
// 9th clock bit complete
return 1;
} // WaitForI2CAcknowledge()
//------------------------------------------------------------------------------
void SendI2CAcknowledge( void )
{
//////////////////////////////////////////////
// the slave RTC has left the SDA line high //
// for us to send an ACKNOWLEDGE
//
//////////////////////////////////////////////
SET_SDA;
SET_DATA_TO_OUTPUT;
RESET_SCL;
SetUpAndHoldTimingDelay();
RESET_SDA;
SetUpAndHoldTimingDelay();
SET_SCL;
SetUpAndHoldTimingDelay();/
RESET_SCL;
SetUpAndHoldTimingDelay();/
SET_DATA_TO_INPUT;
//////////////////////////////////////////////
// ensure output transistor is '1' before
//
// making an output
//
// take control of the SDA line
//
// an ACKNOWLEGE occurs
//
//
//
// when the SDA is stable lo
//
//
//
// when the clock
//
/
//
// goes hi->lo
//
/
//
// relinquish control back to the slave RTC //
//////////////////////////////////////////////
} // SendI2CAcknowledge()
//------------------------------------------------------------------------------
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
121
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
unsigned char InClock( void )
{
unsigned char
temp;
SET_SCL;
SET_DATA_TO_INPUT;
SetUpAndHoldTimingDelay();
if (READ_SDA)
temp = 1;
else
temp = 0;
RESET_SCL;
SetUpAndHoldTimingDelay();
// reset clock lo to complete read
return temp;
} // InClock()
//------------------------------------------------------------------------------
void OutClock( void )
{
SET_SCL;
SetUpAndHoldTimingDelay();
RESET_SCL;
SetUpAndHoldTimingDelay();
} // OutClock()
//------------------------------------------------------------------------------
void StartBit( void )
{
//////////////////////////////////
// bus inactive conditions here //
//////////////////////////////////
SET_SDA;
SET_SCL;
SET_CLOCK_TO_OUTPUT;
SET_DATA_TO_OUTPUT;
SetUpAndHoldTimingDelay();
/////////////////
// apply START //
/////////////////
SET_SDA;
SetUpAndHoldTimingDelay();
SET_SCL;
SetUpAndHoldTimingDelay();
RESET_SDA;
SetUpAndHoldTimingDelay();
RESET_SCL;
SetUpAndHoldTimingDelay();
} // StartBit()
//------------------------------------------------------------------------------
Central Heating Controller
122
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[i2c.c]
void StopBit( void )
{
RESET_SDA;
SetUpAndHoldTimingDelay();
SET_SCL;
SetUpAndHoldTimingDelay();
SET_SDA;
SetUpAndHoldTimingDelay();
} // StopBit()
//------------------------------------------------------------------------------
void SendI2CByte( unsigned char value )
{
unsigned char
loop;
SET_DATA_TO_OUTPUT;
///////////////////////////////////
// clock is reset from start bit //
///////////////////////////////////
for ( loop = 0; loop < 8; loop++ )
{
value <<= 1;
// load carry flag with bit7
if ( CarryFlagCheck() )
{
SET_SDA;
}
else
{
RESET_SDA;
}
//////////////////////////////////////////
OutClock();
// data is ready now generate the clock //
}
//////////////////////////////////////////
} // SendI2CByte()
//------------------------------------------------------------------------------
unsigned char GetI2CByte( void )
{
unsigned char loop;
unsigned char receiving_value;
SET_DATA_TO_INPUT;
receiving_value = 0;
for ( loop = 0; loop < 8; loop++ )
{
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
123
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
receiving_value <<= 1;
// shifting data left
if ( InClock() )
{
receiving_value |= 1;
}
}
// get next bit sample...
// returns either 0 or 1
// setting bit0 if hi
return receiving_value;
} // GetI2CByte()
//------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
// We require function call-content-return to take 5us (worst case timing).
//
// 5us/(1/2.0E6) == 10 bus cycles
//
//
//
// The call (jsr) is [5] cycles, the return (rts) is [4] cycles leaving the
//
// function body to occupy 10-(5+4) == 1 cycle
//
////////////////////////////////////////////////////////////////////////////////
void SetUpAndHoldTimingDelay( void )
{
NOP();
} // SetUpAndHoldTimingDelay()
//------------------------------------------------------------------------------
void ExternalTemperatureRead( void )
{
union uPORT
lobyte;
char
unsigned short int
dec;
hibyte;
SET_DATA_TO_OUTPUT;
StartBit();
SendI2CByte(BASE_ADDRESS_0);
if ( WaitForI2CAcknowledge() )
{
SendI2CByte(START);
if ( WaitForI2CAcknowledge() )
{
StartBit();
SendI2CByte(BASE_ADDRESS_0);
if ( WaitForI2CAcknowledge() )
{
SendI2CByte(READ);
if ( WaitForI2CAcknowledge() )
{
StartBit();
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
device address - R/W bit = 0
start conversion
repeated start bit
re send device address
command to read double byte of data
re send start condition
Central Heating Controller
124
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Routines
[i2c.c]
SendI2CByte(BASE_ADDRESS_1);
if ( WaitForI2CAcknowledge() )
{
SET_DATA_TO_INPUT;
hibyte = ( char )GetI2CByte();
SendI2CAcknowledge();
lobyte.byte = GetI2CByte();
sign = 0;
//
//
//
//
//
//
//
//
re send device address
prepare to receive high byte of data
get high byte
get low byte
// assume temp're will be +ve
Freescale Semiconductor, Inc...
///////////////////////////
// -ve temperature check //
///////////////////////////
if ( hibyte < 0 )
{
sign = 1;
////////////////////////////////////////////////////////
// integer result, convert from 2's complement to
//
// magnitude.
//
// NOTE: no +1 required for 2's complement conversion //
// as 2's complement value is 1 lower than actual
//
//
//
// This next line produces Lint Warning 502:
//
// Expected unsigned type -- Unary ~ being a bit //
// operator would more logically be applied to
//
// unsigned quantities rather than signed quantities //
//
//
// The 'com' instruction is used and the result is
//
// correct.
//
////////////////////////////////////////////////////////
hibyte = ~hibyte;
// fractional result, convert from 2's com to magnitude
lobyte.byte = ~lobyte.byte + 1;
}
////////////////////////////////
// fractional part processing //
////////////////////////////////
dec = 0;
if ( lobyte.byte >= 0x10 )// is bit 4 or greater, set
{
if ( lobyte.bit.bit7 )
{
dec += 5000;
// 0.5*10000
}
if ( lobyte.bit.bit6 )
{
dec += 2500;
}
// 0.25*10000
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
125
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
if ( lobyte.bit.bit5 )
{
dec += 1250;
}
if ( lobyte.bit.bit4 )
{
dec += 625;
}
// 0.125*10000
// 0.0625*10000
// checking for '0.05' second dec place rounding
if ( dec%1000 >= 500 ) // is remainder >= 0.05
{
dec += 1000;
// 0.1 correction on first decimal
}
// div by 1000 (not 10000) to
dec /= 1000;
// produce integer value for first
// decimal place
////////////////////////////////
// assignment to global space //
////////////////////////////////
external_temperature
= ( unsigned char )hibyte
+ EXTERNAL_CALIBRATION;
external_temperature_decimal = ( unsigned char )dec;
}
}
}
}
}
}
} // ExternalTemperatureRead()
//------------------------------------------------------------------------------
unsigned char CarryFlagCheck( void )
{
unsigned char result = 0;
// assume carry clear
#asm
bcc
CARRY_CHECK_COMPLETE
lda
#$01
sta
result
CARRY_CHECK_COMPLETE:
#endasm
return result;
} // CarryFlagCheck()
//------------------------------------------------------------------------------
Central Heating Controller
126
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[i2c.h]
A.20 [i2c.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : i2c.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for 'i2c.c'
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 17/06/00 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__I2C_H_
#define
__I2C_H_
/////////////////
// I2C defines //
/////////////////
// data
#define SET_DATA_TO_OUTPUT
#define SET_DATA_TO_INPUT
#define RESET_SDA
#define SET_SDA
#define READ_SDA
DDRD.bit.bit2
DDRD.bit.bit2
PTD.bit.bit2
PTD.bit.bit2
PTD.bit.bit2
=
=
=
=
// clock
#define SET_CLOCK_TO_OUTPUT
#define RESET_SCL
#define SET_SCL
DDRD.bit.bit3
PTD.bit.bit3
PTD.bit.bit3
= 1
= 0
= 1
// temperature commands
#define BASE_ADDRESS_0
0x90
1
0
0
1
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
127
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
#define BASE_ADDRESS_1
#define START
#define READ
void
void
unsigned
void
unsigned
void
unsigned
void
void
unsigned
void
char
char
char
char
0x91
0x51
0xaa
SetUpAndHoldTimingDelay( void );
ExternalTemperatureRead( void );
WaitForI2CAcknowledge( void );
SendI2CAcknowledge( void );
CarryFlagCheck( void );
SendI2CByte( unsigned char );
GetI2CByte( void );
OutClock( void );
StartBit( void );
InClock( void );
StopBit( void );
#endif
Central Heating Controller
128
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[interrupt.c]
A.21 [interrupt.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : interrup.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Interrupt routines
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
#include
#include
#include
"interrup.h"
"Display.h"
"startup.h"
"Alarm.h"
#pragma TRAP_PROC
void RTC_INTERRUPT( void )
{
unsigned char temp;
/////////////////////////////////
// 100Hz chronograph interrupt //
/////////////////////////////////
if ( RTCSR.bit.CHRF && RTCCR1.bit.CHRIE )
{
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
129
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
temp
= CHRR.reg;
// clear interrupt by reading CHRR reg
flags1.bit._10MS = 1;
// main() sequencer
}
// RTC_INTERRUPT()
//------------------------------------------------------------------------------
#pragma TRAP_PROC
void LVI_INTERRUPT( void )
{
ServiceWatchDog();
PTB.byte = 0x00;
LVISR.bit.LVIIAK = 1;
// Turn off heating/cooling & LED's
// Resets the interrupt flag
if ( LVISR.bit.LVIOUT )
{
DDRB.reg = 0x00;
DDRD.reg = 0x00;
RTCCR1.bit.CHRIE = 0;
// Set ports to input to reduce...
// current drain
// Disables RTC 100Hz interrupt
ClearDisplay();
LCDCR.reg = 0xb0;
LDAT6.byte = 0x36;
LDAT5.byte = 0x23;
LDAT4.byte = 0x33;
LDAT3.byte = 0x36;
LDAT2.byte = 0x03;
LDAT1.byte = 0x60;
// Adjust LCD to lower power mode
// Displays 'bAtt'
//
//
//
//
//
STOP();
}
else
{
RTCCR2.bit.CHRCLR = 1;
// Reset chronograph counter
MicroStartUp();
// Reinitialises the micro
Alarm();
// Load next alarm into the register
}
}
// LVI_INTERRUPT()
//------------------------------------------------------------------------------
Central Heating Controller
130
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[interrupt.h]
A.22 [interrupt.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : interrup.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for interrup.c
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__INTERRUP_H_
#define
__INTERRUP_H_
////////////////
// prototypes //
////////////////
void RTC_INTERRUPT( void );
#endif
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
131
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
A.23 [lj12.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : lj12.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// register definitions for MC68HC908LJ12
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__LJ12_H_
#define
__LJ12_H_
#ifndef
#include
#endif
__DECLARED_H_
"declared.h"
///////////////////
// CPU Registers //
///////////////////
#define PTA
(*(volatile
#define PTB
(*(volatile
#define PTC
(*(volatile
#define PTD
(*(volatile
#define DDRA
(*(volatile
#define DDRB
(*(volatile
#define DDRC
(*(volatile
#define DDRD
(*(volatile
#define LEDB
(*(volatile
#define SPCR
(*(volatile
union
union
union
union
union
union
union
union
union
union
uPORT*)0x0000)
uPORT*)0x0001)
uPORT*)0x0002)
uPORT*)0x0003)
uPORT*)0x0004)
uPORT*)0x0005)
uPORT*)0x0006)
uPORT*)0x0007)
uPORT*)0x000C)
uPORT*)0x0010)
Central Heating Controller
132
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[lj12.h]
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
SPSCR
SPDR
SCC1
SCC2
SCC3
SCS1
SCS2
SCDR
SCBR
SCIRCR
KBSCR
KBIER
CONFIG2
INTSCR
CONFIG1
T1SC
T1CNTH
T1CNT
T1CNTL
T1MODH
T1MOD
T1MODL
T1SC0
T1CH0H
T1CH0
T1CH0L
T1SC1
T1CH1H
T1CH1
T1CH1L
T2SC
T2CNTH
T2CNT
T2CNTL
T2MODH
T2MOD
T2MODL
T2SC0
T2CH0H
T2CH0
T2CH0L
T2SC1
T2CH1H
T2CH1
T2CH1L
PTCL
PBWC
PMSH
PMS
PMSL
PMRS
PMDS
ADSCR
ADRH
ADR
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
union uPORT*)0x0011)
union uPORT*)0x0012)
union uPORT*)0x0013)
union uPORT*)0x0014)
union uPORT*)0x0015)
union uPORT*)0x0016)
union uPORT*)0x0017)
union uPORT*)0x0018)
union uPORT*)0x0019)
union uPORT*)0x001A)
union uPORT*)0x001B)
union uPORT*)0x001C)
union uPORT*)0x001D)
union uPORT*)0x001E)
union uPORT*)0x001F)
union uPORT*)0x0020)
union uPORT*)0x0021)
USHORT*)0x0021)
union uPORT*)0x0022)
union uPORT*)0x0023)
USHORT*)0x0023)
union uPORT*)0x0024)
union uPORT*)0x0025)
union uPORT*)0x0026)
USHORT *)0x0026)
union uPORT*)0x0027)
union uPORT*)0x0028)
union uPORT*)0x0029)
USHORT*)0x0029)
union uPORT*)0x002A)
union uPORT*)0x002B)
union uPORT*)0x002C)
USHORT*)0x002C)
union uPORT*)0x002D)
union uPORT*)0x002E)
USHORT*)0x002E)
union uPORT*)0x002F)
union uPORT*)0x0030)
union uPORT*)0x0031)
USHORT*)0x0031)
union uPORT*)0x0032)
union uPORT*)0x0033)
union uPORT*)0x0034)
USHORT*)0x0034)
union uPORT*)0x0035)
union uPORT*)0x0036)
union uPORT*)0x0037)
union uPORT*)0x0038)
USHORT*)0x0038)
union uPORT*)0x0039)
union uPORT*)0x003A)
union uPORT*)0x003B)
union uPORT*)0x003C)
union uPORT*)0x003D)
USHORT*)0x003D)
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
133
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
ADRL
ADCLK
RTCCR1
RTCCR2
RTCSR
ALMR
ALHR
SECR
MINR
HRR
DAYR
MTHR
YRR
DOWR
CHRR
LCDCLK
LCDCR
LDAT1
LDAT2
LDAT3
LDAT4
LDAT5
LDAT6
LDAT7
LDAT8
LDAT9
LDAT10
LDAT11
LDAT12
LDAT13
LDAT14
SBSR
SRSR
SBFCR
INT1
INT2
INT3
FLCR
FLBPR
BRKH
BRK
BRKL
BRKSCR
LVISR
COPCTL
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
(*(volatile
union uPORT*)0x003E)
union uPORT*)0x003F)
union uPORT*)0x0042)
union uPORT*)0x0043)
union uPORT*)0x0044)
union uPORT*)0x0045)
union uPORT*)0x0046)
union uPORT*)0x0047)
union uPORT*)0x0048)
union uPORT*)0x0049)
union uPORT*)0x004A)
union uPORT*)0x004B)
union uPORT*)0x004C)
union uPORT*)0x004D)
union uPORT*)0x004E)
union uPORT*)0x004F)
union uPORT*)0x0051)
union uPORT*)0x0052)
union uPORT*)0x0053)
union uPORT*)0x0054)
union uPORT*)0x0055)
union uPORT*)0x0056)
union uPORT*)0x0057)
union uPORT*)0x0058)
union uPORT*)0x0059)
union uPORT*)0x005A)
union uPORT*)0x005B)
union uPORT*)0x005C)
union uPORT*)0x005D)
union uPORT*)0x005E)
union uPORT*)0x005F)
union uPORT far *)0xFE00)
union uPORT far *)0xFE01)
union uPORT far *)0xFE03)
union uPORT far *)0xFE04)
union uPORT far *)0xFE05)
union uPORT far *)0xFE06)
union uPORT far *)0xFE08)
union uPORT far *)0xFE09)
union uPORT far *)0xFE0C)
USHORT far *)0xFE0C)
union uPORT far *)0xFE0D)
union uPORT far *)0xFE0E)
union uPORT far *)0xFE0F)
union uPORT far *)0xFFFF)
//////////////////////////////
// CPU register bit defines //
//////////////////////////////
//////////
// INT1 //
//////////
#define IF1
#define IF2
bit2
bit3
Central Heating Controller
134
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[lj12.h]
#define
#define
#define
#define
IF3
IF4
IF5
IF6
bit4
bit5
bit6
bit7
//////////
// INT2 //
//////////
#define IF7
#define IF8
#define IF9
#define IF10
#define IF11
#define IF12
#define IF13
#define IF14
bit0
bit1
bit2
bit3
bit4
bit5
bit6
bit7
//////////
// INT3 //
//////////
#define IF15
#define IF16
#define IF17
bit0
bit1
bit2
//////////////
// T1SC reg //
//////////////
#define PS0
#define PS1
#define PS2
#define TRST
#define TSTOP
#define TOIE
#define TOF
bit0
bit1
bit2
bit4
bit5
bit6
bit7
///////////////
// T1SC0 reg //
///////////////
#define CH0MAX
#define TOV0
#define ELS0A
#define ELS0B
#define MS0A
#define MS0B
#define CH0IE
#define CH0F
bit0
bit1
bit2
bit3
bit4
bit5
bit6
bit7
//////////////
// TSC1 reg //
//////////////
#define CH1MAX
#define TOV1
#define ELS1A
#define ELS1B
#define MS1A
bit0
bit1
bit2
bit3
bit4
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
135
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
#define CH1IE
#define CH1F
bit6
bit7
//////////////////////////////////////
// A2D status & control reg (ADSCR) //
//////////////////////////////////////
#define ADCH0
bit0
#define ADCH1
bit1
#define ADCH2
bit2
#define ADCH3
bit3
#define ADCH4
bit4
#define ADCO
bit5
#define AIEN
bit6
#define COCO
bit7
//////////////////////////////////
// A2D input clock reg (ADICLK) //
//////////////////////////////////
#define MODE0
bit2
#define MODE1
bit3
#define ADICLK
bit4
#define ADIV0
bit5
#define ADIV1
bit6
#define ADIV2
bit7
//////////////////////////
// FLASH control (FLCR) //
//////////////////////////
#define PGM
bit0
#define ERASE
bit1
#define MASS
bit2
#define HVEN
bit3
/////////////////////////////
// KEYBOARD status/control //
/////////////////////////////
#define MODEK
bit0
#define IMASKK
bit1
#define ACKK
bit2
#define KEYF
bit3
///////////////////////////////
// KEYBOARD interrupt enable //
///////////////////////////////
#define KBIE0
bit0
#define KBIE1
bit1
#define KBIE2
bit2
#define KBIE3
bit3
#define KBIE4
bit4
#define KBIE5
bit5
#define KBIE6
bit6
#define KBIE7
bit7
//////////////////////////
// PLL bandwith control //
Central Heating Controller
136
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[lj12.h]
//////////////////////////
#define AUTO
bit7
#define LOCK
bit6
#define ACQ
bit5
/////////////////
// PLL control //
/////////////////
#define PLLIE
#define PLLF
#define PLLON
#define BCS
#define PRE1
#define PRE0
#define VPR1
#define VPR0
bit7
bit6
bit5
bit4
bit3
bit2
bit1
bit0
//////////
// SCS1 //
//////////
#define SCTE
#define TC
#define SCRF
#define IDLE
#define OR
#define NF
#define FE
#define PE
bit7
bit6
bit5
bit4
bit3
bit2
bit1
bit0
//////////
// SCC2 //
//////////
#define SCTIE
#define TCIE
#define SCRIE
#define ILIE
#define TE
#define RE
#define RWU
#define SBK
bit7
bit6
bit5
bit4
bit3
bit2
bit1
bit0
///////////////////////////
// RTC control1 (RTCCR1) //
///////////////////////////
#define TB2IE
bit0
#define TB1IE
bit1
#define SECIE
bit2
#define MINIE
bit3
#define HRIE
bit4
#define DAYIE
bit5
#define CHRIE
bit6
#define ALMIE
bit7
//////////////////////////
// RTC control (RTCCR2) //
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
137
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
//////////////////////////
#define XTL0
bit0
#define XTL1
bit1
#define XTL2
bit2
#define RTCE
bit4
#define CHRE
bit5
#define CHRCLR
bit6
////////////////////////
// RTC Status (RTCSR) //
////////////////////////
#define TB2F
bit0
#define TB1F
bit1
#define SECF
bit2
#define MINF
bit3
#define HRF
bit4
#define DAYF
bit5
#define CHRF
bit6
#define ALMF
bit7
////////////////////////////
// IRQ status and control //
////////////////////////////
#define MODE
bit0
#define IMASK
bit1
#define ACK
bit2
#define IRQF
bit3
////////////////////////
// LVI Status (LVISR) //
////////////////////////
#define LVIIAK
bit4
#define LVIIF
bit5
#define LVIIE
bit6
#define LVIOUT
bit7
#endif
Central Heating Controller
138
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[main.c]
A.24 [main.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : main.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// main application routine
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
#include
#include
#include
#include
#include
#include
#include
"temperature.h"
"operation.h"
"Clockset.h"
"Alarmset.h"
"Display.h"
"startup.h"
"button.h"
"Alarm.h"
void main( void )
{
MicroStartUp();
DOWR.byte = 0x01;
// Initialise micro
// Set DOW to Mon on first startup
for ( ;; )
{
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
139
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
ServiceWatchDog();
TenMsSynchronise();
ReadButtons();
NewDayRefresh();
switch ( set_mode )
{
case MODE_DEFAULT:
TimeRefresh();
InsideTemperature();
OverrideCheck();
AlarmFlag();
ClimateControl();
break;
case MODE_CLOCKSET:
Cset();
break;
case MODE_ALARMSET:
ModeAlarmSet();
break;
case MODE_VIEWTEMP:
TemperatureView();
break;
}
///////////////
// 10ms sync //
///////////////
while ( !flags1.bit._10MS ) ;
// Waiting for interrupt
flags1.bit._10MS = 0;
// reset, for next loop iteration
}
// end of 'for( ;; )'
}
// end of main
//------------------------------------------------------------------------------
Central Heating Controller
140
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[operation.c]
A.25 [operation.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : operation.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// General Operations
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 17/07/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
#include
#include
"Clockset.h"
"Display.h"
"Alarm.h"
void ClimateControl( void )
{
switch ( mode )
{
case AUTOMATIC:
PTB.bit.bit4 = 1;
PTB.bit.bit5 = 1;
break;
case HEAT:
PTB.bit.bit4 = 0;
PTB.bit.bit5 = 1;
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
141
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
break;
case COOL:
PTB.bit.bit4 = 1;
PTB.bit.bit5 = 0;
break;
case OFF:
PTB.bit.bit4 = 0;
PTB.bit.bit5 = 0;
break;
}
if ( Active )
// If heating control is on
{
if ( user_temperature > (( internal_temperature/10 ) + 1 ))
{
// Divide by 10 for integer value
if ( mode == AUTOMATIC || mode == HEAT )
{
// If heating is needed
PTB.bit.bit0 = 0x01;
// Heating on
PTB.bit.bit1 = 0x00;
// Cooling off
if ( one_second ) PTB.bit.bit5 = 0;// Set mode LED to flash on heating
else
PTB.bit.bit5 = 1;//
}
else if ( mode == COOL || mode == OFF )
{
// If heating is not needed
PTB.bit.bit0 = 0x00;
// Heating off
}
}
else if (user_temperature < (( internal_temperature/10 ) + 1 ))
{
// Divide by 10 for integer value
if ( mode == AUTOMATIC || mode == COOL )
{
// If cooling is needed
PTB.bit.bit0 = 0x00;
// Heating off
PTB.bit.bit1 = 0x01;
// Cooling on
if ( one_second ) PTB.bit.bit4 = 0;// Set mode LED to flash on cooling
else
PTB.bit.bit4 = 1;//
}
else if ( mode == HEAT || mode == OFF )
{
// If cooling is not needed
PTB.bit.bit1 = 0x00;
// Cooling off
}
}
else
{
PTB.bit.bit0 = 0x00;
// Heating off
PTB.bit.bit1 = 0x00;
// Cooling off
}
}
} // ClimateControl()
//------------------------------------------------------------------------------
void SmartTimeCheck( void )
{
Central Heating Controller
142
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[operation.c]
if ( HRR.byte == SHour && MINR.byte == SMin )// One hour before on time
{
if ( smart )
// Is smart mode active
{
smart_time = (( 1000 * internal_temperature )/10 )/user_temperature;
// Divide by 10 for integer value
// Smart calculations, stage 1
if ( smart_time > 1000 )
// For Smart cooling
{
//
smart_time -= 1000;
//
}
//
else
// For Smart heating
{
//
smart_time = 1000 - smart_time;//
}
//
smart_time = 3 * (( smart_time * ( internal_temperature/10 )) /
( 100 * external_temperature
));
// Divide by 10 for integer value
// Smart calculations, stage 2
if ( smart_time > 50 )
//
{
// Maximum cap for smart minutes
smart_time = 50;
//
}
//
if ( SMin < smart_time )
// Prevention for negative minutes
{
//
SMin += 50;
// Maximum cap
}
//
else
{
SHour += 1;
// Adds 1 hour back on to Shour
}
SMin -= (unsigned char)smart_time;// Alarm minutes reduced by smart
program[PRNumber].min_on = SMin;// Loads new on minutes into array
program[PRNumber].hour_on = SHour;// Loads new on hour into array
PRNumber = NO_PROGRAM;
Alarm();
// New times loaded into Alarm reg
}
}
} // SmartTimeCheck()
//------------------------------------------------------------------------------
void OverrideCheck( void )
{
if ( Override == 1 )
// If override is active
{
if ( OverrideH == HRR.byte && OverrideM == MINR.byte )
{
// If override period expired
Override = 0;
// Reset override
if ( !PR2 )
// Program is not currently running
{
Active = 0;
// Turn heating/cooling off
PTB.bit.bit0 = 0x00;
//
PTB.bit.bit1 = 0x00;
//
}
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
143
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
}
}
} // OverrideCheck()
//------------------------------------------------------------------------------
void TimeRefresh( void )
{
if ( BatteryCheck <= LOWBATT && two_second )
{
LDAT12.byte = 0x00;
// Clears unused digit
LDAT11.byte = 0x03;
// Displays 'Lo'
LDAT10.byte = 0x40;
//
LDAT9.byte = 0x26;
//
LDAT8.byte = 0x20;
//
LDAT7.byte = 0x00;
// Clears unused digit
LDAT6.byte = 0x36;
// Displays 'bAtt'
LDAT5.byte = 0x23;
//
LDAT4.byte = 0x33;
//
LDAT3.byte = 0x36;
/
LDAT2.byte = 0x03;
//
LDAT1.byte = 0x60;
//
}
else
{
LDAT6.byte = 0x00;
// Removes the 'b'
LDAT5.byte &= 0x0f;
//
MINClr();
// Refresh TOD display
HRClr();
//
Refresh = 1;
// Refresh internal temperature
ChevronRefresh();
}
} // TimeRefresh()
//------------------------------------------------------------------------------
void TenMsSynchronise( void )
{
if ( ++_10ms%25
== 0 )
{
_0P25sec
^= 0x01;
if ( _10ms%50
{
SFLASH
}
== 0 )
^= 0x01;
if ( _10ms%100 == 0 )
{
one_second ^= 0x01;
_5sectick++;
}
if ( _10ms >= 200 )
{
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
every 0.25s
every 0.5s
every 1.0s
Unsigned char, 256 max
Central Heating Controller
144
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Software Routines
[operation.c]
two_second
10ms = 0;
}
^= 0x01;
// every 2.0s
// reset for next
//
//
Freescale Semiconductor, Inc...
}
} // TenMsSynchronise()
//------------------------------------------------------------------------------
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
145
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
A.26 [operation.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : operation.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for 'operation.c'
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 17/07/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__OPERATION_H_
#define
__OPERATION_H_
void
void
void
void
void
TenMsSynchronise( void );
SmartTimeCheck( void );
ClimateControl( void );
OverrideCheck( void );
TimeRefresh( void );
#endif
Central Heating Controller
146
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[startup.c]
A.27 [startup.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : startup.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// startup routines
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
#include
#include
"Display.h"
"button.h"
"startup.h"
////////////////////////////////////////////////////////////////////////////////
// This function is the first ATEECC function called out of reset, after the //
// Metrowerks startup code.
//
//
//
// A basic initialisation takes place as we enter STOP mode after this
//
// function awaiting a button press.
//
//
//
// Args
: none
//
// Returns: none
//
////////////////////////////////////////////////////////////////////////////////
void MicroStartUp( void )
{
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
147
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
volatile union uPORT*ptr = &LDAT1;
CONFIG1.reg = 0xe2;
// (2^13 - 2^4)/47^3 (ICLK) = 174ms
// watchdog, LVI reset disabled
ServiceWatchDog();
CONFIG2.reg = 0x2e;
INTSCR.reg
SEI();
//
//
//
//
//
= 0x02;
XTAL will still run in STOP()
5V LVI trip, Enables Port C...
to drive LCD (FP19 - FP23)
IRQ interrupts disabled
re-affirm
InitialisePLL();
// LVI setup
LVISR.bit.LVIIAK = 1;
LVISR.bit.LVIIE = 1;
LVISR.bit.LVIIAK = 1;
// Clears Interrupt Acknowledge bit
// Enables LVI interrupt
// Clears Interrupt Acknowledge bit
////////////////////////////////////////////////////////////////////////////////
// Motorola data book MC68HC908LJ12 Rev. 2.0 page 314, states :
//
// "the ADC clock should be set to between 32kHz and 2MHz". Aiming for 1MHz. //
// Therefore divide by 2, since using a 8.00MHz Xtal the bus speed will be
//
// 2MHz. Check this for final pll frequency and adjust accordingly.
//
// Using RIGHT JUSTIFIED mode to store raw unsigned data.
//
////////////////////////////////////////////////////////////////////////////////
// A2D setup
ADCLK.reg = 0x34;
// RTC setup
RTCCR2.reg
= 0x60;
//
//
//
//
RTCCR1.reg
= 0x40;
RTCCR2.bit.RTCE = 1;
/////////////////////
// micro reg setup //
/////////////////////
DDRA.byte
=
DDRD.byte
&=
DDRD.bit.bit0
=
PTD.bit.bit0
=
KBSCR.bit.IMASK
=
KBIER.byte
=
KBSCR.bit.ACKK
=
// Activates keyboard
DDRB.byte
=
rtc off, set for 32.768kHz xtal...
chronograph setup
CHRIE set
...all done, start RTC
0x00;
// Sets button pins to be inputs
0x0f;
1;
// PTD.bit.bit0 is set to output, ...
0;
// low for button release on wakeup
1;
// Masks keyboard interrups
0xff;
1;
interrups and pull up resistors
0xff;
// Sets port B to output
//////////////////////////////////
// user variable initialisation //
//////////////////////////////////
_5sectick
= 5;
PR2
= 0;
user_temperature
= 20;
Central Heating Controller
148
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[startup.c]
Override
PRNumber
_10ms
Aset_mode
Cset_mode
set_mode
button_press_status
SMin
ALHR.reg
ALMR.reg
=
=
=
=
=
=
=
=
=
=
0;
NO_PROGRAM;
0;
0;
0;
MODE_DEFAULT;
NO_BUTTON_PRESS;
60;
23;
59;
// Prevents Alarm being activated...
// accidentaly in the first minute...
// of power up
/////////////////////
// Display Startup //
/////////////////////
LCDCLK.byte = 0x29;
//
= 00101001;
//
|||||||
//
|||||||___ Base Clock/Frame Rate
//
||||||____
"
"
"
"
//
|||||_____
"
"
"
"
//
||||______ LCD Duty Selection
//
|||_______ "
"
"
//
||________ Fast Charge
//
|_________ "
"
LCDCR.reg
//
//
//
//
//
//
//
//
//
//
= 0xbc;
= 10111100;
||||||||
||||||||___
|||||||____
||||||_____
|||||______
||||_______
|||________
||_________
|__________
Contrast Controls
"
"
"
"
"
"
Low Current
Fast Charge
LCD Enable (1 = enabled)
// displays all segments, (NOTE: ptr initialised in declaration)
for ( ; ptr <= &LDAT12; ptr++ )
{
ptr->reg = 0xff;
}
InitialDisplay();
//////////////////
// Interputs on //
//////////////////
CLI();
} // MicroStartUp()
//------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
// This function initialises the onboard pll to provide a bus frequency of
//
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
149
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
// 2.0MHz using a 32.768kHz xtal.
//
//
//
// Args
: none
//
// Returns: none
//
////////////////////////////////////////////////////////////////////////////////
void InitialisePLL( void )
{
/////////////////////////////////////////////
PBWC.reg
= 0x80;
// auto mode
//
PTCL.reg
= 0x00;
// settings here...
//
PMS
= 0x00F5;
// as described in...
//
PMRS.reg
= 0xD1;
// the MC68HC908LJ12
//
PMDS.reg
= 0x01;
// Rev2.0 data book section 8.4.6 page 113 //
PTCL.bit.PLLON = 1;
// turn pll on after settings 'set'
//
/////////////////////////////////////////////
///////////////////////////////////////////////////
// wait for the required frequency to be reached //
///////////////////////////////////////////////////
ServiceWatchDog();
while ( !PBWC.bit.LOCK );
PTCL.bit.BCS = 1;
// pll clock drives CGMOUT
} // InitialisePLL()
//------------------------------------------------------------------------------
Central Heating Controller
150
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[startup.h]
A.28 [startup.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : startup.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for 'startup.c'
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 15/05/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__STARTUP_H_
#define
__STARTUP_H_
////////////////
// prototypes //
////////////////
void MicroStartUp( void );
void InitialisePLL( void );
#endif
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
151
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
A.29 [temperature.c]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : temperature.c
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Temperature Operations
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 17/07/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__EXTERN_H_
#include
"extern.h"
#endif
#include
#include
#include
"Display.h"
"i2c.h"
"a2d.h"
void TemperatureView( void )
{
ClearDisplay();
LDAT12.byte = 0x33;
LDAT11.byte = 0x10;
if ( sign )
{
LDAT8.byte
= 0x03;
LDAT7.byte
= 0x70;
LDAT6.bit.bit1 = 1;
}
else LDAT6.byte = 0x37;
// Displays "P"
//
// Displays "E" in digit 5
//
// Displays "-"
Central Heating Controller
152
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[temperature.c]
DisplayNumber( external_temperature_decimal, 1 );
DP = 1;
// Display inside temperature decimal
DisplayNumber(( unsigned char )(external_temperature%10 ), 2 );
DP = 0;
if ( external_temperature >= 10 )// Clears 'tens' digit when not needed
{
//
DisplayNumber(( unsigned char )( external_temperature/10 ), 3 );
}
DisplayNumber( (unsigned char)(user_temperature/10), 7 );
DisplayNumber( (unsigned char)(user_temperature%10), 6);
if ( smart )LDAT2.bit.bit2 = 1;
// Displays smart chevron if needed
else
LDAT2.bit.bit2 = 0;
Refresh = 1;
// Refresh the inside temp
} // TemperatureView()
//------------------------------------------------------------------------------
void InsideTemperature( void )
{
unsigned char temp, temp2;
if ( _5sectick >= 5 )
{
Refresh = 1;
5sectick = 0;
ExternalTemperatureRead();
/////////////////////////////////////////////////////////////////////////////
// The internal temperature calculations:
//
//
//
// The A2D byte is multiplied by 4.8V (ref V) to convert it to 10000 * the //
// i/p voltage, it is then / by 100 to convert it to 100 * the i/p voltage //
//
//
// The result is then * by 40 which is the desired maximum temperature,
//
// and / by 5 which is the maximum input voltage from the opamp.
//
//
//
// Finally the result is / by 10 to leave it in a manageable form
//
/////////////////////////////////////////////////////////////////////////////
internal_temperature = ( 48 * ReadA2D( CHANNEL0 ))/100;
internal_temperature = ( internal_temperature * 40 )/( 5 * 10 );
BatteryCheck = ReadA2D( CHANNEL2 );
}
if ( Refresh
{
Refresh =
temp = (
temp2 = (
)
0;
unsigned char )( internal_temperature/100 );
unsigned char )( internal_temperature - ( 100 * temp ));
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
153
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
if ( temp )
// If number is >= 10
{
DisplayNumber(( unsigned char )( temp ), 3 );
}
// Tens displayed
else
{
LDAT4.byte = 0x00;
// Clear tens number
LDAT5.byte &= 0xf0;
//
}
DP = 1;
DisplayNumber(( unsigned char )( temp2/10 ), 2 );
DP = 0;
// Units displayed with decimal point
DisplayNumber(( unsigned char )( temp2%10 ), 1);
if ( smart )LDAT2.bit.bit2 = 1;
// Displays smart chevron if needed
else
LDAT2.bit.bit2 = 0;
ChevronRefresh();
}
} // InsideTemperature()
//------------------------------------------------------------------------------
Central Heating Controller
154
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
Software Routines
[temperature.h]
A.30 [temperature.h]
////////////////////////////////////////////////////////////////////////////////
//
AA
TTTTTTTTTTTT EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
//
AAAA
TTTTTTTTTTTT EEE
EEE
CC
CC
//
//
AAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAAAAAA
TTTT
EEEEE
EEEEE
CC
CC
//
//
AAAA AAAA
TTTT
EEE
EEE
CC
CC
//
// AAAA
AAAA
TTTT
EEEEEEEEEEE EEEEEEEEEEE
CCCCCCCCC CCCCCCCCC //
////////////////////////////////////////////////////////////////////////////////
// AT Electronic Embedded Control Consultants
//
// Unit 32, Consett Business Park
//
// Villa Real, Consett
//
// Co. Durham
//
// DH8 6BP
//
// England
//
//
//
// Telephone: 0044 1207 693920
//
// Fax
: 0044 1207 693921
//
// email
: [email protected]
//
// web
: www.ateecc.com
//
////////////////////////////////////////////////////////////////////////////////
// Project
: Motorola Central Heating Reference Design
//
// Filename : temperature.h
//
// Author
: T. Mudryk
//
// Compiler : CodeWarrior v5.2
//
// CPU
: MC68HC908LJ12
//
///////////////////// File Contents //////////////////////////////////////////
// Header file for 'temperature.c'
//
////////////////////////// Update Information ////////////////////////////////
// Ed. Date
Init's Modification
//
// --- -------- ------ ----------------------------------------------------//
// 001 17/07/03 tm
creation
//
////////////////////////////////////////////////////////////////////////////////
#ifndef
__TEMPERATURE_H_
#define
__TEMPERATURE_H_
void InsideTemperature( void );
void TemperatureView( void );
#endif
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Software Routines
For More Information On This Product,
Go to: www.freescale.com
155
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Software Routines
Central Heating Controller
156
DRM044 — Rev 0
Software Routines
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
Freescale Semiconductor, Inc...
Appendix B. Main Circuit Diagram
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Main Circuit Diagram
For More Information On This Product,
Go to: www.freescale.com
157
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Main Circuit Diagram
Central Heating Controller
158
DRM044 — Rev 0
Main Circuit Diagram
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
Freescale Semiconductor, Inc...
Appendix C. Main Circuit Bill of Materials
Resistors
R1
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13
R20
R22
R23
R24
R25
R26
R27
330k +/-5%
10k+/-5%
680R+/-5%
5k6 +/-5%
12k +/-1%
5k6 +/-5%
10k +/-1%
680R +/-5%
1k +/-5%
0R (see text)
0R (see text)
100k +/-1%
10M +/-5%
22k +/-5%
10k +/-5%
220R +/-5%
10k +/-5%
10k +/-5%
10k +/-5%
10k +/-5%
1206
1206
1206
1206
1206
1206
1206
1206
1206
1206
1206
1206
1206
1206
1206
1206
1206
1206
1206
1206
Capacitors
C1
C2
C3
C4
C5
C6
C7
C8
C9
C11
C13
C23
C22
10nF 30V
100nF 30V
100nF 30V
100uF 10V
100nF 30V
33nF 30V
100nF 30V
15pF 30V
15pF 30V
220uF 10v
220uF 25v
100nF 30V
100nF 30V
1206
1206
1206
Radial
1206
1206
1206
1206
1206
Radial
Radial
1206
1206
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Main Circuit Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
159
Freescale Semiconductor, Inc.
Main Circuit Bill of Materials
Freescale Semiconductor, Inc...
Semiconductors
D1
D3
D4
D5
D8
D9
Q1
Q2
Q3
Q4
Q7
Q8
U2
U1
LED1
LED2
LED3
LED4
Miscellaneous
XT1
BT1
RL1
RL2
DISP1
PCB
PCB
Connectors
J3
J4
J5
J6
J8
J9
J15
J16 - J17
CN1-CN4
LL4148
LL4148
LL4148
LL4001
LL4001
BAT754
BC850
BC850
LM35CZ
TS942ID
DS1721
BC850
LM78L05
MC68HC908LJ12
Blue
Red
White
White
MINI MELF
MINI MELF
MINI MELF
MELF
MELF
SOT-23
SOT-23
SOT-23
TO92
SO8
SO-8
SOT-23
TO92
64pin QFP
3mm
3mm
5mm
5mm
32.768kHz
Coin Cell Battery Holder
3V Lithium
Omron_G5B 12VDC Coil
Omron_G5B 12VDC Coil
Varitronix VIM-838
FR4 PTH 130mm x 75mm
FR4 15mm x 25mm
Radial
Main PCB
Remote sensor
3 -pin 0.1" pitch header
3-pin Molex kk connector
4-pin Molex kk connector
2-pin 0.1" pitch header
2-pin 0.1" pitch header
12VDC
4-pin Molex kk connector
10 -way 0.1" pitch box header
0.625" Faston Blade
Central Heating Controller
160
Coin
DRM044 — Rev 0
Main Circuit Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
Freescale Semiconductor, Inc...
Appendix D. Programming Circuit Diagram
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Programming Circuit Diagram
For More Information On This Product,
Go to: www.freescale.com
161
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Programming Circuit Diagram
Central Heating Controller
162
DRM044 — Rev 0
Programming Circuit Diagram
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
Freescale Semiconductor, Inc...
Appendix E. Programming Circuit Bill of Materials
Resistors
R14
R15
R16
R17
R18
R19
R21
1k +/-5%
10k +/-5%
10k +/-5%
10k +/-5%
10k +/-5%
10k +/-5%
10k +/-5%
Package
1206
1206
1206
1206
1206
1206
1206
Capacitors
C12
C14
C15
C16
C17
C18
C19
C20
C21
100nF 30V
100nF 30V
100nF 30V
100nF 30V
100nF 30V
220µF 10V
100nF 30V
100nF 30V
100nF 30V
1206
1206
1206
1206
1206
Radial
1206
1206
1206
Semiconductors
Q5
Q6
D6
D7
U3
U4
U5
XT2
BC850
BC850
LL4148
MMBZ5229
74HC125D
MAX232D
LM78L08
9.8304 MHz
SOT23
SOT23
MINI MELF
SOT23
SO-14
SO-16 Wide
TO92
Oscillator Module
Connectors
J1, J7
J2
J14
10 -way 0.1" pitch box header
9-way 'D' type
2-pin 0.1" pitch header
Female
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
Programming Circuit Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
163
Freescale Semiconductor, Inc.
Freescale Semiconductor, Inc...
Programming Circuit Bill of Materials
Central Heating Controller
164
DRM044 — Rev 0
Programming Circuit Bill of Materials
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
Designer Reference Manual — DRM044
Appendix F. PCB Details
Freescale Semiconductor, Inc...
F.1 Component Trace
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
PCB Details
For More Information On This Product,
Go to: www.freescale.com
165
Freescale Semiconductor, Inc.
PCB Details
Freescale Semiconductor, Inc...
F.2 Component Silk Screen
Central Heating Controller
166
DRM044 — Rev 0
PCB Details
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc.
PCB Details
Solder Trace
Freescale Semiconductor, Inc...
F.3 Solder Trace
DRM044 — Rev 0
MOTOROLA
Central Heating Controller
PCB Details
For More Information On This Product,
Go to: www.freescale.com
167
Freescale Semiconductor, Inc.
PCB Details
Freescale Semiconductor, Inc...
F.4 Solder Silk Screen
Central Heating Controller
168
DRM044 — Rev 0
PCB Details
For More Information On This Product,
Go to: www.freescale.com
MOTOROLA
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc...
Freescale Semiconductor, Inc.
HOW TO REACH US:
USA/EUROPE/LOCATIONS NOT LISTED:
Motorola Literature Distribution;
P.O. Box 5405, Denver, Colorado 80217
1-303-675-2140 or 1-800-441-2447
JAPAN:
Motorola Japan Ltd.; SPS, Technical Information Center,
3-20-1, Minami-Azabu Minato-ku, Tokyo 106-8573 Japan
81-3-3440-3569
ASIA/PACIFIC:
Motorola Semiconductors H.K. Ltd.;
Silicon Harbour Centre, 2 Dai King Street,
Tai Po Industrial Estate, Tai Po, N.T., Hong Kong
852-26668334
Information in this document is provided solely to enable system and software
implementers to use Motorola products. There are no express or implied copyright
licenses granted hereunder to design or fabricate any integrated circuits or
integrated circuits based on the information in this document.
TECHNICAL INFORMATION CENTER:
Motorola reserves the right to make changes without further notice to any products
1-800-521-6274
herein. Motorola makes no warranty, representation or guarantee regarding the
suitability of its products for any particular purpose, nor does Motorola assume any
HOME PAGE:
http://motorola.com/semiconductors
liability arising out of the application or use of any product or circuit, and specifically
disclaims any and all liability, including without limitation consequential or incidental
damages. “Typical” parameters which may be provided in Motorola data sheets
and/or specifications can and do vary in different applications and actual
performance may vary over time. All operating parameters, including “Typicals”
must be validated for each customer application by customer’s technical experts.
Motorola does not convey any license under its patent rights nor the rights of
others. Motorola products are not designed, intended, or authorized for use as
components in systems intended for surgical implant into the body, or other
applications intended to support or sustain life, or for any other application in which
the failure of the Motorola product could create a situation where personal injury or
death may occur. Should Buyer purchase or use Motorola products for any such
unintended or unauthorized application, Buyer shall indemnify and hold Motorola
and its officers, employees, subsidiaries, affiliates, and distributors harmless
against all claims, costs, damages, and expenses, and reasonable attorney fees
arising out of, directly or indirectly, any claim of personal injury or death associated
with such unintended or unauthorized use, even if such claim alleges that Motorola
was negligent regarding the design or manufacture of the part.
Motorola and the Stylized M Logo are registered in the U.S. Patent and Trademark
Office. digital dna is a trademark of Motorola, Inc. All other product or service
names are the property of their respective owners. Motorola, Inc. is an Equal
Opportunity/Affirmative Action Employer.
© Motorola, Inc. 2003
DRM044
For More Information On This Product,
Go to: www.freescale.com