16×16LED扫描输出实验
一. 实验目的
使用户学会利用单片机的IO 口进行LED 点阵的扫描显示。
二. 实验设备及器件
IBM PC 机 一台
DP-51PROC 单片机综合仿真实验仪 一台
三. 实验内容
编写一段程序,用P1 口控制C3 区4 片74HC164 进行行列扫描,使C3 区的16×
16 LED 点阵显示用户指定的汉字。
四. 实验要求
学会使用单片机对LED 点阵进行扫描显示。
五. 实验步骤
1. 使用导线将A2 区的P10~P14 与C3 区的L_DAT_H、L_DAT_L、L_CLK、L_OE、
L_STR 依次连接。
2. 运行光盘中的程序,显示“感谢您使用DP-51PROC 单片机综合仿真实验仪!”,
先是向左滚动,后是向上滚动
3. 如果用户希望改变显示的汉字, 可以使用光盘中附带的字模提取软件
(Pctolcd2002)提取用户希望显示汉字的字模,字模提取软件的设置为阴码、逐列
式、逆向、十六进制、C51 格式自定义,将生成的字模拷贝到程序中所指定的位置
插入即可。
六. 实验预习要求
阅读本书的2.8.19 节内容,理解硬件结构,还可以先把程序编好,然后在Keil C51
环境下进行软件仿真。
七. 实验参考程序
#include
typedef unsigned char byte;
typedef unsigned int word;
sbit datah595=P1^0;
sbit datal595=P1^1;
sbit clk595=P1^2;
sbit oe595=P1^3;
sbit str595=P1^4;
word data datah,datal;
byte code displaydata[]=
{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,0x04,0x00,0x43,0xFC,0x70,0x14,0x00,0xD4,0x39,0x54,0x41,
0x54,0x41,0xD4,0x49,
0x04,0x50,0x3F,0x42,0xC4,0x41,0x45,0x61,0x36,0x0A,0x04,0x34,
0x00,0x27,0x00,0x00,/*"感",0*/
0x40,0x00,0x42,0x00,0xCC,0x3F,0x04,0x50,0x00,0x29,0xFC,0x11,
0x56,0x4D,0x55,0x83,
0xFC,0x7F,0x50,0x00,0x90,0x41,0x10,0x80,0xFF,0x7F,0x10,0x00,
0x10,0x00,0x00,0x00,/*"谢",1*/
0x80,0x00,0x40,0x20,0x30,0x38,0xFC,0x03,0x03,0x38,0x90,0x40,
0x68,0x40,0x06,0x49,
0x04,0x52,0xF4,0x41,0x04,0x40,0x24,0x70,0x44,0x00,0x8C,0x09,
0x04,0x30,0x00,0x00,/*"您",2*/
0x40,0x00,0x20,0x00,0xF0,0x7F,0x1C,0x00,0x07,0x40,0xF2,0x41,
0x94,0x22,0x94,0x14,
0x94,0x0C,0xFF,0x13,0x94,0x10,0x94,0x30,0x94,0x20,0xF4,0x61,
0x04,0x20,0x00,0x00,/*"使",3*/
0x00,0x80,0x00,0x40,0x00,0x30,0xFE,0x0F,0x22,0x02,0x22,0x02,
0x22,0x02,0x22,0x02,
0xFE,0xFF,0x22,0x02,0x22,0x02,0x22,0x42,0x22,0x82,0xFE,0x7F,
0x00,0x00,0x00,0x00,/*"用",4*/
0x08,0x20,0xF8,0x3F,0x08,0x20,0x08,0x20,0x08,0x20,0x10,0x10,
0xE0,0x0F,0x00,0x00,/*"D"*/
0x08,0x20,0xF8,0x3F,0x08,0x21,0x08,0x01,0x08,0x01,0x08,0x01,
0xF0,0x00,0x00,0x00,/*"P", 5*/
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,
0x80,0x00,0x80,0x00,
0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,/*"-",6*/
0x00,0x00,0xF8,0x19,0x08,0x21,0x88,0x20,0x88,0x20,0x08,0x11,
0x08,0x0E,0x00,0x00,/*"5"*/
0x00,0x00,0x10,0x20,0x10,0x20,0xF8,0x3F,0x00,0x20,0x00,0x20,
0x00,0x00,0x00,0x00,/*"1", 7*/
0x08,0x20,0xF8,0x3F,0x08,0x21,0x08,0x01,0x08,0x01,0x08,0x01,
0xF0,0x00,0x00,0x00,/*"P"*/
0x08,0x20,0xF8,0x3F,0x88,0x20,0x88,0x00,0x88,0x03,0x88,0x0C,
0x70,0x30,0x00,0x20,/*"R", 8*/
0xE0,0x0F,0x10,0x10,0x08,0x20,0x08,0x20,0x08,0x20,0x10,0x10,
0xE0,0x0F,0x00,0x00,/*"O"*/
0xC0,0x07,0x30,0x18,0x08,0x20,0x08,0x20,0x08,0x20,0x08,0x10,
0x38,0x08,0x00,0x00,/*"C", 9*/
0x00,0x08,0x00,0x08,0xF8,0x0B,0x28,0x09,0x29,0x09,0x2E,0x09,
0x2A,0x09,0xF8,0xFF,
0x28,0x09,0x2C,0x09,0x2B,0x09,0x2A,0x09,0xF8,0x0B,0x00,0x08,
0x00,0x08,0x00,0x00,/*"单",10*/
0x00,0x80,0x00,0x40,0x00,0x30,0xFE,0x0F,0x10,0x01,0x10,0x01,
0x10,0x01,0x10,0x01,
0x10,0x01,0x1F,0x01,0x10,0x01,0x10,0xFF,0x10,0x00,0x18,0x00,
0x10,0x00,0x00,0x00,/*"片",11*/
0x08,0x04,0x08,0x03,0xC8,0x00,0xFF,0xFF,0x48,0x00,0x88,0x41,
0x08,0x30,0x00,0x0C,
0xFE,0x03,0x02,0x00,0x02,0x00,0x02,0x00,0xFE,0x3F,0x00,0x40,
0x00,0x78,0x00,0x00,/*"机",12*/
0x20,0x22,0x30,0x23,0xA8,0x22,0x67,0x12,0x32,0x12,0x00,0x20,
0x0C,0x11,0x24,0x0D,
0x24,0x41,0x25,0x81,0x26,0x7F,0x24,0x01,0x24,0x05,0x24,0x09,
0x0C,0x31,0x00,0x00,/*"综",13*/
0x40,0x00,0x40,0x00,0x20,0x00,0x50,0x7E,0x48,0x22,0x44,0x22,
0x42,0x22,0x41,0x22,
0x42,0x22,0x44,0x22,0x68,0x22,0x50,0x7E,0x30,0x00,0x60,0x00,
0x20,0x00,0x00,0x00,/*"合",14*/
0x40,0x00,0x20,0x00,0x10,0x00,0xEC,0x7F,0x07,0x40,0x0A,0x20,
0x08,0x18,0x08,0x06,
0xF9,0x01,0x8A,0x10,0x8E,0x20,0x88,0x40,0x88,0x20,0xCC,0x1F,
0x88,0x00,0x00,0x00,/*"仿",15*/
0x00,0x10,0x04,0x90,0x04,0x90,0x04,0x50,0xF4,0x5F,0x54,0x35,
0x5C,0x15,0x57,0x15,
0x54,0x15,0x54,0x35,0x54,0x55,0xF4,0x5F,0x04,0x90,0x06,0x90,
0x04,0x10,0x00,0x00,/*"真",16*/
0x00,0x00,0x10,0x82,0x0C,0x82,0x04,0x42,0x4C,0x42,0xB4,0x23,
0x94,0x12,0x05,0x0A,
0xF6,0x07,0x04,0x0A,0x04,0x12,0x04,0xE2,0x14,0x42,0x0C,0x02,
0x04,0x02,0x00,0x00,/*"实",17*/
0x02,0x08,0xFA,0x08,0x82,0x04,0x82,0x24,0xFE,0x40,0x80,0x3F,
0x40,0x22,0x60,0x2C,
0x58,0x21,0x46,0x2E,0x48,0x20,0x50,0x30,0x20,0x2C,0x20,0x23,
0x20,0x20,0x00,0x00,/*"验",18*/
0x40,0x00,0x20,0x00,0xF0,0xFF,0x0C,0x00,0x03,0x40,0x00,0x40,
0x38,0x20,0xC0,0x10,
0x01,0x0B,0x0E,0x04,0x04,0x0B,0xE0,0x10,0x1C,0x20,0x00,0x60,
0x00,0x20,0x00,0x00,/*"仪",19*/
0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x5F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,/*"!",20*/
//至此字模插入结束
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
};
byte *p=&displaydata[0];
byte *q=&displaydata[32];
void delay(word a)
{
word b;
for(b=0;b}
void senddata(word datah,datal)
{
byte i=0;
word m,n;
oe595=0;
str595=0;
for(;i<16;i++)
{
clk595=0;
m=datah;
n=~datal;
m&=0x8000;
n&=0x8000;
datah595=(bit)m;
datal595=(bit)n;
datah<<=1;
datal<<=1;
clk595=1;
}
str595=1;
str595=0;
}
void horizontal(byte time,word counth) //水平移动子程序
{
byte x,y;
word j,k,z;
for(z=0;z
for(y=0;y
}
void vertical(byte a,time,word countv) //垂直移动子程序
{
byte x,y,e,w=0;
word j,k,z;
word datah1,datah2;
for(z=countv;z>0;z--)
{
for(e=0;e<16;e++)
{
for(y=0;y
w++;
if(w==16) w=0;
}
if((a==16)&&(z==2))
{ p+=32;q+=16; }
else
{ p+=32;q+=32; }
}
p=&displaydata[0];
q=&displaydata[32];
oe595=1;
}
void main(void)
{
byte time=8;
word size=sizeof(displaydata);
word countv=((size-2)>>5)-1;
word counth=countv<<4;
byte a=(byte)((size-2)%32);
if(a==16)
{
counth+=8;
countv+=1;
}
while(1)
{
horizontal(time,counth);
delay(65535);
delay(65535);
vertical(a,time,countv);
delay(65535);
delay(65535);
}
}
八. 实验思考题
(1) 请用户思考一下,如何改变字体滚动的速度。
(2) 请用户再思考一下,如何实现字体的反白显示。
评论
查看更多