找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 993|回復(fù): 0
收起左側(cè)

51單片機(jī)測(cè)雙電機(jī)轉(zhuǎn)速程序

[復(fù)制鏈接]
ID:1080652 發(fā)表于 2023-5-29 13:03 | 顯示全部樓層 |閱讀模式
大佬幫忙看下中斷服務(wù)程序和初始化部分有什么問(wèn)題,在Proteus里仿真的時(shí)候LCD屏不顯示數(shù)字。


0.png

void init()                                                   //定時(shí)器0初始化
{
        EA=1;
        EX0=1;//開(kāi)外部INTO中斷
        IT0=1;        //INT0負(fù)跳變觸發(fā)
        EX1=1;//開(kāi)外部INT1中斷
        IT1=1;        //INT1負(fù)跳變觸發(fā)        
    TMOD=0x01;//定時(shí)器0工作于方式1
        TH0=0x3c;          //50ms
        TL0=0xb0;
        ET0=1;//開(kāi)定時(shí)中斷
    TR0=1;//啟動(dòng)定時(shí)
}


void display()                        //顯示函數(shù)
{
          Velocity3=Velocity1+Velocity2;
                Velocity=Velocity3/2;
          Mileage=Mileage+Velocity*500/36;
                write_1602com(0x80+2);
                if(Velocity/100==0)
                write_1602dat(' ');
                else
                write_1602dat(0x30+Velocity/100);
                if((Velocity/100+Velocity%100/10)==0)
                write_1602dat(' ');
                else
                write_1602dat(0x30+Velocity%100/10);
                write_1602dat(0x30+Velocity%10);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼

                write_1602com(0x80+14);
                if((VH/10)==0)
                write_1602dat(' ');
                else
                write_1602dat(0x30+VH/10);
                write_1602dat(0x30+VH%10);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼

                write_1602com(0x80+0x40+8);
                write_1602dat(0x30+Mileage/1000000);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
                write_1602dat(0x30+Mileage%1000000/100000);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
                write_1602com(0x80+0x40+11);
                write_1602dat(0x30+Mileage%100000/10000);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
                write_1602dat(0x30+Mileage%10000/1000);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
               
                write_1602dat(0x30+Mileage%1000/100);//數(shù)字+30得到該數(shù)字的LCD1602顯示碼
}

void main()                           //主函數(shù)
{
        lcd_init();
        init;
        while(1)
        {
                anjian();
                display();
                alarm();
        }
}


void EXINT0() interrupt 0  //外部中斷函數(shù)
{
        count1++;                           //有信號(hào)加
}

void EXINT1() interrupt 2  //外部中斷函數(shù)
{
        count2++;                           //有信號(hào)加
}

void time0() interrupt 1   //定時(shí)器中斷執(zhí)行函數(shù)
{
        uchar m;
        TH0=0x3c;
        TL0=0xb0;         //50ms
        m++;
        if(m%5==0&&flag_alarm==1)
        {
                BUZZ=!BUZZ;
        }
        if(m>=10)
        {
            Velocity1=count1/5;//(速度是將500ms內(nèi)的脈沖數(shù)除以5)(此處的速度值和轉(zhuǎn)數(shù)沒(méi)有計(jì)算公式,只是為了得到一個(gè)隨轉(zhuǎn)速大小變化的速度值)
                Velocity2=count2/5;
                m=0;               
                count1=0;
                count2=0;        

        }
}



回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表