完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
Ht1621m.h
#ifndef _HT1621M_HPP_ #define _HT1621M_HPP_ #define HT1621M_RAM_SIZE 16 struct _ht1621m_ { uint8_t _port_cs; uint8_t _port_wr; uint8_t _port_dat; uint8_t _pin_cs; uint8_t _pin_wr; uint8_t _pin_dat; uint8_t _ram_last[HT1621M_RAM_SIZE]; uint8_t _ram[HT1621M_RAM_SIZE]; }; extern struct _ht1621m_ sg_ht1621m; #define GET_HT1621M() (&sg_ht1621m) #define GET_HT1621M_RAM(ht1621m) ((ht1621m)->_ram) boolean_t ht1621m_init(struct _ht1621m_* ht1621m, uint8_t port_cs, uint8_t pin_cs, uint8_t port_wr, uint8_t pin_wr, uint8_t port_dat, uint8_t pin_dat); boolean_t ht1621m_update(struct _ht1621m_* ht1621m); #endif Ht1621m.c #include "BaseDef.h" #include "Ht1621m.h" #include "gpio.h" #include struct _ht1621m_ sg_ht1621m; #define BIAS 0x29 // 0x50// 1/3 bias 4 com #define SYSEN 0x01 // 0X02//Turn on system oscillator振荡 #define LCDON 0x03 // 0x06//Turn on LCD bias generator偏压发生器 #define LCDOFF 0x02 // 0x04//Turn off LCD bias generator #define RC256 0X18 #define HT1621M_CTRL_CS(ht1621m, stat) Gpio_WriteOutputIO((en_gpio_port_t)(ht1621m)->_port_cs, (en_gpio_pin_t)(ht1621m)->_pin_cs, stat) // 控制cs:true:拉高,false:拉低 #define HT1621M_CTRL_WR(ht1621m, stat) Gpio_WriteOutputIO((en_gpio_port_t)(ht1621m)->_port_wr, (en_gpio_pin_t)(ht1621m)->_pin_wr, stat) // 控制wr:true:拉高,false:拉低 #define HT1621M_CTRL_DAT(ht1621m, stat) Gpio_WriteOutputIO((en_gpio_port_t)(ht1621m)->_port_dat, (en_gpio_pin_t)(ht1621m)->_pin_dat, stat) // 控制dat:true:拉高,false:拉低 // 传地址,高六位 void _ht1621m_sendbit_high(struct _ht1621m_* ht1621m, uint8_t data, uint8_t cnt) { uint8_t i; for (i = 0; i < cnt; i++) { HT1621M_CTRL_DAT(ht1621m, data & 0x80); HT1621M_CTRL_WR(ht1621m, FALSE); delay10us(1); HT1621M_CTRL_WR(ht1621m, TRUE); data <<= 1; delay10us(1); } } // 传送数据,低四位 void _ht1621m_sendbit_low(struct _ht1621m_* ht1621m, uint8_t data, uint8_t cnt) { uint8_t i; for (i = 0; i < cnt; i++) { HT1621M_CTRL_DAT(ht1621m, data & 0x01); HT1621M_CTRL_WR(ht1621m, FALSE); delay10us(1); HT1621M_CTRL_WR(ht1621m, TRUE); data >>= 1; delay10us(1); } } // 写命令 void _ht1621m_send_cmd(struct _ht1621m_* ht1621m, uint8_t command) { HT1621M_CTRL_CS(ht1621m, FALSE); _ht1621m_sendbit_high(ht1621m, 0x80, 3); _ht1621m_sendbit_high(ht1621m, command, 8); _ht1621m_sendbit_high(ht1621m, 0x0, 1); HT1621M_CTRL_CS(ht1621m, TRUE); } // 写地址和数据 void _ht1621m_write_byte(struct _ht1621m_* ht1621m, uint8_t addr, uint8_t data) { HT1621M_CTRL_CS(ht1621m, FALSE); _ht1621m_sendbit_high(ht1621m, 0xa0, 3); _ht1621m_sendbit_high(ht1621m, addr << 3, 6); _ht1621m_sendbit_low(ht1621m, data, 8); HT1621M_CTRL_CS(ht1621m, TRUE); } // 初始化 boolean_t ht1621m_init(struct _ht1621m_* ht1621m, uint8_t port_cs, uint8_t pin_cs, uint8_t port_wr, uint8_t pin_wr, uint8_t port_dat, uint8_t pin_dat) { uint8_t i; ht1621m->_port_cs = port_cs; ht1621m->_pin_cs = pin_cs; ht1621m->_port_wr = port_wr; ht1621m->_pin_wr = pin_wr; ht1621m->_port_dat = port_dat; ht1621m->_pin_dat = pin_dat; _ht1621m_send_cmd(ht1621m, RC256); _ht1621m_send_cmd(ht1621m, BIAS); _ht1621m_send_cmd(ht1621m, SYSEN); _ht1621m_send_cmd(ht1621m, LCDON); memset(ht1621m->_ram, 0X00, HT1621M_RAM_SIZE); for (i = 0; i < HT1621M_RAM_SIZE; ++i) { _ht1621m_write_byte(ht1621m, i, ht1621m->_ram); } return TRUE; } // 更新RAM boolean_t ht1621m_update(struct _ht1621m_* ht1621m) { uint8_t i; if (0==memcmp(ht1621m->_ram_last, ht1621m->_ram, HT1621M_RAM_SIZE)) { return lc_false; } memcpy(ht1621m->_ram_last, ht1621m->_ram, HT1621M_RAM_SIZE); for (i=0; i _ht1621m_write_byte(ht1621m, i, ht1621m->_ram); } return TRUE; } |
|
|
|
只有小组成员才能发言,加入小组>>
3320 浏览 9 评论
2999 浏览 16 评论
3496 浏览 1 评论
9069 浏览 16 评论
4089 浏览 18 评论
1190浏览 3评论
612浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
602浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2339浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1899浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-27 01:10 , Processed in 1.234629 second(s), Total 79, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号