51单片机流水灯用C语言编写的设计程序是什么?

Python031

51单片机流水灯用C语言编写的设计程序是什么?,第1张

#include<reg51.h>

#include<intrins.h>

#define uchar unsigned char

void delay(void)

{

uchar i,j

for(i=0i<150i++)

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

}

main()

{

uchar led,i,j

while(1)

{

for(i=0i<8i++)

{

led=0xfe<<i

for(j=0j<8-ij++)

{

P0=led

led=_crol_(led,1)

delay()

}

}

}

}

#include<stc89.h>

#include<intrins.h>

#define uchar unsigned char

#define uint unsigned int

uchar code table[]={

0x3f,0x06,0x5b,0x4f,

0x66,0x6d,0x7d,0x07,

0x7f,0x6f,0x77,0x7c,

0x39,0x5e,0x79,0x71,

0x00}

uchar led[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,0x00,0xFF}

sbit adrd=P3^7

sbit adwr=P3^6

sbit dula=P2^6

sbit wela=P2^7

uchar date1=0

uchar date2=50

uchar date3=100

uchar date4=150

uchar date5=200

uchar date6=255

uchar a,sz

void init()

void delay(uint z)

uchar adchushihua()

void shumaguan(uint shu)

void processing()

void main()

{

init()

while(1)

{

sz=adchushihua()

for(a=10a>0a--)

{

shumaguan(sz)

processing()

}

}

}

void init()

{

P0=0x7f

}

void delay(uint z)

{

uint x,y

for(x=zx>0x--)

for(y=110y>0y--)

}

uchar adchushihua()

{

uchar shuzhi

adwr=1

_nop_()

adwr=0

_nop_()

adwr=1

P1=0xff

adrd=1

_nop_()

adrd=0

_nop_()

shuzhi=P1

adrd=1

return shuzhi

}

void shumaguan(uint shu)

{

uchar bai,shi,ge

bai=shu/100

shi=shu%100/10

ge=shu%10

dula=1

P0=table[bai]

dula=0

P0=0xff

wela=1

P0=0x7e

wela=0

delay(5)

dula=1

P0=table[shi]

dula=0

P0=0xff

wela=1

P0=0x7d

wela=0

delay(5)

dula=1

P0=table[ge]

dula=0

P0=0xff

wela=1

P0=0x7b

wela=0

delay(5)

}

void processing()

{

if((sz>=date1)&&(sz<=date2))

{

P1=0xfe

}

else if((sz>=date2)&&(sz<=date3))

{

P1=0xfd

}

else if((sz>=date3)&&(sz<=date4))

{

P1=0xfb

}

else if((sz>=date4)&&(sz<=date5))

{

P1=0xf7

}

else if((sz>=date5)&&(sz<date6))

{

P1=0xef

}

else if(sz==date6)

{

P1=~P1

delay(20)

}

}

这个是我刚刚写的 根据你的需要 反正闲来无事 我写的比较笼统 需要你自己根据 自己的实际情况来判断确定 我只是利用AD简单的处理 成数码管显示的数字 你要是 转换成电压 那就把里面的变量 修改一下 我写的那个控制LED灯亮就不要动了 只是修改一下他前面定义的数字就可以 最后那个是我自己加上去的有点趣味性 希望对你有帮助