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) 請用戶再思考一下,如何實現字體的反白顯示。
評論
查看更多