本帖最后由 比神乐 于 2022-3-6 15:13 编辑
今天搞了一一下HT1621
DA->B8,WR->B7,CS->B5
代码:
#include "at32f425_board.h"
#include "at32f425_clock.h"
#include "stdio.h"
#include "at32f425.h"
/** @addtogroup AT32F425_periph_examples
* @{
*/
#define uchar unsigned char
#define uint unsigned int
/** @addtogroup 425_GPIO_led_toggle GPIO_led_toggle
* @{
*/
#define DA_PIN GPIO_PINS_8
#define DA_GPIO GPIOB
#define DA_GPIO_CRM_CLK CRM_GPIOB_PERIPH_CLOCK
#define WR_PIN GPIO_PINS_7
#define WR_GPIO GPIOB
#define WR_GPIO_CRM_CLK CRM_GPIOB_PERIPH_CLOCK
#define CS_PIN GPIO_PINS_5
#define CS_GPIO GPIOB
#define CS_GPIO_CRM_CLK CRM_GPIOB_PERIPH_CLOCK
#define DA_1 gpio_bits_set(GPIOB,GPIO_PINS_8)
#define DA_0 gpio_bits_reset(GPIOB,GPIO_PINS_8)
#define WR_1 gpio_bits_set(GPIOB,GPIO_PINS_7)
#define WR_0 gpio_bits_reset(GPIOB,GPIO_PINS_7)
#define CS_1 gpio_bits_set(GPIOB,GPIO_PINS_5)
#define CS_0 gpio_bits_reset(GPIOB,GPIO_PINS_5)
#define Smg_a 0x80
#define Smg_b 0x40
#define Smg_c 0x20
#define Smg_d 0x01
#define Smg_e 0x02
#define Smg_f 0x08
#define Smg_g 0x04
#define Smg_dp 0x10
#define Bmp0Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f
#define Bmp1Map Smg_b | Smg_c
#define Bmp2Map Smg_a | Smg_b | Smg_d | Smg_e | Smg_g
#define Bmp3Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_g
#define Bmp4Map Smg_b | Smg_c | Smg_f | Smg_g
#define Bmp5Map Smg_a | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp6Map Smg_a | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp8Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp9Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp7Map Smg_a | Smg_b | Smg_c
#define BmpAMap Smg_a | Smg_b | Smg_c | Smg_e | Smg_f | Smg_g
#define BmpBMap Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpCMap Smg_a | Smg_d | Smg_e | Smg_f
#define BmpDMap Smg_b | Smg_c | Smg_d | Smg_e | Smg_g
#define BmpEMap Smg_a | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpFMap Smg_a | Smg_e | Smg_f | Smg_g
uint16_t HT1621_PIN[3] = {DA_PIN,WR_PIN,CS_PIN};
crm_periph_clock_type HT1621_gpio_crm_clk[3] = {DA_GPIO_CRM_CLK, WR_GPIO_CRM_CLK, CS_GPIO_CRM_CLK};
gpio_type *HT1621_port[3] = {DA_GPIO,WR_GPIO,CS_GPIO};
const unsigned char SegCode[] = {Bmp0Map,Bmp1Map,Bmp2Map,Bmp3Map,Bmp4Map,Bmp5Map,Bmp6Map,Bmp7Map,Bmp8Map,Bmp9Map,BmpAMap,BmpBMap,BmpCMap,BmpDMap,BmpEMap,BmpFMap};
unsigned char DpyNum[6] = {Smg_g,Smg_g,Smg_g,Smg_g,Smg_g,Smg_g}; //显示缓冲区
unsigned int i;
void COMMAND_HT1621(unsigned char comm)
{
//unsigned char i;
CS_0;
WR_0;
for(i=0;i<3;i++) //写命令
{
if((0x04<<i)&0x04) DA_1; //100
else DA_0;
WR_0;
WR_1;
}
for(i=0;i<9;i++) //写命令数据
{
if((comm<<i)&0x80) DA_1; //100
else DA_0;
WR_0;
WR_1;
}
CS_1;
}
void HT1621_Display(void)
{
//unsigned char i;
CS_0; //片选CS
WR_0;
for(i=0;i<3;i++) //写命令
{
if((0x05<<i)&0x04) DA_1;
else DA_0;
WR_0;
WR_1;
}
for(i=0;i<6;i++) //写地址
{
if((20<<i)&0x20) DA_1; //20对应 SEG地址
else DA_0;
WR_0;
WR_1;
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[5]<<i)&0x80) DA_1;
else DA_0;
WR_0;
WR_1;
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[4]<<i)&0x80) DA_1;
else DA_0;
WR_0;
WR_1;
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[3]<<i)&0x80) DA_1;
else DA_0;
WR_0;
WR_1;
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[2]<<i)&0x80) DA_1;
else DA_0;
WR_0;
WR_1;
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[1]<<i)&0x80) DA_1;
else DA_0;
WR_0;
WR_1;
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[0]<<i)&0x80) DA_1;
else DA_0;
WR_0;
WR_1;
}
CS_1; //释放CS
}
void LCD_Init(void)
{
COMMAND_HT1621(0x01); //SYS EN
COMMAND_HT1621(0x03); //LCD ON
COMMAND_HT1621(0x29); //4 COM 1/3 BIAS
HT1621_Display(); //clear screen
}
void HT1621_io_init(void)
{
gpio_init_type gpio_init_struct;
/* enable the led clock */
crm_periph_clock_enable(HT1621_gpio_crm_clk[0],TRUE);
crm_periph_clock_enable(HT1621_gpio_crm_clk[1],TRUE);
crm_periph_clock_enable(HT1621_gpio_crm_clk[2],TRUE);
/* set default parameter */
gpio_default_para_init(&gpio_init_struct);
/* configure the led gpio */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = HT1621_PIN[0];
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(HT1621_port[0],&gpio_init_struct);
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = HT1621_PIN[1];
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(HT1621_port[1],&gpio_init_struct);
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = HT1621_PIN[2];
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(HT1621_port[2],&gpio_init_struct);
}
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] main function.
* @param none
* @retval none
*/
int main(void)
{
long int i;
system_clock_config();
at32_board_init();
HT1621_io_init();
LCD_Init();
DpyNum[0] = Smg_a|Smg_d|Smg_g; //"三"
DpyNum[1] = SegCode[1];
DpyNum[2] = SegCode[3];
DpyNum[3] = SegCode[5];
DpyNum[4] = SegCode[7];
DpyNum[5] = SegCode[9];
HT1621_Display(); //刷新LCD
while(1)
{
// at32_led_toggle(LED2);
// delay_ms(200);
// at32_led_toggle(LED3);
// delay_ms(200);
// at32_led_toggle(LED4);
// delay_ms(200);
// CLK_0;
// for(i=0;i<500000;i++);
// CLK_1;
// for(i=0;i<500000;i++);
}
}
效果图
|