MAX7219程序显示程序



      #include<reg51.h> 

      #define  HIGH     1

      #define  LOW      0

      #define  TRUE      1

      #define  FALSE      0

      #define  ZERO      0 

      #define  MSB       0x80

      #define  LSB       0x01

      #define  DECODE_MODE   0x09 

      #define  INTENSITY     0x0A 

      #define  SCAN_LIMIT    0x0B 

      #define  SHUT_DOWN     0x0C 

      #define  DISPLAY_TEST  0x0F 

 #define uchar unsigned char

      sbit DIN=P1^1; //MAX7219    Serial-Data Input:   rising edge  pin 1

      sbit LOAD=P1^2; //MAX7219    Load-Data Input:    rising edge  pin 12 

      sbit CLK=P1^3; //MAX7219   Serial-Clock Input:  maximum 10MHz  pin 13

      void Write_Max7219_byte(unsigned char temp);//write max7219 a byte

      void Write_Max7219a(uchar address1,dat1);

      void Write_Max7219b(uchar address2,dat2);

      void Init_Max7219(void);//Initize max7219

      void main(void)

      {

        Init_Max7219();  

      Write_Max7219a(0x01,0x00);  

        Write_Max7219a(0x02,0x00);  

        Write_Max7219a(0x03,0x00);  

        Write_Max7219a(0x04,0x00);  

        Write_Max7219a(0x05,0x02);  

        Write_Max7219a(0x06,0x02);  

        Write_Max7219a(0x07,0x02);  

        Write_Max7219a(0x08,0x02);

  

    Write_Max7219b(0x01,0x09);  

        Write_Max7219b(0x02,0x01);  

        Write_Max7219b(0x03,0x08);  

        Write_Max7219b(0x04,0x02);  

        Write_Max7219b(0x05,0x07);  

        Write_Max7219b(0x06,0x03);  

        Write_Max7219b(0x07,0x06);  

        Write_Max7219b(0x08,0x04);  

     

        

      }

/***********************************************************************/

void Write_Max7219_byte(unsigned char temp)

{

 unsigned char i;

 for (i=1;i<9;i++)     

  { 

   CLK=LOW;

     DIN=(bit)(temp&MSB);      

     temp<<=1;  

     CLK=HIGH;

   }

}

/***********************************************************************/

 void Write_Max7219a(uchar address1,dat1)

   LOAD=LOW;

   Write_Max7219_byte(address1); 

   Write_Max7219_byte(dat1);

   LOAD=HIGH;                 

}

 void Write_Max7219b(uchar address2,dat2)

   LOAD=LOW;

   Write_Max7219_byte(address2); 

   Write_Max7219_byte(dat2);

   LOAD=HIGH;                 

}

/***********************************************************************/

void Init_Max7219(void)      

 Write_Max7219a(SHUT_DOWN, 0x01);      //0x0C  关闭

 Write_Max7219b(SHUT_DOWN, 0x01);      //0x0C

 Write_Max7219a(DISPLAY_TEST, 0x00);   //0x0F  显示测试

 Write_Max7219b(DISPLAY_TEST, 0x00);   //0x0F

 Write_Max7219a(DECODE_MODE, 0xff);    //0x09  译码方式

 Write_Max7219b(DECODE_MODE, 0xff);    //0x09 

 Write_Max7219a(SCAN_LIMIT, 0x07);     //0x0B  扫描界限

 Write_Max7219b(SCAN_LIMIT, 0x07);     //0x0B 

 Write_Max7219a(INTENSITY, 0x04);      //0x0A  亮度

 Write_Max7219a(INTENSITY, 0x0a);      //0x0A 

}

      #include<reg51.h> 

      #define  HIGH     1

      #define  LOW      0

      #define  TRUE      1

      #define  FALSE      0

      #define  ZERO      0 

      #define  MSB       0x80

      #define  LSB       0x01

      #define  DECODE_MODE   0x09 

      #define  INTENSITY     0x0A 

      #define  SCAN_LIMIT    0x0B 

      #define  SHUT_DOWN     0x0C 

      #define  DISPLAY_TEST  0x0F 

 #define uchar unsigned char

      sbit DIN=P1^1; //MAX7219    Serial-Data Input:   rising edge  pin 1

      sbit LOAD=P1^2; //MAX7219    Load-Data Input:    rising edge  pin 12 

      sbit CLK=P1^3; //MAX7219   Serial-Clock Input:  maximum 10MHz  pin 13

      void Write_Max7219_byte(unsigned char temp);//write max7219 a byte

      void Write_Max7219a(uchar address1,dat1);

      void Write_Max7219b(uchar address2,dat2);

      void Init_Max7219(void);//Initize max7219

      void main(void)

      {

        Init_Max7219();  

      Write_Max7219a(0x01,0x00);  

        Write_Max7219a(0x02,0x00);  

        Write_Max7219a(0x03,0x00);  

        Write_Max7219a(0x04,0x00);  

        Write_Max7219a(0x05,0x02);  

        Write_Max7219a(0x06,0x02);  

        Write_Max7219a(0x07,0x02);  

        Write_Max7219a(0x08,0x02);

  

    Write_Max7219b(0x01,0x09);  

        Write_Max7219b(0x02,0x01);  

        Write_Max7219b(0x03,0x08);  

        Write_Max7219b(0x04,0x02);  

        Write_Max7219b(0x05,0x07);  

        Write_Max7219b(0x06,0x03);  

        Write_Max7219b(0x07,0x06);  

        Write_Max7219b(0x08,0x04);  

     

        

      }

