經(jīng)過幾天的不眠不休,結(jié)合我們老師是方法和網(wǎng)絡(luò)資料,加上自己不斷的學(xué)習(xí),思考,修改,終于成功的讓數(shù)碼管動態(tài)顯示出來,并且能從0~99自動跳轉(zhuǎn)。接下來繼續(xù)努力,把程序再簡化。耶,又成功了一步,辛苦的付出總能見到美好的收獲。加油加油!
#include"reg51.h" #define uchar unsigned char #define uint unsigned int uchar code smg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; uchar data yy[2]={0,0}; uint a; sbit P30=P3^0; sbit P31=P3^1; void delayms(uint m) { uchar i,j; for(i=m;i>0;i--) for(j=110;j>0;j--); } void calc() { P30=1; P2=smg[yy[6]]; delayms(10); P3=0; P31=1; P2=smg[yy[7]]; delayms(10); P3=0; } void JS() { a++; if(a==10) a=0; yy[7]=a%10; //個位 yy[6]=a/10; //十位 } void main() { uint i; while(1) { for(i=250;i>0;i--) { calc(); } JS(); } }