- #include "reg51.h"
- sbit dula=P1^3;
- sbit g1=P1^4;
- sbit c=P1^5;
- sbit b=P1^6;
- sbit a=P1^7;
- char s=6,ms=0;
- unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- bit flag=0;
- void delay()
- {
- unsigned char i;
- for(i=0;i<255;i++);
- }
- initial()
- {
- TMOD=1;
- TL0=0XF0;
- TH0=0XD8;
-
- TR0=1;
- ET0=1;
- EA=1;
- P2=0x0f;
- g1=0;
- }
- display()
- {
- // P0=tab[ms/10];dula=1;
- // c=1;b=1;a=0;g1=1;
- // delay();
- // g1=0;
- // P0=tab[ms%10];dula=1;
- // c=1;b=1;a=1;g1=1;
- // delay();
- // g1=0;
- P0=tab[s%10];dula=1;
- c=1;b=1;a=1;g1=1;
- delay();
- g1=0;
- P0=tab[s/10];dula=1;
- c=1;b=1;a=0;g1=1;
- delay();
- g1=0;
- }
- main()
- {
- initial();
- while(1)
- {
- display();
- }
- }
- t_0() interrupt 1
- {
- TL0=0XF0;
- TH0=0XD8;
- ms++;
- if(ms==50&&s<=3)
- {
- P2=0x55;
- }
-
- if(ms==100)
- {
- if(flag==0){
- P2=0x0f;
- }else{
- P2=0xf0;
- }
- ms=0;
- s--;
- if(s==0)
- {
- s=6;
- flag=~flag;
- P2=~P2;
- }
- }
- }
复制代码 P0口接LED灯(所以有上拉电源(power)),共阴极,代码中的a,b,c是用3-8译码器定位LED,方式一中断
|