/***********************************************************************///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 boardsbit LOAD="P1"^2; //MAX7219 Load-Data Input: rising edge pin 12 sbit DIN="P1"^1; //MAX7219 Serial-Data Input: rising edge pin 1sbit CLK="P1"^0; //MAX7219 Serial-Clock Input: maximum 10MHz pin 13
//function define/***********************************************************************/void Write_Max7219_byte(unsigned char temp);//write max7219 a bytevoid Write_Max7219(unsigned char address,unsigned char dat);//write max7219 command and datavoid 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}
发布
用户383150 2010-11-1 09:48