ECE 367 - Exprimnt #4 Svn Smnt Disply Intrfin n Timin Sprin 2006 Smstr Introution This xprimnt rquirs tht you onstrut iruit intrfin th MiroStmp11 moul with svn smnt isply, n writ ssmly lnu o to ontinuously isply iml iit tht inrmnts xtly 1 on pr son. Rquir Hrwr In ition to th MiroStmp11 moul, this xprimnt rquirs on sinl-iit svn smnt LED isply n th 220Ω DIP rsistors. Hr r th iml iits 0 throuh 9 s isply on svn smnt isply: f CC f Th pinout irm on th lft is for th Lth UC5641-11 (Jmo #334879) svn smnt plus iml point LED isply tht is in your prts kit. Th two ommon tho (CC) trminls r ti to ll svn LEDs s shown low: CC CC f p p CC p 1 s trmin y th ury of th miroontrollr s mstr lok rystl osilltor
Wirin Dirm Buil th followin iruit on solrlss ror. Not tht PA7 n ll six its in PortD r onfiur to oprt s output lins: f f Ω CC Smpl iruit lyout for Lortory Exprimnt #4. Softwr Dsin First onsir th tsk of isplyin iml iit usin svn smnts. For xmpl, th wirin irm ov tlls us tht w n to hv th followin output t on PA7, PD5... PD0 in orr to isply iit 3 :
Output lin loil stt to isply 3 orrsponin smnt ll PA7 1 PD5 1 PD4 1 PD3 1 PD2 0 PD1 0 f PD0 1 f Assumin tht PA7, PD5... PD0 hv lry n onfiur to outputs, hr r fw lins of o tht will us 3 to isply: LDAA #$79 ; 7-smnt o for "3" STAA PortD,X ; snt to PD5...PD0 BSET PortA,X,$80 ; PA7<--1 (hih it of th 7-s o) (As usul, ristr X hs n initiliz to th strtin rss of th ristr lok n PortA/PortD lls hv n qut with thir rsptiv offst vlus.) Th sist wy to isply th iml iit whos vlu is in mmory vril Diit, for xmpl, is y usin squn of if/thn loks suh s this on: Chk_if_3: Chk_if_4: LDAA Diit CMPA #3 ; ompr Diit to th vlu 3 BNE Chk_if_4 LDAA #$79 ; sn 7-s. o for 3 to th output STAA PortD,X BSET PortA,X,$80 JMP Finish_Tsk (t.) Inrmntin th Disply Diit On Pr Son Now tht you know how to show iml iit on svn smnt isply vi, nxt w will nxt ovr th timin spts of this xprimnt. In prvious xprimnts ll lys wr hiv usin softwr loops, so it is nturl to onsir tkin th sm pproh hr. But w will tk this opportunity to lrn out spil susystm insi th Motorol 68HC11 miroontrollr th hrwr timr.
A softwr ly loop rquirs tht your o o th ountin, n nothin ls ts on in th mntim. A hrwr timr, on th othr hn, os th ountin for you whil th CPU (in ontroll y your prorm o) is fr to o othr thins. 16 it Timr Ristr TCNT Th 68HC11 hrwr timr TCNT hs 16 its n is onstntly ountin up in inry (ylin throuh 2 16 uniqu stts). It is ll fr-runnin ountr us it is lwys runnin inpnntly of wht th CPU is oin. TCNT my not initiliz, lr, nor my its ountin pross stopp. It ssntilly funtions s r-only 16 it ristr whos ontnts hn vry {1, 4, 8 or 16} mstr lok yls, pnin on how thins r onfiur. TCNT my onfiur to ount in on of four wys: TCNT Prslin Ftor N : Tim it tks TCNT to inrmnt on: Tim it tks TCNT to inrmnt 2 16 tims: 1 0.5 us = on lok prio 2 0.032768 s 4 2.0 us = four lok prios 0.131072 s 8 4.0 us = iht lok prios 0.262144 s 16 8.0 us = sixtn lok prios 0.524288 s For xmpl, w n hiv 0.25 s ly in ths four wys: Wit for TCNT to inrmnt 500,000 tims whn N = 1; Wit for TCNT to inrmnt 125,000 tims whn N = 4; Wit for TCNT to inrmnt 62,500 tims whn N = 8; Wit for TCNT to inrmnt 31,250 tims whn N = 16. Howvr, y sltin prslin ftor N so tht th numr of tims TCNT ns to inrmnt is lss thn 2 16 = 65,536 (th numr of stts in omplt ount yl), w rtly simplify th tsk of ttin whn th sir ly hs pss. Thus ithr N=8 or N=16 woul us to rliz 0.25 s ly. To minimiz miroontrollr powr onsumption on shoul lwys slow own th TCNT ountr s muh s possil (hoosin th lrst possil N), so th hoi of N=16 is st in th xmpl ov. Thr lso xist four Timr Output Compr ristrs TOC1 TOC4, whos 16-it ontnts r onstntly in ompr to th TCNT ountr stt. Whn hrwr tts tht TCNT hs inrmnt to vlu qul to tht stor in on of th TOC ristrs, thn orrsponin fl is st. 3 For xmpl, whn TCNT = TOC1 thn OC1F (Output Compr 1 Fl) oms st. 2 Sin th MiroStmp11 tht you hv purhs hs n intrnl lok ( E Clok ) frquny = 2 MHz 3 Also, hrwr intrrupt my trir or n output pin my m to hn stt. TCNT lon with its output ompr ristrs is on of th most usful susystms on th miroontrollr.
Th followin hrwr irm sris th intrtion twn TCNT, TOC1 n OC1F: TCNT qul? St TOC1 Q Rst flip-flop r OC1F writ OC1F utomtilly oms st whn TOC1 = TCNT, n only softwr writ oprtion n rst it. On must writ 1 to OC1F in orr to rst it; writin 0 hs no fft. Ths stps r tkn to rliz 0.25 s ly usin th TCNT timr susystm: ) onfiur 4 prslin ftor N = 16; ) r 5 th vlu of TCNT; ) 31,250 to this vlu n stor it in TOC1 6 ; ) lr OC1F 7 ; ) wit until OC1F = 1 (pollin this fl vry so oftn whil prformin othr tsks); f) th tsk tht hs n witin for th 0.25 s ly to pss. Usully th TCNT timr is us to trir xution of prtiulr tsk t uniform inrmnts of tim, suh s vry 0.25 s. In suh s on woul ppn th followin stps to thos ov: ) inrmnt th vlu of TOC1 y 31,250; h) jump to stp () Answr this qustion: why is stp () oin TOC1 TOC1 + 31,250 inst of TOC1 TCNT + 31,250? 4 PR1, PR0 1 in TMSK2 ristr; this must on within th first 64 lok yls ftr powr-on rst. 5 TCNT is t rsss Rs+[$0E,$0F] 6 TOC1 is t rsss Rs+[$16,$17] 7 OC1F = it 7 of TFLG1, foun t Rs+$23.
Th followin softwr flowhrt shows how TCNT my us to ontrol th timin of up to fiv tsks t on: on runnin most of th tim (Tsk0) n th othrs (Tsk1, Tsk2, Tsk3 n Tsk4) xutin only t rtin uniformly-sp tims 8 : Tsk0 OC1F = 1? no OC2F = 1? no OC3F = 1? no OC4F = 1? no Tsk1 Tsk2 Tsk3 Tsk4 offst1 to TOC1, rst OC1F offst2 to TOC2, rst OC2F offst3 to TOC3, rst OC3F offst4 to TOC4, rst OC4F In this xprimnt you will usin TCNT n TOC1 to only two tsks. Hr is simplifi flowhrt: Tsk0: isply Diit OC1F = 1? no Tsk1: upt Diit offst to TOC1, rst OC1F Tsk0: Disply mmory vlu Diit on 7-s. LED isply Tsk1 psuoo: ( vry 0.1 s) Count Count + 1 if (Count = 10) Count 0 Diit Diit + 1 if (Diit = 10) Diit 0 n if n if (initilly Count = 0, Diit = 0) 8 Assum tht th tim rquir to h tsk is muh shortr thn th lys ministr y TCNT
Th psuoo sription of Tsk1 shows th intr Count in inrmnt. Whn Count rhs 10 it is rst to 0, n thn intr Diit is inrmnt. Whn Diit rhs 10 it is rst to 0. Thus Count is iml ountr for tnths of son n Diit is iml ountr for sons. W o this is us TCNT yls too quikly (0.524 s t its slowst p) to irtly rliz 1.0 s ly tims. Finlly, hr is som usful o tht you my us for this l: 1. Dfinin mmory lls ($0040 - $00FF is RAM on th MiroStmp11): Count EQU $0040 ; RAM yt rss: tnth-of-s ountr Diit EQU $0041 ; RAM yt rss: isply iit vlu 2. Confiurin th ports n prslin ftor: LDAA #$01 ; PR1,PR0 <-- 0,1 STAA TMSK2,X ; (slow own TCNT y ftor 4) BSET PACTL,X,$80 ; onfiur PA7 s output BSET DDRD,X,$3F ; onfiur PD0-PD6 s outputs 3. Mnipultin Count s prt of Tsk1: INC Count LDAA Count CMPA #10 BNE Ll_1 ; if Count = 10, CLR Count ; thn rst it k to zro (t.) 4. Ain 1/10 s offst to TOC1 (Inr must qut with th offst vlu): LDD TOC1,X ADDD #Inr STD TOC1,X LDAA #$80 STAA TFLG1,X ; D <-- TOC1 ; D <-- D + Inr ; TOC1 <-- D ; Clr th TCNT Output Compr 1 fl Don t try to t vrythin workin t on in y isplyin th iit 8 on th 7 smnts. 9 This will hk oth your iruit wirin n orrtnss of port onfiurtion. Only thn pro to writin n uin th timin lorithm. All timin must on usin TCNT no softwr lys r llow. Dmonstrt th workin iruit to your T.A. 9 Don t isply 8 for vry lon s this miroontrollr is not rt to riv tht muh urrnt t on. To o it orrtly w shoul uffr th output lins for rivin th 7-s. LED isply (.. TTL invrtrs).