楼主的源码:
- #include<reg51.h>
- #include<intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- sbit DTData=P2^6;
- sbit DTCtrl=P2^7;
- //共阴管8根数据线,8个管
- //高电平控制管子的选择,低电平控制亮灭
- uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,
- 0x40};
- uchar code position[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0xff};
- void delayms(uint xms)
- {
- uint i,j;
- for(i=xms;i>0;i--)
- for(j=110;j>0;j--)
- {;}
- }
- void dtshow(uchar digit,uchar dat)
- {
- uchar dat1=dat;
- P0=0;
- P0=position[digit];
- DTCtrl=1;
- DTCtrl=0;
- P0=0x0;
- P0=table[dat1];
- DTData=1;
- DTData=0;
- DTData=0;
- delayms(1);
- }
- void dtshowstring(uchar datstring[])
- {
- uchar k=8;
- uchar temp;
- for(k=0;k<8;k++)
- {
- temp=datstring[k];
- dtshow(k,temp);
- delayms(1);
- }
- }
- void main()
- {
- uchar num=0;
- uint tnum=0;
- uchar numstring[]={1,2,16,4,5,16,7,8,9,3};
- while(1)
- {
- for(tnum=50;tnum>0;tnum--)
- {
- for(num=0;num<8;num++)
- {
- dtshowstring(numstring);
- }
- }
- delayms(500);
- }
- }
复制代码 |