/***********************************************************************/

void Write_Max7219_byte(unsigned char temp)

{

 unsigned char i;

 for (i=1;i<9;i++)     

  { 

   CLK=LOW;

     DIN=(bit)(temp&MSB);      

     temp<<=1;  

     CLK=HIGH;

   }

}

/***********************************************************************/

 void Write_Max7219a(uchar address1,dat1)

   LOAD=LOW;

   Write_Max7219_byte(address1); 

   Write_Max7219_byte(dat1);

   LOAD=HIGH;                 

}

 void Write_Max7219b(uchar address2,dat2)

   LOAD=LOW;

   Write_Max7219_byte(address2); 

   Write_Max7219_byte(dat2);

   LOAD=HIGH;                 

}

/***********************************************************************/

void Init_Max7219(void)      

 Write_Max7219a(SHUT_DOWN, 0x01);      //0x0C  关闭

 Write_Max7219b(SHUT_DOWN, 0x01);      //0x0C

 Write_Max7219a(DISPLAY_TEST, 0x00);   //0x0F  显示测试

 Write_Max7219b(DISPLAY_TEST, 0x00);   //0x0F

 Write_Max7219a(DECODE_MODE, 0xff);    //0x09  译码方式

 Write_Max7219b(DECODE_MODE, 0xff);    //0x09 

 Write_Max7219a(SCAN_LIMIT, 0x07);     //0x0B  扫描界限

 Write_Max7219b(SCAN_LIMIT, 0x07);     //0x0B 

 Write_Max7219a(INTENSITY, 0x04);      //0x0A  亮度

 Write_Max7219a(INTENSITY, 0x0a);      //0x0A 

}




      #include<reg51.h> 

      #define  HIGH     1

      #define  LOW      0

      #define  TRUE      1

      #define  FALSE      0

      #define  ZERO      0 

      #define  MSB       0x80

      #define  LSB       0x01

      #define  DECODE_MODE   0x09 

      #define  INTENSITY     0x0A 

      #define  SCAN_LIMIT    0x0B 

      #define  SHUT_DOWN     0x0C 

      #define  DISPLAY_TEST  0x0F 

 #define uchar unsigned char

      sbit DIN=P1^1; //MAX7219    Serial-Data Input:   rising edge  pin 1

      sbit LOAD=P1^2; //MAX7219    Load-Data Input:    rising edge  pin 12 

      sbit CLK=P1^3; //MAX7219   Serial-Clock Input:  maximum 10MHz  pin 13

      void Write_Max7219_byte(unsigned char temp);//write max7219 a byte

      void Write_Max7219a(uchar address1,dat1);

      void Write_Max7219b(uchar address2,dat2);

      void Init_Max7219(void);//Initize max7219

      void main(void)

      {

        Init_Max7219();  

      Write_Max7219a(0x01,0x00);  

        Write_Max7219a(0x02,0x00);  

        Write_Max7219a(0x03,0x00);  

        Write_Max7219a(0x04,0x00);  

        Write_Max7219a(0x05,0x02);  

        Write_Max7219a(0x06,0x02);  

        Write_Max7219a(0x07,0x02);  

        Write_Max7219a(0x08,0x02);

  

    Write_Max7219b(0x01,0x09);  

        Write_Max7219b(0x02,0x01);  

        Write_Max7219b(0x03,0x08);  

        Write_Max7219b(0x04,0x02);  

        Write_Max7219b(0x05,0x07);  

        Write_Max7219b(0x06,0x03);  

        Write_Max7219b(0x07,0x06);  

        Write_Max7219b(0x08,0x04);  

     

        

      }

