普中51单片机开发板8*8点阵滚动显示汉字代码
时间: 2023-07-30 13:06:28 浏览: 211
课程设计51单片机+74HC138+16×16点阵组成的汉字滚动显示电路原理图+源代码+proteus仿真+word文档
以下是基于Keil C51集成开发环境的普中51单片机开发板8*8点阵滚动显示汉字的代码示例:
```
#include <reg51.h>
// 汉字点阵信息数组
unsigned char code Hanzi[] = {0x00, 0x00, 0x7C, 0x44, 0x7C, 0x00, 0x00, 0x00};
// 定义8*8点阵的引脚
sbit LED_ROW_1 = P2^0;
sbit LED_ROW_2 = P2^1;
sbit LED_ROW_3 = P2^2;
sbit LED_ROW_4 = P2^3;
sbit LED_ROW_5 = P2^4;
sbit LED_ROW_6 = P2^5;
sbit LED_ROW_7 = P2^6;
sbit LED_ROW_8 = P2^7;
sbit LED_COL_1 = P1^0;
sbit LED_COL_2 = P1^1;
sbit LED_COL_3 = P1^2;
sbit LED_COL_4 = P1^3;
sbit LED_COL_5 = P1^4;
sbit LED_COL_6 = P1^5;
sbit LED_COL_7 = P1^6;
sbit LED_COL_8 = P1^7;
// 定义滚动显示的位置和速度
unsigned char x = 0;
unsigned char speed = 100;
// 定义定时器中断服务函数
void timer0_isr() interrupt 1
{
// 将点阵信息向左移动一列
Hanzi[0] <<= 1;
Hanzi[1] <<= 1;
Hanzi[2] <<= 1;
Hanzi[3] <<= 1;
Hanzi[4] <<= 1;
Hanzi[5] <<= 1;
Hanzi[6] <<= 1;
Hanzi[7] <<= 1;
// 如果已经滚动到最后一列,重新从第一列开始
if(x == 8) x = 0;
// 将点阵信息显示在8*8点阵上
LED_ROW_1 = Hanzi[0] & 0x80;
LED_ROW_2 = Hanzi[1] & 0x80;
LED_ROW_3 = Hanzi[2] & 0x80;
LED_ROW_4 = Hanzi[3] & 0x80;
LED_ROW_5 = Hanzi[4] & 0x80;
LED_ROW_6 = Hanzi[5] & 0x80;
LED_ROW_7 = Hanzi[6] & 0x80;
LED_ROW_8 = Hanzi[7] & 0x80;
LED_COL_1 = ~(1 << x);
LED_COL_2 = ~(1 << x);
LED_COL_3 = ~(1 << x);
LED_COL_4 = ~(1 << x);
LED_COL_5 = ~(1 << x);
LED_COL_6 = ~(1 << x);
LED_COL_7 = ~(1 << x);
LED_COL_8 = ~(1 << x);
x++;
}
// 主函数
void main()
{
// 设置定时器0的工作方式和频率
TMOD |= 0x01;
TH0 = (65536 - speed) / 256;
TL0 = (65536 - speed) % 256;
// 启动定时器0
TR0 = 1;
// 开启定时器0的中断功能
ET0 = 1;
EA = 1;
// 循环等待中断发生
while(1);
}
```
请注意,这只是一个简单的代码示例,具体的实现还需要根据开发板和点阵的接口及使用说明进行调整和修改。
阅读全文