- #include <stc15f2k60s2.h>
- #include <intrins.h>
- #define LED P2
- sbit L1=P4^4;
- sbit L2=P4^2;
- sbit L3=P4^1;
- sbit L4=P3^7;
- sbit L5=P3^6;
- sbit L6=P3^5;
- sbit L7=P3^4;
- sbit L8=P3^3;
- void Timer1Init();//¶¨Ê±Æ÷³õʼ
- unsigned char code table[]={0x3f,0x06,0x5b,0x4f,
- 0x66,0x6d,0x7d,0x07,
- 0x7f,0x6f};
- unsigned char i,j;
- void xs();//ÊýÂë¹ÜÏÔʾ
- void Delay1ms() //@11.0592MHz
- {
- unsigned char i, j;
- _nop_();
- _nop_();
- _nop_();
- i = 11;
- j = 190;
- do
- {
- while (--j);
- } while (--i);
- }
- void main()
- {
- Timer1Init();
- while(1)
- {
- xs();
- if(j==20)
- {
- i++;
- j=0;
- }
-
- }
- }
- void xs()
- {
- L1=0;L2=1;L3=1;L4=1;L5=1;L6=1;L7=1;L8=1;
- LED=table[i/100%10];
- Delay1ms();
- L1=1;L2=0;L3=1;L4=1;L5=1;L6=1;L7=1;L8=1;
- LED=table[i/10%10];
- Delay1ms();
- L1=1;L2=1;L3=0;L4=1;L5=1;L6=1;L7=1;L8=1;
- LED=table[i/1%10];
- Delay1ms();
- }
- void Timer1Init() ////¶¨Ê±Æ÷³õʼ
- {
- TMOD = 0x01;
- TH0 = (65536-50000)/256;
- TL0 = (65536-50000)/256;
- EA = 1;
- ET0 = 1;
- TR0 = 1;
- }
- void Timer0() interrupt 1
- {
- TH0 = (65536-50000)/256;
- TL0 = (65536-50000)/256;
- j++;
- }
- //void xs 这个函数是如何执行的 还有为什么要判断j==20
复制代码
|