Alarm Clock Assembly Code
Transcript of Alarm Clock Assembly Code
-
8/22/2019 Alarm Clock Assembly Code
1/26
;-----------------------------------------------------------------------------; Copyright (C) 2001 Samuel Barnes.; All rights reserved.;; Name Samuel Barnes
; !ogin "arnsa; #ome$or% & '; ate 11-2'-01; *!+ NA,+ "arnsa.AS,; A/+ ,C C01000; +SC*3*4N imer program5 $ill 6ount three things 6ount se6onds a7ter you hit ,4,0; a simple stop $at6h5 $ill 6ount ho$ long you hold do$n ,4,0 in se6onds5 and; $ill 6ount ho$ many times you press ,4,25 ,4,1 is a reset. No !As on is stop; $at6h mode5 !A0 on is hold do$n mode5 and !A1 on is 6ount "utton press mode5; i7 !A0 and !A1 are "oth on nothing $ill run.;
;; N4+S; (1) ,emory usage; Bytes; 85 15 2 9 Clo6% egisters :-< 9 Alarm egisters -' 9 otal imer=alue 0 9 (indire6t addressing);; 0h 9 Clo6% 1>20 o7 a se6 "yte; 0?h 9 Blin% elay "yte; 0Ah-0Bh 9 Set mode display "ytes; 0Ch 9 imer delay "yte
; 0h 9 Alarm delay "yte; 0+h 9 Alarm time limit "yte; 0h 9 4ld time value; 10h-11h 9 4ld display "ytes value (used so it is only updated $hen they 6hange); 12h 9 Set isplay mode; 1:h - 1h 9 Current Chrono =alues; 1'h - 1h 9 indire6t addressing "ytes; 20h-22h 9 *nstant timer value; 2:h-2h 9 4ld *nstant timer value; 2'h 9 4ld Chrono =alue; 28h 9 Chrono delay "yte; 2h 9 Bit values; @2?h 9 Saved 7or 7uture "it values; 2Ah 9 enths o7 se6ond 6hrono "it; 2Bh 9 Alarm on o77 "yte; 2Ch - 2h 9 n-sed;; Bits;
-
8/22/2019 Alarm Clock Assembly Code
2/26
;
-
8/22/2019 Alarm Clock Assembly Code
3/26
; =A*AB!+S;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------; +S+ and *N+3 =+C4S;-----------------------------------------------------------------------------
; eset =e6tor 6seg A 0 lDmp ,ain ; !o6ate a Dump to the start o7 6ode at
; the reset ve6tor.
org 000BhlDmp imer0E*nt
org 001BhlDmp imer1E*nt
org 002BhlDmp imer2E*nt
org 008:hlDmp imer:E*nt
;-----------------------------------------------------------------------------; C4+ S+/,+N;-----------------------------------------------------------------------------
CodeESeg segment C4+
rseg CodeESeg ; S$it6h to this 6ode segment. using 0 ; Spe6i7y register "an% 7or the 7ollo$ing ; program 6ode.
,ain ; isa"le the . (*s not ena"led at this point.); *7 interrupts $ere ena"led5 $e $ould need to eFpli6itly disa"le; them so that the 2nd move to CN o66urs no more than 7our 6lo6%; 6y6les a7ter the 7irst move to CN.mov CN5 &0+hmov CN5 &0Ah
-
8/22/2019 Alarm Clock Assembly Code
4/26
;------------------------------------------------------------------------------------------;Cyrstal initialiGation
;------------------------------------------------------------------------------------------;H4SC, 110;HCN 101
mov 4SCHCN5 &'h ;11100101mov 4SC*CN5 &1h ;00011000
;------------------------------------------------------------------------------------------;3ort *>4 Cross"ar *nitialiGation
;------------------------------------------------------------------------------------------
mov HB25 &
-
8/22/2019 Alarm Clock Assembly Code
5/26
mov 0Ch5 &01h ;timer delay "ytemov 0h5 &01h ;alarm delay "ytemov 05 &00hmov 15 &00hmov 25 &00h
mov :5 &00hmov
-
8/22/2019 Alarm Clock Assembly Code
6/26
mov ,:!#5 &08' ; imer : eload egister #igh Bytemov ,:!!5 &001 ; imer : eload egister !o$ Byte
,4= #15&08' ;#igh "yte o7 timer 8' (ma%es 1>20 o7 a se6),4= !15&01 ;!o$ "yte o7 time1
;,4= #05&0h ;#igh "yte o7;,4= !05&01h ;!o$ "yte o7
;S+B 0 ;starts timer0;S+B 1 ;starts timer1
;------------------------------------------------------------------------------------------; #eadphone *nitialiGation;------------------------------------------------------------------------------------------
mov +0CN5 &0:hmov AC0CN5 &0
-
8/22/2019 Alarm Clock Assembly Code
7/26
Dmp Clo6%
imer,ode!lDmp imer,ode
Setimer!
lDmp Setimer
SetAlarm;mov ,:CN5 &00
-
8/22/2019 Alarm Clock Assembly Code
8/26
DG rap#ourADmp SetAlarm
rap#ourAmov
-
8/22/2019 Alarm Clock Assembly Code
9/26
add A5 2 ;in6riments the hours on the alarmmov 25 A66
mov A665 &2< ;2< $raps $hen hours get to 2:su"" A5 2
DG rap#ourCDmp SetClo6%
rap#ourCmov 25 &00hDmp SetClo6%
;end set Clo6%
Setimer;mov ,:CN5 &00
-
8/22/2019 Alarm Clock Assembly Code
10/26
mov 5 &00hDmp Setimer
Add#ourD" ,4,:5 Add#our ;$ait 7or "utton release
mov A665 &1hadd A5 ' ;in6riments the hours on the alarmmov '5 A66
mov A665 &18h ;(2: "ase 10) $raps $hen hours get to 2:su"" A5 'DG rap#ourDmp Setimer
rap#ourmov '5 &00h
Dmp Setimer
;end set timer
/oClo6%;mov ,:CN5 &000h ;stops timer :mov 10h5 &0h ;$rites h to old display "its so display $ill re7reshmov 11h5 &0h ;as soon as you go into set modelDmp Clo6%
imer,odeD" ,4,05 imer,ode ;$aits 7or "utton to "e relased!CA!! e7reshEisplay
imer,ode!oop ;so the $rong D" ,4,0 $onIt get sele6tedD" ,4,15 StartStop!D" ,4,25 esetimer!D" ,4,05 Chrono,ode!D" !A15 Clo6%!!D" !A25 Clo6%!!D" !A:5 Clo6%!!
;move timer memory 20h-22h to displayJJJJJJJ;6omapre old instant values (2:h-2h) $ith ne$ to see i7 you
update display
-
8/22/2019 Alarm Clock Assembly Code
11/26
mov A5 2:h ;6ompares the se6onds6Dne A5 20h5 pdateimermov A5 2
-
8/22/2019 Alarm Clock Assembly Code
12/26
mov 0h5 20h ;se6onds!CA!! e7reshEisplay
S+B +N ;moves to se6ond hal7 o7 display
C! S,4= 305&0C0h!CA!! A*E!CC! +N
mov A5 &I I!CA!! riteEeFtmov A5 &ItI!CA!! riteEeFtmov A5 &IiI!CA!! riteEeFt
mov A5 &ImI!CA!! riteEeFtmov A5 &IeI!CA!! riteEeFtmov A5 &IrI!CA!! riteEeFt
Dmp imer,ode!oop
StartStopD" ,4,15 ;$ait 7or "utton release
D"
-
8/22/2019 Alarm Clock Assembly Code
13/26
esetimerD" ,4,25 ;$ait 7or "utton release
6lr 1 ;stops the timer
6lr
-
8/22/2019 Alarm Clock Assembly Code
14/26
mov 2'h5 1:h ;updates old 6hrono value sin6e $e are re7reshing
mov 0h5 1h!CA!! e7reshEisplay ;$rite hours to display
mov A5 &II!CA!! riteEeFt ;6olon
mov 0h5 1
-
8/22/2019 Alarm Clock Assembly Code
15/26
Dmp Chrono,ode
StopC6lr
-
8/22/2019 Alarm Clock Assembly Code
16/26
!CA!! riteEeFt;se6onds
mov 0h5 8!CA!! e7reshEisplay
+FitC+
e7reshESet
mov A5 10h ;6ompare 0Ah and 10h6Dne A5 0Ah5 Continuepdatemov A5 11h ;6ompares 0Bh and 11h6Dne A5 0Bh5 Continuepdate
Dmp +FitS
Continuepdate ;uses display "ytes (this timer used 7or multiples sets)mov 10h5 0Ah ;updates old values "e6ause display is re7eshingmov 11h5 0Bh
!CA!! ClearE!C!CA!! CursorE#ome
mov 0h5 0Bh ;hours!CA!! e7reshEisplay
mov A5 &II ;6olon!CA!! riteEeFt ;$rite the a66 to display
;minutesmov 0h5 0Ah!CA!! e7reshEisplay
mov A5 &I I!CA!! riteEeFtmov A5 &ISI!CA!! riteEeFtmov A5 &IeI!CA!! riteEeFt
S+B +N ;moves to se6ond hal7 o7 displayC! S,4= 305&0C0h!CA!! A*E!CC! +N
-
8/22/2019 Alarm Clock Assembly Code
17/26
mov A5 &ItI!CA!! riteEeFt
mov A5 12h ;12h 9 Set display mode "yte
de6 ADG isplayEClo6% ;6hoses to $rite Set Clo6%5 Set Alarm5 or Set imer;su"" A5 &01hde6 ADG isplayEimer;su"" A5 &01hde6 ADG isplayEAlarm
isplayEAlarm
mov A5 &I I!CA!! riteEeFtmov A5 &IAI!CA!! riteEeFtmov A5 &IlI!CA!! riteEeFtmov A5 &IaI!CA!! riteEeFtmov A5 &IrI!CA!! riteEeFtmov A5 &ImI!CA!! riteEeFt
Dmp +FitS
isplayEimermov A5 &I I!CA!! riteEeFtmov A5 &II!CA!! riteEeFtmov A5 &IiI!CA!! riteEeFtmov A5 &ImI!CA!! riteEeFtmov A5 &IeI!CA!! riteEeFtmov A5 &IrI!CA!! riteEeFt
Dmp +FitS
-
8/22/2019 Alarm Clock Assembly Code
18/26
isplayEClo6%mov A5 &I I!CA!! riteEeFt
mov A5 &ICI!CA!! riteEeFtmov A5 &IlI!CA!! riteEeFtmov A5 &IoI!CA!! riteEeFtmov A5 &I6I!CA!! riteEeFtmov A5 &I%I!CA!! riteEeFt
Dmp +FitS
+FitS+
;------------------------------------------------------; *nterupts Code;------------------------------------------------------
imer0E*nt ;Alarm imer push A66push Bpush 3Spush 00h
,4= #05&0+8h ;#igh "yte o7 timer0 0+8h (per7e6t annoying alarm pit6h),4= !05&000h ;!o$ "yte o7 timer05 00h
Dn" !A05 Alarm477 ;i7 alarm !A is turned o775 turn o77 alarm
dDnG 0h5 Alarming ;pro"a"ly need to 6hange thisJJJJJJJmov 0h5 &0h
de6 0+h ;de6riments alarm time "yte and 6he6%s itmov A665 0+hDG Alarm477
;alarming stu77JJJJJJJJJJJJJJ
-
8/22/2019 Alarm Clock Assembly Code
19/26
AlarmingdDnG 2Bh5 lash
6pl
-
8/22/2019 Alarm Clock Assembly Code
20/26
imer1E*nt ;Count o$n imer push A66push B
push 3Spush 00h
dDnG 0Ch5 +Fit1mov 0Ch5 &20 ;ma%es it run 20 times (1 se6)
mov A665 22h ;6he6%s to see i7 timer has run outDnG S%ipmov A665 21hDnG S%ipmov A665 20h
DG imerAlarm
S%ipmov A665 20h ;only time se6onds $ould "e Gero $ithout the de6riment getting
it isDG MeroSe6onds ;the 7irst run5 so this only applies to then
dDnG 20h5 +Fit1 ;pro"lem se6onds 6an still "e GeroJJJJJJJJ(* thin% it is 7iFed)
MeroSe6ondsmov A665 21hDG Che6%#ourde6 21h ;i7 se6onds are Gero de6riment minutesmov 20h5 &? ;reset se6onds to ?Dmp +Fit1
Che6%#ourmov A665 22hDG +Fit1de6 22h ;i7 minutes are Gero also de6riment hoursmov 21h5 &? ;resets minutes to ?mov 20h5 &? ;resets se6onds to ?Dmp +Fit1
imerAlarmC! 1 ;stops timer set" 0 ;starts alarm timer mov 0+h5 &0h ;sets alarm time (time un%no$n)JJJJJJJJJJJJJJJJset"
-
8/22/2019 Alarm Clock Assembly Code
21/26
+Fit1,4= #15&08' ;#igh "yte o7 timer 1>20th o7 a se6ond,4= !15&01 ;!o$ "yte o7 time1pop 00hpop 3S
pop Bpop A66+*
imer2E*nt ;Clo6% imer mov 2C4N5 &00
-
8/22/2019 Alarm Clock Assembly Code
22/26
Dmp Che6%Alarm
Clear#ourmov 25 &00hDmp Che6%Alarm
Che6%AlarmDn" !A05 +Fit2 ;6he6%s alarm ena"le lat5 i7 not set5 no alarmD"
-
8/22/2019 Alarm Clock Assembly Code
23/26
Dmp +Fit:
*n6,inCmov 1:h5 &0h ;6lears the se6ondsmov A665 &1h
add A5 1
-
8/22/2019 Alarm Clock Assembly Code
24/26
mov A5 @0 ;puts the 10Is value 7or se6onds in the a66!CA!! riteEeFt
;mov 0h5 0Bhpop 0h ;gets 0h again 7or ones position
mov A5 0mov B5 &10div ABmov A5 B ;%eeps remainder or the oneIs positionadd A5 &1'hmov 05 A66
mov A5 @0 ;indire6t adresses the ones value (7or the display) to the a66!CA!! riteEeFt
+
*+E+H
S+B +NS+B S6lr ,4= 305 A!CA!! A*E!CC! +N
+
initEl6dS+B +NC! S6lr ,4= 305 &:h ;sets "it input5 1 line display5 and F8 dots!CA!! A*E!CC! +N ;:0 old!CA!! A*E!C
S+B +NC! S,4= 305 &0+h ;turne display on and 6ursor on!CA!! A*E!CC! +N
-
8/22/2019 Alarm Clock Assembly Code
25/26
!CA!! A*E!C
S+B +NC! S,4= 305 &0'h ;display not shi7ted5 and in6riments
!CA!! A*E!CC! +N!CA!! A*E!C
!CA!! C!+AE!C+
C!+AE!C
S+B +NC! S6lr,4= 305&01hC! +N!CA!! A*E!C+
CS4E#4,+
S+B +NC! S6lr,4= 305&02hC! +N!CA!! A*E!C+
A*E!C
;S+B +N ;Start !C 6ommand;C! S ;*tIs a 6ommand;S+B ;*tIs a read 6ommand;,4= 305 &08h ;Set all pins to initially;,4= A5 30 ;ead the return value;C! +N ;inish the 6ommand
;N! ACC5&
-
8/22/2019 Alarm Clock Assembly Code
26/26
;C! ;urn o77 7or 7uture 6ommands
mov 05 &00hdDnG 05 mov 05 &00h
dDnG 05 mov 05 &00hdDnG 05 mov 05 &00hdDnG 05 mov 05 &00hdDnG 05 mov 05 &00hdDnG 05 mov 05 &00hdDnG 05
mov 05 &00hdDnG 05
+
+N