#include #include //#include /*--------------------------------------------------*/
sbit dis_DIN=P1^0; /*显示串行数据输入端*/
sbit dis_LOAD=P1^1; /*显示数据锁存端*/
sbit dis_CLK=P1^2; /*显示时钟输入端*/
#define NoOp 0x00 /*空操作*/
#define Digit0 0x01 /*数码管1*/
#define Digit1 0x02 /*数码管2*/
#define Digit2 0x03 /*数码管3*/
#define Digit3 0x04 /*数码管4*/
#define Digit4 0x05 /*数码管5*/
#define Digit5 0x06 /*数码管6*/
#define Digit6 0x07 /*数码管7*/
#define Digit7 0x08 /*数码管8*/
#define DecodeMode 0x09 /*译码模式*/
#define Intensity 0x0a /*亮度*/
#define ScanLimit 0x0b /*扫描界限*/
#define ShutDown 0x0c /*掉电模式*/
#define DisplayTest 0x0f /*显示测试*/
#define ShutdownMode 0x00 /*掉电方式工作*/
#define NormalOperation 0x01 /*正常操作方式*/
#define DecodeDigit 0xff /*译码位数设置*/
#define IntensityGrade 0x0a /*显示亮度级别设置*/
#define ScanDigit 0x07 /*扫描位数设置*/
#define TestMode 0x01 /*显示测试方式*/
#define TextEnd 0x00 /*显示测试结束,正常工作*/
unsigned char data DisBuffer[8]={0,0,0,0,0,0,0,0}; /*显示缓存区*/
unsigned char code dispaly_list[]=
{
0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b, /*0,1,2,3,4,5,6,7,8,9*/
0x77,0x1f,0x4e,0x3d,0x4f,0x47,0x67,0x3e,0xff,0x00}; /*A,B,C,D,E,F,P,U,全
亮,全灭*/
/*--------------------------------------------------------
10ms延时子程序
---------------------------------------------------------*/
void delayX10ms(unsigned char count)
{
unsigned char j,k;
while(count--!=0)
{
for(j=0;j<43;j++)
for(k=0;k<73;k++)
;
}
}
/*-------------------------------------------------
向MAX7219写入字节(8位)
--------------------------------------------------*/
void SendChar (unsigned char ch)
{
unsigned char i,temp;
_nop_();
for (i=0;i<8;i++)
{
temp=ch&0x80;
ch=ch<<1;
if(temp)
{
dis_DIN=1;
dis_CLK=0;
dis_CLK=1;
}
else
{
dis_DIN=0;
dis_CLK=0;
dis_CLK=1;
}
}
}
/*-------------------------------------------------
向MAX7219写入字(16位)
-------------------------------------------------*/
void WriteWord (unsigned char addr,unsigned char num)
{
dis_LOAD=0;
_nop_();
SendChar (addr);
_nop_();
SendChar (num);
_nop_();
dis_LOAD=1;
}
/*-------------------------------------------------
MAX7219初始化
-------------------------------------------------*/
void InitDis (void)
{
WriteWord (ScanLimit,ScanDigit); /*设置扫描界限*/
WriteWord (DecodeMode,DecodeDigit); /*设置译码模式*/
WriteWord (Intensity,IntensityGrade); /*设置亮度*/
WriteWord (ShutDown,NormalOperation); /*设置电源工作模式*/
}
/*-------------------------------------------------
系统上电初始化
-------------------------------------------------*/
void InitMain (void)
{
IE=0x00; /*设置中断允许寄存器*/
IP=0x00; /*设置中断优先级管理寄存器*/
TH0=0xd8; /*设定时器初值,10ms*/
TL0=0xf0;
TMOD=0x01; /*T1 定时器模式2,波特率发生器,T0 定时器模式1*/
TCON=0x11; /*设置定时器控制寄存器,INT0设置为边沿触发方式*/
PSW=0x00;
}
/*-------------------------------------------------
主函数
-------------------------------------------------*/
void main(void)
{
InitMain ();
InitDis ();
WriteWord (DisplayTest,TestMode);
delayX10ms(0x64);
delayX10ms(0x64);
WriteWord (DisplayTest,TextEnd);
while(1)
{
unsigned char i;
for (i=0;i<=9;i++)
{
delayX10ms(0x64);
delayX10ms(0x64);
InitDis ();
DisBuffer[0]=i;
DisBuffer[1]=i;
DisBuffer[2]=i;
DisBuffer[3]=i;
DisBuffer[4]=i;
DisBuffer[5]=i;
DisBuffer[6]=i;
DisBuffer[7]=i;
WriteWord (Digit0,DisBuffer[0]);
WriteWord (Digit1,DisBuffer[1]);
WriteWord (Digit2,DisBuffer[2]);
WriteWord (Digit3,DisBuffer[3]);
WriteWord (Digit4,DisBuffer[4]);
WriteWord (Digit5,DisBuffer[5]);
WriteWord (Digit6,DisBuffer[6]);
WriteWord (Digit7,DisBuffer[7]);
}
}
}
关注eeworld公众号
快捷获取更多信息
关注eeworld服务号
享受更多官方福利
推荐阅读
MAX7219驱动点阵的原理图如下:单片机+MAX7219点阵源程序如下:#include #include #define uchar unsigned char#define uint unsigned int//定义Max7219端口sbit Max7219_pinCLK = P2^2;sbit Max7219_pinCS = P2^1;sbit Max7219_pinDIN = P2^0;uchar code disp1[38][8]={{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//0{0x10
发表于 2020-12-25
main.c#include #include "intrins.h"#include "Max7219.h"uchar code laji[][8]={{0x18,0x24,0x42,0x42,0x7E,0x42,0x42,0x42},//A{0x7C,0x42,0x42,0x7C,0x42,0x42,0x42,0x7C},//B{0x3C,0x42,0x40,0x40,0x40,0x40,0x42,0x7C},//C{0x7C,0x42,0x42,0x42,0x42,0x42,0x42,0x7C},//D};/*n毫秒的延时程序*//*void Delay
发表于 2020-12-23
SEND1SEND0 BIC.B #DIN,&P1OUTJMP GOONSEND1 BIS.B #DIN,&P1OUTGOON BIS.B #CLK,&P1OUTRLA R10BIC.B #CLK,&P1OUTDEC R6JNZ SENDLOOPRETENDMAX7219的c程序/*--------------------------------------------------------- *  
发表于 2020-12-16
; // 定义数码管3#define DIG3 0x04 // 定义数码管4void delay(uint i);void T0_init();void MAX7219(uchar addr,uchar num);void MAX7219_init();  
发表于 2020-11-11
买了几块MAX7219点阵模块,弄了个点阵级联,时间上翻显示,有秒点上下闪动,里面有两段,一段是点阵屏水平放置时数字上翻,另一段是点阵屏垂直放置时数字上翻,程序纯属业余爱好,高手勿喷,下面直接代码,3个IO口不能有其他器件,下面是压缩过的图像,有点变化,其实是没有拖影的, 单片机源程序如下:#include #include #include #include #define uchar unsigned char#define uint unsigned intuchar
发表于 2020-09-18
/***************************************************程序名称: MAX7219 C语言控制程序 *程序功能: 3线串行控制8位共阴数码管  
发表于 2020-09-16