(2)数码管动态显现(循环显现0~9,时刻距离为1秒,1秒的时刻距离用守时器T0完成)
①汇编言语:ORG 0000HAJMP MAINORG 000BHAJMP INTT0ORG 0030HMAIN:CLR P2.7MOV DPTR,#TABCLR AMOV R2,#0HMOV R3,#0HMOV TMOD,#01HMOV TH0,#4CHMOV TL0,#00HSETB EASETB ET0SETB TR0HERE: CJNE R2,#14H,HEREMOV R2,#0HPUSH ACCMOVC A,@A+DPTRMOV P0,APOP ACCINC AINC R3 CJNE R3,#0AH,HEREMOV R3,#00H ;此处用DJNZ 更便利,只不过R3的初始值;要设置为0AH,一起撤销INC R3指令(此行上面第二行) CLR AAJMP HEREORG 80HINTT0:MOV TH0,#4CHMOV TL0,#00HINC R2RETITAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90HEND②C言语#include#define uint unsigned int#define uchar unsigned charsbit p27=P2^7;//数码管位选端界说uchar c,i;//数码管译码表unsigned char code NumDecode[] ={0XC0,//;00XF9,//;10XA4,//;20XB0,//;30X99,//;40X92,//;50X82,//;60XF8,//;70X80,//;80X90,//;9};void main(){i=0;//10秒计时设置c=0;//中止次数计数p27=1;//数码管位选端封闭TMOD=1;//设置守时器0为工作方式1TH0=(65536-46080)/256;//守时50ms高8位求模TL0=(65536-46080)%256;//守时50ms低8位求余EA=1;//开总中止ET0=1;//守时器0中止TR0=1;//发动守时器0while(1){if(c==20)//50ms中止20次{c=0;i++;//倒计时总数每秒减1}if(i<10){p27=0;//数码管位选选通P0=NumDecode[i];//显现数据}else //循环计时设置{i=0;}}}void timer0() interrupt 1//守时器0中止进口{TH0=(65536-46080)/256;//守时器从头赋初值TL0=(65536-46080)%256;c++;//中止次数}