单片机案例
结合proteus和keil
变化多样的流水灯
原理图
程序
#include<reg52.h>
#define INT8U unsigned char
#define INT16U unsigned int
code INT16U array[]=
{
0xFCFF,0xF9FF,0xF3FF,0xE7FF,0xCFFF,0x9FFF,0x3FFF,0x7FFE,0xFFFC,
0xFFF9,0xFFF3,0xFFE7,0xFFCF,0xFF9F,0xFF3F,0xFFFF,0xE7E7,0xDBDB,
0xBDBD,0x7E7E,0xBDBD,0xDBDB,0xE7E7,0xFFFF,0xE7E7,0xC3C3,0x8181,
0x0000,0x8181,0xC3C3,0xE7E7,0xFFFF,0xAAAA,0x5555,0x1818,0xFFFF,
0xF0F0,0x0F0F,0x0000,0xFFFF,0xF8F8,0xF1F1,0xE3E3,0xC7C7,0x8F8F,
0x1F1F,0x3F3F,0x7F7F,0x7F7F,0x3F3F,0x1F1F,0x8F8F,0xC7C7,0xE3E3,
0xF1F1,0xF8F8,0xFFFF,0x0000,0x0000,0xFFFF,0xFFFF,0x0F0F,0xF0F0,
0xFEFF,0xFDFF,0xFBFF,0xE7FF,0xEFFF,0xDFFF,0xBFFF,0x7FFF,0xFFFE,
0xFFFD,0xFFFB,0xFFF7,0xFFEF,0xFFDF,0xFFBF,0xFF7F,0xFF7F,0xFFBF,
0xFFDF,0xFFEF,0xFFF7,0xFFFB,0xFFFD,0xFFFE,0x7FFF,0xBFFF,0xDFFF,
0xEFFF,0xF7FF,0xFBFF,0xFDFF,0xFEFF,0xFEFF,0xFCFF,0xF8FF,0xF0FF,
0xE0FF,0xC0FF,0x80FF,0x00FF,0x00FE,0x00FC,0x00F8,0x00F0,0x00E0,
0x00C0,0x0080,0x0000,0x0000,0x0080,0x00C0,0x00E0,0x00F0,0x00F8,
0x00FC,0x00FE,0x00FF,0x80FF,0xC0FF,0xE0FF,0xF0FF,0xF8FF,0xFCFF,
0xFEFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF,0x0000,0xFFFF
};
void delay_ms(INT16U x)
{
INT8U t;
while(x--)
{
for(t=0;t<120;t++);
}
}
void main()
{
INT8U i;
while(1)
{
for(i=0;i<136;i++)
{
P0=array[i]>>8;
P2=array[i];
delay_ms(60);
}
}
}
|