使用四块8×8的点阵拼成16×16的点阵,用了两个译码器,只设置了三个字(改字可以用字模转换器)按键控制左移、右移、暂停、启动。
电路原理图如下:
单片机源程序如下:
- /************************************************
- 16x16点阵汉字滚动显示
- ************************************************/
- #include <reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit LA=P1^0; //138译码器地址选择引脚
- sbit LB=P1^1;
- sbit LC=P1^2;
- sbit LD=P1^3;
- sbit k1=P3^6; //启动或暂停按键
- sbit k2=P3^7; //改变方向按键
- bit fx=0; //滚动方向
- uint index=0; //列扫描索引
- uchar code hztab[]={
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //空格
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
-
- 0x08,0x04,0x10,0x04,0x20,0x24,0x40,0x24,0xfc,0x24,0xa2,0x24,0x22,0xfd,0x22,0x26, //老
- 0x42,0x24,0x42,0x2c,0x42,0x14,0x82,0x24,0x1e,0x44,0x00,0x04,0x00,0x04,0x00,0x00,
-
- 0x00,0x00,0xe1,0x3f,0x02,0x00,0x0c,0x00,0xf0,0xff,0x00,0x00,0x00,0x40,0xf8,0x47, //师
- 0x00,0x44,0x00,0x44,0xff,0x7f,0x10,0x44,0x08,0x44,0xf0,0x47,0x00,0x40,0x00,0x00,
-
- 0x02,0x08,0x44,0x08,0xa8,0x0f,0x10,0xf8,0x68,0x08,0x86,0x0f,0x00,0x00,0x00,0x01, //好
- 0x02,0x41,0x01,0x41,0xfe,0x47,0x00,0x49,0x00,0x51,0x00,0x61,0x00,0x01,0x00,0x00,
-
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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 T0_Init(); //定时器0初始化
- void delayus(uint us); //延时函数
- void keyscan(); //按键扫描函数
- //====================主程序=====================
- void main()
- {
- uchar i,j;
- T0_Init(); //定时器0初始化
- while(1)
- {
- keyscan(); //按键扫描
- for(i=0;i<16;i++) //点阵16列
- {
- LA=i&0x01; //用级联138进行列选
- LB=i&0x02;
- LC=i&0x04;
- LD=i&0x08;
- j=index+i; //定位当前要显示的列
- P0=hztab[j*2+1]; //发送点阵数据
- P2=hztab[j*2]; //共两个字节
- delayus(100); //延时
- P0=P2=0x00; //消影
- }
- delayus(100); //延时
- }
- }
- //=================定时器0初始化=================
- void T0_Init()
- {
- TMOD=0x01; //定时器0,工作方式1
- TH0=(65536-10000)/256; //定数器初值
- TL0=(65536-10000)%256; //10ms定时
- ET0=1; //打开定时器0中断允许
- EA=1; //打开总中断允许
- TR0=0; //暂不启动定时器0
- }
- //===============定时中断0服务程序===============
- void timer0() interrupt 1
- {
- static uchar tick=0; //嘀嗒计时
- TH0=(65536-10000)/256; //重装装初值
- TL0=(65536-10000)%256; //10ms定时
- tick++; //计数
- if(tick==5) //5次
- {
- tick=0; //清0
- if(fx==0)index=(index+1)%64; //若方向为左移,则扫描线加1
- else index=(index-1+64)%64; //否则扫描线减1
- }
- }
- //===================延时函数====================
- void delayus(uint us)
- {
- while(us--);
- }
- //=================按键扫描函数==================
- void keyscan()
- {
- if(k1==0) //检测k1是否按下
- {
- delayus(100); //延时消抖
- if(k1==0) //确认k1被按下
- {
- TR0=~TR0; //定时器启停反转
- while(k1==0); //等待按键松开
- }
- }
- if(k2==0) //检测k2是否按下
- {
- delayus(100); //延时消抖
- if(k2==0) //确认k2被按下
- {
- fx=~fx; //方向反转
- while(k2==0); //等待按键松开
- }
- }
- }
复制代码
所有资料51hei提供下载:
16×16点阵.zip
(22.41 KB, 下载次数: 59)
|