數(shù)碼管動態(tài)顯示程序
電路連接圖
#include"reg51.h"#define uchar unsigned char#define uint unsigned intuchar 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();}}
評論