- #include <reg51.h>
- //#include <stdio.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- sbit clk = P3^0;
- sbit dat = P3^1;
- sbit sclk1 = P3^2;
- //sbit sclk2 = P3^3;
- uchar code num[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- uchar data buf[8];
- ulong n,m;
- uchar i,k;
- uint j;
- void data_num(uchar dat8,digit) //串口数据发送数字数据
- {
- uchar i;
- for(i=0;i<8;i++)
- {
- clk = 0;
- dat = (dat8 >> i) & 0x01;
- clk = 1;
- }
- for(i=0;i<8;i++)
- {
- clk = 0;
- dat = (digit >> i) & 0x01;
- clk = 1;
- }
- sclk1 = 0;
- sclk1 = 1;
- }
- void InitTimer0(void)//@12MHz 1ms
- {
- TMOD = 0x01;
- TH0 = 0x0FC;
- TL0 = 0x18;
- EA = 1;
- ET0 = 1;
- TR0 = 1;
- }
- int main(void)
- {
- InitTimer0();
- while(1)
- {
- m=n;
- for(i=0;i<8;i++)
- {
- buf[i]=m%10;
- m/=10;
- }
- }
- }
- void Timer0Interrupt(void) interrupt 1
- {
- TH0 = 0xFC;
- TL0 = 0x18;
- j++;
- if(j>=500)//500ms
- {
- j=0;
- if(++n>99999999)
- n=0;
- }
- data_num(0x01<<k,num[buf[k]]);
- k=++k%8;
- }
复制代码
|