/***********************************************************************/

void Write_Max7219_byte(unsigned char temp)

{

 unsigned char i;

 for (i=1;i<9;i++)     

  { 

   CLK=LOW;

     DIN=(bit)(temp&MSB);      

     temp<<=1;  

     CLK=HIGH;

   }

}

/***********************************************************************/

 void Write_Max7219a(uchar address1,dat1)

   LOAD=LOW;

   Write_Max7219_byte(address1); 

   Write_Max7219_byte(dat1);

   LOAD=HIGH;                 

}

 void Write_Max7219b(uchar address2,dat2)

   LOAD=LOW;

   Write_Max7219_byte(address2); 

   Write_Max7219_byte(dat2);

   LOAD=HIGH;                 

}

/***********************************************************************/

void Init_Max7219(void)      

 Write_Max7219a(SHUT_DOWN, 0x01);      //0x0C  关闭

 Write_Max7219b(SHUT_DOWN, 0x01);      //0x0C

 Write_Max7219a(DISPLAY_TEST, 0x00);   //0x0F  显示测试

 Write_Max7219b(DISPLAY_TEST, 0x00);   //0x0F

 Write_Max7219a(DECODE_MODE, 0xff);    //0x09  译码方式

 Write_Max7219b(DECODE_MODE, 0xff);    //0x09 

 Write_Max7219a(SCAN_LIMIT, 0x07);     //0x0B  扫描界限

 Write_Max7219b(SCAN_LIMIT, 0x07);     //0x0B 

 Write_Max7219a(INTENSITY, 0x04);      //0x0A  亮度

 Write_Max7219a(INTENSITY, 0x0a);      //0x0A 

}



      #include<reg51.h> 

      #define  HIGH     1

      #define  LOW      0

      #define  TRUE      1

      #define  FALSE      0

      #define  ZERO      0 

      #define  MSB       0x80

      #define  LSB       0x01

      #define  DECODE_MODE   0x09 

      #define  INTENSITY     0x0A 

      #define  SCAN_LIMIT    0x0B 

      #define  SHUT_DOWN     0x0C 

      #define  DISPLAY_TEST  0x0F 

 #define uchar unsigned char

      sbit DIN=P1^1; //MAX7219    Serial-Data Input:   rising edge  pin 1

      sbit LOAD=P1^2; //MAX7219    Load-Data Input:    rising edge  pin 12 

      sbit CLK=P1^3; //MAX7219   Serial-Clock Input:  maximum 10MHz  pin 13

      void Write_Max7219_byte(unsigned char temp);//write max7219 a byte

      void Write_Max7219a(uchar address1,dat1);

      void Write_Max7219b(uchar address2,dat2);

      void Init_Max7219(void);//Initize max7219

      void main(void)

      {

        Init_Max7219();  

      Write_Max7219a(0x01,0x00);  

        Write_Max7219a(0x02,0x00);  

        Write_Max7219a(0x03,0x00);  

        Write_Max7219a(0x04,0x00);  

        Write_Max7219a(0x05,0x02);  

        Write_Max7219a(0x06,0x02);  

        Write_Max7219a(0x07,0x02);  

        Write_Max7219a(0x08,0x02);

  

    Write_Max7219b(0x01,0x09);  

        Write_Max7219b(0x02,0x01);  

        Write_Max7219b(0x03,0x08);  

        Write_Max7219b(0x04,0x02);  

        Write_Max7219b(0x05,0x07);  

        Write_Max7219b(0x06,0x03);  

        Write_Max7219b(0x07,0x06);  

        Write_Max7219b(0x08,0x04);  

     

        

      }

/***********************************************************************/

void Write_Max7219_byte(unsigned char temp)

{

 unsigned char i;

 for (i=1;i<9;i++)     

  { 

   CLK=LOW;

     DIN=(bit)(temp&MSB);      

     temp<<=1;  

     CLK=HIGH;

   }

}

