关于八个灯的循环显示0到9的问题
时间:10-02
整理:3721RD
点击:
各位大神,我是一个单片机菜鸟,老师刚刚讲完例题,想把例题改一改,让八个灯从左到右然后再从右到左循环显示0—9十个数!问题是我直接写了14个灯的位码,而不是用右移或者左移函数来解决的,这样显得很复杂,但是不知道如何去改正!另外,我们的灯一直是全亮,假如说我想要他从左到右逐渐变亮,然后再从右到左逐渐变暗怎么办?菜鸟求教,不胜感激,谢谢!
#include <REGX51.H>
#define LED_SELECT P2
#define LED_DATA P0
void Delay(unsigned int t);
//-------------------------------------
//主函数
//-------------------------------------
main(void)
{
unsigned char i,count=0;
unsigned char code DATA[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//段码
unsigned char code LED_SELECT_MAP[] = //位码
{
0xef, 0xdf, 0xbf, 0x7f, 0xfe, 0xfd, 0xfb, 0xf7,0xfb, 0xfd, 0xfe, 0x7f ,0xbf, 0xdf
};
while(1)
{
for(i = 0; i < 14; i++)
{
LED_SELECT = LED_SELECT_MAP;//灯的选择
LED_DATA=DATA[count];//数字选择
count++;
if(count>9)
count=0;
Delay(15000);
}
}
}
//-------------------------------------
//延时
//-------------------------------------
void Delay(unsigned int t)
{
for (t; t>0; t--) ;
}
#include <REGX51.H>
#define LED_SELECT P2
#define LED_DATA P0
void Delay(unsigned int t);
//-------------------------------------
//主函数
//-------------------------------------
main(void)
{
unsigned char i,count=0;
unsigned char code DATA[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//段码
unsigned char code LED_SELECT_MAP[] = //位码
{
0xef, 0xdf, 0xbf, 0x7f, 0xfe, 0xfd, 0xfb, 0xf7,0xfb, 0xfd, 0xfe, 0x7f ,0xbf, 0xdf
};
while(1)
{
for(i = 0; i < 14; i++)
{
LED_SELECT = LED_SELECT_MAP;//灯的选择
LED_DATA=DATA[count];//数字选择
count++;
if(count>9)
count=0;
Delay(15000);
}
}
}
//-------------------------------------
//延时
//-------------------------------------
void Delay(unsigned int t)
{
for (t; t>0; t--) ;
}
到底是灯还是数码管,有几位管子,没时间来猜测,上个图吧,这个不难
呵呵,不好意思,是数码管,一共有八个!刚刚接触,不是很懂,求指导!谢谢
LED_SELECT = LED_SELECT_MAP;//灯的选择
此句改为:
LED_SELECT = LED_SELECT_MAP[i];