7219控制的8*8点阵程序,如何改成控制32*32(16个8*8)点阵的程序呢?

2019-07-15 16:42发布

如题,我需要做个32*32的点阵,所以买了16个7219控制的8*8模块,8*8对应的代码如下(代码是从网上找的,没试过)
  1. #include <reg52.h>
  2. #include <intrins.h>
  3. #define uchar unsigned char
  4. #define uint  unsigned int
  5. //定义Max7219端口
  6. sbit Max7219_pinCLK = P2^2;
  7. sbit Max7219_pinCS  = P2^1;
  8. sbit Max7219_pinDIN = P2^0;
  9. uchar code disp1[38][8]={
  10. {0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//0
  11. {0x10,0x18,0x14,0x10,0x10,0x10,0x10,0x10},//1
  12. {0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E},//2
  13. {0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0},//3
  14. {0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8},//4
  15. {0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0},//5
  16. {0x3C,0x20,0x20,0x3C,0x24,0x24,0x3C,0x0},//6
  17. {0x3E,0x22,0x4,0x8,0x8,0x8,0x8,0x8},//7
  18. {0x0,0x3E,0x22,0x22,0x3E,0x22,0x22,0x3E},//8
  19. {0x3E,0x22,0x22,0x3E,0x2,0x2,0x2,0x3E},//9
  20. {0x8,0x14,0x22,0x3E,0x22,0x22,0x22,0x22},//A
  21. {0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C,0x0},//B
  22. {0x3C,0x40,0x40,0x40,0x40,0x40,0x3C,0x0},//C
  23. {0x7C,0x42,0x42,0x42,0x42,0x42,0x7C,0x0},//D
  24. {0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C},//E
  25. {0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40},//F
  26. {0x3C,0x40,0x40,0x40,0x40,0x44,0x44,0x3C},//G
  27. {0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44},//H
  28. {0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C},//I
  29. {0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30},//J
  30. {0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24},//K
  31. {0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C},//L
  32. {0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81},//M
  33. {0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0},//N
  34. {0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//O
  35. {0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20},//P
  36. {0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D},//Q
  37. {0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21},//R
  38. {0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C},//S
  39. {0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8},//T
  40. {0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C},//U
  41. {0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18},//V
  42. {0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0},//W
  43. {0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41},//X
  44. {0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8},//Y
  45. {0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F},//Z
  46. {0x8,0x7F,0x49,0x49,0x7F,0x8,0x8,0x8},//中
  47. {0xFE,0xBA,0x92,0xBA,0x92,0x9A,0xBA,0xFE},//国
  48. };
  49. void Delay_xms(uint x)
  50. {
  51. uint i,j;
  52. for(i=0;i<x;i++)
  53.   for(j=0;j<112;j++);
  54. }
  55. //--------------------------------------------
  56. //功能:向MAX7219(U3)写入字节
  57. //入口参数:DATA
  58. //出口参数:无
  59. //说明:
  60. void Write_Max7219_byte(uchar DATA)         
  61. {
  62.             uchar i;   
  63.                 Max7219_pinCS=0;               
  64.             for(i=8;i>=1;i--)
  65.           {                  
  66.             Max7219_pinCLK=0;
  67.             Max7219_pinDIN=DATA&0x80;
  68.             DATA=DATA<<1;
  69.             Max7219_pinCLK=1;
  70.            }                                 
  71. }
  72. //-------------------------------------------
  73. //功能:向MAX7219写入数据
  74. //入口参数:address、dat
  75. //出口参数:无
  76. //说明:
  77. void Write_Max7219(uchar address,uchar dat)
  78. {
  79.      Max7219_pinCS=0;
  80.          Write_Max7219_byte(address);           //写入地址,即数码管编号
  81.      Write_Max7219_byte(dat);               //写入数据,即数码管显示数字
  82.          Max7219_pinCS=1;                        
  83. }

  84. void Init_MAX7219(void)
  85. {
  86. Write_Max7219(0x09, 0x00);       //译码方式:BCD码
  87. Write_Max7219(0x0a, 0x03);       //亮度
  88. Write_Max7219(0x0b, 0x07);       //扫描界限;8个数码管显示
  89. Write_Max7219(0x0c, 0x01);       //掉电模式:0,普通模式:1
  90. Write_Max7219(0x0f, 0x00);       //显示测试:1;测试结束,正常显示:0
  91. }
  92. void main(void)
  93. {
  94. uchar i,j;
  95. Delay_xms(50);
  96. Init_MAX7219();  
  97. while(1)
  98. {
  99.   for(j=0;j<38;j++)
  100.   {
  101.    for(i=1;i<9;i++)
  102.     Write_Max7219(i,disp1[j][i-1]);
  103.    Delay_xms(1000);
  104.   }  
  105. }
  106. }
复制代码求问大家,我如何改程序才能使它可以驱动32*32的点阵呢?




友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。