/***********************************************************************/

 void Write_Max7219a(uchar address1,dat1)

   LOAD=LOW;

   Write_Max7219_byte(address1); 

   Write_Max7219_byte(dat1);

   LOAD=HIGH;                 

}

 void Write_Max7219b(uchar address2,dat2)

   LOAD=LOW;

   Write_Max7219_byte(address2); 

   Write_Max7219_byte(dat2);

   LOAD=HIGH;                 

}

/***********************************************************************/

void Init_Max7219(void)      

 Write_Max7219a(SHUT_DOWN, 0x01);      //0x0C  关闭

 Write_Max7219b(SHUT_DOWN, 0x01);      //0x0C

 Write_Max7219a(DISPLAY_TEST, 0x00);   //0x0F  显示测试

 Write_Max7219b(DISPLAY_TEST, 0x00);   //0x0F

 Write_Max7219a(DECODE_MODE, 0xff);    //0x09  译码方式

 Write_Max7219b(DECODE_MODE, 0xff);    //0x09 

 Write_Max7219a(SCAN_LIMIT, 0x07);     //0x0B  扫描界限

 Write_Max7219b(SCAN_LIMIT, 0x07);     //0x0B 

 Write_Max7219a(INTENSITY, 0x04);      //0x0A  亮度

 Write_Max7219a(INTENSITY, 0x0a);      //0x0A 

}

      #include<reg51.h> 

      #define  HIGH     1

      #define  LOW      0

      #define  TRUE      1

      #define  FALSE      0

      #define  ZERO      0 

      #define  MSB       0x80

      #define  LSB       0x01

      #define  DECODE_MODE   0x09 

      #define  INTENSITY     0x0A 

      #define  SCAN_LIMIT    0x0B 

      #define  SHUT_DOWN     0x0C 

      #define  DISPLAY_TEST  0x0F 

 #define uchar unsigned char

      sbit DIN=P1^1; //MAX7219    Serial-Data Input:   rising edge  pin 1

      sbit LOAD=P1^2; //MAX7219    Load-Data Input:    rising edge  pin 12 

      sbit CLK=P1^3; //MAX7219   Serial-Clock Input:  maximum 10MHz  pin 13

      void Write_Max7219_byte(unsigned char temp);//write max7219 a byte

      void Write_Max7219a(uchar address1,dat1);

      void Write_Max7219b(uchar address2,dat2);

      void Init_Max7219(void);//Initize max7219

      void main(void)

      {

        Init_Max7219();  

      Write_Max7219a(0x01,0x00);  

        Write_Max7219a(0x02,0x00);  

        Write_Max7219a(0x03,0x00);  

        Write_Max7219a(0x04,0x00);  

        Write_Max7219a(0x05,0x02);  

        Write_Max7219a(0x06,0x02);  

        Write_Max7219a(0x07,0x02);  

        Write_Max7219a(0x08,0x02);

  

    Write_Max7219b(0x01,0x09);  

        Write_Max7219b(0x02,0x01);  

        Write_Max7219b(0x03,0x08);  

        Write_Max7219b(0x04,0x02);  

        Write_Max7219b(0x05,0x07);  

        Write_Max7219b(0x06,0x03);  

        Write_Max7219b(0x07,0x06);  

        Write_Max7219b(0x08,0x04);  

     

        

      }

/***********************************************************************/

void Write_Max7219_byte(unsigned char temp)

{

 unsigned char i;

 for (i=1;i<9;i++)     

  { 

   CLK=LOW;

     DIN=(bit)(temp&MSB);      

     temp<<=1;  

     CLK=HIGH;

   }

}

/***********************************************************************/

 void Write_Max7219a(uchar address1,dat1)

   LOAD=LOW;

   Write_Max7219_byte(address1); 

   Write_Max7219_byte(dat1);

   LOAD=HIGH;                 

}

 void Write_Max7219b(uchar address2,dat2)

   LOAD=LOW;

   Write_Max7219_byte(address2); 

   Write_Max7219_byte(dat2);

   LOAD=HIGH;                 

}

/***********************************************************************/

