标题:
<新手求助>单片机LED灯!
[打印本页]
作者:
627431363
时间:
2017-7-14 22:20
标题:
<新手求助>单片机LED灯!
假设LED1~LED8 怎么从LED4 LED5向两边扩散依次亮?
依次亮
作者:
952263371
时间:
2017-7-14 22:55
设个数组,用for循环4次
作者:
sldx
时间:
2017-7-15 00:47
a=0x10;b=0x01;for(i=0;i<4;i--){a<<=1;b>>=1;c=a|b;P0=c;delay();}
作者:
HC6800-ES-V2.0
时间:
2017-7-15 08:26
很简单啊,就是这样的:
#include<reg51.h>
#include<intrins.h>
#define LED8 P2
void Delay10ms(unsigned char c);
unsigned char code LLED[7]={0x81,0x42,0x24,0x18,0x24,0x42,0x81};
void main()
{
unsigned char c,n;
LED8=0xff;
c=50;
while(1)
{
for (n=0;n<7;n++)
{
LED8=~LLED[n];
Delay10ms(c);
}
}
}
void Delay10ms(unsigned char c)
{
unsigned char a,b;
for(;c>0;c--)
for(b=38;b>0;b--)
for(a=130;a>0;a--);
}
作者:
青苹果
时间:
2017-7-15 09:53
建个表,一次一次读出来显示
作者:
DSP28XX
时间:
2017-7-15 10:06
首先要看控制器的型号,51系列可以使用一组IO口进行中间向两侧的移位操作,其他型号要具体分析
作者:
here
时间:
2017-7-15 11:42
unsigned char LED[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
作者:
qingtian2090
时间:
2017-7-15 14:37
把每种状态引脚值存数组里,循环调用数组
作者:
627431363
时间:
2017-7-15 15:27
qingtian2090 发表于 2017-7-15 14:37
把每种状态引脚值存数组里,循环调用数组
用那个函数啊?
作者:
hzlsw1
时间:
2017-7-15 15:32
左移,右移 #include<intrins.h>
作者:
hyzhang2015
时间:
2017-7-15 17:51
从LED4 LED依次左移右移
作者:
hello——world
时间:
2017-7-15 18:11
unsigned char i; for(i=4;i<=8;i++) { LED(i)=亮;LED(8-i)=亮;delay(xxx);LED(i)=灭;LED(8-i)=灭;}
作者:
hello——world
时间:
2017-7-15 18:12
看我的就OK了,效率高,注意是伪代码,我看楼上很多的数据结构都学得不怎样
作者:
1311638554
时间:
2017-7-15 18:23
设个数组,用for循环4次
作者:
mwh1233
时间:
2017-7-15 20:46
用一个case语句就能解决
作者:
sunstar
时间:
2017-7-17 11:48
通过两个灯两个灯的亮,里面加入延时函数就行
作者:
627431363
时间:
2017-7-17 20:39
#include<reg51.h>
#include<intrins.h>
#define LED8 P0
void Delay20ms(unsigned char c);
unsigned char code LLED[7]={0x18,0x24,0x42,0x81,0x18,0x24,0x42};
void main()
{
unsigned char c,n;
LED8=0x01;
c=200;
while(1)
{
for (n=0;n<7;n++)
{
LED8=LLED[n];
Delay20ms(c);
}
}
}
void delay20ms(unsigned char c) //误差 0us
{
unsigned char a,b;
for(;c>0;c--)
for(b=215;b>0;b--)
for(a=45;a>0;a--);
_nop_(); //if Keil,require use intrins.h
_nop_(); //if Keil,require use intrins.h
}
作者:
wxy2000
时间:
2017-7-20 11:29
看你连接在那个io口上了,假设连接在P1口,让P1口的值依次为11100111,11011011,10111101,01111110就行了
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1