标题: 如何用单片机C语言编程,实现p1.1口的led闪烁1/2/3次和不断闪烁与常亮 真的不会呀! [打印本页]

作者: HuJohn    时间: 2017-4-18 20:36
标题: 如何用单片机C语言编程,实现p1.1口的led闪烁1/2/3次和不断闪烁与常亮 真的不会呀!
如何用C语言编程,实现p1.1口的led闪烁1/2/3次和不断闪烁与常亮;用p3.3 int1口控制闪烁状态呀?

作者: HuJohn    时间: 2017-4-18 21:21
是要沉的节奏么?大家都不会呀??
作者: imxuheng    时间: 2017-4-18 21:58
HuJohn 发表于 2017-4-18 21:21
是要沉的节奏么?大家都不会呀??

p3.3 int1口控制是什么意思,主要是你要怎么控制
作者: HuJohn    时间: 2017-4-18 22:13
imxuheng 发表于 2017-4-18 21:58
p3.3 int1口控制是什么意思,主要是你要怎么控制

就是按钮接在p3.3,按一下,更改led闪烁次数
作者: HuJohn    时间: 2017-4-18 22:14
imxuheng 发表于 2017-4-18 21:58
p3.3 int1口控制是什么意思,主要是你要怎么控制

以下程序怎么改才能达到我的目的呢?主要是延时那部分还是?
#include<reg51.h>
#define uchar unsigned char
sbit key=P3^3;
sbit led=P1^1;
uchar timeCnt=0;
void delay break( unsigned int t)
{
uchar i,j;
for(i=t;i>0;i--)
for(j=250;j>0;j--);
}
void shanshuo1()
{
led=~led;
delay(1);
}
void shanshuo2()
{
led=~led;
break(2);
}
void shanshuo3()
{
led=~led;
break(3);
}
void shanshuo4()
{
led=0;
delay(1500);
led=1;
delay(1500);
}
void shanshuo5()
{
led=0;
delay(60000);
led=1;
delay(60000);
}
void main()
{
while(1)
{
if(key==0)
{
timeCnt++;
if(timeCnt==6) timeCnt=0;
}
if(timeCnt==1) shanshuo1();
if(timeCnt==2) shanshuo2();
if(timeCnt==3) shanshuo3();
if(timeCnt==4) shanshuo4();
if(timeCnt==5) shanshuo5();

}
}
作者: FxMan    时间: 2017-4-19 10:55
#include<reg51.h>
#define uchar unsigned char
sbit key=P3^3;
sbit led=P1^1;
uchar timeCnt=0;
void delay break( unsigned int t)
{
uchar i,j;
for(i=t;i>0;i--)
for(j=250;j>0;j--);
}
void shanshuo1()
{
led=~led;
delay(1);
}
void shanshuo2()
{
led=~led;
break(2);
}
void shanshuo3()
{
led=~led;
break(3);
}
void shanshuo4()
{
led=0;
delay(1500);
led=1;
delay(1500);
}
void shanshuo5()
{
led=0;
delay(60000);
led=1;
delay(60000);
}
void main()
{
while(1)
{
if(key==0)
{
timeCnt++;
if(timeCnt==6) timeCnt=0;
}
if(timeCnt==1) shanshuo1();
if(timeCnt==2) shanshuo2();
if(timeCnt==3) shanshuo3();
if(timeCnt==4) shanshuo4();
if(timeCnt==5) shanshuo5();

}
}
程序加上注释
作者: imxuheng    时间: 2017-4-19 11:25
HuJohn 发表于 2017-4-18 22:14
以下程序怎么改才能达到我的目的呢?主要是延时那部分还是?
#include
#define uchar unsigned char

led闪烁1/2/3次是闪烁是只1/2/3次,还是隔一段时间闪烁1/2/3次
作者: HuJohn    时间: 2017-4-19 22:23
imxuheng 发表于 2017-4-19 11:25
led闪烁1/2/3次是闪烁是只1/2/3次,还是隔一段时间闪烁1/2/3次

p3.3接个按键,led分别接p1.0 p1.1 p1.2 。按一下闪一次,再按一下闪两下,接着是三次、闪烁、常亮
作者: HuJohn    时间: 2017-4-19 22:40
FxMan 发表于 2017-4-19 10:55
#include
#define uchar unsigned char
sbit key=P3^3;

编译有两个错误
“delay”:void on variable
missing before break




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1