MAX7219产品级驱动分享

2024-08-21 22:18
文章标签 驱动 分享 产品 max7219

本文主要是介绍MAX7219产品级驱动分享,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在2008年开发的红酒自动售卖机上用MAX7219实现8个4位LED显示,一直稳定运行,今天由于要修改一下红酒机的代码,特此分享下MAX7219的驱动。

MAX7219.h

/*
*********************************(C) COPYRIGHT 2008 HB **************************************************
*
* File Name          : sp_max7219.h
* Author             : qzm
* Date First Issued  :  11/28/2008 qzm
* Description        : Header for spi_max7219.c file.
*
* History:
* 2009/02/19: V2.0 begin
* 待增加的功能如下:
* (1)每个4位LED可单独寻址修改
* (2)增加单个4位LED闪烁功能
* (3)增加可显示英文字符的功能
*
* 2009/01/04: V1.0
* (1)实现了4个MAX7219控制8个4位共阴极LED显示驱动,每个4位LED对应0000-9999的整数。
* (2)先调用IniFourMax7219 fun ini SPI and Max7219的工作模式,然后用
Max7219_SendFourWord FUN 发送形如 d[0] d[1] d[2] d[3] d[4] d[5] d[6] d[7]
*										1234 5678 1234 5678 1234 5678 1234 5678 
*                                       LED1 LED2 LED3 LED4 LED5 LED6 LED7 LED8
* 在该版本中的发送函数中并没有加入延时之类的代码,运行很稳定。
*
* 2008/11/28: beta1
--------------------------------------------------------------------------------------------------------
*								  Version2.0 Debug Sum-up
(1)在初始化 Mcu's SPI Module 后要延迟一定的时钟周期后再发送初始化数据给MAX7219
如:	Max7219_Init();
for (i=0;i<999999;i++); // Delay, 必要条件,当 i<9时,初始化出错的机率达到90%
// 当注释掉 延迟,初始化出错机率为100%
SendDataToFirstMax7219(REG_DECODE, DECODE_MODE_BCD_FOR_ALL_DIGIT);	NOTE: 在之后的调试中发现,(1)中的分析是错误的,在初始化SPI后,立即发送数据是可行的,
而(1)中的错误假象是由于没在拉高( SPI_NSS_HIGH())之前检查数据是否发送完毕所致。KeyPoint:
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_NSS_HIGH();(2)
在发送数据之前要查看忙状态标志,QZM不会忽略
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1, temp1);
!!!!! 在置高之前也要查看忙状态标志,QZM忽略着 !!!!!
这会使本是要发送给第一个MAX7219却发给了第4个MAX7219,发送给第二个却发给了第三个,发给
第四个却发给了第一个。
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_NSS_HIGH();(3) 在看FWLIB2.03's example 发现很多SPI的例子用
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); 
而之前我一直用
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);
也工作得很好,为了比较,把基于 SPI_I2S_FLAG_BSY 改为 SPI_I2S_FLAG_TXE ,正在测试较果2009/2/23 !!!!! << 关于 while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET); 和  while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET); 的实测比较>>用SPI_I2S_FLAG_TXE == RESET 来控制发送,在 SPI_BaudRatePrescaler_256 - SPI_BaudRatePrescaler_2 时4个MAX7219
的显示都不正常,在调节分频为SPI_BaudRatePrescaler_2时,第一个MAX7219显示正常,其他的MAX7219显示不正常,但当转其他的
SPI_BaudRatePrescaler_X,4个MAX729的显示大都不正常。代码如下所示:(不加任何延时)
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1, NULL_OP);用 while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET); 来控制发送,在SPI_BaudRatePrescaler_2 时只有第一个MAX7219显示正常,其他MAX7219显示不正常
但,SPI_BaudRatePrescaler_4 - SPI_BaudRatePrescaler_256 4个MAX7219都显示正常。<< 结论 >> 用while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);而不是用SPI_I2S_FLAG_TXE == RESET,来控制MAX7219的发送更加稳定!!!!!(4)经过几天的改MAX7219底层代码和测试的心得 - 2009/2/23
1、当SPI的预分频为“SPI_BaudRatePrescaler_2”时,无论PLC板上的22R或RC滤波使能与否,都只有第一个MAX7219能正常工作,其他三个都不能因此只能用“SPI_BaudRatePrescaler_4”以上的预分频。2、while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);比while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);用于控制SPI发送数据给MAX7219稳定得多。*********************************************************************************************************
*//* Define to prevent recursive inclusion -------------------------------------*/
#ifndef MAX7219_H
#define MAX7219_H/* Includes ------------------------------------------------------------------*//* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/#define SPI_NSS_LOW()     GPIO_ResetBits(GPIOA, GPIO_Pin_4)		/* Select SPI FLASH: ChipSelect pin low  */
#define SPI_NSS_HIGH()    GPIO_SetBits(GPIOA, GPIO_Pin_4)		/* Deselect SPI FLASH: ChipSelect pin high *//* Exported functions ------------------------------------------------------- *//*----- Version 1.0 use -----------------------------*/
/*----- High layer function -----*/
void IniFourMax7219(void);
void SPI_Max7219_SendFourWord(s32* pEightLedData);
/*----- Low layer function -----*//*----- Version 2.0 use -----------------------------*/
/*----- 2009-2-20 new add ------*/
void IniMax7219s(void);                             // 把PLC板上的4个MAX7219初始化为No decode for digits7-0;void MAX7219_CloseAllLedDisplay(void);
void MAX7219_OpenAllLedDisplay(void);void MAX7219_Send4BitNum(u8 LedIndex, u16 data);		// 发送 十进制的   0000-9999; 当data >= 0xF000时,表示要显示其他编码 void MAX7219_Send4BitDark(u8 LedIndex);					// 使指定LED全     DARK
void MAX7219_Send4BitLow(u8 LedIndex);					// 使指定LED显示   "____"
void MAX7219_Send4BitMiddle(u8 LedIndex);				// 使指定LED显示   "----"
void MAX7219_Send4BitHeight(u8 LedIndex);				// 使指定LED显示   "~~~~"void MAX7219_IntensityAdjust(u8 MAX7219Index, u8 IntensityValue/* 0x00-0x0F */); // 亮度调整/*----- Low layer function -----*/
u8 MAX7219_LedBitCoding(u8 data);					// 把输入字节转换为MAX7219能处理的编码void MAX7219_SendDataToFirstMax7219(u8 Reg, u8 data);	// 发送数据到第一个MAX7219的指定寄存器中,可用于初始化MAX7219和数据显示
void MAX7219_SendDataToSecMax7219(u8 Reg, u8 data);		// 发送数据到第二个MAX7219的指定寄存器中,可用于初始化MAX7219和数据显示
void MAX7219_SendDataToThirdMax7219(u8 Reg, u8 data);	// 发送数据到第三个MAX7219的指定寄存器中,可用于初始化MAX7219和数据显示
void MAX7219_SendDataToFourMax7219(u8 Reg, u8 data);	// 发送数据到第四个MAX7219的指定寄存器中,可用于初始化MAX7219和数据显示#endif /* MAX7219_H *//******************* (C) HB 2008/11/21 qzm *****END OF FILE********************************************/

