THE ENGINEER’S ALARM CLOCK Ryan Crawford Chris Douglas

advertisement
THE ENGINEER’S
ALARM CLOCK
Ryan Crawford
Chris Douglas
EGGN 383
December 3,
2012
PURPOSE & MOTIVATION
Alarm Clock
LCD display
Keypad interface
 This makes it easy to input times
User input required to turn off alarm
 Answer some question with a numerical answer
 Usually math-based questions
 This promotes the user being awake after the alarm has stopped
ringing
HARDWARE
KEYPAD
Uses a mesh of crossing wires to determine
which key has been pressed
4 of the pins are connected to input pins on Port
T, these correspond to the rows of the keypad
2 of the pins are connected to output pins on Port
T, these correspond to the columns of the keypad
 These are sequentially turned off to search for which
key was pressed
The other column of the keypad is attached to
+5V
LCD
DB7:DB4 are connected to PM0:PM3
Enable is connected to PT7
Locks in data
RS is connected to PM5
Tells if input is “Instruction” or “Data”
5kΩ potentiometer controls screen
contrast
SPEAKER
Hardwired to PM4
Output sound using square wave input
PT2 drives PM4 so that the output tone
is variable
This allows the tone to be constant, and not be
interrupted by any of the other interrupts (no
“clicking” sound)
SOFTWARE
Initialize PWM,
OC, LCD
Timing
Interrupt
Main Loop
(Do Nothing)
Keypad
Interrupt &
Polling
Alarm
Interrupt
STATES
5 Different States
Seed
Default
Set Time
Set Alarm
Alarm Blaring
Keypad input, time, and current state
determine next state
Finite State Machine
TIMING INTERRUPT
Occurs every 100ms (0.1s)
Increments current time by 0.1s
Time stored in an unsigned char array
(hhmmsst)
Handles rollover
Checks if alarm should sound
 If so, changes to ‘Alarm Blaring’ state
Updates LCD with “new” time
Uses output compare interrupt on PT5
KEYPAD INTERRUPT
Occurs every 3.2ms
Checks if any of the Port T input pins are high
 If one is high, goes into a control structure to see
which key was pressed by pulling PT4 and then PT6
low
 Don’t need to pull the other column low by process of
elimination -> Saves on pins
 Debouncing code compares current detected key
press to previous detected key press
KEYPAD INTERRUPT (CONTINUED)
Once a key press has been detected, the
key press is handled in a lengthy control
structure
Current state determines how each press
changes the system
 For example, if ‘#’ is pressed in the default state,
the state changes to ‘Set Alarm’
Updates the LCD
ALARM INTERRUPT
Occurs every 100ms (0.1s)
Interrupt only enabled when in ‘Alarm
Blaring’ state
Changes the tone of the alarm
This allows patterns or ‘songs’
Disabled once correct answer is input
OTHER ASPECTS
Main loop initializes all the components
and then does nothing
PWM system
3 Output Compares
Initialize LCD
Several other peripheral functions to
write to the LCD, move cursor position,
etc.
LCD OUTPUT
There are five screens
Press any button
Default (displays current time)
Alarm set
Time set
Answer the alarm question
PICTURES OF LCD SCREEN
Default
Set Time
Set Alarm
Answer Question
QUICK DEMO
SUMMARY
Project utilizes Timing and Output
Compare, PWM system, and Interrupts from
HCS12 microcontroller
Additional hardware – Keypad, LCD,
speaker
Alarm clock for engineers
Set time, alarm time, toggle alarm on/off, answer
math question to turn alarm off
Math questions must be answered to turn alarm
off
QUESTIONS?
Download