基于51单片机的POV旋转LED屏设计所用到的C语言程序
时间: 2023-09-03 14:09:51 浏览: 64
以下是基于51单片机的POV旋转LED屏设计的C语言程序示例:
```c
#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit D1=P2^0;
sbit D2=P2^1;
sbit D3=P2^2;
sbit D4=P2^3;
sbit D5=P2^4;
sbit D6=P2^5;
sbit D7=P2^6;
sbit D8=P2^7;
uchar code LedChar[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //数码管编码数组
void delay(uint xms); //延时函数
void main()
{
uchar i,j,k;
P2=0xff;
while(1)
{
for(i=0;i<8;i++)
{
D1=LedChar[i]&0x01;
D2=LedChar[i]&0x02;
D3=LedChar[i]&0x04;
D4=LedChar[i]&0x08;
D5=LedChar[i]&0x10;
D6=LedChar[i]&0x20;
D7=LedChar[i]&0x40;
D8=LedChar[i]&0x80;
delay(1); //控制转速
}
}
}
void delay(uint xms) //延时函数
{
uint i,j;
for(i=xms;i>0;i--)
{
for(j=110;j>0;j--);
}
}
```
这个程序可以使LED屏幕上的数字以POV(Persistence of Vision)的方式旋转显示出来。其中,LedChar数组存储了数码管的编码,通过控制P2口的8个引脚分别控制LED屏幕上8个LED的亮灭。delay函数用于控制LED屏幕的转速。