AT89C51單片機(jī)流水燈c語言程序
2、下面來編寫程序,先來寫入頭函數(shù)
3、根據(jù)自己在proteus畫的圖,定義一下管腳根據(jù)你的原理圖進(jìn)行編寫
sbit p0=P1^0;
sbit p1=P1^1;
sbit p2=P1^2;
sbit p3=P1^3;
sbit p4=P1^4;
sbit p5=P1^5;
sbit p6=P1^6;
sbit p7=P1^7;
4、然后寫一個(gè)延時(shí)函數(shù),來調(diào)節(jié)流水燈的時(shí)間間隔延時(shí)時(shí)間自己定義
void mdelay(unsigned int t)
{
unsigned char n;
for(;t》0;t--)
for(n=0;n《125;n++)
{;}
}
5、下面就是主函數(shù),包括流水燈的反復(fù)循環(huán)和j流水燈的方向
6、檢查沒有錯(cuò)誤,編譯一下。就可以進(jìn)行仿真了
單片機(jī)32位LED花樣流水燈程序及原理圖
原理圖
LED心形排布圖:
程序:
#include《reg52.h》
#define uchar unsigned char
uchar flag=200;
///////////////////////////////////////////////////////////////////////
uchar code Tab1[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,0xFF};
uchar code Tab2[]={0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF};
uchar code Tab3[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00};
uchar code Tab4[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00};
uchar code Tab11[]={0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0xff};
uchar code Tab22[]={0x7F,0x3F,0x1F,0x0F,0x07,0x03,0x01,0x00,0xff};
////////////////////////////////////////////////////////////////////
uchar code Tab33[]={0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xFF};
uchar code Tab44[]={0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF};
uchar code Tab55[]={0x08,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xff};
uchar code Tab5[]={0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xff};
uchar code Tab6[]={0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xff};
uchar code Tab7[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
uchar code Tab8[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
////////////////////////////////////////////////////////////////
void shansuo();
void xl();
///////////////////////////////////////////////////////////////
void delay(void)
{
unsigned char m,n;
for(m=0;m《flag;m++)
for(n=0;n《250;n++)
;
}
///////////////////////////////////
void hy1(void) //點(diǎn)亮狀態(tài)逆時(shí)針旋轉(zhuǎn)90度(一個(gè)一個(gè)滅)
{
unsigned char i;
for(i=0;i《8;i++)
{
P0=Tab11[i];P1=Tab22[i];
P2=Tab11[i];P3=Tab22[i];
delay();
}
for(i=0;i《8;i++)
{
P0=Tab44[i];P1=Tab55[i];
P2=Tab44[i];P3=Tab55[i];
delay();
}
}
///////////////////////////////////////////
void hy2(void) //暗中逆時(shí)針轉(zhuǎn)360。(一個(gè)一個(gè)點(diǎn)亮)
{
unsigned char i;
for(flag=250;flag》0;flag=flag-50)
{
P0=0xff;P1=0xff;P2=0xff;P3=0xff;
for(i=0;i《8;i++)
{
P0=Tab11[i];
delay();
}
for(i=0;i《8;i++)
{
P2=Tab11[i];
delay();
}
for(i=0;i《8;i++)
{
P3=Tab22[i];
delay();
}
for(i=0;i《8;i++)
{
P1=Tab22[i];
delay();
}
}
flag=250;
}
評(píng)論
查看更多