void Init_Max7219(void)      

 Write_Max7219a(SHUT_DOWN, 0x01);      //0x0C  关闭

 Write_Max7219b(SHUT_DOWN, 0x01);      //0x0C

 Write_Max7219a(DISPLAY_TEST, 0x00);   //0x0F  显示测试

 Write_Max7219b(DISPLAY_TEST, 0x00);   //0x0F

 Write_Max7219a(DECODE_MODE, 0xff);    //0x09  译码方式

 Write_Max7219b(DECODE_MODE, 0xff);    //0x09 

 Write_Max7219a(SCAN_LIMIT, 0x07);     //0x0B  扫描界限

 Write_Max7219b(SCAN_LIMIT, 0x07);     //0x0B 

 Write_Max7219a(INTENSITY, 0x04);      //0x0A  亮度

 Write_Max7219a(INTENSITY, 0x0a);      //0x0A 

}

      #include<reg51.h> 

      #define  HIGH     1

      #define  LOW      0

      #define  TRUE      1

      #define  FALSE      0

      #define  ZERO      0 

      #define  MSB       0x80

      #define  LSB       0x01

      #define  DECODE_MODE   0x09 

      #define  INTENSITY     0x0A 

      #define  SCAN_LIMIT    0x0B 

      #define  SHUT_DOWN     0x0C 

      #define  DISPLAY_TEST  0x0F 

 #define uchar unsigned char

      sbit DIN=P1^1; //MAX7219    Serial-Data Input:   rising edge  pin 1

      sbit LOAD=P1^2; //MAX7219    Load-Data Input:    rising edge  pin 12 

      sbit CLK=P1^3; //MAX7219   Serial-Clock Input:  maximum 10MHz  pin 13

      void Write_Max7219_byte(unsigned char temp);//write max7219 a byte

      void Write_Max7219a(uchar address1,dat1);

      void Write_Max7219b(uchar address2,dat2);

      void Init_Max7219(void);//Initize max7219

      void main(void)

      {

        Init_Max7219();  

      Write_Max7219a(0x01,0x00);  

        Write_Max7219a(0x02,0x00);  

        Write_Max7219a(0x03,0x00);  

        Write_Max7219a(0x04,0x00);  

        Write_Max7219a(0x05,0x02);  

        Write_Max7219a(0x06,0x02);  

        Write_Max7219a(0x07,0x02);  

        Write_Max7219a(0x08,0x02);

  

    Write_Max7219b(0x01,0x09);  

        Write_Max7219b(0x02,0x01);  

        Write_Max7219b(0x03,0x08);  

        Write_Max7219b(0x04,0x02);  

        Write_Max7219b(0x05,0x07);  

        Write_Max7219b(0x06,0x03);  

        Write_Max7219b(0x07,0x06);  

        Write_Max7219b(0x08,0x04);  

     

        

      }

/***********************************************************************/

void Write_Max7219_byte(unsigned char temp)

{

 unsigned char i;

 for (i=1;i<9;i++)     

  { 

   CLK=LOW;

     DIN=(bit)(temp&MSB);      

     temp<<=1;  

     CLK=HIGH;

   }

}

/***********************************************************************/

 void Write_Max7219a(uchar address1,dat1)

   LOAD=LOW;

   Write_Max7219_byte(address1); 

   Write_Max7219_byte(dat1);

   LOAD=HIGH;                 

}

 void Write_Max7219b(uchar address2,dat2)

   LOAD=LOW;

   Write_Max7219_byte(address2); 

   Write_Max7219_byte(dat2);

   LOAD=HIGH;                 

}

/***********************************************************************/

void Init_Max7219(void)      

 Write_Max7219a(SHUT_DOWN, 0x01);      //0x0C  关闭

 Write_Max7219b(SHUT_DOWN, 0x01);      //0x0C

 Write_Max7219a(DISPLAY_TEST, 0x00);   //0x0F  显示测试

 Write_Max7219b(DISPLAY_TEST, 0x00);   //0x0F

 Write_Max7219a(DECODE_MODE, 0xff);    //0x09  译码方式

 Write_Max7219b(DECODE_MODE, 0xff);    //0x09 

 Write_Max7219a(SCAN_LIMIT, 0x07);     //0x0B  扫描界限

 Write_Max7219b(SCAN_LIMIT, 0x07);     //0x0B 

 Write_Max7219a(INTENSITY, 0x04);      //0x0A  亮度

 Write_Max7219a(INTENSITY, 0x0a);      //0x0A 

}

猜你喜欢

转载自blog.csdn.net/czhaii/article/details/17881487
今日推荐