写单片机AT89C52关于点阵显示16*64的keil程序
时间: 2023-11-27 10:54:34 浏览: 108
以下是一个基本的AT89C52点阵显示16*64的Keil程序,其中使用了74HC138译码器来控制行选择,74HC595移位寄存器来控制列数据:
```
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit RCLK = P1^0; // 74HC595 RCLK引脚
sbit SRCLK = P1^1; // 74HC595 SRCLK引脚
sbit SER = P1^2; // 74HC595 SER引脚
sbit OE = P2^5; // 输出使能引脚
sbit RS = P2^6; // 74HC138 RS0引脚
sbit RW = P2^7; // 74HC138 RW0引脚
sbit EN = P3^5; // 74HC138 EN引脚
uchar code table[]={ // 16*64点阵的显示数据
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
void delay(uint x) // 延时函数
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void write595(uchar dat) // 写入74HC595移位寄存器
{
uchar i;
for(i=0;i<8;i++)
{
SRCLK = 0;
SER = dat & 0x80;
dat <<= 1;
SRCLK = 1;
}
RCLK = 0;
RCLK = 1;
}
void init138() // 初始化74HC138译码器
{
RS = 0;
RW = 0;
EN = 0;
}
void main()
{
uchar i,j,k;
OE = 0; // 输出使能
while(1)
{
for(i=0;i<64;i++) // 64列
{
init138(); // 初始化译码器
write595(0); // 清零数据
write595(0);
write595(0);
write595(0);
RS = i & 0x03; // 行选择
RW = (i >> 2) & 0x03;
EN = (i >> 4) & 0x03;
for(j=0;j<16;j++) // 16行
{
k = table[i*16+j]; // 获取点阵数据
write595(~k); // 取反输出
}
delay(10); // 延时控制刷新速度
}
}
}
```
需要注意的是,这只是一个基本的程序,具体的实现方式可能会因为不同的点阵屏幕型号而有所不同。因此,在编写程序之前,需要详细阅读点阵屏幕的数据手册,并根据手册中的数据格式和控制方式来编写程序。同时,还需要根据具体情况选择合适的外部电路和器件来实现程序。
阅读全文