1024手机基地看电影,午夜福利视频导航,国产精品福利在线一区,亚洲欧美日韩另类成人,在线观看午夜日本理论片,成年超爽免费网站,国产精品成人免费,精品动作一级毛片,成人免费观看网站,97精品伊人久久大香蕉

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3054|回復: 3
打印 上一主題 下一主題
收起左側

51單片機 定時器無法進入中斷

[復制鏈接]
跳轉到指定樓層
樓主
ID:591385 發表于 2019-11-5 17:31 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include<reg51.h>
#include<absacc.h>
#include<stdio.h>
unsigned char code seg[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c};
int tim=0;
int num=0;
int ge=0,shi=0,bai=0;
int count_high=0;
int count_low=0;
void shumaguan(int ge,int shi,int bai);
void read_count(void);
void delay(unsigned int x)
{
        int i;
        while(x--)
                for(i=0;i<100;i++)
                        ;
}
void timer1() interrupt 3
{
       
        //1S¼Æê±
        TH1=(65536-10000)/256;
        TL1=(65536-10000)%256;
        shumaguan(1,2,3);
        tim++;
        if(tim==100)
        {
               
                TR0=0;
                TR1=0;
                read_count();
    ge=num%10;
          shi=num/10%10;
    bai=num/100;       
                shumaguan(ge,shi,bai);
  }
}


void read_count(void)
{
        do
        {
                count_high=TH0;
                count_low=TL0;
  }while(count_high!=TH0);
        num=count_high*256+count_low;
       
}


void shumaguan(int ge,int shi,int bai)
{
        int i=100;
        while(i--)
        {
                P2=0xfe;
                P0=seg[bai];
          delay(10);
          P2=0xfd;
                P0=seg[shi];
          delay(10);
          P2=0xfb;
                P0=seg[ge];
          delay(10);
  }
}




void main()
{
        TMOD=0x15;
        EA=1;
        ET1=1;
       
        TR0=0;
  TR1=0;
        TH1=(65536-10000)/256;
        TL1=(65536-10000)%256;
        while(P3&0x10==0);
        TR0=1;
  TR1=1;               
       
       
}


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:213173 發表于 2019-11-5 21:11 | 只看該作者
因為你的程序main函數不完整,初始化不到1ms就運行完了。退出后再次進入main函數初始化,周而復始,永遠不會有發生中斷的機會。必須加while(1)約束。
回復

使用道具 舉報

板凳
ID:94031 發表于 2019-11-5 22:01 | 只看該作者
/*TR1=0;
        TH1=(65536-10000)/256;
        TL1=(65536-10000)%256;
        while(P3&0x10==0);
        TR0=1;*/
  TR1=1; 按這樣改一下你再試,注釋掉的是多余的。           
回復

使用道具 舉報

地板
ID:560467 發表于 2019-11-5 22:41 | 只看該作者
你的主函數缺少一個while循環體,因該讓 他一直在循環里面運行才對,否則會一直在重新運行一遍既把所有程序重新跑一邊void main() {   while(){} }
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表