单片机学习小组
直播中

史靖文

7年用户 214经验值
私信 关注

请问进不了T0定时器内部中断是什么原因,芯片是STC15F2K60S2

#include
#include
#include
unsigned char code LEDchar[]={0xC0,0xF9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
unsigned char come[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
***it ds1302_ck = P1^7;
***it ds1302_io = P2^3;
***it ds1302_ce = P1^3;
bit flag200ms = 0;
//unsigned char T0RH = 0,T0RL = 0;
void delay(unsigned int t)
{
   do{
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   }while(--t);
}
void dsiplay()
{
   unsigned char i,j;
   j = 0x80;
   for(i=0;i<8;i++)
   {
      P2 = 0xE0;
          P0 = LEDchar[come];
          P2 = 0xC0;
          P0 = j;
          j>>=1;
          delay(100);
   }
}
void ds1302bytewrite(unsigned char dat)
{
   unsigned char mask;
   for(mask=0x01;mask!=0;mask<<=1)
   {
      if((mask&dat)==0)
             ds1302_io = 0;
          else
             ds1302_io = 1;
      ds1302_ck = 1;
          ds1302_ck = 0;
   }
   ds1302_io = 1;
}
unsigned char ds1302byteread()
{
   unsigned char mask;
   unsigned char dat = 0;
   for(mask=0x01;mask!=0;mask<<=1)
   {
      if(ds1302_io!=0)
          {
            dat |= mask;
          }
          ds1302_ck = 1;
          ds1302_ck = 0;
   }
   //ds1302_io = 1;
   return dat;
}
void ds1302singlewrite(unsigned char reg,unsigned char dat)
{
   ds1302_ce = 1;
   ds1302bytewrite((reg<<1)|0x80);
   ds1302bytewrite(dat);
   ds1302_ce = 0;
}
unsigned char ds1302singleread(unsigned char reg)
{
     unsigned char dat;
     ds1302_ce = 1;
         ds1302bytewrite((reg<<1)|0x81);
         dat = ds1302byteread();
         ds1302_ce = 0;
         return dat;
}
void initds1302()
{
    unsigned char i;
        unsigned char code inittime[] = {0x48,0x58,0x47};
        ds1302_ce = 0;
        ds1302_ck = 0;
        i = ds1302singleread(0);
        if((i & 0x80)!=0)
        {
           ds1302singlewrite(7,0x00);
           for(i=0;i<3;i++)
           {
               ds1302singlewrite(i,inittime);
           }
        }
}
void main()
{
    unsigned char i;
        unsigned char psec = 0xaa;
        unsigned char time[2];
        unsigned char tmr200ms = 0;
         
        TMOD = 0x21;
    TH0 = 0xFC;
    TL0 = 0x67;         
        ET0 = 1;
    TR0 = 1;
        EA = 1;
        initds1302();
           while(1)
        {
             if(flag200ms==1)
                 {
                   flag200ms = 0;
               for(i=0;i<3;i++)
                   {
                    time = ds1302singleread(i);
                   }
         if(psec != time[0])
                        {
                           come[0] = 0x40;
                           come[1] = 0x40;
                           come[2] = time[0]&0x0f;
                           come[3] = time[0]>>4;
                           come[4] = time[1]&0x0f;
                           come[5] = time[1]>>4;
                           come[6] = time[2]&0x0f;
                           come[7] = time[2]>>4;
                           dsiplay();
                           psec = time[0];
                            }     
        }
                  }
}
void interrupttime() interrupt 1
{
    static unsigned char tmr200ms = 0;
        TH0 = 0xFC;
        TL0 = 0x67;
        tmr200ms++;
        if(tmr200ms >= 200)
        {
           tmr200ms = 0;
           flag200ms = 1;
        }
                        
}

回帖(1)

陈迪

2019-5-17 09:39:18
帮顶
举报

更多回帖

发帖
×
20
完善资料,
赚取积分