用Keil uVision4写出51单片机8x8点阵屏循环显示0~9
时间: 2024-06-08 18:07:28 浏览: 124
下面是使用Keil uVision4编写的51单片机程序,实现8x8点阵屏循环显示0~9:
```c
#include <reg52.h>
// 定义8x8点阵屏的端口连接
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
sbit LED=P2^7;
// 8x8点阵屏显示字符数组
unsigned char code Display[10][8]={
{0x3c,0x42,0x42,0x42,0x42,0x42,0x42,0x3c}, // 0
{0x10,0x18,0x14,0x12,0x7f,0x10,0x10,0x10}, // 1
{0x1c,0x22,0x22,0x22,0x22,0x22,0x22,0x22}, // 2
{0x18,0x24,0x24,0x24,0x24,0x24,0x24,0x18}, // 3
{0x08,0x08,0x7e,0x88,0x88,0x88,0x08,0x08}, // 4
{0x3c,0x42,0x42,0x42,0x42,0x42,0x42,0x24}, // 5
{0x3c,0x42,0x42,0x42,0x42,0x42,0x24,0x18}, // 6
{0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x7c}, // 7
{0x18,0x24,0x24,0x24,0x24,0x24,0x24,0x18}, // 8
{0x10,0x20,0x20,0x20,0x20,0x20,0x20,0x1c} // 9
};
// 延时函数
void Delay(unsigned int i){
while(i--);
}
// 8x8点阵屏显示函数
void Display8x8(unsigned char *p){
unsigned char i;
for(i=0;i<8;i++){
P0=*p++;
LSA=0;
LSA=1;
Delay(100);
}
}
// 主函数
void main(){
unsigned char i,j;
LED=0; // 打开LED灯
while(1){
for(i=0;i<10;i++){ // 循环显示0~9
for(j=0;j<100;j++){ // 每个数字显示100次
Display8x8(&Display[i][0]);
}
}
}
}
```
程序中使用了一个Display数组,存储了0~9的8x8点阵显示字符。在主函数中使用双重循环,先循环显示0~9,再在每个数字内部循环显示100次,达到循环显示的效果。在Display8x8函数中,使用LSA、LSB、LSC三个端口分别控制8x8点阵屏的行和列,使得每个字符都能够正确地显示出来。
阅读全文