补全代码#include"reg51.h" #define uint unsigned int #define uchar unsigned char const tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f, 0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff, 0xaa,0x55,0xaa,0x55,0xaa,0x55,0xff, 0xf0,0x0f,0xf0,0x0f,0xff, 0x33,0xcc,0x33,0xcc,0x33,0xcc,0xff}; void delay(void) { uint i,j,k; for(i=10;i>0;i--) { for(j=200;j>0;j--) { for(k=230;k>0;k--);}} }使依次4/5灯亮;3/6灯亮;2/7灯亮;1/8灯亮,循环反复
时间: 2023-09-28 22:12:13 浏览: 69
eeprom.rar_EEPROM int_Unsigned_intrins.h_site:www.pudn.com_换头文件e
#include"reg51.h"
#define uint unsigned int
#define uchar unsigned char
const uchar tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff,
0xaa,0x55,0xaa,0x55,0xaa,0x55,0xff,
0xf0,0x0f,0xf0,0x0f,0xff,
0x33,0xcc,0x33,0xcc,0x33,0xcc,0xff};
void delay(void)
{
uint i,j,k;
for(i=10;i>0;i--)
{
for(j=200;j>0;j--)
{
for(k=230;k>0;k--);
}
}
}
void main()
{
uchar i;
while(1)
{
for(i=0;i<4;i++)
{
P1=tab[i];
delay();
}
for(i=4;i<8;i++)
{
P1=tab[i];
delay();
}
}
}
这段代码可以实现依次4/5灯亮;3/6灯亮;2/7灯亮;1/8灯亮,循环反复的功能。其中,使用了一个常量数组tab来存储LED灯的亮灭状态,通过控制P1口的输出来操作LED灯的状态。在每次循环中,先循环输出tab数组中前4个元素(即4/5/6/7灯亮),再循环输出tab数组中后4个元素(即3/2/1/8灯亮),然后不断循环执行该过程。通过delay函数来实现延时,从而达到控制LED灯闪烁的效果。
阅读全文