四位.png (14.08 KB, 下載次數: 54)
下載附件
2017-4-25 20:02 上傳
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code SegCode[]=
- {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
- uchar code BitCode[]={0xfe,0xfd,0xfb,0xf7};
- uchar DispBuf[4];
- uint Count;
- void DelayMs(uchar n)
- {
- uchar j;
- while(n--)
- {
- for(j=0;j<113;j++);
- }}
- void NumToBuf(void)
- {
- DispBuf[3]=Count/1000;
- DispBuf[2]=Count/100%10;
- DispBuf[1]=Count/10%10;
- DispBuf[0]=Count%10;
- }
- void BufToSeg(void)
- {
- uchar i;
- for(i=0;i<4;i++)
- {
- P0=SegCode[DispBuf[i]];
- P2=BitCode[i];
- DelayMs(2);
- P2|=0x0F;
- }}
- void main(void)
- {
- uint k;
- while(1)
- {
- if(++k==220)
- {
- k=0;
- if(++Count==10000)Count=0;
- }
- NumToBuf();
- BufToSeg();
- }}
復制代碼 |