ECE 367 - Exprimnt #6 Kithn Timr Sprin 2006 Smstr Introution This xprimnt hs you onstrut iruit intrfin nin I/O lins from th 68HC11 with two svn smnt isplys n mtrix kyp, n writ ssmbly lnu o to rliz prormmbl ountown kithn timr tht llows th usr to prform vrious funtions: prst ount vlu, strt/rsum n pus ountown. Th purpos of this xprimnt is to th vn hrwr n softwr thniqus of intrfin miroontrollrs. Rquir Hrwr In ition to th MiroStmp11 moul, this xprimnt rquirs two svn smnt LED isplys, mtrix kyp, two TTL hx invrtrs (on 74LS04 IC), th 220Ω DIP rsistors n th 10KΩ SIP rsistors. Hr is photo of th omplt iruit:
Wirin Dirm Buil th followin iruit on solrlss brbor th iruit is vry similr to tht in Exprimnt 5. Th biirtionl rrows nxt to {PD2, PD1, PD0} init tht ths lins will b us for both input n output urin run-tim. Ω b tns of sons iit f b b sons iit f b f f CC CC n.. Ω
On in, for your rfrn, hr r pinout irms of th mtrix kyp n svn smnt LED isply in your lb prts kit: )(*$+%&,(*$+% -(*$+%,(*$+%',(!.( " -( " /'0 1 0 #! " " # $%& $% $% $%' f CC b Smnt: Output Lin: PA7 b PD5 PD4 PD3 PD2 f PD1 PD0 CC (lft iit) PA6 CC (riht iit) PA5 f b CC p
Softwr Dsin OC1F = 1? no OC2F = 1? no OC3F = 1? no ys xut Tsk1 ys xut Tsk2 ys xut Tsk3 offst1 to TOC1, rst OC1F offst1 to TOC2, rst OC2F offst3 to TOC3, rst OC3F In this xprimnt you will b usin TCNT n thr Output Compr ristrs to xut thr tsks t iffrnt frqunis. Hr is hih-lvl sription of th thr tsks: Tsk1 kps ount of tim usin thr iml iits (s in 54.7 s). This ount is rmnt vry 0.1 s whn th timr is runnin. Tsk1 xuts vry 1/10 s. Tsk2 multiplxs n upts th 7-smnt isplys; it xuts vry 1/200 s. Tsk3 polls th kyp to tt ky prsss n rspons orinly; it xuts vry 1/20 s.
Tsk1 Dtils Th mmory byt Mo is us to init whthr or not th ountr is runnin or is pus: Mo = 1 inits tht th timr is ountin own, n Mo = 0 inits tht it is frozn t th urrnt ount. Tsk1 psuoo: (xut vry 0.1 s) Diit3 Diit2 Diit1 (Th hrwr isplys only Diit3 n Diit2) if (Mo = 1 n Ky_Prss = 0) Diit1 Diit1 1 if (Diit1 = 1) Diit1 9 Diit2 Diit2 1 if (Diit2 = 1) Diit2 9 Diit3 Diit3 1 if (Diit3 = 1) Diit1 0 Diit2 0 Diit3 0 Mo 0 ; rmnt 0.1 s iit ; rmnt 1.0 s iit ; rmnt 10 s iit ; n of ountown is rh ; stop ountr (initilly Diit1 = 0, Diit2 = 0, Diit3 = 0, Mo = 0) S Tsk3 sription for xplntion of Ky_Prss.
Tsk2 Dtils Tsk2 prforms tim-ivision multiplxin by ltrntin th iit bin isply vry 1/200 s. This rsults in n ovrll 100 Hz rfrsh rt for both iits. Mmory byt Diit_Slt is n initor of wht iit (lft or riht) is urrntly bin isply. Tsk2 psuoo: (xut vry 0.005 s) if (Diit_Slt = 0) Diit_Slt 1 PA6 1 PA5 0 Diit Diit3 ls Diit_Slt 0 PA6 0 PA5 1 Diit Diit2 ; tivt lft 7-s. isply ; isply tns of s vlu ; tivt riht 7-s. isply ; isply s vlu Thn, output 7-smnt t orrsponin to mmory vlu Diit just s it ws on in Exprimnts 4 n 5. (initilly Diit_Slt = 0, Diit = 0, PA6 = 0, PA5 = 1)
Tsk3 Dtils Tsk3 xuts vry 1/20 s; it hks if ny ky is prss n rspons orinly. Mmory byt Ky_Prss kps trk of th kyp sttus: Ky_Prss = 1 whn kyprss is tt, Ky_Prss = 0 whn no kys r prss. To frz th ount, on must prss ny ky in th first thr olumns of th kyp (A, B, C, D kys r intiv). To strt th ountown squn on must prss n rls ithr E or F whn th ount is frozn. To ntr nw strtin tim vlu on must prss numri kys whn th ount is frozn. Tsk3 psuoo: (xut vry 0.05 s) if (ny ky is prss) if (Ky_Prss = 0) Ky_Prss 1 if (Mo = 1) Mo 0 ls if (E or F is prss) Mo 1 ls Ky_Prss 0 ls ; if now ountin thn ; stop ountin ; strt/rsum ountin Diit3 Diit2, Diit1 0 ; initiliz ount by shiftin in iits from th riht if (0 is prss) Diit2 0 lsif (1 is prss) Diit2 1 lsif (2 is prss) Diit2 2 lsif (9 is prss) Diit2 9 (initilly Ky_Prss = 0)
Bus w r shrin I/O lins btwn kyp n isply vis, som of th biirtionl lins of PortD will prioilly b onfiur for input (to r mtrix kyp t) n thn onfiur for output (to output t to th isplys). Th subroutin oin this on-th-fly ronfiurin is Tsk3. To sv you som prormmin tim hr is th o listin for subroutin Tsk3 (bs on th psuoo shown prviously): ;-------------------------------------------------------------------------- ; Tsk 3 (xut vry 1/20 s) - Poll th mtrix kyp: Tsk3: BCLR PortA,X,$60 ; PA6,PA5 <-- 0 (turn off both isplys) BCLR DDRD,X,$07 ; mk PD2...PD0 inputs, to r kyp ols ; riv ll kyp row lins hih: BSET PortA,X,$80 ; PA7 <-- 1 BSET PortD,X,$38 ; PD5...PD3 <-- 1 ; r kyp olumn lins to tt if ny ky is prss: BRCLR PortD,X,$07,C0 ; (hkin if PD2...PD0 r ll zro) JMP C1 C0: CLR Ky_Prss ; no ky is now prss C1: LDAA #0 ; on of th kys is now prss CMPA Ky_Prss BEQ C2 ; ky ws prss lst tim, so o ; nothin n wit for its rls C2: LDAA #1 ; nw kyprss is tt STAA Ky_Prss LDAA #0 CMPA Mo BEQ C3 CLR Mo ; stop th ountown if runnin C3: ; nw kyprss is tt in pus mo ; hk for ky prss in Row4 of th mtrix kyp: BCLR PortA,X,$80 ; PA7 <-- 0 (Row1) BCLR PortD,X,$20 ; PD5 <-- 0 (Row2) BCLR PortD,X,$10 ; PD4 <-- 0 (Row3) BSET PortD,X,$08 ; PD3 <-- 1 (Row4) BRSET PortD,X,$01,C4 ; jump to C4 if E is prss BRSET PortD,X,$02,C4 ; jump to C4 if F is prss JMP C5 C4: ; E or F ky is prss, hn mo to rsum ountown: LDAA #1 STAA Mo
C5: ; on of th numri kys is prss in pus mo; lr th ; tnths-of-s iit n shift in th numri ky vlu from ; th riht: (tns s iit) <-- (s iit) <-- (ky vlu) CLR LDAA STAA Diit1 Diit2 Diit3 ; tt ky0 prss (hk in Row4 still in fft from bov) BRCLR PortD,X,$04,C6 LDAA #0 C6: ; hk for ky prss in Row1 of th mtrix kyp: BSET PortA,X,$80 ; PA7 <-- 1 (Row1) BCLR PortD,X,$20 ; PD5 <-- 0 (Row2) BCLR PortD,X,$10 ; PD4 <-- 0 (Row3) BCLR PortD,X,$08 ; PD3 <-- 0 (Row4) ; tt ky1 prss: BRCLR PortD,X,$04,C7 LDAA #1 C7: ; tt ky2 prss: BRCLR PortD,X,$02,C8 LDAA #2 C8: ; tt ky3 prss: BRCLR PortD,X,$01,C9 LDAA #3 C9: ; hk for ky prss in Row2 of th mtrix kyp: BCLR PortA,X,$80 ; PA7 <-- 0 (Row1) BSET PortD,X,$20 ; PD5 <-- 1 (Row2) BCLR PortD,X,$10 ; PD4 <-- 0 (Row3) BCLR PortD,X,$08 ; PD3 <-- 0 (Row4) ; tt ky4 prss: BRCLR PortD,X,$04,C10 LDAA #4 C10: ; tt ky5 prss: BRCLR PortD,X,$02,C11 LDAA #5 C11: ; tt ky6 prss: BRCLR PortD,X,$01,C12 LDAA #6
C12: ; hk for ky prss in Row3 of th mtrix kyp: BCLR PortA,X,$80 ; PA7 <-- 0 (Row1) BCLR PortD,X,$20 ; PD5 <-- 0 (Row2) BSET PortD,X,$10 ; PD4 <-- 1 (Row3) BCLR PortD,X,$08 ; PD3 <-- 0 (Row4) ; tt ky7 prss: BRCLR PortD,X,$04,C13 LDAA #7 C13: ; tt ky8 prss: BRCLR PortD,X,$02,C14 LDAA #8 C14: ; tt ky9 prss: BRCLR PortD,X,$01,Quit_Tsk3 LDAA #9 Quit_Tsk3: BSET DDRD,X,$07 ; rturn PD2...PD0 to output mo ;Not: w h turn off both isplys by lrin PA5 n PA6, ; but Tsk2 will rfrsh thm in t most 1/200 s so w n ; not o tht hr. ;inrmnt TOC3 by 1/20 s from its lst vlu: LDD TOC3,X ; D <-- TOC3 ADDD #Inr3 ; D <-- D + Inr3 STD TOC3,X ; TOC3 <-- D LDAA #$20 STAA TFLG1,X ; Clr th TCNT Output Compr 3 fl RTS ;-------------------------------------------------------------------------- You my opy n pst from n on-lin listin of this subroutin tht is foun t: http://www..ui.u/~onhro/367_xp6_tsk3.txt Your job is to writ th rst of th o n to implmnt this kithn timr, buil th iruit, n monstrt its oprtion to your T.A. Thr will b som flikr in th isply. Cn you xplin why? How woul you sust to limint it? Why wr two output lins it to th ommon tho trminls of th svn smnt isplys, s ompr to only on lin in Exprimnt 5?