本帖最后由 hyg1997 于 2018-8-11 22:47 編輯
編譯0錯(cuò)誤,0警告,但是蜂鳴器就是不響。。。。。。
#include<reg52.h> #include <LCD1602.h> #include<MOTOR.H> #include<BEEP.H> #define uchar unsigned char #define uint unsigned int void main() { uinti,j; Delay_xms(50);//等待系統(tǒng)穩(wěn)定 /* 系統(tǒng)初始化 */ TMOD = 0x20; //定時(shí)器T1使用工作方式2 TH1= 253; // 設(shè)置初值 TL1= 253; TR1= 1; // 開始計(jì)時(shí) SCON = 0x50; //工作方式1,波特率9600bps,允許接收 ES= 1; EA= 1; // 打開所以中斷 TI= 0; RI= 0; SendData(str) ; //發(fā)送到串口 Delay(1); //延時(shí)100US(12M晶振) while(1) { if((K==0)&&(G==1)) { for(j=0;j<4;j++) //圈數(shù) { for(i=0;i<500;i++) //一圈 { MotorCW(); //順時(shí)針轉(zhuǎn)動(dòng) } } //Delay_xms(500); } else if ((G==0) &&(K==1)) { for(j=0;j<4;j++) //圈數(shù) { for(i=0;i<500;i++) { MotorCCW(); //逆時(shí)針轉(zhuǎn)動(dòng) } Delay_xms(500); } } else if ((G==0) &&(K==0)) { MotorStop( ); } { beep=1; if((FIRE==0)||(DOUT==0)) { delay(); if((FIRE==0)||(DOUT==0)) { beep=0;//蜂鳴器 } } } { //------------------------ //調(diào)用溫濕度讀取子程序 RH(); //串口顯示程序 //-------------------------- str[0]=U8RH_data_H; str[1]=U8RH_data_L; str[2]=U8T_data_H; str[3]=U8T_data_L; str[4]=U8checkdata; SendData(str) ; //發(fā)送到串口 //讀取模塊數(shù)據(jù)周期不易小于 2S lcddisplay(); Delay(20000); //elihw } } // main { beep=1; if((FIRE==0)||(DOUT==0)) { delay(); if((FIRE==0)||(DOUT==0)) { beep=0; } } } } void RSINTR() interrupt 4 using 2 { U8 InPut3; if(TI==1) //發(fā)送中斷 { TI=0; if(count!=5) //發(fā)送完5位數(shù)據(jù) { SBUF= outdata[count]; count++; } } if(RI==1) //接收中斷 { InPut3=SBUF; indata[count_r]=InPut3; count_r++; RI=0; if (count_r==5)//接收完4位數(shù)據(jù) { //數(shù)據(jù)接收完畢處理。 count_r=0; str[0]=indata[0]; str[1]=indata[1]; str[2]=indata[2]; str[3]=indata[3]; str[4]=indata[4]; P0=0; } } }
|