/***************max7219.h****************/
#ifndef _max7219_h_
#define _max7219_h_
#define _max7219_h_
#include
#include “link.h”
/***************操控引脚界说****************/
sbit _7219_DIN = P2^0;
sbit _7219_CS = P2^1;
sbit _7219_CLK = P2^2;
#include “link.h”
/***************操控引脚界说****************/
sbit _7219_DIN = P2^0;
sbit _7219_CS = P2^1;
sbit _7219_CLK = P2^2;
/***************操控字界说****************/
#define _7219_NO_OP0x00 //Digit0~Digit7坐落RAM的地址
#define _7219_DIG00x01
#define _7219_DIG10x02
#define _7219_DIG20x03
#define _7219_DIG30x04
#define _7219_DIG40x05
#define _7219_DIG50x06
#define _7219_DIG60x07
#define _7219_DIG70x08
#define _7219_NO_OP0x00 //Digit0~Digit7坐落RAM的地址
#define _7219_DIG00x01
#define _7219_DIG10x02
#define _7219_DIG20x03
#define _7219_DIG30x04
#define _7219_DIG40x05
#define _7219_DIG50x06
#define _7219_DIG60x07
#define _7219_DIG70x08
#define _7219_DECODE0x09 //译码方法地址
#define _7219_INTENSITY0x0A //亮度寄存器地址
#define _7219_SCANLIMIT0x0B //扫描边界寄存器地址,用于设置外接数码管个数
#define _7219_SHUTDOWN0x0C //停机寄存器地址,使其处于低功耗
#define _7219_DISPTEST0x0F //显现测验寄存器地址,用于测验数码管和MAX2719是否作业
#define _7219_INTENSITY0x0A //亮度寄存器地址
#define _7219_SCANLIMIT0x0B //扫描边界寄存器地址,用于设置外接数码管个数
#define _7219_SHUTDOWN0x0C //停机寄存器地址,使其处于低功耗
#define _7219_DISPTEST0x0F //显现测验寄存器地址,用于测验数码管和MAX2719是否作业
//Decode Mode
#define _7219_DECODE_ALL0xff
#define _7219_DECODE_NONE0x00
#define _7219_DECODE_ALL0xff
#define _7219_DECODE_NONE0x00
// Intensity
#define _7219_INTENSITY_MIN0x01
#define _7219_INTENSITY_MAX0x0f
#define _7219_INTENSITY_MIN0x01
#define _7219_INTENSITY_MAX0x0f
// Scanlimit
#define _7219_SCANLIMIT_70x07
#define _7219_SCANLIMIT_60x06
#define _7219_SCANLIMIT_50x05
#define _7219_SCANLIMIT_40x04
#define _7219_SCANLIMIT_30x03
#define _7219_SCANLIMIT_20x02
#define _7219_SCANLIMIT_10x01
#define _7219_SCANLIMIT_00x00
#define _7219_SCANLIMIT_70x07
#define _7219_SCANLIMIT_60x06
#define _7219_SCANLIMIT_50x05
#define _7219_SCANLIMIT_40x04
#define _7219_SCANLIMIT_30x03
#define _7219_SCANLIMIT_20x02
#define _7219_SCANLIMIT_10x01
#define _7219_SCANLIMIT_00x00
//Shutdown mode
#define _7219_SHUTDOWN_ON 0x01
#define _7219_SHUTDOWN_OFF 0x00
#define _7219_SHUTDOWN_ON 0x01
#define _7219_SHUTDOWN_OFF 0x00
//Display test
#define _7219_DISPTEST_ON0x01
#define _7219_DISPTEST_OFF 0x00
#define _7219_DISPTEST_ON0x01
#define _7219_DISPTEST_OFF 0x00
//7219 CO DE B
//BCD译码对应的字符段位
#define _7219_00x00
#define _7219_10x01
#define _7219_20x02
#define _7219_30x03
#define _7219_40x04
#define _7219_50x05
#define _7219_60x06
#define _7219_70x07
#define _7219_80x08
#define _7219_90x09
#define _7219_E0x0B
#define _7219_H0x0C
#define _7219_L0x0D
#define _7219_P0x0E
#define _7219_BLANK0x0F
//BCD译码对应的字符段位
#define _7219_00x00
#define _7219_10x01
#define _7219_20x02
#define _7219_30x03
#define _7219_40x04
#define _7219_50x05
#define _7219_60x06
#define _7219_70x07
#define _7219_80x08
#define _7219_90x09
#define _7219_E0x0B
#define _7219_H0x0C
#define _7219_L0x0D
#define _7219_P0x0E
#define _7219_BLANK0x0F
//7219 NO Co de
#define _7219_SEG_DP7
#define _7219_SEG_A6
#define _7219_SEG_B5
#define _7219_SEG_C4
#define _7219_SEG_D3
#define _7219_SEG_E2
#define _7219_SEG_F1
#define _7219_SEG_G0
#define _7219_SEG_DP7
#define _7219_SEG_A6
#define _7219_SEG_B5
#define _7219_SEG_C4
#define _7219_SEG_D3
#define _7219_SEG_E2
#define _7219_SEG_F1
#define _7219_SEG_G0
/***************函数声明****************/
extern void Write_Max7219(uchar Addr, uchar Content);
extern void Init_Max7219();
extern void Write_Max7219(uchar Addr, uchar Content);
extern void Init_Max7219();
#endif
/**************************max7219.c*******************************/
#include “max7219.h”
#include “link.h”
#include
#include “link.h”
#include
/****************************************************************
*函数功用:写入一个字节到max7219
*进口参数:数据Content
*出口参数:无
*****************************************************************/
void Write_Max7219_byte(unsigned char temp)
{
unsigned char i;
for (i=0;i<8;i++)
{
_7219_CLK=0;
_7219_DIN=(bit)(temp&0x80);
temp<<=1;
_7219_CLK=1;
}
}
/****************************************************************
*函数功用:在max7219指定的地址写入一个字节的内容
*进口参数:要写入数据的地址:Address
写入数据的详细值:Content
*出口参数:无
****************************************************************/
void Write_Max7219(unsigned char address,unsigned char dat)
{
_7219_CS=0;
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
_7219_CS=1;
}
*函数功用:写入一个字节到max7219
*进口参数:数据Content
*出口参数:无
*****************************************************************/
void Write_Max7219_byte(unsigned char temp)
{
unsigned char i;
for (i=0;i<8;i++)
{
_7219_CLK=0;
_7219_DIN=(bit)(temp&0x80);
temp<<=1;
_7219_CLK=1;
}
}
/****************************************************************
*函数功用:在max7219指定的地址写入一个字节的内容
*进口参数:要写入数据的地址:Address
写入数据的详细值:Content
*出口参数:无
****************************************************************/
void Write_Max7219(unsigned char address,unsigned char dat)
{
_7219_CS=0;
Write_Max7219_byte(address);
Write_Max7219_byte(dat);
_7219_CS=1;
}
/****************************************************************
*函数功用:装备max7219的基本参数
*进口参数:无
*出口参数:无
****************************************************************/
void Init_Max7219()
{
Write_Max7219(_7219_SHUTDOWN , _7219_SHUTDOWN_OFF);
Write_Max7219(_7219_INTENSITY, 0x05);
Write_Max7219(_7219_DECODE , _7219_DECODE_ALL);
Write_Max7219(_7219_DISPTEST , _7219_DISPTEST_OFF);
Write_Max7219(_7219_SHUTDOWN , _7219_SHUTDOWN_ON);
Write_Max7219(_7219_SCANLIMIT , _7219_SCANLIMIT_7);
}
*函数功用:装备max7219的基本参数
*进口参数:无
*出口参数:无
****************************************************************/
void Init_Max7219()
{
Write_Max7219(_7219_SHUTDOWN , _7219_SHUTDOWN_OFF);
Write_Max7219(_7219_INTENSITY, 0x05);
Write_Max7219(_7219_DECODE , _7219_DECODE_ALL);
Write_Max7219(_7219_DISPTEST , _7219_DISPTEST_OFF);
Write_Max7219(_7219_SHUTDOWN , _7219_SHUTDOWN_ON);
Write_Max7219(_7219_SCANLIMIT , _7219_SCANLIMIT_7);
}