电子专业设计
51单片机+MAX7219做数码管显示,8位数码管,0-9循环显示
附件内有protues仿真电路和源码
MAX7219是美国MAXIM(美信)公司生产的串行输入/输出共阴极显示驱动器。它采用了3线串行接口,传送速率达10M数据,能驱动8位七段数字型LED或条形显示器或64只独立的LED。MAX7219内置BCD码译码器、多路扫描电路、段和数字驱动器和存储每一位的8*8静态RAM。能方便的用模拟或数字方法控制段电流的大小,改变显示器的数量;能进入低功耗的关断模式(仅消耗150uA电流,数据保留);能方便地进行级联。可广泛用于条形图显示、七段显示、工业控制、仪器仪表面板等领域。而且其最重要的一点是,每个显示位都能个别寻址和刷新,而不需要重写其他的显示位,这使得软件编程十分简单且灵活。MAX719后缀表示其封装方式和工作温度,如表所示:
单片机源程序如下:
- /**********************************************************************/
- #include <reg52.h>
- #include <stdio.h>
- #define uchar unsigned char
- void delayms(unsigned int ms);
- /************************************************************************
- I/O定义
- *************************************************************************/
- sbit DIN=P0^0;//数据输入端
- sbit LOAD=P0^1;//地址锁存端
- sbit CLK=P0^2; //时钟输入端
- sbit P2_0=P2^0;
- sbit P2_1=P2^1;
- sbit P2_2=P2^2;
- sbit P2_5=P2^5;
- sbit P2_6=P2^6;
- sbit P2_7=P2^7;
- /************************************************************************
- 数据输入
- *************************************************************************/
- void send(uchar add,uchar dat)
- {
- uchar ADS,i,j;
- CLK=0;
- LOAD=0;
- DIN=0;
- i=4;
- while(i<16)
- {
- if(i<8)
- {
- ADS=add;
- }
- else
- {
- ADS=dat;
- }
- for(j=8;j>=1;j--)
- {
- if((ADS&0x80)==0)
- {
- DIN=0 ;
- }
- else
- {
- DIN=1;
- }
- ADS=ADS<<1;
- CLK=1;
- CLK=0;
- }
- i=i+8;
- }
- LOAD=1;
- }
- /************************************************************************
- 主函数
- *************************************************************************/
- void main(void)
- {
- uchar d=0;
-
- send(0x0c,0x01);//正常状态
- send(0x0b,0x07);//设置扫描范围DIG0-7
- send(0x0a,0x05);//设置亮度11/32
- send(0x09,0xff);//采用译码方式
- while(1)
- {
- for(d=0;d<10;d++)
- {
- switch(d)
- {
- case 0:send(0x01,0x00);send(0x02,0x01);send(0x03,0x02);send(0x04,0x03);send(0x05,0x04);send(0x06,0x05);send(0x07,0x06);send(0x08,0x07);break;
- case 1:send(0x01,0x01);send(0x02,0x02);send(0x03,0x03);send(0x04,0x04);send(0x05,0x05);send(0x06,0x06);send(0x07,0x07);send(0x08,0x08);break;
- case 2:send(0x01,0x02);send(0x02,0x03);send(0x03,0x04);send(0x04,0x05);send(0x05,0x06);send(0x06,0x07);send(0x07,0x08);send(0x08,0x09);break;
- case 3:send(0x01,0x03);send(0x02,0x04);send(0x03,0x05);send(0x04,0x06);send(0x05,0x07);send(0x06,0x08);send(0x07,0x09);send(0x08,0x00);break;
- case 4:send(0x01,0x04);send(0x02,0x05);send(0x03,0x06);send(0x04,0x07);send(0x05,0x08);send(0x06,0x09);send(0x07,0x00);send(0x08,0x01);break;
- case 5:send(0x01,0x05);send(0x02,0x06);send(0x03,0x07);send(0x04,0x08);send(0x05,0x09);send(0x06,0x00);send(0x07,0x01);send(0x08,0x02);break;
- case 6:send(0x01,0x06);send(0x02,0x07);send(0x03,0x08);send(0x04,0x09);send(0x05,0x00);send(0x06,0x01);send(0x07,0x02);send(0x08,0x03);break;
- case 7:send(0x01,0x07);send(0x02,0x08);send(0x03,0x09);send(0x04,0x00);send(0x05,0x01);send(0x06,0x02);send(0x07,0x03);send(0x08,0x04);break;
- case 8:send(0x01,0x08);send(0x02,0x09);send(0x03,0x00);send(0x04,0x01);send(0x05,0x02);send(0x06,0x03);send(0x07,0x04);send(0x08,0x05);break;
- case 9:send(0x01,0x09);send(0x02,0x00);send(0x03,0x01);send(0x04,0x02);send(0x05,0x03);send(0x06,0x04);send(0x07,0x05);send(0x08,0x06);break;
- default:send(0x01,0x00);send(0x02,0x00);send(0x03,0x00);send(0x04,0x00);send(0x05,0x00);send(0x06,0x00);send(0x07,0x00);send(0x08,0x00);break;
- }
- delayms(1000);
- // send(0x01,0x00);send(0x02,0x02);
- // send(0x01,0x04);send(0x02,0x07);
- // send(0x01,0x08);send(0x02,0x05);
- }
- }
- }
- void delayms(unsigned int ms)
- {
- unsigned int i,j;
- for(j=0;j<ms;j++)
- for(i=0;i<115;i++);
- }
复制代码
所有资料51hei提供下载:
MAX7219应用.zip
(320.77 KB, 下载次数: 30)
|