16*16点阵滚动显示制作出来的实物图如下:
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- //宏定义
- #define uchar unsigned char
- #define uint unsigned int
- #define zishu 10 //汉字数,两个字符是一个汉字,如果有单个字符,那么就加0.5
- //包含头文件
- #include <reg51.h>
- #include <intrins.h>
- //管脚定义
- //154
- sbit A_=P0^0; //74HC154的A
- sbit B_=P0^1; //74HC154的B
- sbit C_=P0^2; //74HC154的C
- sbit D_=P0^3; //74HC154的D
- sbit G2=P0^7; //74HC154的使能 低电平有效
- //595
- sbit SI=P0^6;//数据脚
- sbit SCK=P0^5;//上升沿时数据寄存器的数据移位。QA-->QB-->QC-->...-->QH;下降沿移位寄存器数据不变
- sbit RCK=P0^4;//上升沿时移位寄存器的数据进入数据存储寄存器,下降沿时存储寄存器数据不变。通常我将
- //RCK置为低电平,当移位结束后,在RCK端产生一个正脉冲(5V时,大于几十纳秒就行了。我
- //通常都选微秒级),更新显示数据。
- //函数声明
- void Init595();
- void Write_byte595(uchar temp);
- void WriteS(uchar data1,uchar data2);
- void Wei_154(uchar W);
- void delay(uint z);
- //汉字数组
- uchar code HanZi[]=
- {
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",0*/
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",1*/ //这两行不要动改字时保留
- 0xFF,0xFF,0x80,0x00,0xBF,0xFF,0xB7,0xFF,0xB6,0x07,0xB6,0xEF,0xB6,0xEF,0xB6,0xEF,
- 0xB6,0xEF,0xB6,0xEF,0xB6,0x07,0xB7,0xFD,0xBF,0xFE,0x80,0x01,0xFF,0xFF,0xFF,0xFF,/*"同",0*/
- 0xFF,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,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FF,0xCF,0xFF,0x38,0x01,
- 0xDF,0xFF,0xEF,0xFF,0xF7,0xFF,0xFB,0xFF,0xF9,0xFF,0xFC,0xFF,0xFD,0xFF,0xFF,0xFF,/*"个",7*/
- 0xFD,0xFF,0xDD,0xFE,0xDB,0xEE,0xD7,0xEE,0x00,0x9D,0xD6,0x5D,0xD9,0x6B,0xFD,0x73,
- 0xDB,0x77,0xD7,0x6F,0x00,0x5F,0xCF,0x3F,0xD3,0x7F,0xD9,0xFF,0xDB,0xFF,0xFF,0xFF,/*"梦",8*/
- 0xEF,0x7F,0xEC,0xFD,0xE3,0xF1,0x00,0x7F,0xE7,0xE3,0xE9,0xFD,0xEF,0xFD,0xFF,0xDD,
- 0x80,0x65,0xAB,0x7D,0xAB,0x7D,0xAB,0x79,0xAB,0x7F,0x80,0x6F,0xFF,0xF3,0xFF,0xFF,/*"想",9*/
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",10*/
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",11*/ //这两行不要动改字时保留
- };
- //主函数
- void main()
- {
- uchar i=1,j=0;
- uint X=0;
- //595c初始化
- Init595();
- //循环演示
- while(1) //循环
- {
- for(j=0;j<10;j++) //更改j<10为j<5,可以加速
- {
- for(i=1;i<17;i++) //一个for循环,分别选中16个列
- {
- WriteS(0xff,0xff); //消影
- Wei_154(i); //选中列数据
- WriteS(HanZi[i*2-2+2*X],HanZi[i*2-1+2*X]); //显示内容
- Wei_154(i); //再选中列数据
- delay(7); //延时的时间就是显示的时间
- G2=0; //打开列选
- }
- }
- X++; //显示左移
- if(X==8*((zishu+1)*2)) //左移到最后一个字--更改字时,8*n中的n的取值为:字符数+2(一个汉字=两个字符,字母数字为1个字符)
- X=0; //重头开始
- }
- }
- //初始化595
- void Init595()
- {
- SI=1;
- SCK=0;
- RCK=0;
- }
- void Write_byte595(uchar temp) //写数据到595
- {
- uchar i,data_=temp;
- G2=1; //关闭列选
- for(i=0;i<8;i++) //传值8位
- {
- if(data_&0x01==0x01) //判断低位为1
- {
- SI=1; //数据脚就写入1
- }
- else //判断低位为0
- {
- SI=0; //数据脚写入0
- }
- //产生一个上升沿
- SCK=0;
- SCK=1;
- SCK=0;
- data_>>=1; //将要写入的数据右移一位
- }
- RCK=0;//显示数据
- RCK=1;
- RCK=0;
- }
- //595写入一行的字节
- void WriteS(uchar data1,uchar data2)
- {
- Write_byte595(data2); //写入高8位数据
- Write_byte595(data1); //写入低8位数据 一共是一行16个数据
- }
- //154位选驱动
- void Wei_154(uchar W)
- {
- G2=0;//使能
- switch(W) //判断W的值,选中不同的列线
- {
- case 16: //如果W=16
- {
- A_=1;
- B_=1;
- C_=1;
- D_=1; //1111:选中第16列
- break;
- }
- case 15:
- {
- A_=0;
- B_=1;
- C_=1;
- D_=1; //1110:选中第15列
- break;
- }
- case 14:
- {
- A_=1;
- B_=0;
- C_=1;
- D_=1; //1101:选中第14列
- break;
- }
- case 13:
- {
- A_=0;
- B_=0;
- C_=1;
- D_=1; //1100:选中第13列
- break;
- }
- case 12:
- {
- A_=1;
- B_=1;
- C_=0;
- D_=1; //1011:选中第12列
- break;
- }
- case 11:
- {
- A_=0;
- B_=1;
- C_=0;
- D_=1; //1010:选中第11列
- break;
- }
- case 10:
- {
- A_=1;
- B_=0;
- C_=0;
- D_=1; //1001:选中第10列
- break;
- }
- case 9:
- {
- A_=0;
- B_=0;
- C_=0;
- D_=1; //1000:选中第9列
- break;
- }
- case 8:
- {
- A_=1;
- B_=1;
- C_=1;
- D_=0; //0111:选中第8列
- break;
- }
- case 7:
- {
- A_=0;
- B_=1;
- C_=1;
- D_=0; //0110:选中第7列
- break;
- }
- case 6:
- {
- A_=1;
- B_=0;
- C_=1;
- D_=0; //0101:选中第6列
- break;
- }
- case 5:
- {
- A_=0;
- B_=0;
- C_=1;
- D_=0; //0100:选中第5列
- break;
- }
- case 4:
- {
- A_=1;
- B_=1;
- C_=0;
- D_=0; //0011:选中第4列
- break;
- }
- case 3:
- {
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
42-16乘16点阵滚动显示.7z
(1.04 MB, 下载次数: 70)
|