最近做了一个项目用到了HT1621,电路图+datasheet+code
#include "ht1621.h" void ht1621_send_high_order_data(UCHAR data, UCHAR len) { UCHAR i; for (i=0; i<len; i++) { if((data&0x80) == 0) { Set_Port_Val(HT_DATA, 0); } else { Set_Port_Val(HT_DATA, 1); } Set_Port_Val(HT_WR, 0); Delay(4); Set_Port_Val(HT_WR, 1); data <<= 1; } } void ht1621_send_low_order_data(UCHAR data, UCHAR len) { UCHAR i; for (i=0; i<len; i++) { if((data&0x01) == 0) { Set_Port_Val(HT_DATA, 0); } else { Set_Port_Val(HT_DATA, 1); } Set_Port_Val(HT_WR, 0); Delay(4); Set_Port_Val(HT_WR, 1); data >>= 1; } } void ht1621_send_cmd(UCHAR command) { Set_Port_Val(HT_CS, 0); ht1621_send_high_order_data(0x80, 4); ht1621_send_high_order_data(command, 8); Set_Port_Val(HT_CS, 1); } void ht1621_write(UCHAR addr, UCHAR data) { Set_Port_Val(HT_CS, 0); ht1621_send_high_order_data(0xA0, 3); ht1621_send_high_order_data(addr<<2, 6); ht1621_send_low_order_data(data, 8); Set_Port_Val(HT_CS, 1); } void ht1621_write_all(UCHAR addr, UCHAR *p, UCHAR len) { UCHAR i; Set_Port_Val(HT_CS, 0); ht1621_send_high_order_data(0xA0, 3); ht1621_send_high_order_data(addr<<2, 6); for (i=0; i<len; i++, p++) { ht1621_send_low_order_data(*p, 8); } Set_Port_Val(HT_CS, 1); } void ht1621_clr_all_display() { UCHAR i; UCHAR addr = 0; for (i=0; i<16; i++) { ht1621_write(addr, 0x00); addr += 2; } } void ht1621_all_display() { UCHAR i; UCHAR addr = 0; for (i=0; i<16; i++) { ht1621_write(addr, 0xFF); addr += 2; } } void ht1621_init() { ht1621_send_cmd(HT_SYS_EN); ht1621_send_cmd(HT_RCOSC); ht1621_send_cmd(HT_BISA_COM); ht1621_send_cmd(HT_LCD_ON); } void set_lcd_on() { ht1621_send_cmd(HT_LCD_ON); } void set_lcd_off() { ht1621_send_cmd(HT_LCD_OFF); }
#ifndef _HT1621_H #define _HT1621_H #define HT_BISA_COM 0x52 //(1<<1) | (0<<3) | (1<<4) | (0<<5) | (1<<6) | (0<<7) | (0<<8) | (0<<9) | (0<<10) | (1<<11) #define HT_LCD_OFF 0x04 //(0<<1) | (1<<2) | (0<<4) | (0<<5) | (0<<6) | (0<<7) | (0<<8) | (0<<9) | (0<<10) | (1<<11) #define HT_LCD_ON 0x06 //(1<<1) | (1<<2) | (0<<4) | (0<<5) | (0<<6) | (0<<7) | (0<<8) | (0<<9) | (0<<10) | (1<<11) #define HT_WRITE_CMD 0x80 //(0<<0) | (0<<1) | (1<<2) | (0<<3) | (1<<4) | (0<<5) | (1<<6) | (0<<7) | (1<<8) #define HT_WRITE_DATA 0xA0 #define HT_SYS_EN 0x02 #define HT_RCOSC 0x30 #endif
原文地址:http://blog.csdn.net/w89436838/article/details/42778201