日志档案

发表于 2006-10-20 7:45:31

3

标签: max7219  

max7219c语言驱动程序

//max7219 led drive program
//for 51 mcu
//designed by zhaoliang
//2005-6-12 13:52
#i nclude

/***********************************************************************/
//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
}

系统分类: 单片机   |   用户分类: 51单片机应用程序   |   来源: 原创   |   【推荐给朋友】

    阅读(1327)    回复(0)  

投一票您将和博主都有获奖机会!