MAX7219.c

/*
*********************************(C) COPYRIGHT 2008 HB **************************************************
*
* File Name          : sp_max7219.h
* Author             : qzm
* Date First Issued  :  11/28/2008 qzm
* Description        : Header for spi_max7219.c file.
*
* History:
* 2009/02/19: V2.0 begin
* 待增加的功能如下:
* (1)每个4位LED可单独寻址修改
* (2)增加单个4位LED闪烁功能
* (3)增加可显示英文字符的功能
*
* 2009/01/04: V1.0
* (1)实现了4个MAX7219控制8个4位共阴极LED显示驱动,每个4位LED对应0000-9999的整数。
* (2)先调用IniFourMax7219 fun ini SPI and Max7219的工作模式,然后用
* SPI_Max7219_SendFourWord FUN 发送形如 d[0] d[1] d[2] d[3] d[4] d[5] d[6] d[7]
*										1234 5678 1234 5678 1234 5678 1234 5678 
*                                       LED1 LED2 LED3 LED4 LED5 LED6 LED7 LED8
* 在该版本中的发送函数中并没有加入延时之类的代码,运行很稳定。
*
* 2008/11/28: beta1
--------------------------------------------------------------------------------------------------------
*								  Version2.0 Debug Sum-up
(1)在初始化 Mcu's SPI Module 后要延迟一定的时钟周期后再发送初始化数据给MAX7219
如:	SPI_Max7219_Init();
for (i=0;i<999999;i++); // Delay, 必要条件,当 i<9时,初始化出错的机率达到90%
// 当注释掉 延迟,初始化出错机率为100%
SPI_SendDataToFirstMax7219(REG_DECODE, DECODE_MODE_BCD_FOR_ALL_DIGIT);	NOTE: 在之后的调试中发现,(1)中的分析是错误的,在初始化SPI后,立即发送数据是可行的,
而(1)中的错误假象是由于没在拉高( SPI_NSS_HIGH())之前检查数据是否发送完毕所致。KeyPoint:
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_NSS_HIGH();(2)
在发送数据之前要查看忙状态标志,QZM不会忽略
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_I2S_SendData(SPI1, temp1);
!!!!! 在置高之前也要查看忙状态标志,QZM忽略着 !!!!!
这会使本是要发送给第一个MAX7219却发给了第4个MAX7219,发送给第二个却发给了第三个,发给
第四个却发给了第一个。
while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
SPI_NSS_HIGH();*********************************************************************************************************
*//* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "MAX7219.h"/* Private typedef -----------------------------------------------------------*//* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
//------------------------------------------------------------------------------
//  MAX7219 Register
//
#define		REG_DIGIT0				0x01		/* Digit 0 */
#define		REG_DIGIT1				0x02		/* Digit 1 */
#define		REG_DIGIT2				0x03		/* Digit 2 */
#define		REG_DIGIT3				0x04		/* Digit 3 */
#define		REG_DIGIT4				0x05		/* Digit 4 */
#define		REG_DIGIT5				0x06		/* Digit 5 */
#define		REG_DIGIT6				0x07		/* Digit 6 */
#define		REG_DIGIT7				0x08		/* Digit 7 */
#define    	REG_H					0x0C        /*   H     */
#define     REG_M					0x0A        /*   -     */
#define     REG_L					0x0D        /*   L     */#define		REG_DECODE				0x09        /*译码方式寄存器            */
#define		REG_INTENSITY			0x0A        /*亮度寄存器                */
#define		REG_LIMIT				0x0B        /*扫描界限寄存器            */
#define		REG_SHUTDOWN			0x0C        /*停机寄存器                */
#define		REG_DISPTEST			0x0F        /*显示测试寄存器            */
#define		REG_NO_OP               0xF0		/*不进行操作寄存器          */#define     DECODE_MODE_NO_DECODE       0x00
#define     DECODE_MODE_BCD_FOR_DIGIT0  0x01
#define     DECODE_MODE_BCD_FOR_DIGIT0_TO_DIGIT3 0x0F
#define     DECODE_MODE_BCD_FOR_ALL_DIGIT		 0xFF#define		INTENSITY_1_32           0x00
#define		INTENSITY_3_32           0x01
#define		INTENSITY_5_32           0x02
#define		INTENSITY_7_32           0x03
#define		INTENSITY_9_32           0x04
#define		INTENSITY_11_32          0x05
#define		INTENSITY_13_32          0x06
#define		INTENSITY_15_32          0x07
#define		INTENSITY_17_32          0x08
#define		INTENSITY_19_32          0x09
#define		INTENSITY_21_32          0x0A
#define		INTENSITY_23_32          0x0B
#define		INTENSITY_25_32          0x0C
#define		INTENSITY_27_32          0x0D
#define		INTENSITY_29_32          0x0E
#define		INTENSITY_31_32          0x0F#define     SCAN_LIMIT_DIG0			 0x00
#define     SCAN_LIMIT_DIG01		 0x01
#define     SCAN_LIMIT_DIG012		 0x02
#define     SCAN_LIMIT_DIG0123		 0x03
#define     SCAN_LIMIT_DIG01234		 0x04
#define     SCAN_LIMIT_DIG012345	 0x05
#define     SCAN_LIMIT_DIG0123456	 0x06
#define     SCAN_LIMIT_DIG01234567	 0x07#define		SHUTDOWN_SHUTDOWN		 0x00
#define		SHUTDOWN_NORMAL			 0x01#define		DISPLAY_TEST_NORMAL		 0x00
#define		DISPLAY_TEST_TEST		 0x01//----- No-Decode Mode Data Bits and Corresponding Segment Lines ------------
//--------- Standard 7-Segment LED ---------------------
//                A
//               ___
//			  F |   | B
//              |_G_|
//				|   | 
//			  E	|___| C
//				  D     。DP
//--------- Register data ------------------------------
#define     LED_SEG_G                    0x01  /* D0 */
#define     LED_SEG_F                    0x02  /* D1 */
#define     LED_SEG_E                    0x04  /* D2 */
#define     LED_SEG_D                    0x08  /* D3 */
#define     LED_SEG_C                    0x10  /* D4 */
#define     LED_SEG_B                    0x20  /* D5 */
#define     LED_SEG_A                    0x40  /* D6 */
#define     LED_SEG_DP                   0x80  /* D7 *///
// normal macro
//
#define     NULL_OP                 (u16)((REG_NO_OP<<8)&0xFF00)/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void SPI_Max7219_Init(void);
void IniFourMax7219(void);
void SPI_Max7219_SendFourWord(s32* pEightLedData);/* Private functions ---------------------------------------------------------*//*******************************************************************************
* Function Name  : SPI_Max7219_Init
* Description    : Initializes the peripherals used by the Max7219 driver.
* Input          : None
* Output         : None
* Return         : None
*
* 
* 2009/02/20 更改备注:
* (1)SPI_BaudRatePrescaler 之前一直设置为最保守的“SPI_BaudRatePrescaler_256”,
* 改为“SPI_BaudRatePrescaler_2”测试。
*******************************************************************************/
void SPI_Max7219_Init(void)
{SPI_InitTypeDef  SPI_InitStructure;GPIO_InitTypeDef GPIO_InitStructure;/* Enable SPI1 and GPIOA clocks */RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 | RCC_APB2Periph_GPIOA, ENABLE);/* Configure SPI1 pins: NSS, SCK, MISO and MOSI */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_Init(GPIOA, &GPIO_InitStructure);/* Configure PA.4 as Output push-pull, used as Flash Chip select */GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_Init(GPIOA, &GPIO_InitStructure);/* SPI1 configuration */ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;SPI_InitStructure.SPI_Mode = SPI_Mode_Master;SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b/*SPI_DataSize_8b*/;SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;	 // okSPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; // okSPI_InitStructure.SPI_NSS = SPI_NSS_Soft ;// = SPI_NSS_Hard 时 MAX7219不能工作 !!!!!SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; /*  SPI_BaudRatePrescaler_2    只有第一个MAX7219正常,其他都不正常(无论是15元的还是5元)SPI_BaudRatePrescaler_4    在接4个5元的MAX7219S,极不稳定SPI_BaudRatePrescaler_32   改为:5元的, 不太稳定,有时某个LED会灭或全8888SPI_BaudRatePrescaler_64   测试中SPI_BaudRatePrescaler_128  8个LED后面的显示有些延迟 */SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;SPI_InitStructure.SPI_CRCPolynomial = 7;SPI_Init(SPI1, &SPI_InitStructure);/* Enable SPI1 TXE interrupt *///SPI_I2S_ITConfig( SPI1, SPI_I2S_IT_TXE, ENABLE);/* Enable SPI1  */SPI_Cmd(SPI1, ENABLE);   /* 由于MAX7219在NSS的上升沿处开始锁存数据,所以在初始化MAX7219时先置为高,在传送数据之前,再置为低,当传送数据完成后再置高,即锁存入MAX7219*/SPI_NSS_HIGH();
}/*******************************************************************************
* Function Name  : IniFourMax7219
* Description    : Initializes board Max7219 
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void IniFourMax7219(void)
{int i;u8 ucs[10] = { 	REG_DECODE,    0xFF, // 8个Digit都使能译码 0-8REG_INTENSITY, 0x06, // 25/32REG_LIMIT,     0x07, // 只扫描0-3 DIGITREG_SHUTDOWN,  0x01, // (0)Shutdown Mode ; (1)Normal OperationREG_DISPTEST,  0x00	 // (0)Normal Operation Mode ; (1)Display Test Mode};SPI_Max7219_Init();// 给4个MAX7219发送第一个初始化命令SPI_NSS_LOW();// while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[0]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[1]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[0]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[1]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[0]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[1]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[0]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[1]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);// 拉高SS,通知MAX7219将移位Register(16bit)的数据锁存起来。SPI_NSS_HIGH();//for(i=0;i<10000;i++);// 给4个MAX7219发送第二个初始化命令SPI_NSS_LOW();// while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[2]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[3]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[2]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[3]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[2]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[3]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[2]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[3]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);	// 拉高SS,通知MAX7219将移位Register(16bit)的数据锁存起来。SPI_NSS_HIGH();for(i=0;i<100;i++);// 给4个MAX7219发送第三个初始化命令SPI_NSS_LOW();// while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[4]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[5]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[4]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[5]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[4]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[5]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[4]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[5]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);	// 拉高SS,通知MAX7219将移位Register(16bit)的数据锁存起来。SPI_NSS_HIGH();for(i=0;i<100;i++);// 给4个MAX7219发送第四个初始化命令SPI_NSS_LOW();// while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[6]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[7]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[6]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[7]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[6]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[7]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[6]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[7]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);	// 拉高SS,通知MAX7219将移位Register(16bit)的数据锁存起来。SPI_NSS_HIGH();for(i=0;i<100;i++);// 给4个MAX7219发送第五个初始化命令SPI_NSS_LOW();// while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[8]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[9]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[8]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[9]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[8]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[9]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[8]);	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);			SPI_I2S_SendData(SPI1,ucs[9]);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);	// 拉高SS,通知MAX7219将移位Register(16bit)的数据锁存起来。SPI_NSS_HIGH();
}/*******************************************************************************
* Function Name  : void IniMax7219s(void)
* Description    : Initializes board Max7219 
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void IniMax7219s(void)
{s32 i;SPI_Max7219_Init();for (i=0;i<999999;i++); // Ini First Max7219MAX7219_SendDataToFirstMax7219(REG_DECODE, DECODE_MODE_NO_DECODE);		// Decode Mode//for (i=0;i<99999;i++);MAX7219_SendDataToFirstMax7219(REG_INTENSITY, INTENSITY_31_32);			// Intensity//for (i=0;i<99999;i++);MAX7219_SendDataToFirstMax7219(REG_LIMIT, SCAN_LIMIT_DIG01234567);      // Scan Limit//for (i=0;i<99999;i++);MAX7219_SendDataToFirstMax7219(REG_SHUTDOWN, SHUTDOWN_NORMAL);          // Shutdown//for (i=0;i<99999;i++);MAX7219_SendDataToFirstMax7219(REG_DISPTEST, DISPLAY_TEST_NORMAL);        //Display TestMAX7219_Send4BitNum(0,0);MAX7219_Send4BitNum(1,1);MAX7219_SendDataToSecMax7219(REG_DECODE, DECODE_MODE_NO_DECODE);		// Decode Mode//for (i=0;i<99999;i++);MAX7219_SendDataToSecMax7219(REG_INTENSITY, INTENSITY_31_32);			// Intensity//for (i=0;i<99999;i++);MAX7219_SendDataToSecMax7219(REG_LIMIT, SCAN_LIMIT_DIG01234567);      // Scan Limit//for (i=0;i<99999;i++);MAX7219_SendDataToSecMax7219(REG_SHUTDOWN, SHUTDOWN_NORMAL);          // Shutdown//for (i=0;i<99999;i++);MAX7219_SendDataToSecMax7219(REG_DISPTEST, DISPLAY_TEST_NORMAL);        //Display TestMAX7219_Send4BitNum(2,0);MAX7219_Send4BitNum(3,1);MAX7219_SendDataToThirdMax7219(REG_DECODE, DECODE_MODE_NO_DECODE);		// Decode Mode//for (i=0;i<99999;i++);MAX7219_SendDataToThirdMax7219(REG_INTENSITY, INTENSITY_31_32);			// Intensity//for (i=0;i<99999;i++);MAX7219_SendDataToThirdMax7219(REG_LIMIT, SCAN_LIMIT_DIG01234567);      // Scan Limit//for (i=0;i<99999;i++);MAX7219_SendDataToThirdMax7219(REG_SHUTDOWN, SHUTDOWN_NORMAL);          // Shutdown//for (i=0;i<99999;i++);MAX7219_SendDataToThirdMax7219(REG_DISPTEST, DISPLAY_TEST_NORMAL);        //Display TestMAX7219_SendDataToThirdMax7219(REG_DIGIT0, 1);MAX7219_Send4BitNum(4,4);MAX7219_Send4BitNum(5,5);MAX7219_SendDataToFourMax7219(REG_DECODE, DECODE_MODE_NO_DECODE);		// Decode Mode//for (i=0;i<99999;i++);MAX7219_SendDataToFourMax7219(REG_INTENSITY, INTENSITY_31_32);			// Intensity//for (i=0;i<99999;i++);MAX7219_SendDataToFourMax7219(REG_LIMIT, SCAN_LIMIT_DIG01234567);      // Scan Limit//for (i=0;i<99999;i++);MAX7219_SendDataToFourMax7219(REG_SHUTDOWN, SHUTDOWN_NORMAL);          // Shutdown//for (i=0;i<99999;i++);MAX7219_SendDataToFourMax7219(REG_DISPTEST, DISPLAY_TEST_NORMAL);        //Display TestMAX7219_Send4BitNum(6,6);MAX7219_Send4BitNum(7,7);
}/*******************************************************************************
* Function Name  : SPI_Max7219_SendFourWord
* Description    : 发送 data TO 4个 max7219
* Input          : s32* pEightLedData 指针指向一个s32数据类型的一维数组(8个成员变量,每个成员变量的位数=4)
*                : 形如:s32 unitPrice1[8] = {1111,2222,3333,4444,5555,6666,7777,8888};
*                : 数入指针的和 board 中的LED实际对应关系
*                : EightLedData[0] <-> LED1 : EightLedData[1] <-> LED2 ... EightLedData[7] <-> LED8
* Output         : None
* Return         : None
*******************************************************************************/
void SPI_Max7219_SendFourWord(s32* pEightLedData)
{/* variable define -------------------------------------------*/s32 i;          // 用于迭代二维数组中的第1维s32 j;			// 用于迭代二维数组中的第2维s32 m;			// 用于分解算法u8  leds[4][8]; // 用于SPI的发送暂存u8 digit[8];    // 用于暂存分解之后的位值s32 temp;	    // 用于分解算法/* Get u8 array for send ------------------------------------*/for (i=0,m=0;i<4;i++,m+=2){/* 分解整数算法 -----------------------------------------*/temp = pEightLedData[m+1];			digit[4] = temp/1000;  // 得到千位temp %= 1000;digit[5] = temp/100;   // 得到百位temp %= 100;digit[6] = temp/10;    // 得到十位digit[7] = temp%10;    // 得到个位temp = pEightLedData[m];digit[0] = temp/1000;  // 得到千位temp %= 1000;digit[1] = temp/100;   // 得到百位temp %= 100;digit[2] =temp/10;     // 得到十位digit[3] = temp%10;    // 得到个位/* 存到SPI发送用到的二维数组中 --------------------------*/for (j=0;j<8;j++){leds[i][j] = digit[j];}}/* data Send ------------------------------------------------*/for(i=7;i>=0;i--){	SPI_NSS_LOW();for(j=3;j>=0;j--){while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1,i+1 );	while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, leds[j][i]);				} while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_NSS_HIGH();}
}/*******************************************************************************
* Function Name  : void MAX7219_SendDataToFirstMax7219(u8 Reg, u8 data)
* Description    : 发送由 寄存器地址和BYTE数据组合成的u16数据FRAME到第一个MAX7219
*
* Input          : Reg-对应MAX7219的寄存器的地址;data-对应发送的数据
*                 
* Output         : None
* Return         : None
*******************************************************************************/
void MAX7219_SendDataToFirstMax7219(u8 Reg, u8 data)
{//u32 i;u16 temp1;u16 temp2;temp1 = (u16)Reg;temp2 = (u16)data;temp1<<=8;temp1 &= 0xFF00;temp2 &= 0x00FF;temp1 |= temp2;SPI_NSS_LOW();while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);//for (i=0;i<999;i++);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);//for (i=0;i<999;i++);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);//for (i=0;i<999;i++);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, temp1);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_NSS_HIGH();
}/*******************************************************************************
* Function Name  : void MAX7219_SendDataToSecMax7219(u8 Reg, u8 data)
*
* Description    : 发送由 寄存器地址和BYTE数据组合成的u16数据FRAME到第一个MAX7219
*
* Input          : Reg-对应MAX7219的寄存器的地址;data-对应发送的数据
*                 
* Output         : None
* Return         : None
*******************************************************************************/
void MAX7219_SendDataToSecMax7219(u8 Reg, u8 data)
{//u32 i;u16 temp1;u16 temp2;temp1 = (u16)Reg;temp2 = (u16)data;temp1<<=8;temp1 &= 0xFF00;temp2 &= 0x00FF;temp1 |= temp2;SPI_NSS_LOW();while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);//for (i=0;i<999;i++);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);//for (i=0;i<999;i++);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, temp1);//for (i=0;i<999;i++);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_NSS_HIGH();
}/*******************************************************************************
* Function Name  : void MAX7219_SendDataToThirdMax7219(u8 Reg, u8 data)
*
* Description    : 发送由 寄存器地址和BYTE数据组合成的u16数据FRAME到第一个MAX7219
*
* Input          : Reg-对应MAX7219的寄存器的地址;data-对应发送的数据
*                 
* Output         : None
* Return         : None
*******************************************************************************/
void MAX7219_SendDataToThirdMax7219(u8 Reg, u8 data)
{u16 temp1;u16 temp2;temp1 = (u16)Reg;temp2 = (u16)data;temp1<<=8;temp1 &= 0xFF00;temp2 &= 0x00FF;temp1 |= temp2;SPI_NSS_LOW();while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, temp1);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_NSS_HIGH();
}/*******************************************************************************
* Function Name  : void MAX7219_SendDataToFourMax7219(u8 Reg, u8 data)
*
* Description    : 发送由 寄存器地址和BYTE数据组合成的u16数据FRAME到第一个MAX7219
*
* Input          : Reg-对应MAX7219的寄存器的地址;data-对应发送的数据
*                 
* Output         : None
* Return         : None
*******************************************************************************/
void MAX7219_SendDataToFourMax7219(u8 Reg, u8 data)
{u16 temp1;u16 temp2;temp1 = (u16)Reg;temp2 = (u16)data;temp1<<=8;temp1 &= 0xFF00;temp2 &= 0x00FF;temp1 |= temp2;SPI_NSS_LOW();while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, temp1);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_I2S_SendData(SPI1, NULL_OP);while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);SPI_NSS_HIGH();
}/*
*********************************************************************************************************
*					            	u8 MAX7219_LedBitCoding(u8 data)
*
* Description  : 把输入的数据编码为MAX7219要求的LED 标准码
*
* Argument     : (IN) u8 data // 0、1、2、3、4、5、6、7、8、9在LED中显示0-9
*							  // A-A ; B-小数点 ; D-Dark
* 
*			
* Returns	   : SM_TRUE - 定时时间到		SM_FALSE - 定时时间未到
*********************************************************************************************************
* Version 1.0
* Author: qzm
*/
u8 MAX7219_LedBitCoding(u8 data)
{u8 ret;switch ((u16)data){case 0x00:ret = LED_SEG_A|LED_SEG_B|LED_SEG_C|LED_SEG_D|LED_SEG_E|LED_SEG_F;break;case 0x01:ret = LED_SEG_B|LED_SEG_C;break;case 0x02:ret = LED_SEG_A|LED_SEG_B|LED_SEG_G|LED_SEG_E|LED_SEG_D;break;case 0x03:ret = LED_SEG_A|LED_SEG_B|LED_SEG_G|LED_SEG_C|LED_SEG_D;break;case 0x04:ret = LED_SEG_F|LED_SEG_G|LED_SEG_B|LED_SEG_C;break;case 0x05:ret = LED_SEG_A|LED_SEG_F|LED_SEG_G|LED_SEG_C|LED_SEG_D;break;case 0x06:ret = LED_SEG_A|LED_SEG_F|LED_SEG_E|LED_SEG_C|LED_SEG_D|LED_SEG_G;break;case 0x07:ret = LED_SEG_A|LED_SEG_B|LED_SEG_C;break;case 0x08:ret = LED_SEG_A|LED_SEG_B|LED_SEG_C|LED_SEG_D|LED_SEG_E|LED_SEG_F|LED_SEG_G;break;case 0x09:ret = LED_SEG_A|LED_SEG_B|LED_SEG_C|LED_SEG_D|LED_SEG_F|LED_SEG_G;break;case 0x0A:ret = LED_SEG_A|LED_SEG_F|LED_SEG_E|LED_SEG_B|LED_SEG_C|LED_SEG_G;break;case 0x0B: // 小数点ret = LED_SEG_DP;break;case 0x0C:ret = LED_SEG_A|LED_SEG_F|LED_SEG_E|LED_SEG_D;break;case 0x0D: // Darkret = 0;break;case 0x0E:ret = LED_SEG_A|LED_SEG_F|LED_SEG_E|LED_SEG_D|LED_SEG_G;break;case 0x0F:ret = LED_SEG_A|LED_SEG_F|LED_SEG_E|LED_SEG_G;break;case 0x10: // Low line    _ret = LED_SEG_D;break;case 0x11: // Middle line -ret = LED_SEG_G;break;case 0x12: // Height line ~ret = LED_SEG_A;break;default:ret = 0x00;break;}return ret;
}/*
*********************************************************************************************************
*							void MAX7219_SPI_Send4BitNum(u8 LedIndex, u16 data)
*
* Descript : 使 指定的4Bit LED 显示 十进制 0000 - 9999的数值 或 其他编码显示
* 
* Param(s) :
* (in)	 	 u8 LedIndex   - 从近RS485-1开始数 0、1、2、3、...7
* (in)       u16 data      - 待显示的十进制整数或其他显示编码
* (out)    : none
* (return) : none
*********************************************************************************************************
* NOTE:输入的 data 只能显示 0000-9999的数字范围,当data >= 0xF000时,表示要显示其他编码 
* data = 0xF000 显示: DARK
*/
void MAX7219_Send4BitNum(u8 LedIndex, u16 data)
{/* variable define ----------------------------------------------------*/u8 digit[4];  // 用于暂存分解之后的位值u16 temp;     // 用于分解算法
//	u8 leds;      // 用于SPI的发送暂存if ( data<=9999 ) // 显示十进制数字{/* --------------------------------------------------------------------*/temp = data;digit[0] = temp/1000;    // 得到千位temp    %= 1000;digit[1] = temp/100;     // 得到百位temp    %= 100;digit[2] = temp/10;		 // 得到十位digit[3] = temp%10;      // 得到个位switch (LedIndex){case 0: // LED0MAX7219_SendDataToFirstMax7219(REG_DIGIT0, MAX7219_LedBitCoding(digit[0]));MAX7219_SendDataToFirstMax7219(REG_DIGIT1, MAX7219_LedBitCoding(digit[1]));MAX7219_SendDataToFirstMax7219(REG_DIGIT2, MAX7219_LedBitCoding(digit[2]));MAX7219_SendDataToFirstMax7219(REG_DIGIT3, MAX7219_LedBitCoding(digit[3]));break;case 1: // LED1MAX7219_SendDataToFirstMax7219(REG_DIGIT4, MAX7219_LedBitCoding(digit[0]));MAX7219_SendDataToFirstMax7219(REG_DIGIT5, MAX7219_LedBitCoding(digit[1]));MAX7219_SendDataToFirstMax7219(REG_DIGIT6, MAX7219_LedBitCoding(digit[2]));MAX7219_SendDataToFirstMax7219(REG_DIGIT7, MAX7219_LedBitCoding(digit[3]));break;case 2: // LED2MAX7219_SendDataToSecMax7219(REG_DIGIT0, MAX7219_LedBitCoding(digit[0]));MAX7219_SendDataToSecMax7219(REG_DIGIT1, MAX7219_LedBitCoding(digit[1]));MAX7219_SendDataToSecMax7219(REG_DIGIT2, MAX7219_LedBitCoding(digit[2]));MAX7219_SendDataToSecMax7219(REG_DIGIT3, MAX7219_LedBitCoding(digit[3]));break;case 3: // LED3MAX7219_SendDataToSecMax7219(REG_DIGIT4, MAX7219_LedBitCoding(digit[0]));MAX7219_SendDataToSecMax7219(REG_DIGIT5, MAX7219_LedBitCoding(digit[1]));MAX7219_SendDataToSecMax7219(REG_DIGIT6, MAX7219_LedBitCoding(digit[2]));MAX7219_SendDataToSecMax7219(REG_DIGIT7, MAX7219_LedBitCoding(digit[3]));break;case 4: // LED4MAX7219_SendDataToThirdMax7219(REG_DIGIT0, MAX7219_LedBitCoding(digit[0]));MAX7219_SendDataToThirdMax7219(REG_DIGIT1, MAX7219_LedBitCoding(digit[1]));MAX7219_SendDataToThirdMax7219(REG_DIGIT2, MAX7219_LedBitCoding(digit[2]));MAX7219_SendDataToThirdMax7219(REG_DIGIT3, MAX7219_LedBitCoding(digit[3]));break;case 5: // LED5MAX7219_SendDataToThirdMax7219(REG_DIGIT4, MAX7219_LedBitCoding(digit[0]));MAX7219_SendDataToThirdMax7219(REG_DIGIT5, MAX7219_LedBitCoding(digit[1]));MAX7219_SendDataToThirdMax7219(REG_DIGIT6, MAX7219_LedBitCoding(digit[2]));MAX7219_SendDataToThirdMax7219(REG_DIGIT7, MAX7219_LedBitCoding(digit[3]));break;case 6: // LED6MAX7219_SendDataToFourMax7219(REG_DIGIT0, MAX7219_LedBitCoding(digit[0]));MAX7219_SendDataToFourMax7219(REG_DIGIT1, MAX7219_LedBitCoding(digit[1]));MAX7219_SendDataToFourMax7219(REG_DIGIT2, MAX7219_LedBitCoding(digit[2]));MAX7219_SendDataToFourMax7219(REG_DIGIT3, MAX7219_LedBitCoding(digit[3]));break;case 7: // LED7MAX7219_SendDataToFourMax7219(REG_DIGIT4, MAX7219_LedBitCoding(digit[0]));MAX7219_SendDataToFourMax7219(REG_DIGIT5, MAX7219_LedBitCoding(digit[1]));MAX7219_SendDataToFourMax7219(REG_DIGIT6, MAX7219_LedBitCoding(digit[2]));MAX7219_SendDataToFourMax7219(REG_DIGIT7, MAX7219_LedBitCoding(digit[3]));break;default:break;}/* switch (LedIndex) */}/* if ( (data>=0)||(data<=9999) ) // 显示十进制数字 */else if (data==0xF000) // 显示 DARK{MAX7219_Send4BitDark(LedIndex);}}/*
*********************************************************************************************************
*							void MAX7219_Send4BitDark(u8 LedIndex)
*
* Descript : 使 指定的4Bit LED 全世界DARK
* 
* Param(s) :
* (in)	 	 u8 LedIndex   - 从近RS485-1开始数 0、1、2、3、...7
* (out)    : none
* (return) : none
*********************************************************************************************************
*/
void MAX7219_Send4BitDark(u8 LedIndex)
{
#define LED_DARK	0x0Dswitch (LedIndex){case 0: // LED0MAX7219_SendDataToFirstMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFirstMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFirstMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFirstMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_DARK));break;case 1: // LED1MAX7219_SendDataToFirstMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFirstMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFirstMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFirstMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_DARK));break;case 2: // LED2MAX7219_SendDataToSecMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToSecMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToSecMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToSecMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_DARK));break;case 3: // LED3MAX7219_SendDataToSecMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToSecMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToSecMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToSecMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_DARK));break;case 4: // LED4MAX7219_SendDataToThirdMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToThirdMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToThirdMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToThirdMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_DARK));break;case 5: // LED5MAX7219_SendDataToThirdMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToThirdMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToThirdMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToThirdMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_DARK));break;case 6: // LED6MAX7219_SendDataToFourMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFourMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFourMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFourMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_DARK));break;case 7: // LED7MAX7219_SendDataToFourMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFourMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFourMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_DARK));MAX7219_SendDataToFourMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_DARK));break;default:break;}
}/*
*********************************************************************************************************
*							void MAX7219_Send4BitLow(u8 LedIndex)
*
* Descript : 使 指定的4Bit LED显示低 LINE
* 
* Param(s) :
* (in)	 	 u8 LedIndex   - 从近RS485-1开始数 0、1、2、3、...7
* (out)    : none
* (return) : none
*********************************************************************************************************
*/
void MAX7219_Send4BitLow(u8 LedIndex)
{
#define LED_LOW_LINE	0x10switch (LedIndex){case 0: // LED0MAX7219_SendDataToFirstMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_LOW_LINE));break;case 1: // LED1MAX7219_SendDataToFirstMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_LOW_LINE));break;case 2: // LED2MAX7219_SendDataToSecMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_LOW_LINE));break;case 3: // LED3MAX7219_SendDataToSecMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_LOW_LINE));break;case 4: // LED4MAX7219_SendDataToThirdMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_LOW_LINE));break;case 5: // LED5MAX7219_SendDataToThirdMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_LOW_LINE));break;case 6: // LED6MAX7219_SendDataToFourMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_LOW_LINE));break;case 7: // LED7MAX7219_SendDataToFourMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_LOW_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_LOW_LINE));break;default:break;}
}/*
*********************************************************************************************************
*							void MAX7219_Send4BitMiddle(u8 LedIndex)
*
* Descript : 使 指定的4Bit LED显示中 LINE
* 
* Param(s) :
* (in)	 	 u8 LedIndex   - 从近RS485-1开始数 0、1、2、3、...7
* (out)    : none
* (return) : none
*********************************************************************************************************
*/
void MAX7219_Send4BitMiddle(u8 LedIndex)
{
#define LED_MIDDLE_LINE	0x11switch (LedIndex){case 0: // LED0MAX7219_SendDataToFirstMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_MIDDLE_LINE));break;case 1: // LED1MAX7219_SendDataToFirstMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_MIDDLE_LINE));break;case 2: // LED2MAX7219_SendDataToSecMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_MIDDLE_LINE));break;case 3: // LED3MAX7219_SendDataToSecMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_MIDDLE_LINE));break;case 4: // LED4MAX7219_SendDataToThirdMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_MIDDLE_LINE));break;case 5: // LED5MAX7219_SendDataToThirdMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_MIDDLE_LINE));break;case 6: // LED6MAX7219_SendDataToFourMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_MIDDLE_LINE));break;case 7: // LED7MAX7219_SendDataToFourMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_MIDDLE_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_MIDDLE_LINE));break;default:break;}
}/*
*********************************************************************************************************
*							void MAX7219_Send4BitHeight(u8 LedIndex)
*
* Descript : 使 指定的4Bit LED显示高 LINE
* 
* Param(s) :
* (in)	 	  u8 LedIndex   - 从近RS485-1开始数 0、1、2、3、...7
* (out)    : none
* (return) : none
*********************************************************************************************************
*/
void MAX7219_Send4BitHeight(u8 LedIndex)
{
#define LED_HEIGHT_LINE	0x12switch (LedIndex){case 0: // LED0MAX7219_SendDataToFirstMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_HEIGHT_LINE));break;case 1: // LED1MAX7219_SendDataToFirstMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFirstMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_HEIGHT_LINE));break;case 2: // LED2MAX7219_SendDataToSecMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_HEIGHT_LINE));break;case 3: // LED3MAX7219_SendDataToSecMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToSecMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_HEIGHT_LINE));break;case 4: // LED4MAX7219_SendDataToThirdMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_HEIGHT_LINE));break;case 5: // LED5MAX7219_SendDataToThirdMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToThirdMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_HEIGHT_LINE));break;case 6: // LED6MAX7219_SendDataToFourMax7219(REG_DIGIT0, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT1, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT2, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT3, MAX7219_LedBitCoding(LED_HEIGHT_LINE));break;case 7: // LED7MAX7219_SendDataToFourMax7219(REG_DIGIT4, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT5, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT6, MAX7219_LedBitCoding(LED_HEIGHT_LINE));MAX7219_SendDataToFourMax7219(REG_DIGIT7, MAX7219_LedBitCoding(LED_HEIGHT_LINE));break;default:break;}
}/*
*********************************************************************************************************
*                     void MAX7219_IntensityAdjust(u8 MAX7219Index, u8 IntensityValue)
*
* Descript : 调节指定 MAX7219 的亮度
* 
* Param(s) :
* (in)	 	 u8 MAX7219Index   - 从近RS485-1开始数 0、1、2、3
* (in)       u8 IntensityValue - 亮度代码;从0x00-0x0F,共16种亮度选择 
* (out)    : none
* (return) : none
*********************************************************************************************************
*/
void MAX7219_IntensityAdjust(u8 MAX7219Index, u8 IntensityValue/* 0x00-0x0F */)
{switch (MAX7219Index){case 0: // MAX7219_0MAX7219_SendDataToFirstMax7219(REG_INTENSITY, IntensityValue);break;case 1: // MAX7219_1MAX7219_SendDataToSecMax7219(REG_INTENSITY, IntensityValue);break;case 2: // MAX7219_2MAX7219_SendDataToThirdMax7219(REG_INTENSITY, IntensityValue);break;case 3: // MAX7219_3MAX7219_SendDataToFourMax7219(REG_INTENSITY, IntensityValue);break;default:break;}
}void MAX7219_CloseAllLedDisplay(void)
{MAX7219_SendDataToFirstMax7219(REG_SHUTDOWN, SHUTDOWN_SHUTDOWN);          // ShutdownMAX7219_SendDataToSecMax7219(REG_SHUTDOWN,   SHUTDOWN_SHUTDOWN);          // ShutdownMAX7219_SendDataToThirdMax7219(REG_SHUTDOWN, SHUTDOWN_SHUTDOWN);          // ShutdownMAX7219_SendDataToFourMax7219(REG_SHUTDOWN,  SHUTDOWN_SHUTDOWN);          // Shutdown
}void MAX7219_OpenAllLedDisplay(void)
{MAX7219_SendDataToFirstMax7219(REG_SHUTDOWN, SHUTDOWN_NORMAL);          // ShutdownMAX7219_SendDataToSecMax7219(REG_SHUTDOWN,   SHUTDOWN_NORMAL);          // ShutdownMAX7219_SendDataToThirdMax7219(REG_SHUTDOWN, SHUTDOWN_NORMAL);          // ShutdownMAX7219_SendDataToFourMax7219(REG_SHUTDOWN,  SHUTDOWN_NORMAL);          // Shutdown
}/*******************************************************************************
* Function Name  : SPI_FLASH_ReadID
* Description    : Reads FLASH identification.
* Input          : None
* Output         : None
* Return         : FLASH identification
*******************************************************************************/
//u32 SPI_FLASH_ReadID(void)
//{
//	u32 Temp = 0, Temp0 = 0, Temp1 = 0, Temp2 = 0;/* Select the FLASH: Chip Select low */
//	SPI_FLASH_CS_LOW();/* Send "RDID " instruction */
///	SPI_FLASH_SendByte(0x9F);/* Read a byte from the FLASH */
//Temp0 = SPI_FLASH_SendByte(Dummy_Byte);/* Read a byte from the FLASH */
//	Temp1 = SPI_FLASH_SendByte(Dummy_Byte);/* Read a byte from the FLASH */
//	Temp2 = SPI_FLASH_SendByte(Dummy_Byte);/* Deselect the FLASH: Chip Select high */
//	SPI_FLASH_CS_HIGH();//	Temp = (Temp0 << 16) | (Temp1 << 8) | Temp2;//	return Temp;
//}/*******************************************************************************
* Function Name  : SPI_FLASH_StartReadSequence
* Description    : Initiates a read data byte (READ) sequence from the Flash.
*                  This is done by driving the /CS line low to select the device,
*                  then the READ instruction is transmitted followed by 3 bytes
*                  address. This function exit and keep the /CS line low, so the
*                  Flash still being selected. With this technique the whole
*                  content of the Flash is read with a single READ instruction.
* Input          : - ReadAddr : FLASH's internal address to read from.
* Output         : None
* Return         : None
*******************************************************************************/
// void SPI_FLASH_StartReadSequence(u32 ReadAddr)
// {
// 	/* Select the FLASH: Chip Select low */
// 	//SPI_FLASH_CS_LOW();
// 
// 	/* Send "Read from Memory " instruction */
// 	//SPI_FLASH_SendByte(READ);
// 
// 	/* Send the 24-bit address of the address to read from -----------------------*/  
// 	/* Send ReadAddr high nibble address byte */
// 	SPI_FLASH_SendByte((ReadAddr & 0xFF0000) >> 16);
// 	/* Send ReadAddr medium nibble address byte */
// 	SPI_FLASH_SendByte((ReadAddr& 0xFF00) >> 8);
// 	/* Send ReadAddr low nibble address byte */
// 	SPI_FLASH_SendByte(ReadAddr & 0xFF);
// }/*******************************************************************************
* Function Name  : SPI_FLASH_ReadByte
* Description    : Reads a byte from the SPI Flash.
*                  This function must be used only if the Start_Read_Sequence
*                  function has been previously called.
* Input          : None
* Output         : None
* Return         : Byte Read from the SPI Flash.
*******************************************************************************/
//u8 SPI_FLASH_ReadByte(void)
//{
//	return (SPI_FLASH_SendByte(Dummy_Byte));
//}/*******************************************************************************
* Function Name  : SPI_FLASH_SendByte
* Description    : Sends a byte through the SPI interface and return the byte 
*                  received from the SPI bus.
* Input          : byte : byte to send.
* Output         : None
* Return         : The value of the received byte.
*******************************************************************************/
//u8 SPI_FLASH_SendByte(u8 byte)
//{
//	/* Loop while DR register in not emplty */
//	while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET);/* Send byte through the SPI1 peripheral */
//	SPI_SendData(SPI1, byte);/* Wait to receive a byte */
//	while(SPI_GetFlagStatus(SPI1, SPI_FLAG_RXNE) == RESET);/* Return the byte read from the SPI bus */
//	return SPI_ReceiveData(SPI1);
//} /*******************************************************************************
* Function Name  : SPI_FLASH_SendHalfWord
* Description    : Sends a Half Word through the SPI interface and return the  
*                  Half Word received from the SPI bus.
* Input          : Half Word : Half Word to send.
* Output         : None
* Return         : The value of the received Half Word.
*******************************************************************************/
//u16 SPI_FLASH_SendHalfWord(u16 HalfWord)
//{
/* Loop while DR register in not emplty */
//	while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET);/* Send Half Word through the SPI1 peripheral */
//	SPI_SendData(SPI1, HalfWord);/* Wait to receive a Half Word */
//	while(SPI_GetFlagStatus(SPI1, SPI_FLAG_RXNE) == RESET);/* Return the Half Word read from the SPI bus */
//	return SPI_ReceiveData(SPI1);
//}/*******************************************************************************
* Function Name  : SPI_FLASH_WriteEnable
* Description    : Enables the write access to the FLASH.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
//void SPI_FLASH_WriteEnable(void)
//{
/* Select the FLASH: Chip Select low */
//	SPI_FLASH_CS_LOW();/* Send "Write Enable" instruction */
//	SPI_FLASH_SendByte(WREN);/* Deselect the FLASH: Chip Select high */
//	SPI_FLASH_CS_HIGH();
//}/*******************************************************************************
* Function Name  : SPI_FLASH_WaitForWriteEnd
* Description    : Polls the status of the Write In Progress (WIP) flag in the  
*                  FLASH's status  register  and  loop  until write  opertaion
*                  has completed.  
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
//void SPI_FLASH_WaitForWriteEnd(void)
//{
//	u8 FLASH_Status = 0;/* Select the FLASH: Chip Select low */
//	SPI_FLASH_CS_LOW();/* Send "Read Status Register" instruction */
//	SPI_FLASH_SendByte(RDSR);/* Loop as long as the memory is busy with a write cycle */
//	do
//	{
/* Send a dummy byte to generate the clock needed by the FLASH 
and put the value of the status register in FLASH_Status variable */
//		FLASH_Status = SPI_FLASH_SendByte(Dummy_Byte);//	} while((FLASH_Status & WIP_Flag) == SET); /* Write in progress *//* Deselect the FLASH: Chip Select high */
//	SPI_FLASH_CS_HIGH();                                                        
//}          /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

这篇关于MAX7219产品级驱动分享的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1094432

相关文章

Redis多种内存淘汰策略及配置技巧分享

《Redis多种内存淘汰策略及配置技巧分享》本文介绍了Redis内存满时的淘汰机制,包括内存淘汰机制的概念,Redis提供的8种淘汰策略(如noeviction、volatile-lru等)及其适用场... 目录前言一、什么是 Redis 的内存淘汰机制?二、Redis 内存淘汰策略1. pythonnoe

Golang操作DuckDB实战案例分享

《Golang操作DuckDB实战案例分享》DuckDB是一个嵌入式SQL数据库引擎,它与众所周知的SQLite非常相似,但它是为olap风格的工作负载设计的,DuckDB支持各种数据类型和SQL特性... 目录DuckDB的主要优点环境准备初始化表和数据查询单行或多行错误处理和事务完整代码最后总结Duck

将Python应用部署到生产环境的小技巧分享

《将Python应用部署到生产环境的小技巧分享》文章主要讲述了在将Python应用程序部署到生产环境之前,需要进行的准备工作和最佳实践,包括心态调整、代码审查、测试覆盖率提升、配置文件优化、日志记录完... 目录部署前夜:从开发到生产的心理准备与检查清单环境搭建:打造稳固的应用运行平台自动化流水线:让部署像

C#读取本地网络配置信息全攻略分享

《C#读取本地网络配置信息全攻略分享》在当今数字化时代,网络已深度融入我们生活与工作的方方面面,对于软件开发而言,掌握本地计算机的网络配置信息显得尤为关键,而在C#编程的世界里,我们又该如何巧妙地读取... 目录一、引言二、C# 读取本地网络配置信息的基础准备2.1 引入关键命名空间2.2 理解核心类与方法

Golang使用etcd构建分布式锁的示例分享

《Golang使用etcd构建分布式锁的示例分享》在本教程中,我们将学习如何使用Go和etcd构建分布式锁系统,分布式锁系统对于管理对分布式系统中共享资源的并发访问至关重要,它有助于维护一致性,防止竞... 目录引言环境准备新建Go项目实现加锁和解锁功能测试分布式锁重构实现失败重试总结引言我们将使用Go作

Python中列表的高级索引技巧分享

《Python中列表的高级索引技巧分享》列表是Python中最常用的数据结构之一,它允许你存储多个元素,并且可以通过索引来访问这些元素,本文将带你深入了解Python列表的高级索引技巧,希望对... 目录1.基本索引2.切片3.负数索引切片4.步长5.多维列表6.列表解析7.切片赋值8.删除元素9.反转列表

Python中处理NaN值的技巧分享

《Python中处理NaN值的技巧分享》在数据科学和数据分析领域,NaN(NotaNumber)是一个常见的概念,它表示一个缺失或未定义的数值,在Python中,尤其是在使用pandas库处理数据时,... 目录NaN 值的来源和影响使用 pandas 的 isna()和 isnull()函数直接比较 Na

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用

【专题】2024飞行汽车技术全景报告合集PDF分享(附原数据表)

原文链接: https://tecdat.cn/?p=37628 6月16日,小鹏汇天旅航者X2在北京大兴国际机场临空经济区完成首飞,这也是小鹏汇天的产品在京津冀地区进行的首次飞行。小鹏汇天方面还表示,公司准备量产,并计划今年四季度开启预售小鹏汇天分体式飞行汽车,探索分体式飞行汽车城际通勤。阅读原文,获取专题报告合集全文,解锁文末271份飞行汽车相关行业研究报告。 据悉,业内人士对飞行汽车行业

Linux_kernel驱动开发11

一、改回nfs方式挂载根文件系统         在产品将要上线之前,需要制作不同类型格式的根文件系统         在产品研发阶段,我们还是需要使用nfs的方式挂载根文件系统         优点:可以直接在上位机中修改文件系统内容,延长EMMC的寿命         【1】重启上位机nfs服务         sudo service nfs-kernel-server resta