-1

我有一个带有 24 个引脚的共阳极双色 LED 矩阵,想用一个微控制器驱动其中两个。所以我决定为此尝试 Max7219 驱动程序。但作为一个新手,我很难弄清楚该做什么,而且在线资源似乎以 arduino 为中心。我确实找到了Davide Gironi 开发的库。但它似乎与一个共同的阴极矩阵一起工作。所以我将行改为列以适应共阳极结构,但没有运气。你能给我一些线索,让我知道在哪里寻找解决方案吗?

4

1 回答 1

1

我会尝试先点亮一个 LED,然后在没有库的情况下点亮一行和一列。一旦你很好地理解了它是如何工作的,你可以自己编写一个库,或者在你正在使用的库中调整低级驱动固件。一旦你有了工作代码,你就可以调试库直到它工作。

这是一些伪代码。我对 Atmega 16 的确切功能不是很熟悉,但我相信您能够用正确的代码替换延迟和端口配置。

  #define CLOCK  PORT1.0 // Replace PORT1.x with proper port
  #define DIN    PORT1.1
  #define LOAD   PORT1.2
  #define nCS    PORT1.3

  void SetupIO()
  {
     //Set clock as an output
     //Set DIN as an output
     //Set LOAD as an output
     //Set nCS as an output
  }

  void DoClock()
  {
     CLOCK = 1;
     delay_us(1);
     CLOCK = 0;
     delay_us(1);
  }

  void WriteBits(char address, char data)
  {
     char i;
     // Set LOAD and nCS low
     LOAD = 0;
     nCS = 0;
     delay_us(1); // replace all delay functions/macros with proper delay macro

     // write address
     for( i = 7; i > 0 ; i--)
     {
        DIN = (address >> i) & 1;  // shift data to the proper bit
        delay_us(1);               // allow signal to settle
        DoClock();                 // clock the bit into the MAX7219
     }

     // write data
     for( i = 7; i > 0 ; i--)
     {
        DIN = (data >> i) & 1;     // shift data to the proper bit
        delay_us(1);
        DoClock();                 // clock the bit into the MAX7219
     }

     // Latch the address/data
     LOAD = 1;
     nCS = 1;
     delay_us(1);
     LOAD = 0;
     nCS = 0;
     delay_us(1);
  }

  void main()
  {
     SetupPins();

     // initialize display
     WriteBits(0x0C, 0x01); // Normal operation
     WriteBits(0x09, 0x00); // BCD decoder off
     WriteBits(0x0A, 0xFF); // Max intensity
     WriteBits(0x0B, 0x07); // Scan all digits

     //Test display 8, all digits on
     WriteBits(0x00, 0xff);
  }
于 2017-05-24T16:18:13.040 回答