- #define CMD_ID 0x80 //command 命令码100 0x80(1000 0000)
- #define WRITE_ID 0xa0 //write 命令码101,0xa0(1010 0000)
- #define SYS_DIS 0x00 //关闭系统震荡
- #define SYS_EN 0x01 //打开系统震荡
- #define LED_OFF 0x02 //关闭LED显示
- #define LED_ON 0x03 //打开LED显示
- #define BLINK_OFF 0x08 //关闭闪烁
- #define BLINK_ON 0x09 //打开闪烁
- #define SLAVE_MODE 0x10 //从模式
- #define RC_MASTER_MODE 0x18 //内部RC时钟
- #define COM_OPTION 0x24 //16COM n-mos模式 ab=01
- #define PWM_DUTY 0xAE //PWM亮度控制 最亮
- #define PWM_DUTY_MIN 0xA0 //PWM亮度控制 最暗
-
- #define CS_LOW() digitalWrite(CS_pin,LOW) //CS置低
- #define CS_HIGH() digitalWrite(CS_pin,HIGH) //CS置高
-
- #define WR_LOW() digitalWrite(WR_pin,LOW) //WR置低
- #define WR_HIGH() digitalWrite(WR_pin,HIGH) //WR置高
-
- #define DATA_LOW() digitalWrite(DATA_pin,LOW) //DATA置低
- #define DATA_HIGH() digitalWrite(DATA_pin,HIGH) //DATA置高
-
- int powerEn = 9;
- int CS_pin = 11;
- int RD_pin = A2;
- int WR_pin = 10;
- int DATA_pin = A1;
-
- unsigned char LED_RAM_ADDR[]= {
- 0x00, 0x02,
- 0x04, 0x06,
- 0x08, 0x0a,
- 0x0c, 0x0e,
- 0x10, 0x12,
- 0x14, 0x16,
- 0x18, 0x1a,
- 0x1c, 0x1e,
- 0x20, 0x22,
- 0x24, 0x26,
- 0x28, 0x2a,
- 0x2c, 0x2e
- };
-
- const unsigned char ASC_II_table_R[]= {0x00,0x00,0x00,0x00,0x78,0x00,0x90,0x00,0x90,0x00,0x70,0x00,
- 0x50,0x00,0x90,0x00,0x90,0x00,0xB8,0x01,0x00,0x00,0x00,0x00};/*"R",0*/
- const unsigned char ASC_II_table_L[] = {0x00,0x00,0x00,0x00,0x38,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
- 0x10,0x00,0x10,0x00,0x10,0x01,0xF8,0x01,0x00,0x00,0x00,0x00};/*"L",0*/
- const unsigned char hartTable_left[]= {0x00,0x00,0x00,0x00,0x8C,0x01,0xDE,0x03,0xFE,0x03,0xFE,0x03,
- 0xFC,0x01,0xF8,0x00,0x70,0x00,0x20,0x00,0x00,0x00,0x00,0x00};/*"Left heart",0*/
- const unsigned char hartTable_right[]= {0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x03,0xBC,0x07,0xFC,0x07,
- 0xFC,0x07,0xF8,0x03,0xF0,0x01,0xE0,0x00,0x40,0x00,0x00,0x00,};/*"Rihgt heart",0*/
- const unsigned char r[]= {0x00,0x00,0x00,0x00,0x78,0x00,0x90,0x00,0x90,0x00,0x70,0x00,
- 0x50,0x00,0x90,0x00,0x90,0x00,0xB8,0x01,0x00,0x00,0x00,0x00,};/*"Rihgt heart",0*/
- const unsigned char face[]= {0xF0,0x00,0x0C,0x03,0x06,0x06,0x02,0x04,0x0B,0x0D,0x0B,0x09,
- 0x01,0x08,0x93,0x0C,0xF2,0x04,0x06,0x06,0x0C,0x03,0xF0,0x00,};/*"Rihgt heart",0*/
- const unsigned char Z[]= {0x00,0x00,0x00,0x00,0xFC,0x03,0x00,0x01,0x80,0x00,0x40,0x00,
- 0x20,0x00,0x10,0x00,0x08,0x00,0xFC,0x03,0x00,0x00,0x00,0x00,};/*"Rihgt heart",0*/
- const unsigned char a1[]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,
- 0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*"Rihgt heart",0*/
- const unsigned char a2[]= {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x00,0x90,0x00,
- 0x90,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*"Rihgt heart",0*/
- const unsigned char a3[]= {0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x01,0x08,0x01,0x08,0x01,
- 0x08,0x01,0x08,0x01,0xF8,0x01,0x00,0x00,0x00,0x00,0x00,0x00,};/*"Rihgt heart",0*/
- const unsigned char a4[]= {0x00,0x00,0x00,0x00,0xFC,0x03,0x04,0x02,0x04,0x02,0x04,0x02,
- 0x04,0x02,0x04,0x02,0x04,0x02,0xFC,0x03,0x00,0x00,0x00,0x00,};/*"Rihgt heart",0*/
- const unsigned char a5[]= {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,};/*"Rihgt heart",0*/
- unsigned char a6[]= {
- 0x00,0x00,0x08,0x00,0x1C,0x00,0x3E,0x00,0x63,0x00,0x63,0x00,
- 0x7F,0x00,0x7F,0x00,0x63,0x00,0x63,0x00,0x63,0x00,0x00,0x00};/*"A",0*/
- const unsigned char a7[]= {
- 0x00,0x00,0x00,0x00,0xF8,0x01,0x60,0x00,0x60,0x00,0x60,0x00,
- 0x60,0x00,0x60,0x00,0xF8,0x01,0x00,0x00,0x00,0x00,0x00,0x00,};/*"I",0*/
- //tx_moode为数据读取的方式,data为输入的数据,cnt为读取数据位数
- const unsigned char a8[]= {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x00,0x88,0x00,0x88,0x00,
- 0x88,0x00,0x88,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*"U",0*/
- const unsigned char a9[]= {
- 0x00,0x00,0x00,0x00,0xFC,0x00,0x04,0x01,0x04,0x02,0x04,0x02,
- 0x04,0x02,0x04,0x02,0x04,0x02,0x04,0x01,0xFC,0x00,0x00,0x00,};/*"D",0*/
- const unsigned char a10[]= {
- 0x00,0x00,0x04,0x04,0x08,0x02,0x10,0x01,0xA0,0x00,0x40,0x00,
- 0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x00,0x00};/*"Y",0*/
-
- const unsigned char a11[]= {
- 0x00,0x00,0x00,0x01,0x80,0x03,0xC0,0x07,0x60,0x0C,0x60,0x0C,
- 0xE0,0x0F,0xE0,0x0F,0x60,0x0C,0x60,0x0C,0x60,0x0C,0x00,0x00};/*"Y",0*/
- const unsigned char a12[]= {
- 0x00,0x00,0x80,0x00,0xC0,0x01,0xE0,0x03,0x30,0x06,0x30,0x06,
- 0xF0,0x07,0xF0,0x07,0x30,0x06,0x30,0x06,0x30,0x06,0x00,0x00};/*"Y",0*/
- const unsigned char a13[]= {
- 0x00,0x00,0x40,0x00,0xE0,0x00,0xF0,0x01,0x18,0x03,0x18,0x03,
- 0xF8,0x03,0xF8,0x03,0x18,0x03,0x18,0x03,0x18,0x03,0x00,0x00};/*"Y",0*/
- const unsigned char a14[]= {
- 0x00,0x00,0x20,0x00,0x70,0x00,0xF8,0x00,0x8C,0x01,0x8C,0x01,
- 0xFC,0x09,0xFC,0x09,0x8C,0x09,0x8C,0x09,0x8C,0x01,0x00,0x00};/*"Y",0*/
- const unsigned char a15[]= {
- 0x00,0x00,0x10,0x00,0x38,0x00,0x7C,0x00,0xC6,0x00,0xC6,0x08,
- 0xFE,0x04,0xFE,0x04,0xC6,0x04,0xC6,0x04,0xC6,0x08,0x00,0x00};/*"Y",0*/
- const unsigned char a16[]= {
- 0x00,0x00,0x08,0x00,0x1C,0x00,0x3E,0x00,0x63,0x00,0x63,0x0C,
- 0x7F,0x02,0x7F,0x02,0x63,0x02,0x63,0x02,0x63,0x0C,0x00,0x00};/*"Y",0*/
- const unsigned char a17[]= {
- 0x00,0x00,0x04,0x00,0x0E,0x00,0x1F,0x00,0x31,0x00,0x31,0x0E,
- 0x3F,0x01,0x3F,0x01,0x31,0x01,0x31,0x01,0x31,0x0E,0x00,0x00};/*"Y",0*/
- const unsigned char a18[]= {
- 0x00,0x00,0x02,0x08,0x07,0x08,0x0F,0x08,0x18,0x08,0x18,0x0F,
- 0x9F,0x08,0x9F,0x08,0x98,0x08,0x98,0x08,0x18,0x07,0x00,0x00};/*"Y",0*/
- const unsigned char a19[]= {
- 0x00,0x00,0x02,0x08,0x07,0x08,0x0F,0x08,0x18,0x08,0x18,0x0F,
- 0x9F,0x08,0x9F,0x08,0x98,0x08,0x98,0x08,0x18,0x0F,0x00,0x00};/*"Y",0*/
- const unsigned char a20[]= {
- 0x00,0x00,0x01,0x04,0x03,0x04,0x07,0x04,0x0C,0x04,0x8C,0x07,
- 0x4F,0x04,0x4F,0x04,0x4C,0x04,0x4C,0x04,0x8C,0x07,0x00,0x00};/*"Y",0*/
- const unsigned char a21[]= {
- 0x00,0x00,0x00,0x02,0x01,0x02,0x03,0x02,0x06,0x02,0xC6,0x03,
- 0x27,0x02,0x27,0x02,0x26,0x02,0x26,0x02,0xC6,0x03,0x00,0x00};/*"Y",0*/
- const unsigned char a22[]= {
- 0x00,0x00,0x00,0x01,0x00,0x01,0x01,0x01,0x03,0x01,0xE3,0x01,
- 0x13,0x01,0x13,0x09,0x13,0x09,0x13,0x09,0xE3,0x01,0x00,0x00};/*"Y",0*/
- const unsigned char a23[]= {
- 0x00,0x00,0x00,0x01,0x00,0x01,0x01,0x01,0x03,0x01,0xE3,0x09,
- 0x13,0x01,0x13,0x09,0x13,0x09,0x13,0x09,0xE3,0x01,0x00,0x00};
- const unsigned char a24[]= {
- 0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x81,0x08,0xF1,0x04,
- 0x89,0x08,0x89,0x04,0x89,0x04,0x89,0x04,0xF1,0x08,0x00,0x00};
- const unsigned char a25[]= {
- 0x00,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x0C,0x78,0x02,
- 0x44,0x0C,0x44,0x02,0x44,0x02,0x44,0x02,0x78,0x0C,0x00,0x00};
- const unsigned char a26[]= {
- 0x00,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x0E,0x3C,0x01,
- 0x22,0x0E,0x22,0x01,0x22,0x01,0x22,0x01,0x3C,0x0E,0x00,0x00};
- const unsigned char a27[]= {
- 0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x07,0x9E,0x08,
- 0x11,0x0F,0x91,0x08,0x91,0x08,0x91,0x08,0x1E,0x07,0x00,0x00};
- const unsigned char a28[]= {
- 0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x88,0x03,0x4F,0x04,
- 0x88,0x07,0x48,0x04,0x48,0x04,0x48,0x04,0x8F,0x03,0x00,0x00};
- const unsigned char a29[]= {
- 0x00,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0xC4,0x01,0x27,0x02,
- 0xC4,0x03,0x24,0x02,0x24,0x02,0x24,0x02,0xC7,0x01,0x00,0x00};
- const unsigned char a30[]= {
- 0x00,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0xE2,0x00,0x13,0x01,
- 0xE2,0x01,0x12,0x01,0x12,0x01,0x12,0x01,0xE3,0x00,0x00,0x00};
- const unsigned char a31[]= {
- 0x00,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x71,0x00,0x89,0x00,
- 0xF1,0x00,0x89,0x00,0x89,0x00,0x89,0x00,0x71,0x00,0x00,0x00};
- const unsigned char a32[]= {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x44,0x00,
- 0x78,0x00,0x44,0x00,0x44,0x00,0x44,0x00,0x38,0x00,0x00,0x00};
- void Write_HT1632C(unsigned char tx_mode , unsigned char data, unsigned char cnt)
- {
- unsigned char i,temp;
- switch (tx_mode){
- case 0:
- temp = 0x01;//从右至左依次写入 若输入数据为0000 0001,则写入为1000 0000
- for(i = 0; i < cnt; i++)
- {
- WR_LOW(); //低电平写入
- if(data & temp)
- DATA_HIGH();
- else
- DATA_LOW();
- temp <<= 1;
- WR_HIGH(); //高电平完成写入保存
- }
- break;
- case 1:
- temp = 0x80; //从左至右,若输入数据为0000 0001,则写入仍为0000 0001
- for(i = 0; i < cnt; i++)
- {
- WR_LOW();
- if(data & temp)
- DATA_HIGH();
- else
- DATA_LOW();
- temp >>= 1;
- WR_HIGH();
- }
- break;
- default : break;
- }
- }
-
- void Write_CMD_HT1632C(unsigned char cmd)
- {
- CS_LOW();
- Write_HT1632C(1,CMD_ID, 3); //command 命令码100 0x80(1000 0000)
- Write_HT1632C(1,cmd, 9); //命令数据,第9位为0
- CS_HIGH();
- }
-
- void Clr_HT1632C(unsigned char bk_mode) //(1:点亮,0:熄灭)
- {
- unsigned char i;
- CS_LOW(); //Successive Address Writing
- Write_HT1632C(1,WRITE_ID, 3); //write 命令码101,0xa0(1010 0000)
- Write_HT1632C(1,0x00,7); //Memory address
- for(i = 0; i < 24; i++) //点阵由24个区域组成
- {
- if(bk_mode) //如果bk_mode为1
- Write_HT1632C(0,0xff,8); //点亮一个区域
- else
- Write_HT1632C(0,0x00,8); // 熄灭一个区域
- }
- CS_HIGH();
- }
-
- void Init_HT1632C(void)
- {
- CS_HIGH();
- WR_HIGH();
- DATA_HIGH();
- Write_CMD_HT1632C(SYS_DIS); //关闭系统震荡
- Write_CMD_HT1632C(COM_OPTION); //16COM n-mos模式 ab=01
- Write_CMD_HT1632C(RC_MASTER_MODE); //内部RC时钟
- Write_CMD_HT1632C(SYS_EN); //关闭系统震荡
- Write_CMD_HT1632C(PWM_DUTY); //PWM亮度控制 最亮
- Write_CMD_HT1632C(BLINK_OFF); //关闭LED闪烁
- Write_CMD_HT1632C(LED_ON); //打开LED显示
- }
-
- void Write_Data_HT1632C(unsigned char addr, unsigned char data) //addr数据需写入的地址,data需写入的数据
- {
- CS_LOW();
- Write_HT1632C(1,WRITE_ID, 3); //write 命令码101,0xa0(1010 0000)
- Write_HT1632C(1,addr << 1, 7); //写入地址
- Write_HT1632C(0,data ,8); //写入数据
- CS_HIGH();
- }
-
- void setBrightness(unsigned char duty) //通过设置PWM来设置LED灯的亮度
- {
- if(duty > 15) //duty的有效范围为0-15
- duty = 15;
- Write_CMD_HT1632C(PWM_DUTY_MIN | duty);
- }
-
- void ledSwitch(bool state) //LED的状态选择,如果state=1则LED亮
- {
- if(state)
- Write_CMD_HT1632C(LED_ON);
- else
- Write_CMD_HT1632C(LED_OFF);
- }
-
- void Show_bitmap(const unsigned char *p) //形状显示,*p:要显示形状的字模
- {
- unsigned char i;
- for(i = 0; i < 24; i++) //依次写入24个单元
- {
- Write_Data_HT1632C(LED_RAM_ADDR, *p);
- p++;
- }
- }
- void Show_roll(const unsigned char *p)
- {
- unsigned char i,j;
- for(j =0; j <8;j++)
- {
- for(i = 0; i < 24; i++) //依次写入24个单元
- {
- Write_Data_HT1632C(LED_RAM_ADDR, *p);
- p++;
- }
- delay(500);
- }
- }
- void setup()
- {
- pinMode(powerEn,OUTPUT); //输出模式
- pinMode(CS_pin, OUTPUT);
- pinMode(WR_pin, OUTPUT);
- pinMode(DATA_pin, OUTPUT);
- digitalWrite(powerEn, HIGH); //置高
- digitalWrite(CS_pin,HIGH);
- digitalWrite(WR_pin,HIGH);
- digitalWrite(DATA_pin,HIGH);
- Init_HT1632C(); //初始化函数调用(运行)
- setBrightness(0.4);
- }
-
- void loop() {
-
- Show_bitmap(a11);
- delay(100);
- Show_bitmap(a12);
- delay(100);
- Show_bitmap(a13);
- delay(100);
- Show_bitmap(a14);
- delay(100);
- Show_bitmap(a15);
- delay(100);
- Show_bitmap(a16);
- delay(100);
- Show_bitmap(a17);
- delay(100);
- Show_bitmap(a18);
- delay(100);
-
- Show_bitmap(a20);
- delay(100);
- Show_bitmap(a21);
- delay(100);
- //Show_bitmap(a22);
- //delay(100);
- Show_bitmap(a23);
- delay(100);
- Show_bitmap(a24);
- delay(100);
- Show_bitmap(a25);
- delay(100);
- Show_bitmap(a26);
- delay(100);
- Show_bitmap(a27);
- delay(100);
- Show_bitmap(a28);
- delay(100);
- Show_bitmap(a29);
- delay(100);
- Show_bitmap(a30);
- delay(100);
- Show_bitmap(a31);
- delay(100);
- Show_bitmap(a32);
- delay(100);
- Show_bitmap(face);
- delay(2000);
- Show_bitmap(a7);
- delay(400);
- Show_bitmap(hartTable_left);
- delay(400);
- Show_bitmap(hartTable_right);
- delay(400);
- /*Show_bitmap(hartTable_left); //跳动的心
- delay(400);
- Show_bitmap(hartTable_right);
- delay(400);
- Show_bitmap(a1);
- delay(50);
-
- Show_bitmap(a2);
- delay(50);
-
- Show_bitmap(a3);
- delay(50);
-
- Show_bitmap(a4);
- delay(50);
- //Write_CMD_HT1632C(BLINK_ON);
- Show_bitmap(Z);
- delay(1000);
-
- Show_bitmap(face);
- delay(1000);
- Show_bitmap(a7);
- delay(400);
- Show_bitmap(hartTable_left);
- delay(400);
- Show_bitmap(hartTable_right);
- delay(400); */
-
- }
复制代码
|