LED_Array.h & cpp
#ifndef LED_Array_H
#define LED_Array_H
#define HaltSize 1
#define LIGHT 160
#define R0 D2
#define R1 D3
#define G0 D8
#define G1 D9
#define L0 D11
#define L1 D12
#define STB A4//RCLK STCP//STB 正脉冲(几十纳秒)更新输出
#define CLK A5//SCLK SHCP//CLK 上升沿位移输入数据
#define EN D13//OE 低电平开启
#define RowA A0
#define RowB A1
#define RowC A2
#define RowD A3
/*色权
* 基本:
* 0——无色
* 1——红色
* 2——绿色
* 4——蓝色
* 扩展:
* 3——红绿:黄
* 5——红蓝:桃
* 6——蓝绿:青、
* 7——白
*/
#define OFF 0
#define RED 1
#define GREEN 2
#define BLUE 4
#define PINK 5
#define YELLO 3
#define CYAN 6
#define WHITE 7
const unsigned char Dot[] =
{
0x00, 0xFE, 0xC6, 0xCE, 0xD6, 0xE6, 0xC6, 0xFE,//G:\WPad\0.BMP0
0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C,//G:\WPad\1.BMP0
0x00, 0xFE, 0x06, 0x06, 0xFE, 0xC0, 0xC0, 0xFE,//G:\WPad\2.BMP0
0x00, 0xFE, 0x06, 0x06, 0xFE, 0x06, 0x06, 0xFE,//G:\WPad\3.BMP0
0x00, 0xC6, 0xC6, 0xC6, 0xFE, 0x06, 0x06, 0x06,//G:\WPad\4.BMP0
0x00, 0xFE, 0xC0, 0xC0, 0xFE, 0x06, 0x06, 0xFE,//G:\WPad\5.BMP0
0x00, 0xFE, 0xC0, 0xC0, 0xFE, 0xC6, 0xC6, 0xFE,//G:\WPad\6.BMP0
0x00, 0xFE, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x60,//G:\WPad\7.BMP0
0x00, 0xFE, 0xC6, 0xC6, 0xFE, 0xC6, 0xC6, 0xFE,//G:\WPad\8.BMP0
0x00, 0xFE, 0xC6, 0xC6, 0xFE, 0x06, 0x06, 0xFE,//G:\WPad\9.BMP0
0x00, 0x10, 0x38, 0x7C, 0xFE, 0x00, 0x00, 0x00,//G:\WPad\up.BMP0
0x00, 0x00, 0x00, 0xFE, 0x7C, 0x38, 0x10, 0x00,//G:\WPad\down.BMP0
0x00, 0x18, 0x24, 0x24, 0x34, 0x34, 0x34, 0x18,//G:\WPad\temp2.BMP0
0x00, 0xE6, 0xA8, 0xE8, 0x08, 0x08, 0x08, 0x06,//G:\WPad\temp.BMP0
0x00, 0x10, 0x10, 0x38, 0x7C, 0x7C, 0x7C, 0x38,//G:\WPad\humb2.BMP0
0x00, 0xE2, 0xA4, 0xE8, 0x10, 0x2E, 0x4A, 0x8E,//G:\WPad\humb.BMP0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//0x00
};//字模
void Write_595(unsigned char Data, PinName PIN_595);
//this is the base driver of 74HC595
void Init_LED_Array(void);
//put this function into setup()
void Display();
//you can modify this function to display contents that you what to show
void Write_LED_Array(unsigned char *Data, unsigned char color);
//this is the base driver of LED array
void DotToData(unsigned char *Data, unsigned char Pos, unsigned char Draw);
//将字模放到数组中指定屏幕区域
#endif
#include "mbed.h"
#include "Arduino.h"
#include "LED_Array.h"
void Display()//you can modify this function to display contents that you what to show
{
// unsigned char i;
// for (i = 80; i > 1; i--)
// {
// Write_LED_Array(0, &cod1[0x0000], R0); //Write_LED_Array(pos,data,color);
// Write_LED_Array(1, &cod1[64], R1);
// }
// for (i = 80; i > 1; i--)
// {
// Write_LED_Array(0, &cod1[128], R0); //Write_LED_Array(pos,data,color);
// Write_LED_Array(1, &cod1[192], R1);
// }
}
void Init_LED_Array(void)//put this function into setup()
{
pinMode(R0, OUTPUT);
pinMode(R1, OUTPUT);
pinMode(G0, OUTPUT);
pinMode(G1, OUTPUT);
pinMode(L0, OUTPUT);
pinMode(L1, OUTPUT);
digitalWrite(R0, LOW);
digitalWrite(R1, LOW);
digitalWrite(G0, LOW);
digitalWrite(G1, LOW);
digitalWrite(L0, LOW);
digitalWrite(L1, LOW);
pinMode(STB, OUTPUT);
pinMode(CLK, OUTPUT);
pinMode(EN, OUTPUT);
pinMode(RowA, OUTPUT);
pinMode(RowB, OUTPUT);
pinMode(RowC, OUTPUT);
pinMode(RowD, OUTPUT);
digitalWrite(EN, HIGH);
digitalWrite(STB, LOW);
}
void Write_595(unsigned char Data, PinName PIN_595) //this is the base driver of 74HC595
{
digitalWrite(CLK, LOW);
digitalWrite(PIN_595, (Data & 0x80));
digitalWrite(CLK, HIGH);
digitalWrite(CLK, LOW);
digitalWrite(PIN_595, (Data & 0x40));
digitalWrite(CLK, HIGH);
digitalWrite(CLK, LOW);
digitalWrite(PIN_595, (Data & 0x20));
digitalWrite(CLK, HIGH);
digitalWrite(CLK, LOW);
digitalWrite(PIN_595, (Data & 0x10));
digitalWrite(CLK, HIGH);
digitalWrite(CLK, LOW);
digitalWrite(PIN_595, (Data & 0x08));
digitalWrite(CLK, HIGH);
digitalWrite(CLK, LOW);
digitalWrite(PIN_595, (Data & 0x04));
digitalWrite(CLK, HIGH);
digitalWrite(CLK, LOW);
digitalWrite(PIN_595, (Data & 0x02));
digitalWrite(CLK, HIGH);
digitalWrite(CLK, LOW);
digitalWrite(PIN_595, (Data & 0x01));
digitalWrite(CLK, HIGH);
}
void Write_LED_Array(unsigned char *Data, unsigned char color) //this is the base driver of LED array
{
unsigned char *pTemp;
unsigned char row;
PinName DataPin = R0;
PinName DataPin2 = R1;
if (color == GREEN) {
DataPin = G0;
DataPin2 = G1;
} else if (color == BLUE) {
DataPin = L0;
DataPin2 = L1;
}
for (row = 0; row < 16; row++) {
digitalWrite(EN, HIGH);
pTemp = (Data + row * 2);
if (HaltSize && row >= 8) {
Write_595(*pTemp, DataPin2);
Write_595(*(pTemp + 1), DataPin2);
Write_595(*(pTemp += 32), DataPin2);
Write_595(*(pTemp + 1), DataPin2);
} else {
Write_595(*pTemp, DataPin);
Write_595(*(pTemp + 1), DataPin);
Write_595(*(pTemp += 32), DataPin);
Write_595(*(pTemp + 1), DataPin);
}
digitalWrite(STB, HIGH);
delayMicroseconds(1);
digitalWrite(STB, LOW);
delayMicroseconds(1);
digitalWrite(RowA, (row & 0x01)); //set display line
digitalWrite(RowB, (row & 0x02)); //Sequential scan
digitalWrite(RowC, (row & 0x04));
if (!HaltSize)
digitalWrite(RowD, (row & 0x08));
digitalWrite(EN, LOW);
delayMicroseconds(LIGHT);
}
}
void DotToData(unsigned char *Data, unsigned char Pos, unsigned char Draw)
{
//将字模放到数组中指定屏幕区域
/*区域
Pos:
0 1 4 5
2 3 6 7
*/
const unsigned char *p = &Dot[Draw * 8];//字模编号取得指针
//区域处理
char n = Pos / 2;
Pos = Pos % 2;
for (char i = n * 16; i < (n + 1) * 16; i += 2) {
if (Pos)
Data[i + 1] = *(p++);
else
Data[i] = *(p++);
}
}