⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 max7219.txt

📁 max7219 C语言驱动程序
💻 TXT
字号:
#i nclude<reg51.h>

/***********************************************************************/
//common part 
#define HIGH     1
#define LOW      0
#define TRUE      1
#define FALSE      0
#define ZERO      0 
#define MSB       0x80
#define LSB       0x01
//max7219 part
#define DECODE_MODE   0x09 
#define INTENSITY     0x0A 
#define SCAN_LIMIT    0x0B 
#define SHUT_DOWN     0x0C 
#define DISPLAY_TEST 0x0F

//pin defined
/***********************************************************************/
//change this part at different board
sbit LOAD=P1^2; //MAX7219    Load-Data Input:    rising edge pin 12 
sbit DIN=P1^1; //MAX7219    Serial-Data Input:   rising edge pin 1
sbit CLK=P1^0; //MAX7219   Serial-Clock Input: maximum 10MHz pin 13

//function define
/***********************************************************************/
void Write_Max7219_byte(unsigned char temp);//write max7219 a byte
void Write_Max7219(unsigned char address,unsigned char dat);//write max7219 command and data
void Init_Max7219(void);//Initize max7219

//test program display from 1~8
/***********************************************************************/
void main(void)
{
unsigned char i; 
Init_Max7219(); 
while(TRUE)
{ 
for(i=1;i<9;i++) 
{
   Write_Max7219(i,i);
}
} 
}
/***********************************************************************/
void Write_Max7219_byte(unsigned char temp)
{
unsigned char i;
for (i=0;i<8;i++)     
{ 
   CLK=LOW;
     DIN=(bit)(temp&MSB);      
     temp<<=1; 
     CLK=HIGH;
   }
}
/***********************************************************************/
void Write_Max7219(unsigned char address,unsigned char dat)
{ 
LOAD=LOW;
   Write_Max7219_byte(address); 
   Write_Max7219_byte(dat);
LOAD=HIGH;                 
}
/***********************************************************************/
void Init_Max7219(void)      
{ 
Write_Max7219(SHUT_DOWN, 0x01);   //Normal Operation XXXXXXX1 Shutdown Mode   XXXXXXXX0
Write_Max7219(DISPLAY_TEST, 0x00);   //Normal Operation XXXXXXX0 Display Test Mode XXXXXXXX1
Write_Max7219(DECODE_MODE, 0xff);   //Decode Mode Select D7~D0 1 B decode 0 No decode 
Write_Max7219(SCAN_LIMIT, 0x07);   //SCAN LIMIT 0~7 0xX0~0xX7
Write_Max7219(INTENSITY, 0x04);   //Set Intensity   0xX0~0xXf
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -