Appendix

Schematics

Figure 3 Schematics for the Teachers Timer project.

Listing 1: Main loop from the timer.asm file

;****************************************************************************

; MAIN LOOP

;

loop:

;check for alarm status

check_alm:

mov tempa,state

andi tempa,(1<<sALARM)

breq update_laser

;Update Laser or motor for alarm state

mov tempa,state

andi tempa, (1<<sLASER)

breq alarm_motor

out OCR0B,pwm ;fade laser on

ldi tempa,MOTOR_PWROFF

out OCR0A,tempa ;turn motor off

rjmp check_button1

alarm_motor:

ldi tempa,LASER_PWROFF

out OCR0B,tempa ;turn laser off

out OCR0A,pwm ;turn motor on

rjmp check_button1

;Update Laser and motor for normal state

update_laser:

mov tempa,state

andi tempa, (1<<sLASER)

breq laser_OFF

ldi tempb,LASER_PWR ;turn laser on

out OCR0B,tempb

rjmp update_motor

laser_OFF:

ldi tempb,LASER_PWROFF ;turn laser off

out OCR0B, tempb


update_motor:

mov tempa,state

andi tempa, (1<<sMOTOR)

breq motor_OFF

out OCR0A,pwm

rjmp check_button1

motor_OFF:

ldi tempb, MOTOR_PWROFF ;turn motor off

out OCR0A, tempb


;Read buttons and switches 

check_button1: ;laser control switch

mov tempa,state

andi tempa, (1<<sBUTTON1)

breq check_button2

; check for both buttons

mov tempb,state

andi tempb, (1<<sBUTTON2)

breq toggle_laser

; set to idle mode

rjmp MAIN

toggle_laser:

; Button 1 pushed -> toggle laser state

ldi tempa,(1<<sLASER)

eor state,tempa

cbr state,(1<<sBUTTON1) ;clear button press flag


check_button2: ;timing control switch

mov tempa,state

andi tempa, (1<<sBUTTON2)

breq end

; Button 2 pushed -> add alarm time.

cbr state,(1<<sBUTTON2) ;clear button press flag

cbr state,(1<<sIDLE)


;check if alarm is sounding

mov tempa,state

andi tempa,(1<<sALARM)

breq add_time

;stop alarm

cbr state,(1<<sALARM)

clr alarm ;set alarm to 0 minutes

add_time:

;reset timers

clr minutes

clr seconds

clr countL

clr countH

sbr state,(1<<sCOUNT) ;Flag for long key press

;increment the alarm time

ldi tempa,TIME_INC

add alarm,tempa

sbr state,(1<<sMOTOR) ;pulse to acknowledge

ldi ZL, PWM_ZERO



end:

; Go to sleep and wait for an interupt to wake us. 

; (IDLE MODE) keep timers running. stop main clock.

sei

ldi tempa,(0<<PUD)|(1<<SE)|(0<<SM1)|(0<<SM0)|(0<<ISC01)|(0<<ISC00)

out MCUCR,tempa

sleep;

; just woke up, disable sleep

ldi tempa,(0<<PUD)|(0<<SE)|(0<<SM1)|(0<<SM0)|(0<<ISC01)|(0<<ISC00)

out MCUCR,tempa

cli

rjmp loop