设计花样流水灯,通过点亮组合发光二极管,显示十六个灯不同的花样,设置有开始、停止按键,并且可以通过相关按键来控制各花样运行的速度。在加速和减速按键上花了较多时间,看起来简单的东西自己写出来越困难。还有很多可以改进的地方。
#include<reg51.h>
#include<intrins.h>
unsigned char led_P0[]={
0X01,0X02,0X04,0X08,0X10,0X20,0X40,0X80};
unsigned char led_P2[]={
0X01,0X02,0X04,0X08,0X10,0X20,0X40,0X80};
unsigned char led_P3[]={
0X80,0X40,0X20,0X10,0X08,0X04,0X02,0X01};
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P1_4=P1^4;
sbit P1_5=P1^5;
sbit P1_6=P1^6;
sbit P3_6=P3^6;
sbit P3_7=P3^7;
char i,k,t,zanting, moshi1, moshi2, moshi3, moshi4, moshi5, moshi6,jiasu,jiansu;
int a ,ms ;
void delay(unsigned int z)
{
unsigned int x,y;
for(x = z; x > 0; x--)
for(y = 114; y > 0 ; y--);
}