首页 > 学院 > 开发设计 > 正文

10秒倒计时

2019-11-11 05:07:46
字体:
来源:转载
供稿:网友

寒假集训年后第一天

 #include<reg52.h>//sbit Led1 = P0^0;sbit Latch_seg = P2^0;sbit Latch_bit = P2^1;sbit BUZZ = P2^2; void delay(unsigned char cnt);/*unsigned char code LedChar[16]={   0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};*/unsigned char code LedChar[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};unsigned char code LedBuff[] = {0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F};unsigned char Led[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};unsigned int sec = 10;unsigned int ms = 1;bit flag = 0;bit openbuzz = 0;bit run = 1;unsigned char k = 0;void main(){EA = 1;     TMOD = 0x01;TH0 = 0xFC;TL0 = 0x67;ET0 = 1;     TR0 = 1; while(1){/////////////////////////////////////   if((flag == 1)&&(run == 1)){flag = 0;   ms--;if(ms <= 0){   ms = 99;sec--;if(sec <= 0){   ms = 0;                    sec = 0;openbuzz = 1;run = 0;}}   Led[7] = LedChar[ms%10];       Led[6] = LedChar[ms/10];       Led[5] = 0x40;       Led[4] = LedChar[sec%10];       Led[3] = LedChar[sec/10];       Led[2] = 0x00;Led[1] = 0x00;Led[0] = 0x00;   }  }}void InterruptTimer0() interrupt 1{static unsigned int cnt = 0;     TH0 = 0xFC;TL0 = 0x67;cnt++;if(cnt >= 10){    cnt = 0;flag = 1;}if(openbuzz == 1){    BUZZ = ~BUZZ;}P0 = 0xFF;switch(k){    case 0:  P0 = Led[0];             Latch_seg = 1;             Latch_seg = 0;             P0 = LedBuff[0];             Latch_bit = 1;             Latch_bit = 0; k++; break;case 1:  P0 = Led[1];             Latch_seg = 1;             Latch_seg = 0;             P0 = LedBuff[1];             Latch_bit = 1;             Latch_bit = 0; k++; break;    case 2:  P0 = Led[2];             Latch_seg = 1;             Latch_seg = 0;             P0 = LedBuff[2];             Latch_bit = 1;             Latch_bit = 0; k++; break;case 3:  P0 = Led[3];             Latch_seg = 1;             Latch_seg = 0;             P0 = LedBuff[3];             Latch_bit = 1;             Latch_bit = 0; k++; break;case 4:  P0 = Led[4];             Latch_seg = 1;             Latch_seg = 0;             P0 = LedBuff[4];             Latch_bit = 1;             Latch_bit = 0; k++; break;case 5:  P0 = Led[5];             Latch_seg = 1;             Latch_seg = 0;             P0 = LedBuff[5];             Latch_bit = 1;             Latch_bit = 0; k++; break;case 6:  P0 = Led[6];             Latch_seg = 1;             Latch_seg = 0;             P0 = LedBuff[6];             Latch_bit = 1;             Latch_bit = 0; k++; break;    case 7:  P0 = Led[7];             Latch_seg = 1;             Latch_seg = 0;             P0 = LedBuff[7];             Latch_bit = 1;             Latch_bit = 0; k=0; break;default:break;}}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表