在下面单片机程序中加入按键控制 按一次按键程序暂停,再按一下程序运行
#include<reg51.h>#include<intrins.h>#defineucharunsignedchar#defineuintunsignedintsbi...
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit teep = P2^7; // P2.7口控制蜂鸣器
sbit K3 = P3^2;
Delay(uint);
main ()
{
uchar temp, a, b;
temp = 0xfe;
P1 = temp;
while(1) {
for(a = 0; a < 7; a++) {
temp = _crol_(temp, 1); //左移1位
P1 = temp;
Delay(260);
}
for(b = 0; b < 7; b++) {
temp = _cror_(temp, 1); //右移1位
P1 = temp;
Delay(260);
}
}
}
Delay(uint z) //含有发音功能的延时程序
{
uint i, j;
for(j = z; j > 0; j--) {
teep = 0; for(i = 100; i > 0; i--);
teep = 1; for(i = 100; i > 0; i--);
}
return 0;
} 展开
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit teep = P2^7; // P2.7口控制蜂鸣器
sbit K3 = P3^2;
Delay(uint);
main ()
{
uchar temp, a, b;
temp = 0xfe;
P1 = temp;
while(1) {
for(a = 0; a < 7; a++) {
temp = _crol_(temp, 1); //左移1位
P1 = temp;
Delay(260);
}
for(b = 0; b < 7; b++) {
temp = _cror_(temp, 1); //右移1位
P1 = temp;
Delay(260);
}
}
}
Delay(uint z) //含有发音功能的延时程序
{
uint i, j;
for(j = z; j > 0; j--) {
teep = 0; for(i = 100; i > 0; i--);
teep = 1; for(i = 100; i > 0; i--);
}
return 0;
} 展开
1个回答
展开全部
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit teep = P2^7; // P2.7口控制蜂鸣器
sbit K3 = P3^2;
uchar flag=0;
Delay(uint);
void ext0() interrupt 0
{
flag=~flag;
}
main ()
{
uchar temp, a, b;
temp = 0xfe;
P1 = temp;
while(1) {
for(a = 0; a < 7; a++) {
temp = _crol_(temp, 1); //左移1位
P1 = temp;
while(flag);
Delay(260);
}
for(b = 0; b < 7; b++) {
temp = _cror_(temp, 1); //右移1位
P1 = temp;
while(flag);
Delay(260);
}
}
}
Delay(uint z) //含有发音功能的延时程序
{
uint i, j;
for(j = z; j > 0; j--) {
teep = 0; for(i = 100; i > 0; i--);
teep = 1; for(i = 100; i > 0; i--);
}
return 0;
}
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit teep = P2^7; // P2.7口控制蜂鸣器
sbit K3 = P3^2;
uchar flag=0;
Delay(uint);
void ext0() interrupt 0
{
flag=~flag;
}
main ()
{
uchar temp, a, b;
temp = 0xfe;
P1 = temp;
while(1) {
for(a = 0; a < 7; a++) {
temp = _crol_(temp, 1); //左移1位
P1 = temp;
while(flag);
Delay(260);
}
for(b = 0; b < 7; b++) {
temp = _cror_(temp, 1); //右移1位
P1 = temp;
while(flag);
Delay(260);
}
}
}
Delay(uint z) //含有发音功能的延时程序
{
uint i, j;
for(j = z; j > 0; j--) {
teep = 0; for(i = 100; i > 0; i--);
teep = 1; for(i = 100; i > 0; i--);
}
return 0;
}
追问
按键是哪一个,按k3没有反应,和先前的程序一样。
追答
哦,再加点程序,中断初始化没加。
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit teep = P2^7; // P2.7口控制蜂鸣器
sbit K3 = P3^2;
uchar flag=0;
Delay(uint);
void ext0() interrupt 0
{
flag=~flag;
}
main ()
{
uchar temp, a, b;
EX0=1;
IT0=1;
EA=1;
temp = 0xfe;
P1 = temp;
while(1) {
for(a = 0; a 0; j--) {
teep = 0; for(i = 100; i > 0; i--);
teep = 1; for(i = 100; i > 0; i--);
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询