高分:89C51单片机流水灯程序求步骤详解,看懂了就给分

高分:89C51单片机流水灯程序求步骤详解,看懂了就给分,第1张

uchar

code

display_P0[]={

0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,//P0口由低位高位依次亮灯(前一位的灯灭)

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,//P0口灯全灭

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,,//P0口灯全灭

0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF,//P0口由高位向低位依次亮灯(前一位的灯灭),最后全灭

0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00,//P0口由低位向高位依次亮灯(前一位的灯b不灭)

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

//P0口灯全亮

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//P0口灯全亮

0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,

//P0口灯由高位向低位依次灭(前一位不亮),最后仅剩最低位亮灯。

0xFC,0xF9,0xF3,0xE7,0xCF,0x9F,0x3F,0x7F,//P0口以两个亮灯为单位,由低位向高位逐位移动,最后移至最高位,仅剩最高位亮灯。

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

//P0口全灭

0xE7,0xDB,0xBD,0x7E,0xBD,0xDB,0xE7,0xFF,//P0口中间两位亮灯,然后两个亮灯分别向两端移动,当分别移至最高位和最低位时,再按原方法返回,返回至起始状态后全灭。

0xE7,0xC3,0x81,0x00,0x81,0xC3,0xE7,0xFF,//P0口中间两位亮灯,然后两个亮灯分别向两端扩散,当分别扩散至次高位和次低位时,再按原方法恢复,返回至起始状态后全灭。

0xAA,0x55,0x18,0xFF,0xF0,0x0F,0x00,0xFF,//差位两灭,先是最高位亮,然后最高位灭;再变成中间两位灭,其余的全亮;全灭→低四位亮→高四位亮→全灭。

0xFF,0x00,0x00,0xFF,0xFF

}//全灭→全亮→全亮→全灭→全灭

uchar

code

display_P2[]={

//P2口可参照P0口流水灯情况。基本相同。

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,

0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00,

//

0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

//

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,

0xFC,0xF9,0xF3,0xE7,0xCF,0x9F,0x3F,0xFF,

//

0xE7,0xDB,0xBD,0x7E,0xBD,0xDB,0xE7,0xFF,

0xE7,0xC3,0x81,0x00,0x81,0xC3,0xE7,0xFF,

0xAA,0x55,0x18,0xFF,0xF0,0x0F,0x00,0xFF,

0xFF,0x00,0x00,0xFF,0xFF

}

#include<reg52.h>//头文件

sbit duan=P1^6//定义数码管的段选使能控制端

sbit wei=P1^7//定义数码管的位选使能控制端

unsigned char led_code[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}//定义数组

void Delay_ms(unsigned int x)//子函数声明

void Delay_ms(unsigned int x)

{

unsigned int i,j

for(i=0i<xi++)

for(j=0j<114j++)

}

void main()

{

duan=0//关闭数码管的段选信号

wei=0//关闭数码管的位选信号

P=0xff//将所有LED熄灭

while(1) //一般来讲,一个主函数里一般都要包含一个死循环来防止程序跑飞。

{

int i

if(i<9)

{

P0=led_code[i]//将数组中的值依次赋给P0

Delay_ms(50)//延时500ms

i++//i自?

}

else

i=0//如果>9将i清零,使之循环

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11238607.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存