用Keil uVision4写出51单片机点阵屏循环显示0~9
时间: 2024-05-13 17:19:48 浏览: 21
下面是使用Keil uVision4编写的51单片机点阵屏循环显示0~9的程序:
```
#include<reg52.h>
// 定义数码管显示的数字0~9的编码
unsigned char code table[]={
0x3f, 0x06, 0x5b, 0x4f, 0x66,
0x6d, 0x7d, 0x07, 0x7f, 0x6f
};
void delay(unsigned int i)
{
while(i--);
}
void main()
{
unsigned char i = 0;
while(1)
{
// 显示数字0~9
P0 = table[i++];
delay(50000); // 延时,调整速度
if(i >= 10) // 当i大于9时,重新从0开始循环
i = 0;
}
}
```
该程序使用了一个数组`table`来存储数码管显示的数字0~9的编码,然后在`main`函数中使用一个循环不断地显示数字0~9,每次循环都会通过`P0`口将对应数字的编码输出到点阵屏上,并进行一定的延时,以控制显示速度。当显示完数字9后,`i`会被重新赋值为0,从而重新开始循环。
相关问题
用Keil uVision4写出51单片机8x8点阵屏循环显示0~9
下面是使用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点阵屏的行和列,使得每个字符都能够正确地显示出来。
用Keil uVision5写51单片机的代码
下面是使用 Keil uVision5 写 51 单片机代码的基本步骤:
1. 打开 Keil uVision5 软件,选择 "Create a new µVision Project",并设置好项目的名称和存放路径。
2. 在 "Project" 菜单下选择 "Options for Target",打开目标选项卡。在 "Device" 中选择你要使用的 51 单片机型号,然后点击 "OK"。
3. 在 "Project" 菜单下选择 "New µVision File",添加你的 C 语言源代码文件。
4. 编写你的 C 语言源代码,并保存文件。
5. 在 "Project" 菜单下选择 "Build Target",编译你的代码。
6. 如果编译成功,就可以使用 "Debug" 功能来测试你的代码了。
7. 在 "Debug" 菜单下选择 "Start/Stop Debug Session",打开调试会话。
8. 在调试会话窗口中设置断点,然后点击 "Start" 开始调试。
9. 测试你的代码。
以上就是使用 Keil uVision5 写 51 单片机代码的基本步骤。需要注意的是,不同的单片机型号可能需要不同的编译器和调试器,具体操作步骤可能会有所不同。建议在使用前仔细阅读单片机的开发文档和 Keil uVision5 的使用手册。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)