本帖最后由 conjee 于 2013-5-30 22:33 编辑
以前买的一块16*64LED屏,行选采用两片595位移寄存器芯片级联,数据输出采用8片595位移寄存器芯片级联。
显示效果如下:
完整的代码如下:
- #define DataCLK 4
- #define DataOUT 3
- #define DataSTB 2
- #define DataEn 5
- #define RowCLK 10
- #define RowOUT 9
- #define RowSTB 8
- #define uchar unsigned char
- #define uint unsigned int
- uint K=1; //移动速度控制变量。
- uchar col,disrow; //列移动计数变量。行扫描计数变量。
- uint words; //字形码计数变量。
- uchar BUFF[11]; //64列时应将数值设为11
- uchar HZ[]=
- {
- /*
-
-
-
- 0x00,0x00, 0xFF,0xC0, 0x00,0x40, 0x00,0x48,
- 0x00,0x50, 0x00,0x60, 0x00,0x60, 0x00,0x50,
- 0x00,0x48, 0x00,0x40, 0x00,0x20, 0x00,0x22,
- 0x00,0x12, 0x00,0x0A, 0x00,0x06, 0x00,0x00,
-
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
- 0x01,0x80,0x01,0x80,0x07,0xe0,0x01,0x80,
- 0x01,0x80,0x01,0x80,0x01,0x90,0x01,0x90,
- 0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
- 0x01,0x80,0x01,0x80,0x07,0xe0,0x01,0x80,
- 0x01,0x80,0x01,0x80,0x01,0x90,0x01,0x90,
- 0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x19,0xf0,0x06,0x18,
- 0x06,0x18,0x06,0x18,0x06,0x18,0x06,0x18,
- 0x07,0xe0,0x06,0x00,0x06,0x00,0x0f,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00,
- 0x30,0x00,0x30,0x00,0x00,0x00,0x00,0x00, */
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- /* 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 */
- /* @0 大(16x16,H)@ [suki software]*/
- 0x01,0x00, 0x01,0x00, 0x01,0x00, 0x01,0x00,
- 0x01,0x00, 0xFF,0xFE, 0x01,0x00, 0x02,0x80,
- 0x02,0x80, 0x02,0x40, 0x04,0x40, 0x04,0x20,
- 0x08,0x10, 0x10,0x18, 0x20,0x0E, 0x40,0x04,
- /* @1 家(16x16,H)@ [suki software]*/
- 0x02,0x00, 0x01,0x00, 0x3F,0xFE, 0x40,0x04,
- 0x5F,0xE8, 0x01,0x00, 0x02,0x00, 0x0F,0x20,
- 0x72,0xB0, 0x04,0xC0, 0x19,0xC0, 0x66,0xB0,
- 0x18,0x8E, 0x60,0x84, 0x05,0x00, 0x02,0x00,
- /* @2 好(16x16,H)@ [suki software]*/
- 0x10,0x00, 0x11,0xFC, 0x10,0x08, 0x10,0x10,
- 0xFC,0x20, 0x24,0x20, 0x24,0x20, 0x27,0xFE,
- 0x44,0x20, 0x64,0x20, 0x18,0x20, 0x08,0x20,
- 0x14,0x20, 0x26,0x20, 0x44,0xA0, 0x80,0x40,
- /* @3 这(16x16,H)@ [suki software]*/
- 0x00,0x80, 0x40,0x60, 0x30,0x40, 0x17,0xFC,
- 0x00,0x10, 0x02,0x10, 0xF1,0x20, 0x10,0xA0,
- 0x10,0x40, 0x10,0x40, 0x10,0xA0, 0x11,0x10,
- 0x12,0x08, 0x28,0x00, 0x47,0xFE, 0x80,0x00,
- /* @4 是(16x16,H)@ [suki software]*/
- 0x00,0x00, 0x0F,0xF0, 0x08,0x10, 0x0F,0xF0,
- 0x08,0x10, 0x0F,0xF0, 0x00,0x00, 0xFF,0xFE,
- 0x01,0x00, 0x09,0x00, 0x09,0xF8, 0x09,0x00,
- 0x15,0x00, 0x23,0x00, 0x40,0xFE, 0x00,0x00,
- /* @5 一(16x16,H)@ [suki software]*/
- 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
- 0x00,0x00, 0x00,0x00, 0x00,0x04, 0x7F,0xFE,
- 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
- 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00,
- /* @6 个(16x16,H)@ [suki software]*/
- 0x01,0x00, 0x01,0x00, 0x02,0x80, 0x02,0x40,
- 0x04,0x20, 0x09,0x18, 0x11,0x0E, 0x61,0x04,
- 0x01,0x00, 0x01,0x00, 0x01,0x00, 0x01,0x00,
- 0x01,0x00, 0x01,0x00, 0x01,0x00, 0x00,0x00,
- /* @7 字(16x16,H)@ [suki software]*/
- 0x02,0x00, 0x01,0x00, 0x3F,0xFC, 0x20,0x04,
- 0x40,0x08, 0x1F,0xE0, 0x00,0x40, 0x00,0x80,
- 0x01,0x00, 0x7F,0xFE, 0x01,0x00, 0x01,0x00,
- 0x01,0x00, 0x01,0x00, 0x05,0x00, 0x02,0x00,
- /* @8 幕(16x16,H)@ [suki software]*/
- 0x04,0x40, 0xFF,0xFE, 0x04,0x40, 0x1F,0xF0,
- 0x10,0x10, 0x1F,0xF0, 0x10,0x10, 0x1F,0xF0,
- 0x02,0x00, 0xFF,0xFE, 0x09,0x10, 0x1F,0xE8,
- 0x29,0x26, 0xC9,0x24, 0x09,0x60, 0x01,0x00,
-
- /* @4 張(16x16,H)@ [suki software]
- 0x00,0x00, 0xF8,0xFC, 0x08,0x80, 0x08,0xF8,
- 0x08,0x80, 0x78,0xF8, 0x40,0x80, 0x47,0xFE,
- 0x41,0x40, 0x79,0x24, 0x09,0x28, 0x09,0x10,
- 0x09,0x08, 0x09,0x44, 0x51,0x82, 0x21,0x00,
- @5 曉(16x16,H)@ [suki software]
- 0x00,0x20, 0x00,0x20, 0x79,0xFC, 0x48,0x20,
- 0x4B,0xFE, 0x49,0x08, 0x7B,0x9C, 0x49,0x08,
- 0x49,0x88, 0x4E,0x3E, 0x48,0x00, 0x7B,0xFE,
- 0x48,0x90, 0x00,0x90, 0x01,0x12, 0x02,0x0E,
- @6 軍(16x16,H)@ [suki software]
- 0x00,0x00, 0x7F,0xFE, 0x41,0x02, 0x81,0x04,
- 0x3F,0xF8, 0x01,0x00, 0x1F,0xF0, 0x11,0x10,
- 0x1F,0xF0, 0x11,0x10, 0x1F,0xF0, 0x01,0x00,
- 0xFF,0xFE, 0x01,0x00, 0x01,0x00, 0x01,0x00, */
- //============================================================================
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- };
- byte rowSel[]={0x00, 0x01,
- 0x00, 0x02,
- 0x00, 0x04,
- 0x00, 0x08,
- 0x00, 0x10,
- 0x00, 0x20,
- 0x00, 0x40,
- 0x00, 0x80,
- 0x01, 0x00,
- 0x02, 0x00,
- 0x04, 0x00,
- 0x08, 0x00,
- 0x10, 0x00,
- 0x20, 0x00,
- 0x40, 0x00,
- 0x80, 0x00};
-
- String inputString = ""; // a string to hold incoming data
- boolean stringComplete = false; // whether the string is complete
-
- void setup(){
-
- Serial.begin(9600);
-
- pinMode(DataCLK, OUTPUT);
- pinMode(DataOUT, OUTPUT);
- pinMode(DataSTB, OUTPUT);
- pinMode(DataEn, OUTPUT);
-
- pinMode(RowCLK, OUTPUT);
- pinMode(RowOUT, OUTPUT);
- pinMode(RowSTB, OUTPUT);
- digitalWrite(DataEn, 0);
-
- inputString.reserve(200);
- delay(10);
- // establishContact();
- }
- /*
- SerialEvent occurs whenever a new data comes in the
- hardware serial RX. This routine is run between each
- time loop() runs, so using delay inside loop can delay
- response. Multiple bytes of data may be available.
- */
- void serialEvent() {
- while (Serial.available()) {
- K=1000;
- // get the new byte:
- char inChar = (char)Serial.read();
- // add it to the inputString:
- inputString += inChar;
- // if the incoming character is a newline, set a flag
- // so the main loop can do something about it:
- if (inChar == 'e') {
- stringComplete = true;
- }
- }
- }
- void establishContact() {
- while (Serial.available() <= 0) {
- Serial.print('A'); // send a capital A
- delay(300);
- }
- }
- /********************************************/
- void hc595_write_data(uchar data_ds, int CLK, int OUT)
- {
- uchar n_bit;
- uchar a;
- for(n_bit=0;n_bit<8;n_bit++)
- {
- digitalWrite(CLK,0);
-
- a=data_ds&0x80;
- a=!a;
- digitalWrite(OUT, a);
- data_ds=data_ds<<1;
- digitalWrite(CLK,1);
- }
- }
-
- /**
- 显示数据生成模块:(功能相当于有返回值的函数)
- ***********************************************************************************************************************/
- uchar two_onebyte(uchar h1,uchar h2)
- {
- uchar temp,tempcol;//输出变量;列移动位数变量。
- if(col<8)
- tempcol=col;
- else
- tempcol=col-8;
- temp=(h1<<tempcol)|(h2>>(8-tempcol));//左移显示
- //temp=(h1>>tempcol)|(h2<<(8-tempcol));//右移显示
- //temp=255-temp;//若字模为阴码则不用此句
- return temp;//将显示数据返回显示输出函数。
- }
- /*************************************************************************************
- 待显示数据调取函数
- *************************************************************************************/
- void loadoneline(void)
- {
- char s;//此处不要用uchar定义s
- for(s=0;s<5;s++)//s值为屏数加1(16*16为一屏)
- {
- BUFF[2*s] = HZ[words+32*s+2*disrow];
- BUFF[2*s+1] = HZ[words+1+32*s+2*disrow];//左移显示
- //BUFF[2*s+1]=HZ[words+32*s+2*disrow];
- // BUFF[2*s]=HZ[words+1+32*s+2*disrow];//右移显示
- }
- }
- /*************************************************************************************
- 显示数据输出函数 : 为显示数据生成模块的h1、h2赋值并且输出合成后的新的h1、h2数据
- *************************************************************************************/
- void sendoneline(void)
- {
- char s;
- uchar inc;
- if(col<8)
- inc=0;
- else
- inc=1;
- //for(s=7+inc;s>=0+inc;s--){ //左移显示 :单屏s=1+,4屏s=7+,8屏s=15+;
- for(s=0+inc;s<8+inc;s++){//右移显示
- hc595_write_data(two_onebyte(BUFF[s], BUFF[s+1]), DataCLK, DataOUT);
- // hc595_write_data(BUFF[s], DataCLK, DataOUT);
- }
- }
- void loop(){
-
- digitalWrite(RowSTB, 0);
- digitalWrite(DataSTB, 0);
- digitalWrite(DataCLK, 0);
- digitalWrite(RowCLK, 0);
- col = 0;
- words=0;
- while(1){
-
-
-
- while(col < 16){
- uchar i;
- for(i=0; i<K; i++){
- for(disrow=0; disrow < 16; disrow++){ //1
- if (Serial.available()) {
- // get the new byte:
- char inChar = (char)Serial.read();
- // add it to the inputString:
- inputString += inChar;
- // if the incoming character is a newline, set a flag
- // so the main loop can do something about it:
- if (inChar == 'e') {
- if(K < 30){
- K+=3;
- }else{
- K = 1;
- }
- }
- }
- loadoneline();
- sendoneline();
- hc595_write_data(rowSel[disrow*2] , RowCLK, RowOUT);
- hc595_write_data(rowSel[disrow*2+1] , RowCLK, RowOUT);
- digitalWrite(RowSTB, 0); //595刷新
- digitalWrite(RowSTB, 1);
- digitalWrite(DataEn, 1);
- digitalWrite(DataSTB, 0); //595刷新
- digitalWrite(DataSTB, 1);
- digitalWrite(DataEn, 0);
- delayMicroseconds(300) ; //节电用,
- }
- }
- col++;
- }
-
- col=0;
- words=words+32;
- if(words>=288)
- words=0;//(字数-4)×32 其中字数为汉字、标点符号、其他符号的总和
- }
- }
复制代码 |