📄 my7219.h
字号:
/***************************************************************************
* MAX7219驱动函数库(非译码方式)
* Author:Xieqin
* CopyRight:2004/06/22
****************************************************************************/
#ifndef __MY7219_H__
#define __MY7219_H__
sbit CLK=P1^2; //时钟脉冲口
sbit LOAD=P1^3; //位选口
sbit DIN=P1^4; //数据输入口
/******************************************************************************
/* 定义显示数字0-9数字以及字母A、B、C、D、E、F*/ //数字及字母段码
unsigned int code LED_Code[]={0x7E,0x30,0x6D,0x79,0x33,0x5B,0x5F,0x70,0x7F,0x7B,//0~~~9
0x77,0x1F,0x4E,0x3D,0x4F,0x47};//A,B,C,D,E,F
/* 定义显示位置LED0-LED8数组 */ //数码管地址
unsigned int code LED_Location[]={0x0100,0x0200,0x0300,0x0400,0x0500,0x0600,0x0700,0x0800};
/******************************************************************************
/******************************************************************************
MAX7219 发送命令(16 bit)子程序
******************************************************************************/
void Send_LED( unsigned int n )
{ //n=待发送16位数据
unsigned int i;
CLK = 0;
LOAD = 0;
DIN = 0;
for ( i=0x8000; i>0x0000; i>>=1 )
{
if ((n&i)== 0 ) DIN = 0;
else DIN = 1;
CLK = 1;
CLK = 0;
}
LOAD = 1;
}
/******************************************************************************
MAX7219初始化子程序
******************************************************************************/
void Init_MAX7219()
{
Send_LED( 0x0C01 ); /* 置LED为正常状态 */
Send_LED( 0x0A02 ); /* 置LED亮度为5/32 */
Send_LED( 0x0B06); /* 置LED扫描范围DIGIT0-5 */
Send_LED( 0x0900 ); /* 置LED显示为译码方式 ,00不译码,FF译码*/
Send_LED( 0x0F00 ); /* 置LED显示测试模式寄存器,0正常工作,1测试状态*/
}
/******************************************************************************
MAX7219清屏子程序
******************************************************************************/
void Cls()
{
unsigned int i;
for (i=0x0100; i<=0x0800; i+=0x0100 ) Send_LED( i ); // DIGIT0-7 = 0
}
/******************************************************************************
MAX7219位驱动与段驱动子程序
******************************************************************************/
void LED_Drive(unsigned char location,unsigned char number)
{ //location=数据管序号,number=待显数字
if ( ( number & 0x80 ) == 0 )
{
Send_LED( LED_Location[ location ] | LED_Code[ number ] );
}
else
{
Send_LED( LED_Location[ location ] | LED_Code[ number & 0x7F ] | 0x80 );
}
}
void Delay7219(unsigned int n)//7219专用延时函数
{
unsigned int i;
unsigned char j;
for(i=0;i<n;i++)
for(j=0;j<120;j++);
}
void Loading7219(unsigned char n1,unsigned char n2)//7219初始化显示函数
{
unsigned char i,j;
unsigned int x;
for(x=0x80,j=0;j<10;j++)
{
if(j==8)x=0xff;//各位均显示示8+小数点
if(j==9)x=0x00;//各位清屏
for(i=n1;i<=n2;i++)//8位数码输出显示示代码
{
Send_LED( LED_Location[ i ] | x);
}
Delay7219(1000);
if(j<8)x>>=1;
}
}
//*********************************************************************************
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -