《微机原理与接口技术》课程设计课题:电子时钟的设计与实现完成时间:2004年9月12日实验代码硬件连线:8254硬件连线:片选CS——300HA0——A2A1——A3T0:GATE0——+5VCLK0——47KHZOUT0——IR0T1:GATE1——PC0CLK1——OUT2OUT1——蜂鸣器8255硬件连线:CS_1——CS1CS_2——CS2CS_3——CS3CS_4——CS4PC0——GATE18259硬件连线:CS2——3A0HINT2——INTRSP/2——+5VINT_A——INTAIRQ0——8254的OUT074系列模块硬件连线:Q_0——Q0Q_1——Q1Q_2——Q2Q_3——Q3P_0——P0P_1——P1P_2——P2CS1——340HCS2——360H程序代码段:.486pdatasegmentat0use16ORG1000hHOURdb?MINUTEdb?SECONDdb?STOPdb?COUNTDB0HHOURDB?MMINUTEDB?SSECONDDB?dataendscodesegmentuse16assumecs:code,ds:dataorg1500hBEG:jmpstartTAB1db0c0h,0f9h,0a4h,0b0h,99h,92h,82h,0f8h,80h,90h,88h,83h,0c6h,0a1h,86h,8eh,8ch,0c1h,91h,7fh,0ffhTAB2db3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fhKEYCODdb0eeh,0deh,0beh,0edh,0ddh,0bdh,0ebh,0dbh,0bbh,0e7h,0d7h,0b7hKEYVALdb0,1,2,3,4,5,6,7,8,9,0ah,0bhstart:moveax,60000000hmovcr0,eaxmovax,codemovds,axCLIMOVBYTEPTRHOUR,23MOVBYTEPTRMINUTE,59MOVBYTEPTRSECOND,50MOVBYTEPTRSTOP,0;8255初始化MOVEAX,0A0A0A0AHMOVDX,208HOUTDX,EAX;8254初始化MOVDX,30CHMOVAL,34H;计数器0,16位,方式2,2进制OUTDX,ALMOVDX,300HMOVAX,1175;计数器0初值为25ms*47KHZOUTDX,ALMOVAL,AHOUTDX,ALMOVDX,30CHMOVAL,54H;计数器1,8位,方式2,2进制OUTDX,ALMOVDX,304HMOVAX,40;计数器1初值为40,25ms*40=1sOUTDX,AL;8259初始化偶地址:3A0H奇地址:3A8HMOVDX,3A0H;写ICW1,写入偶地址MOVAL,13HOUTDX,ALMOVDX,3A8H;写ICW2,写入奇地址MOVAL,08H;IR0的中断类型号为08HOUTDX,ALMOVDX,3A8H;写ICW4,写入奇地址MOVAL,05H;主片,8259工作在80X86中OUTDX,AL;设置8259中断向量MOVAX,OFFSETINTERMOVBX,20H;08H*4MOV[BX],AXMOVAX,SEGINTERMOV[BX+2],AX;开放IRQ0MOVDX,3A8HMOVAL,11111110B;开放IRQ0OUTDX,AL;判断G键或S键是否按下G:STINOPCALLINPUTCALLDELAYCMPAL,0D7H;判断G键是否按下,若按下同时设置闹铃时间JNZSNOTSTOPCALLINPUTCALLDELAYCALLALARM;设定闹铃子程序JMPGS:CMPAL,0B7HJNZGMOVSTOP,0FFH;设置时间;设置小时MOVCX,2JMPH1H2:CMPAL,[SI]JZH3INCSIINCDILOOPH2POPCXJMPH1H3:POPCXMOVAL,[DI];AL中内容为所按键的键面值CMPCX,2JNZH4;CX=2设置十位,否则设置个位CMPAL,2JAH1PUSHAXPUSHBXMOVDX,208HINAL,DXMOVBL,ALANDBL,0FCHANDAL,03HNOTALANDAL,BLADDAL,01HOUTDX,ALPOPBXPOPAXMOVAH,ALLEABX,TAB1;查找七段代码值XLATMOVDX,200H;送数码管时的十位OUTDX,ALMOVDL,AHMOVAL,10MULDLMOVHOUR,ALCALLDELAYJMPH6H1:PUSHCXCALLINPUTCALLDELAYLEASI,KEYCODLEADI,KEYVALMOVCX,12JMPH2H4:CALLDELAYPUSHAXPUSHBXMOVDX,208HINAL,DXMOVBL,ALANDBL,0F3HANDAL,0CHNOTALANDAL,BLADDAL,04HOUTDX,ALPOPBXPOPAXCMPDL,2JNZH5CMPAL,4JAH1H5:MOVAH,ALLEABX,TAB1XLATMOVDX,204H;送数码管时的个位OUTDX,ALADDHOUR,AHCALLDELAYH6:LOOPH1;设置分钟MOVCX,2JMPM1M2:CMPAL,[SI]JZM3INCSIINCDILOOPM2POPCXJMPM1M3:POPCXMOVAL,[DI];AL中内容为所按键的键面值CMPCX,2JNZM4;CX=2设置十位,否则设置个位CMPAL,5JAM1PUSHAXPUSHBXMOVDX,209HINAL,DXMOVBL,ALANDBL,0FCHANDAL,03HNOTALANDAL,BLADDAL,01HOUTDX,ALPOPBXPOPAXMOVAH,ALLEABX,TAB1;查找七段代码值XLATMOVDX,201H;送数码管分的十位OUTDX,ALMOVDL,AHMOVAL,10MULDLMOVMINUTE,ALCALLDELAYJMPM6M1:PUSHCXCALLINPUTCALLDELAYLEASI,KEYCODLEADI,KEYVALMOVCX,12JMPM2M4:CALLDELAYPUSHAXPUSHBXMOVDX,209HINAL,DXMOVBL,ALANDBL,0F3HANDAL,0CHNOTALANDAL,BLADDAL,04HOUTDX,ALPOPBXPOPAXCMPDL,5JNZM5CMPAL,9JAM1M5:MOVAH,ALLEABX,TAB1XLATMOVDX,205H;送数码管分的个位OUTDX,ALADDMINUTE,AHCALLDELAYM6:LOOPM1;设置秒钟MOVCX,2JMPS1S2:CMPAL,[SI]JZS3INCSIINCDILOOPS2POPCXJMPS1S3:POPCXMOVAL,[DI];AL中内容为所按键的键面值CMPCX,2JNZS4;CX=2设置十位,否则设置个位CMPAL,5JAS1PUSHAXPUSHBXMOVDX,20AHINAL,DXMOVBL,ALANDBL,0FCHANDAL,03HNOTALANDAL,BLADDAL,01HOUTDX,ALPOPBXPOPAXMOVAH,ALLEABX,TAB1;查找七段代码值XLATMOVDX,202H;送数码管秒的十位OUTDX,ALMOVDL,AHMOVAL,10MULDLMOVSECOND,ALCALLDELAYJMPS6S1:PUSHCXCALLINPUTCALLDELAYLEASI,KEYCODLEADI,KEYVALMOVCX,12JMPS2S4:CALLDELAYPUSHAXPUSHBXMOVDX,20AHINAL,DXMOVBL,ALANDBL,0F3HANDAL,0CHNOTALANDAL,BLADDAL,04HOUTDX,ALPOPBXPOPAXCMPDL,5JNZS5CMPAL,9JAS1S5:MOVAH,ALLEABX,TAB1XLATMOVDX,206H;送数码管秒的个位OUTDX,ALADDSECOND,AHCALLDELAYS6:LOOPS1MOVDX,208HMOVEAX,0A0A0A0AHOUTDX,EAXMOVSTOP,0JMPG;行扫描法读取键入值INPUTPROCPUSHBXPUSHDXWT:MOVAL,00HMOVDX,360HOUTDX,ALNOPNOPMOVDX,360HINAL,DXANDAL,0FHCMPAL,0FHJZWT;al全为0,说明无键按下NOPNOPMOVDX,360H;再次确认是否有键按下INAL,DXANDAL,0FHCMPAL,0FHJZWTMOVCX,3MOVBL,0FEHNEXT:MOVAL,BLMOVDX,360HOUTDX,ALNOPNOPINAL,DXANDAL,0FHCMPAL,0FHJNZKEYROLBL,1LOOPNEXTJMPWTKEY:SHLBL,4ORAL,BLCALLRELEASEPOPDXPOPBXRETINPUTENDP;设定闹钟ALARMPROCPUSHCXPUSHAXPUSHDXMOVCX,2JMPHH1HH2:CMPAL,[SI]JZHH3INCSIINCDILOOPHH2POPCXJMPHH1HH3:POPCXMOVAL,[DI];AL中内容为所按键的键面值CMPCX,2JNZHH4;CX=2设置十位,否则设置个位CMPAL,2JAHH1MOVAH,ALLEABX,TAB1;查找七段代码值XLATMOVDX,200H;送数码管时的十位OUTDX,ALCALLDELAYMOVDL,AHMOVAL,10MULDLMOVHHOUR,ALCALLDELAYJMPHH6HH1:PUSHCXCALLINPUTCALLDELAYLEASI,KEYCODLEADI,KEYVALMOVCX,12JMPHH2HH4:CALLDELAYCMPDL,2JNZHH5CMPAL,4JAHH1HH5:MOVAH,ALLEABX,TAB1XLATMOVDX,204H;送数码管时的个位OUTDX,ALCALLDELAYADDHHOUR,AH;将闹铃值保存在内存中CALLDELAYHH6:LOOPHH1;设置分钟MOVCX,2JMPMM1MM2:CMPAL,[SI]JZMM3INCSIINCDILOOPMM2POPCXJMPMM1MM3:POPCXMOVAL,[DI];AL中内容为所按键的键面值CMPCX,2JNZMM4;CX=2设置十位,否则设置个位CMPAL,5JAMM1MOVAH,ALLEABX,TAB1;查找七段代码值XLATMOVDX,201H;送数码管分的十位OUTDX,ALCALLDELAYMOVDL,AHMOVAL,10MULDLMOVMMINUTE,ALCALLDELAYJMPMM6MM1:PUSHCXCALLINPUTCALLDELAYLEASI,KEYCODLEADI,KEYVALMOVCX,12JMPMM2MM4:CALLDELAYCMPDL,5JNZMM5CMPAL,9JAMM1MM5:MOVAH,ALLEABX,TAB1XLATMOVDX,205H;送数码管分的个位OUTDX,ALCALLDELAYADDMMINUTE,AH;将闹铃值保存在内存中CALLDELAYMM6:LOOPMM1;设置秒钟MOVCX,2JMPSS1SS2:CMPAL,[SI]JZSS3INCSIINCDILOOPSS2POPCXJMPSS1SS3:POPCXMOVAL,[DI];AL中内容为所按键的键面值CMPCX,2JNZSS4;CX=2设置十位,否则设置个位CMPAL,5JASS1MOVAH,ALLEABX,TAB1;查找七段代码值XLATMOVDX,202H;送数码管秒的十位OUTDX,ALCALLDELAYMOVDL,AHMOVAL,10MULDLMOVSSECOND,ALCALLDELAYJMPSS6SS1:PUSHCXCALLI