標(biāo)題: ST89C52中斷方式實(shí)現(xiàn)簡(jiǎn)易三位秒表 [打印本頁]

作者: kkkkkkkk111    時(shí)間: 2021-1-21 20:51
標(biāo)題: ST89C52中斷方式實(shí)現(xiàn)簡(jiǎn)易三位秒表
#include<reg52.h>
#define uchar unsigned char
sbit duan=P2^6;
sbit wei=P2^7 ;
int index=0;
uchar ms;
uchar s;
uchar code duanS[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code weiS[]={0xef,0xdf,0xbf};

void initP1(){
EA=1;
ET0=1;
TR0=1;
TMOD|=0x01;
TH0=(65535-19453)/255;
TL0=(65535-19453)%255;
}
void initP3(){
EA=1;
ET1=1;
TR1=1;
TMOD|=0x10;
TH1=60927/255;
TL1=60927%255;
}

void display(uchar i){
        P0=weiS[index];
    switch(index) {
         case 0:         wei=1;duan=0;wei=0;duan=1;P0=duanS[i/100];
         break;
         case 1:         wei=1;duan=0;wei=0;duan=1;P0=duanS[i/10%10];
         break;
         case 2:         wei=1;duan=0;wei=0;duan=1;P0=duanS[i%10];
         break;
        }
        index++;
        if(index>=3)
        index=0;
}

void main(){          
          initP1();
          initP3();
          while(1);  
}

void interP1() interrupt 1 {
     TH0=(65535-19453)/255;
     TL0=(65535-19453)%255;
         ms++;         
         if(ms==60){
         P1=~P1        ;
         s++;
         ms=0;           
         }
         if(s>=100)
         s=0;
}

void interP3() interrupt 3{
        TH1=60927/255;
    TL1=60927%255;
        display(s);
}






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1