极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 19650|回复: 7

Arduino 16*64LED屏滚动文字

[复制链接]
发表于 2013-5-30 22:29:49 | 显示全部楼层 |阅读模式
本帖最后由 conjee 于 2013-5-30 22:33 编辑

       以前买的一块16*64LED屏,行选采用两片595位移寄存器芯片级联,数据输出采用8片595位移寄存器芯片级联。
显示效果如下:



完整的代码如下:

  1. #define DataCLK 4
  2. #define DataOUT 3
  3. #define DataSTB 2
  4. #define DataEn 5

  5. #define RowCLK 10
  6. #define RowOUT 9
  7. #define RowSTB 8

  8. #define uchar unsigned char
  9. #define uint unsigned int
  10. uint K=1;  //移动速度控制变量。
  11. uchar col,disrow; //列移动计数变量。行扫描计数变量。
  12. uint words; //字形码计数变量。

  13. uchar BUFF[11]; //64列时应将数值设为11

  14. uchar HZ[]=
  15. {

  16. /*



  17. 0x00,0x00,  0xFF,0xC0,  0x00,0x40,  0x00,0x48,  
  18. 0x00,0x50,  0x00,0x60,  0x00,0x60,  0x00,0x50,  
  19. 0x00,0x48,  0x00,0x40,  0x00,0x20,  0x00,0x22,  
  20. 0x00,0x12,  0x00,0x0A,  0x00,0x06,  0x00,0x00,  
  21.   
  22. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
  23. 0x01,0x80,0x01,0x80,0x07,0xe0,0x01,0x80,
  24. 0x01,0x80,0x01,0x80,0x01,0x90,0x01,0x90,
  25. 0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,

  26. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
  27. 0x01,0x80,0x01,0x80,0x07,0xe0,0x01,0x80,
  28. 0x01,0x80,0x01,0x80,0x01,0x90,0x01,0x90,
  29. 0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,

  30. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31. 0x00,0x00,0x00,0x00,0x19,0xf0,0x06,0x18,
  32. 0x06,0x18,0x06,0x18,0x06,0x18,0x06,0x18,
  33. 0x07,0xe0,0x06,0x00,0x06,0x00,0x0f,0x00,

  34. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  35. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  36. 0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00,
  37. 0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00, */

  38. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  39. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  40. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  41. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  42. /* the following data and text is protected by Copyright law and international copyright treaty provisions! please don't copy or sale without Qinwenhao's authorization */
  43. /* @0 大(16x16,H)@ [suki software]*/
  44. 0x01,0x00,  0x01,0x00,  0x01,0x00,  0x01,0x00,  
  45. 0x01,0x00,  0xFF,0xFE,  0x01,0x00,  0x02,0x80,  
  46. 0x02,0x80,  0x02,0x40,  0x04,0x40,  0x04,0x20,  
  47. 0x08,0x10,  0x10,0x18,  0x20,0x0E,  0x40,0x04,  
  48. /* @1 家(16x16,H)@ [suki software]*/
  49. 0x02,0x00,  0x01,0x00,  0x3F,0xFE,  0x40,0x04,  
  50. 0x5F,0xE8,  0x01,0x00,  0x02,0x00,  0x0F,0x20,  
  51. 0x72,0xB0,  0x04,0xC0,  0x19,0xC0,  0x66,0xB0,  
  52. 0x18,0x8E,  0x60,0x84,  0x05,0x00,  0x02,0x00,  
  53. /* @2 好(16x16,H)@ [suki software]*/
  54. 0x10,0x00,  0x11,0xFC,  0x10,0x08,  0x10,0x10,  
  55. 0xFC,0x20,  0x24,0x20,  0x24,0x20,  0x27,0xFE,  
  56. 0x44,0x20,  0x64,0x20,  0x18,0x20,  0x08,0x20,  
  57. 0x14,0x20,  0x26,0x20,  0x44,0xA0,  0x80,0x40,  
  58. /* @3 这(16x16,H)@ [suki software]*/
  59. 0x00,0x80,  0x40,0x60,  0x30,0x40,  0x17,0xFC,  
  60. 0x00,0x10,  0x02,0x10,  0xF1,0x20,  0x10,0xA0,  
  61. 0x10,0x40,  0x10,0x40,  0x10,0xA0,  0x11,0x10,  
  62. 0x12,0x08,  0x28,0x00,  0x47,0xFE,  0x80,0x00,  
  63. /* @4 是(16x16,H)@ [suki software]*/
  64. 0x00,0x00,  0x0F,0xF0,  0x08,0x10,  0x0F,0xF0,  
  65. 0x08,0x10,  0x0F,0xF0,  0x00,0x00,  0xFF,0xFE,  
  66. 0x01,0x00,  0x09,0x00,  0x09,0xF8,  0x09,0x00,  
  67. 0x15,0x00,  0x23,0x00,  0x40,0xFE,  0x00,0x00,  
  68. /* @5 一(16x16,H)@ [suki software]*/
  69. 0x00,0x00,  0x00,0x00,  0x00,0x00,  0x00,0x00,  
  70. 0x00,0x00,  0x00,0x00,  0x00,0x04,  0x7F,0xFE,  
  71. 0x00,0x00,  0x00,0x00,  0x00,0x00,  0x00,0x00,  
  72. 0x00,0x00,  0x00,0x00,  0x00,0x00,  0x00,0x00,  
  73. /* @6 个(16x16,H)@ [suki software]*/
  74. 0x01,0x00,  0x01,0x00,  0x02,0x80,  0x02,0x40,  
  75. 0x04,0x20,  0x09,0x18,  0x11,0x0E,  0x61,0x04,  
  76. 0x01,0x00,  0x01,0x00,  0x01,0x00,  0x01,0x00,  
  77. 0x01,0x00,  0x01,0x00,  0x01,0x00,  0x00,0x00,  
  78. /* @7 字(16x16,H)@ [suki software]*/
  79. 0x02,0x00,  0x01,0x00,  0x3F,0xFC,  0x20,0x04,  
  80. 0x40,0x08,  0x1F,0xE0,  0x00,0x40,  0x00,0x80,  
  81. 0x01,0x00,  0x7F,0xFE,  0x01,0x00,  0x01,0x00,  
  82. 0x01,0x00,  0x01,0x00,  0x05,0x00,  0x02,0x00,  
  83. /* @8 幕(16x16,H)@ [suki software]*/
  84. 0x04,0x40,  0xFF,0xFE,  0x04,0x40,  0x1F,0xF0,  
  85. 0x10,0x10,  0x1F,0xF0,  0x10,0x10,  0x1F,0xF0,  
  86. 0x02,0x00,  0xFF,0xFE,  0x09,0x10,  0x1F,0xE8,  
  87. 0x29,0x26,  0xC9,0x24,  0x09,0x60,  0x01,0x00,  
  88.   

  89. /* @4 張(16x16,H)@ [suki software]
  90. 0x00,0x00,  0xF8,0xFC,  0x08,0x80,  0x08,0xF8,  
  91. 0x08,0x80,  0x78,0xF8,  0x40,0x80,  0x47,0xFE,  
  92. 0x41,0x40,  0x79,0x24,  0x09,0x28,  0x09,0x10,  
  93. 0x09,0x08,  0x09,0x44,  0x51,0x82,  0x21,0x00,  
  94. @5 曉(16x16,H)@ [suki software]
  95. 0x00,0x20,  0x00,0x20,  0x79,0xFC,  0x48,0x20,  
  96. 0x4B,0xFE,  0x49,0x08,  0x7B,0x9C,  0x49,0x08,  
  97. 0x49,0x88,  0x4E,0x3E,  0x48,0x00,  0x7B,0xFE,  
  98. 0x48,0x90,  0x00,0x90,  0x01,0x12,  0x02,0x0E,  
  99. @6 軍(16x16,H)@ [suki software]
  100. 0x00,0x00,  0x7F,0xFE,  0x41,0x02,  0x81,0x04,  
  101. 0x3F,0xF8,  0x01,0x00,  0x1F,0xF0,  0x11,0x10,  
  102. 0x1F,0xF0,  0x11,0x10,  0x1F,0xF0,  0x01,0x00,  
  103. 0xFF,0xFE,  0x01,0x00,  0x01,0x00,  0x01,0x00,  */



  104. //============================================================================
  105. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  106. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  107. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  108. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  109. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  110. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  111. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  112. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

  113. };

  114. byte rowSel[]={0x00, 0x01,
  115.                0x00, 0x02,
  116.                0x00, 0x04,
  117.                0x00, 0x08,
  118.                0x00, 0x10,
  119.                0x00, 0x20,
  120.                0x00, 0x40,
  121.                0x00, 0x80,
  122.                0x01, 0x00,
  123.                0x02, 0x00,
  124.                0x04, 0x00,
  125.                0x08, 0x00,
  126.                0x10, 0x00,
  127.                0x20, 0x00,
  128.                0x40, 0x00,
  129.                0x80, 0x00};
  130.                
  131.   String inputString = "";         // a string to hold incoming data
  132. boolean stringComplete = false;  // whether the string is complete
  133.             
  134. void setup(){
  135.   
  136.    Serial.begin(9600);

  137.     pinMode(DataCLK, OUTPUT);
  138.     pinMode(DataOUT, OUTPUT);
  139.     pinMode(DataSTB, OUTPUT);
  140.     pinMode(DataEn, OUTPUT);
  141.    
  142.     pinMode(RowCLK, OUTPUT);
  143.     pinMode(RowOUT, OUTPUT);
  144.     pinMode(RowSTB, OUTPUT);
  145.     digitalWrite(DataEn, 0);
  146.    
  147.    inputString.reserve(200);
  148.     delay(10);  
  149.    // establishContact();
  150. }

  151. /*
  152.   SerialEvent occurs whenever a new data comes in the
  153. hardware serial RX.  This routine is run between each
  154. time loop() runs, so using delay inside loop can delay
  155. response.  Multiple bytes of data may be available.
  156. */
  157. void serialEvent() {
  158.   while (Serial.available()) {
  159.     K=1000;
  160.     // get the new byte:
  161.     char inChar = (char)Serial.read();
  162.     // add it to the inputString:
  163.     inputString += inChar;
  164.     // if the incoming character is a newline, set a flag
  165.     // so the main loop can do something about it:
  166.     if (inChar == 'e') {
  167.       stringComplete = true;
  168.     }
  169.   }
  170. }

  171. void establishContact() {
  172.   while (Serial.available() <= 0) {
  173.     Serial.print('A');   // send a capital A
  174.     delay(300);
  175.   }
  176. }

  177. /********************************************/
  178. void hc595_write_data(uchar data_ds,  int CLK, int OUT)
  179. {
  180.         uchar n_bit;
  181.         uchar a;
  182.         for(n_bit=0;n_bit<8;n_bit++)
  183.         {
  184.              digitalWrite(CLK,0);
  185.          
  186.             a=data_ds&0x80;
  187.             a=!a;
  188.             digitalWrite(OUT, a);
  189.             data_ds=data_ds<<1;

  190.             digitalWrite(CLK,1);  

  191.         }
  192. }
  193.        

  194. /**
  195. 显示数据生成模块:(功能相当于有返回值的函数)
  196. ***********************************************************************************************************************/
  197. uchar two_onebyte(uchar h1,uchar h2)
  198. {
  199.   uchar temp,tempcol;//输出变量;列移动位数变量。
  200.   if(col<8)
  201.         tempcol=col;
  202.     else
  203.         tempcol=col-8;
  204.     temp=(h1<<tempcol)|(h2>>(8-tempcol));//左移显示
  205.     //temp=(h1>>tempcol)|(h2<<(8-tempcol));//右移显示
  206.     //temp=255-temp;//若字模为阴码则不用此句
  207.     return temp;//将显示数据返回显示输出函数。
  208. }

  209. /*************************************************************************************
  210. 待显示数据调取函数
  211. *************************************************************************************/
  212. void loadoneline(void)
  213. {
  214.   char s;//此处不要用uchar定义s
  215.    for(s=0;s<5;s++)//s值为屏数加1(16*16为一屏)
  216.    {
  217.    BUFF[2*s]   =  HZ[words+32*s+2*disrow];
  218.    BUFF[2*s+1] =  HZ[words+1+32*s+2*disrow];//左移显示
  219.    //BUFF[2*s+1]=HZ[words+32*s+2*disrow];
  220.    // BUFF[2*s]=HZ[words+1+32*s+2*disrow];//右移显示
  221.    }
  222. }

  223. /*************************************************************************************
  224. 显示数据输出函数 : 为显示数据生成模块的h1、h2赋值并且输出合成后的新的h1、h2数据
  225. *************************************************************************************/
  226. void sendoneline(void)
  227. {
  228.   char s;
  229.   uchar inc;
  230.   if(col<8)
  231.     inc=0;
  232.   else
  233.     inc=1;
  234.   //for(s=7+inc;s>=0+inc;s--){  //左移显示 :单屏s=1+,4屏s=7+,8屏s=15+;
  235.     for(s=0+inc;s<8+inc;s++){//右移显示
  236.       hc595_write_data(two_onebyte(BUFF[s], BUFF[s+1]), DataCLK, DataOUT);
  237.     // hc595_write_data(BUFF[s], DataCLK, DataOUT);
  238.   }
  239. }

  240. void loop(){
  241.   
  242.     digitalWrite(RowSTB, 0);         
  243.     digitalWrite(DataSTB, 0);   
  244.     digitalWrite(DataCLK, 0);         
  245.     digitalWrite(RowCLK, 0);
  246.     col = 0;
  247.     words=0;
  248. while(1){
  249.   

  250.   

  251.       while(col < 16){
  252.           uchar i;
  253.           for(i=0; i<K; i++){
  254.                 for(disrow=0; disrow < 16; disrow++){ //1
  255.                        if (Serial.available()) {
  256.                             // get the new byte:
  257.                             char inChar = (char)Serial.read();
  258.                             // add it to the inputString:
  259.                             inputString += inChar;
  260.                             // if the incoming character is a newline, set a flag
  261.                             // so the main loop can do something about it:
  262.                             if (inChar == 'e') {
  263.                                   if(K < 30){
  264.                                     K+=3;
  265.                                   }else{
  266.                                     K = 1;
  267.                                   }
  268.                               }
  269.                         }
  270.                       loadoneline();
  271.                       sendoneline();
  272.                       hc595_write_data(rowSel[disrow*2] ,   RowCLK,  RowOUT);
  273.                       hc595_write_data(rowSel[disrow*2+1] , RowCLK,  RowOUT);
  274.                       digitalWrite(RowSTB, 0);      //595刷新               
  275.                       digitalWrite(RowSTB, 1);
  276.                       digitalWrite(DataEn, 1);
  277.                       digitalWrite(DataSTB, 0);      //595刷新               
  278.                             digitalWrite(DataSTB, 1);        
  279.                       digitalWrite(DataEn, 0);
  280.                             delayMicroseconds(300) ;   //节电用,   
  281.                 }
  282.           }
  283.           col++;  
  284.       }  
  285.       
  286.       col=0;
  287.       words=words+32;
  288.       if(words>=288)
  289.           words=0;//(字数-4)×32 其中字数为汉字、标点符号、其他符号的总和
  290.   }
  291. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-5-30 23:11:55 | 显示全部楼层
很好,我也有好多这种屏,下次去玩玩
回复 支持 反对

使用道具 举报

发表于 2013-5-31 08:37:10 | 显示全部楼层
你这屏什么接口呢,接线图发来看看吧
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-31 11:10:23 | 显示全部楼层
本帖最后由 conjee 于 2013-5-31 11:11 编辑
duocool 发表于 2013-5-31 08:37
你这屏什么接口呢,接线图发来看看吧




结合程序与arduino接口:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2013-10-21 13:56:40 | 显示全部楼层
很强大,没用arduino的spi接口吧  ?
回复 支持 反对

使用道具 举报

发表于 2013-10-21 16:41:00 来自手机 | 显示全部楼层
关注一下,有这方面的用途
回复 支持 反对

使用道具 举报

发表于 2015-6-9 13:58:50 | 显示全部楼层
楼主大大,求模块的原理图!![email protected]
回复 支持 反对

使用道具 举报

发表于 2015-6-10 13:58:50 | 显示全部楼层
有没有人用字库芯片来控制的,就不用取模了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-29 18:19 , Processed in 0.063669 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表