资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,设计要求,总体方案,硬件设计,软件设计,系统调试与运行,第,10,章,单片机的应用系统设计与开发,本章内容,Single Chip Microcomputer,一、,设计要求,设计并制作出具有如下功能的电脑钟:,(1),自动计时,由,6,位,LED,显示器显示时、分、秒。,(2),具备校准功能,可以直接由,0,9,数字键设置当前时间。,(3),具备定时起闹功能。,(4),一天时差不超过,1,秒钟。,二、,总体方案,1.,计时方案,方案一:采用实时时钟芯片。,方案二:软件控制。,2.,键盘,/,显示方案,方案一:串口扩展,,LED,静态显示。,方案二:,8155,扩展,,LED,动态显示。,显示方式框图,(a),静态显示框图;,(b),动态显示框图,三、,硬件设计,1.,电路原理图,2.,系统工作流程,本电脑钟具备以下功能:,(1),时钟显示:,6,位,LED,从左到右依次显示时、分、秒,采用,24,小时计时。,(2),键盘功能:采用,43,键盘,包括:,0,9,数字键,键号为,00H,09HC/R,键 时间设定,/,启动计时键,键号为,0AH,ALM,键 闹钟设置,/,启闹,/,停闹键,键号为,0BH,(1),时间显示:上电后,系统自动进入时钟显示,从,00,:,00,:,00,开始计时,此时可以设定当前时间。,(2),时间调整:按下,C/R,键,系统停止计时,进入时间设定状态,系统保持原有显示,等待键入当前时间。按下,0,9,数字键可以顺序设置时、分、秒,并在相应,LED,管上显示设置值,直至,6,位设置完毕。系统将自动由设定后的时间开始计时显示。,(3),闹钟设置,/,启闹,/,停闹:按下,ALM,键,系统继续计时,显示,00,:,00,:,00,,进入闹钟设置状态,等待键入启闹时间。按下,0,9,数字键可以顺序进行相应的时间设置,并在相应,LED,管上显示设置值,直至,6,位设置完毕。这将启动定时启闹功能,并恢复时间显示。定时时间到,蜂鸣器鸣叫,直至重新按下,ALM,键停闹,并取消闹钟设置。,四、软件设计,1.,系统资源分配,地 址,功 能,名 称,初始化值,30H35H,显示缓冲区,小时、分、秒(高位在前),DISP0DISP5,00H,3CH3FH,计时缓冲区,时、分、秒、,100 ms,HOUR,,,MIN,,,SEC,,,MSEC,00H,40H42H,闹钟值寄存区,时、分、秒,AHOUR,,,AMIN,,,ASEC,FFH,50H7FH,堆栈区,PSW.5,计时显示允许位(,1,:禁止,,0,:允许),F0,0,PSW.1,闹钟标志位(,1,:正在闹响,,0,:未闹响),F1,0,电子钟控制软件片内,RAM,及标志位分配表,2.,软件流程,图,9.3,主程序流程图,图,9.4,计时程序流程图,图,9.5,时间设置,/,闹钟定时流程图,图,9.6,键盘设置子程序流程图,图,9.7,键盘扫描,流,流程图,(4),键盘扫描,程,程序模块,KEYSCAN,:流程图,如,如图,9.7,所示。,图,9.8,显示流程,图,图,图,9.9,定时比较,流,流程图,ORG0000H,AJMPMAIN,ORG000BH,AJMPCLOCK,ORG0030H,PORTEQU 8000H,PORTA EQU 8001H,PORTB EQU8002H,;*主程,序,序,MAIN*,PORTCEQU8003H,DISP0EQU30H,DISP1EQU31H,DISP2EQU32H,DISP3EQU33H,DISP4EQU34H,DISP5EQU35H,HOUREQU3CH,MINEQU3DH,SECEQU3EH,MSECEQU3FH,AHOUREQU40H,AMINEQU41H,ASECEQU42H,F1BITPSW.1,MAIN,:,MOVSP,,,#50H,;设置堆,栈,栈区,MOVXDPTR,,,#PORT,MOVA,,,#03H,MOVXDPTR,,,A,;,8155,初始化,CLRF1,;清零闹,钟,钟标志位,CLRF0,;允许计,时,时显示,MOVAHOUR,#0FFH,MOVAMIN,#0FFH,MOVASEC,#0FFH,MOVR7,#10H,MOVR0,#DISP0,CLRA,LOOP: MOVR0,A,INCR0,DJNZR7,LOOP,;设置初,值,值,MOVTMOD,,,#01H,MOVTL0,,,#0B0H,MOVTH0,,,#3CH,;定时器,0,初始化,,定,定时,时间,100ms,SETBTR0,;启动定,时,时器,SETBEA,SETBET0,;开中断,BEGIN,:,ACALLALARM,;调用定,时,时比较,ACALLKEYSCAN,;调用键,盘,盘扫描,CJNEA,,,#0AH,,,NEXT1,;是,CLR/RST,键否?,CLRTR0,;是则暂,时,时停止计,时,时,MOVR1,,,#HOUR,;地址指,针,针指向计,时,时缓冲区,首,首地址,AJMPMOD,NEXT1,:,CJNEA,,,#0BH,,,BEGIN,;,是,是,ALARM,键,否,否,?,?,JBF1,,,NEXT2,;,闹,闹,钟,钟,正,正,在,在,闹,闹,响,响,否,否,?,?,MOVR1,,,#AHOUR,;,地,地,址,址,指,指,针,针,指,指,向,向,闹,闹,钟,钟,值,值,寄,寄,存,存,区,区,首,首,地,地,址,址,MOD,:,SETBF0,;,置,置,位,位,时,时,间,间,设,设,置,置,/,闹,钟,钟,定,定,时,时,标,标,志,志,,,,,禁,禁,止,止,显,显,示,示,计,计,时,时,时,时,间,间,ACALLMODIFY,;,调,调,用,用,时,时,间,间,设,设,置,置,/,闹,钟,钟,定,定,时,时,程,程,序,序,SETBTR0,;,重,重,新,新,开,开,始,始,计,计,时,时,CLRF0,;,清,清,零,零,时,时,间,间,设,设,置,置,/,闹,钟,钟,定,定,时,时,标,标,志,志,,,,,恢,恢,复,复,显,显,示,示,计,计,时,时,时,时,间,间,AJMPBEGIN,NEXT2,:,SETBP1.0,;,闹,闹,钟,钟,正,正,在,在,闹,闹,响,响,,,,,停,停,闹,闹,CLRF1,;,清,清,零,零,闹,闹,钟,钟,标,标,志,志,AJMPBEGIN,;*,时,时,间,间,设,设,置,/,闹,钟,钟,定,定,时,时,模,模,块,块,MODIFY*,MODIFY,:,ACALLKEYIN,;,调,调,用,用,键,键,盘,盘,设,设,置,置,子,子,程,程,序,序,ACALLCOMB,;,调,调,用,用,合,合,字,字,子,子,程,程,序,序,RET,键,盘,盘,设,设,置,置,子,子,程,程,序,序,KEYIN,:,KEYIN,:,PUSHPSW,PUSHACC,SETBRS1,;,保,保,护,护,现,现,场,场,MOVR0,,,#DISP0,;,R0,指,向,向,显,显,示,示,缓,缓,冲,冲,区,区,首,首,地,地,址,址,MOVR7,,,#06H,;,设,设,置,置,键,键,盘,盘,输,输,入,入,次,次,数,数,L1,:,CLRRS1,ACALLKEYSCAN,;,调,调,用,用,键,键,盘,盘,扫,扫,描,描,程,程,序,序,取,取,按,按,下,下,键,键,的,键,键,号,号,SETBRS1,CJNEA,,,#0AH,,,L2,;,键,键,入,入,数,数,合,合,法,法,性,性,检,检,测,测,(,(,是,是,否,否,大,大,于,9,),L2,:,JNCL1,;,大,大,于,于,9,,,重,重,新,新,键,键,入,入,MOVR0,,,A,;,键,键,号,号,送,送,显,显,示,示,缓,缓,冲,冲,区,区,INCR0,DJNZR7,,,L1,;,6,位,时,时,间,间,输,输,入,入,完,完,否,否,?,?,未,未,完,继,继,续,续,,,,,否,否,则,则,返,返,回,回,POPACC,POPPSW,CLRRS1,;,恢,恢,复,复,现,现,场,场,RET,;*,键,键,盘,盘,扫,扫,描,描,子,子,程,程,序,序,KEYSCAN*,KEYSCAN:ACALLTEST,;,调,调,判,判,按,按,键,键,是,是,否,否,按,按,下,下,子,子,程,程,序,序,TEST,JNZREMOV,;,有,有,键,键,按,按,下,下,调,调,消,消,抖,抖,延,延,时,时,ACALLDISPLAY,ACALLALARM,AJMPKEYSCAN,;,无,无,键,键,按,按,下,下,继,继,续,续,判,判,是,是,否,否,按,按,键,键,REMOV:ACALLDISPLAY,;,调,调,用,用,显,显,示,示,子,子,程,程,序,序,延,延,时,时,消,消,抖,抖,ACALLTEST,;,再,再,判,判,是,是,否,否,有,有,键,键,按,按,下,下,JNZLIST,;,有,有,键,键,按,按,下,下,转,转,逐,逐,列,列,扫,扫,描,描,ACALLDISPLAY,ACALLALARM,AJMPKEYSCAN,;,无,无,键,键,按,按,下,下,继,继,续,续,判,判,是,是,否,否,按,按,键,键,LIST:MOVR2,,,#0FEH,;,首,首,列,列,扫,扫,描,描,字,字,送,送,R2,MOVR3,,,#00H,;,首,首,列,列,键,键,号,号,送,送,R3,LINE0:MOVDPTR,,,#PORTA,;,DPTR,指,针,针,指,指,向,向,8155,的,A,口,MOVA,,,R2,;首列,扫,扫描字,送,送,R2,MOVXDPTR,,,A,;首列,扫,扫描字,送,送,8155,的,A,口,MOVDPTR,,,#PORTC,;,DPTR,指针指,向,向,8155,的,C,口,MOVXA,,,DPTR,;读入,C,口的行,状,状态,JBACC.0,,,LINE1,;第,0,行键无,键,键按下,转,转第,1,行,MOVA,,,#00H,;第,0,行有键,按,按下,,行,行首键,号,号送,A,AJMPTRYK,;求键,号,号,NEXT:INCR3,;扫描,下,下一列,MOVA,,,R2,;列扫,描,描字送,A,JNBACC.3,,,EXIT,;,4,列扫描,完,完,重,新,新进行,下,下一,轮,轮扫描,RLA,;,4,列未扫,描,描完,,扫,扫描字,左,左移扫,描,描下一,列,列,MOVR2,,,A,;扫描,字,字送,A,AJMPLINE0,;转向,扫,扫描下,一,一列,EXIT:AJMPKEYSCAN,;等待,下,下一次,按,按键,TRYK:ADDA,,,R3,;按公,式,式计算,键,键码,,求,求得键,号,号,PUSHACC,;键号,入,入栈保,护,护,LETK:ACALLTEST,;等待,按,按键释,放,放,JNZLETK,;按键,未,未释放,,,,继续,等,等待,POPACC,;按键,释,释放,,键,键号出,栈,栈,RET,;键盘,扫,扫描结,束,束,返,回,回,TEST:MOVDPTR,,,#PORTA,;,DPTR,指针指,向,向,8155,的,A,口,MOVA,,,#00H,MOVXDPTR,,,A,;全扫,描,描字,00H,送,8155,的,A,口,MOVDPTR,,,#PORTC,;,DPTR,指针指,向,向,8155,的,C,口,MOVXA,,,DPTR,;读入,C,口行状,态,态,CPLA,;,A,取反,,以,以高电,平,平表示,有,有,键按下,ANLA,,,#07H,;屏蔽,高,高,5,位,RET,;*,显,显示子,程,程序,DISPLAY*,DISPLAY:JBF0,,,DISP,;允许,时,时间显,示,示标志,F0=1,转,DISP,ACALLSEPA,;否则,调,调用,SEPA,刷新显,示,示缓冲,区,区,DISP:pushpsw,;动态,扫,扫描显,示,示子程,序,序,Pushacc,setbrs0,MOVdptr,,,#PORTA,MOVA,,,#0FFH,MOVXDPTR,,,A,;关显,示,示,movr0,,,#disp0,movr7,,,#00h,movr6,,,#06h,movr5,,,#0feh,dis1:movdptr,,,#tab,mova,,,r0,movca,,,a+dptr,movdptr,,,#portb,movxdptr,,,a,movdptr,,,#porta,mova,,,r5,movxdptr,,,a,here:djnzr7,,,here,incr0,mova,,,r5,rla,movr5,,,a,djnzr6,,,dis1,clrrs0,popacc,poppsw,ret,tab:db 3fh,,,06h,,,5bh,,,4fh,,,66h,,,6dh,,,7dh,,,07h,db7fh,,,6fh,,,77h,,,7ch,,,39h,,,5eh,,,79h,,,71h,;共,阴,阴极,字,字型,码,码表,;*,合,合字,子,子程,序,序,COMB*,COMB,:,MOVR0,,,#DISP1,;,R0,指向,显,显示,缓,缓冲,区,区小,时,时,低位,ACALLCOMB1,;合,字,字,CJNEA,,,#24H,,,CHK,;小,时,时大,于,于,24,否?,CHK,:,JNCEXIT1,;大,于,于,24,则取,消,消本,次,次设,置,,退,退出,MOVR1,,,A,;否,则,则小,时,时送,计,计时,缓,缓冲,区,区,/,闹钟,值,值寄,存,存区,小,小时,单,单元,INCR1,MOVR0,,,#DISP3,;,R0,指向,显,显示,缓,缓冲,区,区分,低,低位,ACALLCOMB1,CJNEA,,,#60H,,,CHK1,CHK1,:,JNCEXIT1,MOVR1,,,A,INCR1,MOVR0,,,#DISP5,;,R0,指向,显,显示,缓,缓冲,区,区秒,低,低位,ACALLCOMB1,CJNEA,,,#60H,,,CHK2,CHK2,:,JNCEXIT1,MOVR1,,,A,RET,EXIT1,:,AJMPMAIN,;输,入,入不,合,合法,退,退出,,,,重,新,新清,零计,时,时,COMB1,:,MOVA,,,R0,ANLA,,,#0FH,;取,出,出低,位,位,MOV43H,,,A,;暂,存,存于,43H,单元,DECR0,;指,向,向高,位,位,MOVA,,,R0,ANLA,,,#0FH,SWAPA,;高,位,位送,高,高,4,位,ORLA,,,43H,;高,低,低位,合,合并,RET,;*,拆,拆字,子,子程,序,序,SEPA*,SEPA,:,PUSHPSW,PUSHACC,SETBRS0,MOVR0,,,#DISP5,;指,向,向显,示,示缓,冲,冲区,秒,秒低,位,位,MOVA,,,SEC,ACALLSEPA1,MOVA,,,MIN,ACALLSEPA1,MOVA,,,HOUR,ACALLSEPA1,POPACC,POPPSW,RET,SEPA1,:,MOV44H,,,A,;暂,存,存,44H,ANLA,,,#0FH,;取,出,出低,位,位,MOVR0,,,A,;送,显,显示,缓,缓冲,区,区低,位,位,DECR0,;指,向,向显,示,示缓,冲,冲区,高,高位,MOVA,,,44H,ANLA,,,#0F0H,;取,出,出高,位,位,SWAPA,;高,位,位送,往,往低,4,位形,成,成高,位,位数,据,据,MOVR0,,,A,;高,位,位数,据,据送,显,显示,缓,缓冲,区,区高,位,位,RET,;*定,时,时比,较,较模,块,块,ALARM*,ALARM,:,MOVA,,,ASEC,CJNEA,,,SEC,,,BACK,;秒,单,单元,相,相同,则,则继,续,续比,较,较,,否,否则,返,返回,MOVA,,,AMIN,CJNEA,,,MIN,,,BACK,;分,单,单元,相,相同,则,则继,续,续比,较,较,,否,否则,返,返回,MOVA,,,AHOUR,CJNEA,,,HOUR,,,BACK,;小,时,时单,元,元相,同,同定,时,时时,间,间到,CLRP1.0,;启,动,动闹,钟,钟鸣,叫,叫,SETBF1,;置,位,位闹,钟,钟标,志,志,BACK,:,RET,;*,定,定时,器,器,0,中断,服,服务,子,子程,序,序,CLOCK*,CLOCK,:,MOVTL0,,,#0B7H,MOVTH0,,,#3CH,;重,装,装初,值,值,,时,时间,校,校正,PUSHPSW,PUSHACC,;保,护,护现,场,场,INCMSEC,MOVA,,,MSEC,CJNEA,,,#0AH,,,DONE,MOVMSEC,,,#00H,MOVA,,,SEC,INCA,DAA,;二,十进,制,制转,换,换,MOVSEC,,,A,CJNEA,,,#60H,,,DONE,MOVSEC,,,#00H,MOVA,,,MIN,INCA,DAA,MOVMIN,,,A,CJNEA,,,#60H,,,DONE,MOVMIN,,,#00H,MOVA,,,HOUR,INCA,DAA,MOVHOUR,,,A,CJNEA,,,#24H,,,DONE,MOVHOUR,,,#00H,DONE,:,POPACC,POPPSW,;恢,复,复现,场,场,RETI,四、,系,系统,调,调试,与,与脱,机,机运,行,行,1.,硬件,调,调试,(1),脱机,检,检查,。,。,(2),联机,调,调试,。,。,2.,软件,调,调试,(1),用仿,真,真器,修,修改,显,显示,缓,缓冲,区,区内,容,容,,屏,屏蔽,拆,拆字,程,程序,,,,调,试,试动,态,态扫,描,描显,示,示功,能,能。,(2),运行,主,主程,序,序调,试,试计,时,时模,块,块,,不,不按,下,下任,何,何键,,,,检,查,查是,否,否能,从,从由,00,:,00,:,00,开,始正,确,确计,时,时。,(3),调试,键,键盘,扫,扫描,模,模块,KEYSCAN,,,(4),调试,时,时间,设,设置,/,闹钟,定,定时,模,模块,MODIFY,。,(5),运行,主,主程,序,序联,调,调,,检,检查,能,能否,用,用键,盘,盘修,改,改当,前,前时,间,间以,及,及设,置,置闹,钟,钟,,能,能否,正,正确,计,计,时,时,、,、启,闹,闹、,停,停闹,。,。,3.,脱机,运,运行,泰山,学,学院,信息,科,科学,技,技术,学,学院,自,自动,化,化教,研,研室,TheEnd!,TANKS,演讲,完,完毕,,,,谢,谢,谢观,看,看!,
展开阅读全文