51单片机 ,用C语言编程 通过独立按键控制蜂鸣器和静态数码管,
5个回答
展开全部
1.数码管前三位显示一个跑表,从000到999之间以1%秒速度运行,当按下一个独立键盘时跑表停止,松开手后跑表继续运行。(用定时器设计表)。
code:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1 = P3^4;
sbit dula = P2^6;
sbit wela = P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uint num;
uchar bai, shi, ge, flag = 0,t0 = 0;
void delay(uchar z);
void display(void);
void main(void)
{
num = 0;
P3 = 0xff;
TMOD = 0x01;
TH0 = (65536-10000) / 256;
TL0 = (65536-10000) % 256;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1) {
if(key1 == 0) {
delay(5);
if(key1 == 0) {
flag = 1;
}
while(!key1);
delay(5);
while(!key1);
}
display();
}
}
void display(void)
{
dula = 1;
P0 = table[num / 100];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfe;
wela = 0;
delay(1);
dula = 1;
P0 = table[num % 100 / 10];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfd;
wela = 0;
delay(1);
dula = 1;
P0 = table[num % 10];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfb;
wela = 0;
delay(1);
}
void delay(uchar z)
{
uchar
code:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1 = P3^4;
sbit dula = P2^6;
sbit wela = P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uint num;
uchar bai, shi, ge, flag = 0,t0 = 0;
void delay(uchar z);
void display(void);
void main(void)
{
num = 0;
P3 = 0xff;
TMOD = 0x01;
TH0 = (65536-10000) / 256;
TL0 = (65536-10000) % 256;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1) {
if(key1 == 0) {
delay(5);
if(key1 == 0) {
flag = 1;
}
while(!key1);
delay(5);
while(!key1);
}
display();
}
}
void display(void)
{
dula = 1;
P0 = table[num / 100];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfe;
wela = 0;
delay(1);
dula = 1;
P0 = table[num % 100 / 10];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfd;
wela = 0;
delay(1);
dula = 1;
P0 = table[num % 10];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfb;
wela = 0;
delay(1);
}
void delay(uchar z)
{
uchar
展开全部
#include<reg51.h>
#define uchar unsigned char
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f};
sbit key=P2^2;
sbit fmq=P2^3;
uchar dat;
void delay()//延时约10毫秒
{
uchar i,j;
for(i=0;i<10;i++)
for(j=0;j<120;j++);
}
main()
{
while(1)
{
if(key==0)
{
delay();
if(key==0)
{
fmq=0;
while(key==0);
fmq=1;
dat++;
dat%=10;
P1=table[dat];
}
}
}
}
追问
如果能使用无源蜂鸣器就好了,兄弟。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <REGX51.H> #include<intrins.h> #define uint unsigned int #define uchar unsigned char sbit buzzer=P2^0; uchar temp[4]={4,0,2,0}; uchar n=1; void delay250uS(void)//延时250us { unsigned char a,b; for(b=19;b>0;b--) for(a=5;a>0;a--); } void main(void) { uchar i=0,n0=0; TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; ET0=1; EA=1; TR0=1; while(1) { n0=n; if(n0!=0) { if(++i==temp[n])i=1; if((i==1)|(i==temp[n]/2))buzzer=~buzzer; delay250uS(); } } } void Timer0Interrupt(void) interrupt 1 { static uchar temp1=0; TH0=(65536-50000)/256; TL0=(65536-50000)%256; if(++temp1==10) { if(++n==4)n=0; } }
追问
兄弟 我新手菜鸟 这个程序我看着 可能有点复杂。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
卫蘅与陆湛相恋,卫蘅却阴错阳差嫁给了自己有断袖之癖的表哥。三年后陆湛谋划让卫蘅和离,娶了卫蘅。婚后却对卫蘅冷若冰霜,更出言辱骂,本文从和气堂陆湛骂走卫蘅开始。卫蘅与陆湛相恋,卫蘅却阴错阳差嫁给了自己有断袖之癖的表哥。三年后陆湛谋划让卫蘅和离,娶了卫蘅。婚后却对卫蘅冷若冰霜,更出言辱骂,本文从和气堂陆湛骂走卫蘅开始。卫蘅与陆湛相恋,卫蘅却阴错阳差嫁给了自己有断袖之癖的表哥。三年后陆湛谋划让卫蘅和离,娶了卫蘅。婚后却对卫蘅冷若冰霜,更出言辱骂,本文从和气堂陆湛骂走卫蘅开始。卫蘅与陆湛相恋,卫蘅却阴错阳差嫁给了自己有断袖之癖的表哥。三年后陆湛谋划让卫蘅和离,娶了卫蘅。婚后却对卫蘅冷若冰霜,更出言辱骂,本文从和气堂陆湛骂走卫蘅开始。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
🤔🤔🤔🤔🤔🤔
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询