[C51代码]MAX7219驱动
#ifndef _max7219_h_
#define _max7219_h_
#include
#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_DECODE0x09 //译码方式地址
#define _7219_INTENSITY0x0A //亮度寄存器地址
#define _7219_SCANLIMIT0x0B //扫描界限寄存器地址,用于设置外接数码管个数
#define _7219_SHUTDOWN0x0C //停机寄存器地址,使其处于低功耗
#define _7219_DISPTEST0x0F //显示测试寄存器地址,用于测试数码管和MAX2719是否工作
//Decode Mode
#define _7219_DECODE_ALL0xff
#define _7219_DECODE_NONE0x00
// Intensity
#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
//Shutdown mode
#define _7219_SHUTDOWN_ON 0x01
#define _7219_SHUTDOWN_OFF 0x00
//Display test
#define _7219_DISPTEST_ON0x01
#define _7219_DISPTEST_OFF 0x00
//7219 CO
//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
#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();
#endif
/**************************max7219.c*******************************/
#include "max7219.h"
#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的基本参数
*入口参数:无
*出口参数:无
****************************************************************/
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);
}
C51代码MAX7219驱 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)