利用Keil uVision4编程程序,在Proteus 8 Professional中创建仿真电路
仿真电路
16进制样式花型
int a[][8] = { 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x03,0x06,0x0c,0x18,0x30,0x60,0xc0,0x80,
0x07,0x0e,0x1c,0x38,0x70,0xe0,0xc0,0x80,
0x0f,0x1e,0x3c,0x78,0xf0,0xe0,0xc0,0x80,
0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0x7f,
};
延迟函数
void delay(unsigned int x)
{
while(x--);
}
循环调用函数
led1() 是指操作P0端口,
以此类推,led4() 是调用四个输出端口,循环闪烁
void led1(int j,int i)
{
while(1)
{
P0 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = 0x00;
break;
}
}
while(1)
{
P2 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P2 = 0x00;
break;
}
}
while(1)
{
P3 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P3 = 0x00;
break;
}
}
while(1)
{
P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P1 = 0x00;
break;
}
}
}
void led3(int j,int i)
{
while(1)
{
P0 = P2 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P2 = 0x00;
break;
}
}
while(1)
{
P2 = P3 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P2 = P3 = 0x00;
break;
}
}
while(1)
{
P3 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P3 = P1 = 0x00;
break;
}
}
while(1)
{
P1 = P0 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P1 = P0 = 0x00;
break;
}
}
}
void led2(int j,int i)
{
while(1)
{
P0 = P3 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P3 = 0x00;
break;
}
}
while(1)
{
P2 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P2 = P1 = 0x00;
break;
}
}
while(1)
{
P3 = P0 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P3 = P0 = 0x00;
break;
}
}
while(1)
{
P1 = P2 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P1 = P2 = 0x00;
break;
}
}
}
void led4(int j,int i)
{
while(1)
{
P0 = P2 = P3 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P2 = P3 = P1 = 0x00;
break;
}
}
while(1)
{
P0 = P2 = P3 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P2 = P3 = P1 = 0x00;
break;
}
} while(1)
{
P0 = P2 = P3 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P2 = P3 = P1 = 0x00;
break;
}
} while(1)
{
P0 = P2 = P3 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P2 = P3 = P1 = 0x00;
break;
}
}
}
C语言代码
#include<reg51.h>
int a[][8] = { 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x03,0x06,0x0c,0x18,0x30,0x60,0xc0,0x80,
0x07,0x0e,0x1c,0x38,0x70,0xe0,0xc0,0x80,
0x0f,0x1e,0x3c,0x78,0xf0,0xe0,0xc0,0x80,
0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f,0x7f,
};
int m = 5000;
void delay(unsigned int x)
{
while(x--);
}
void led1(int j,int i)
{
while(1)
{
P0 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = 0x00;
break;
}
}
while(1)
{
P2 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P2 = 0x00;
break;
}
}
while(1)
{
P3 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P3 = 0x00;
break;
}
}
while(1)
{
P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P1 = 0x00;
break;
}
}
}
void led3(int j,int i)
{
while(1)
{
P0 = P2 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P2 = 0x00;
break;
}
}
while(1)
{
P2 = P3 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P2 = P3 = 0x00;
break;
}
}
while(1)
{
P3 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P3 = P1 = 0x00;
break;
}
}
while(1)
{
P1 = P0 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P1 = P0 = 0x00;
break;
}
}
}
void led2(int j,int i)
{
while(1)
{
P0 = P3 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P3 = 0x00;
break;
}
}
while(1)
{
P2 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P2 = P1 = 0x00;
break;
}
}
while(1)
{
P3 = P0 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P3 = P0 = 0x00;
break;
}
}
while(1)
{
P1 = P2 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P1 = P2 = 0x00;
break;
}
}
}
void led4(int j,int i)
{
while(1)
{
P0 = P2 = P3 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P2 = P3 = P1 = 0x00;
break;
}
}
while(1)
{
P0 = P2 = P3 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P2 = P3 = P1 = 0x00;
break;
}
} while(1)
{
P0 = P2 = P3 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P2 = P3 = P1 = 0x00;
break;
}
} while(1)
{
P0 = P2 = P3 = P1 = a[j][i];
delay(m);
i++;
if(i >= 8)
{
i = 0;
P0 = P2 = P3 = P1 = 0x00;
break;
}
}
}
void main(void)
{
int i = 0;
while(1){
int j = 0;
P0 = 0x00;
P2 = 0x00;
P1 = 0x00;
P3 = 0x00;
while(j <= 4)
{
led1(j,i);
j++;
}
j=0;
while(j <= 4)
{
led2(j,i);
j++;
}
j=0;
while(j <= 4)
{
led3(j,i);
j++;
}
j=0;
while(j <= 4)
{
led4(j,i);
j++;
}
j=0;
}
}
仿真电路和代码
链接:https://pan.baidu.com/s/1vx33QiXO0uhXMq1ItUebNQ 文章来源:https://www.toymoban.com/news/detail-731484.html
提取码:5151文章来源地址https://www.toymoban.com/news/detail-731484.html
到了这里,关于C51单片机开发心形灯流水灯(C语言)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!