欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
關(guān)于單片機定時器中用按鍵控制蜂鳴器
[打印本頁]
作者:
qwer2@45
時間:
2022-2-25 10:33
標題:
關(guān)于單片機定時器中用按鍵控制蜂鳴器
其中,我設(shè)置的按鍵對蜂鳴器進行控制,但是在仿真的時候,按鍵按下,蜂鳴器并不響,同時數(shù)碼管的倒計時顯示也受到了影響
#define _MAIN_C
#include "use.h"
#include "main.h"
#include "time.h"
#include "key.h"
bit flag1s;
sbit nsg = P2^0;
sbit nsy = P2^1;
sbit nsr = P2^2;
sbit weg = P2^5;
sbit wey = P2^4;
sbit wer = P2^3;
sbit k1 = P3^5;
sbit k2 = P3^6;
sbit bp = P1^0;
int key1 = 1;
int key2 = 1;
int Bun=0;
uchar count1s,NS_time,WE_time;
uchar GreenTime=30,RedTime=35;
uchar index=0;
enum eStaSysterm StaSysterm=NormalRun;
void Beep_on()
{
bp=~bp;
Delay10us(2000);
}
void keypros1()
{
if(k1 == 0)
{
if(wer == 1)
{
key1 = 2;
Bun=10;
}
}
while(!k1);
}
void keypros2()
{
if(k2 == 0)
{
if(nsr == 1)
{
key2 = 2;
Bun=10;
}
while(!k2);
}
}
void main()
{
EA=1;
InintTimer0();
while(1)
{
LEDScan();
KeyDriver();
keypros2();
keypros1();
if((Bun > 0 && key1 == 2) || (Bun > 0 && key2 == 2) )
{
Beep_on();
Bun--;
}
if(Bun<0)
{
key1=1;
key2=1;
}
if(flag1s)
{
flag1s=0;
NS_time--;
WE_time--;
}
}
}
void InintTimer0()
{
TMOD=0X01;
TH0=0X4C;
TL0=0X00;
ET0=1;
TR0=1;
}
void Timer0() interrupt 1
{
TH0=0XBB;
TL0=0X00;
KeyScan();
if(++count1s<50) return;
count1s=0;
if(StaSysterm==NormalRun) flag1s=1;
}
void LEDScan()
{
if(StaSysterm==NormalRun)
{
if(NS_time==0 || WE_time==0)
{
switch(index)
{
case 0:
{
index=1;
NS_time=GreenTime;
WE_time=RedTime;
P2=0x09;
}break;
case 1:
{
index=2;
NS_time=RedTime-GreenTime;
P2=0X0A;
}break;
case 2:
{
index=3;
NS_time=RedTime;
WE_time=GreenTime;
P2=0X24;
}break;
case 3:
{
index=0;
WE_time=RedTime-GreenTime;
P2=0X14;
}break;
default:break;
}
}
Seg_Display(NS_time/10,0);
Seg_Display(NS_time%10,1);
Seg_Display(WE_time/10,2);
Seg_Display(WE_time%10,3);
}
else if(StaSysterm==UrgentRun)
{
P2=0x12;
Delayms(200);
P2=0x00;
Delayms(200);
}
}
作者:
man1234567
時間:
2022-2-25 15:23
void Beep_on()
{
bp=~bp; //蜂鳴器分有源、無源,不響是用了后者或器件問題
Delay10us(2000);//蜂鳴器觸發(fā)后延時,程序中更新顯示要等這個結(jié)束
}
作者:
xuyong21717249
時間:
2022-2-25 15:33
沒仔細看,不過你KEYSCAN放中斷里不對,軟件邏輯有問題
作者:
ansonjimli
時間:
2022-2-25 21:48
蜂鳴器,按鍵掃描中都不應該有軟件延時這種阻塞延時,通過定時器計數(shù)方式實現(xiàn)無阻塞延時。
作者:
yzwzfyz
時間:
2022-2-26 10:50
不看程序了,查查有沒有在中斷中用了DELAY()!
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1