(2)數(shù)碼管動(dòng)態(tài)顯示(循環(huán)顯示0~9,時(shí)間間隔為1秒,1秒的時(shí)間間隔用定時(shí)器T0實(shí)現(xiàn))①匯編語言: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的初始值;要設(shè)置為0AH,同時(shí)取消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;//數(shù)碼管位選端定義uchar c,i;//數(shù)碼管譯碼表unsigned char code NumDecode[] ={0XC0,//;00XF9,//;10XA4,//;20XB0,//;30X99,//;40X92,//;50X82,//;60XF8,//;70X80,//;80X90,//;9};void main(){i=0;//10秒計(jì)時(shí)設(shè)置c=0;//中斷次數(shù)計(jì)數(shù)p27=1;//數(shù)碼管位選端關(guān)閉TMOD=1;//設(shè)置定時(shí)器0為工作方式1TH0=(65536-46080)/256;//定時(shí)50ms高8位求模TL0=(65536-46080)%256;//定時(shí)50ms低8位求余EA=1;//開總中斷ET0=1;//定時(shí)器0中斷TR0=1;//啟動(dòng)定時(shí)器0while(1){if(c==20)//50ms中斷20次{c=0;i++;//倒計(jì)時(shí)總數(shù)每秒減1}if(i<10){p27=0;//數(shù)碼管位選選通P0=NumDecode[i];//顯示數(shù)據(jù)}else //循環(huán)計(jì)時(shí)設(shè)置{i=0;}}}void timer0() interrupt 1//定時(shí)器0中斷入口{TH0=(65536-46080)/256;//定時(shí)器重新賦初值TL0=(65536-46080)%256;c++;//中斷次數(shù)}
評(píng)論