资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,设计要求,总体方案,硬件设计,软件设计,系统调试与运行,第,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,PORTEQU8000H,PORTAEQU8001H,PORTBEQU8002H,;*,主,主程序,MAIN*,PORTCEQU8003H,DISP0EQU30H,DISP1EQU31H,DISP2EQU32H,DISP3EQU33H,DISP4EQU34H,DISP5EQU35H,HOUREQU3CH,MINEQU3DH,SECEQU3EH,MSECEQU3FH,AHOUREQU40H,AMINEQU41H,ASECEQU42H,F1BITPSW.1,MAIN,:,MOVSP,,,#50H,;设置,堆,堆栈区,MOVXDPTR,,,#PORT,MOVA,,,#03H,MOVX DPTR,,,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:ACALL TEST,;等待按键,释,释放,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:JB F0,,,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:djnz r7,,,here,incr0,mova,,,r5,rla,movr5,,,a,djnzr6,,,dis1,clrrs0,popacc,poppsw,ret,tab:db3fh,,,06h,,,5bh,,,4fh,,,66h,,,6dh,,,7dh,,,07h,db 7fh,,,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,演讲完毕,,谢,谢谢观看!,
展开阅读全文