本帖最后由 比神乐 于 2021-1-25 13:18 编辑
今天捣鼓了一下HT1621
硬件接线
CS:PD8
WR:PB14
DA:PB12
代码:
#include <stdio.h>
#include "at32f4xx.h"
#include "at32_board.h"
/** @addtogroup AT32F407_StdPeriph_Examples
* @{
*/
/** @addtogroup GPIO_LEDToggle
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
#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
#define CS_0 CS_GPIO->BRE = CS_PIN
#define CS_1 CS_GPIO->BSRE = CS_PIN
#define WR_0 WR_GPIO->BRE = WR_PIN
#define WR_1 WR_GPIO->BSRE = WR_PIN
#define DA_0 DA_GPIO->BRE = DA_PIN
#define DA_1 DA_GPIO->BSRE = DA_PIN
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 delay(unsigned int x)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<5;j++);
}
void COMMAND_HT1621(unsigned char comm)
{
unsigned char i;
CS_0;
delay(2);
WR_0;
delay(2);
for(i=0;i<3;i++) //写命令
{
if((0x04<<i)&0x04) DA_1; //100
else DA_0;
delay(2);
WR_0;
delay(2);
WR_1;
delay(2);
}
for(i=0;i<9;i++) //写命令数据
{
if((comm<<i)&0x80) DA_1; //100
else DA_0;
delay(2);
WR_0;
delay(2);
WR_1;
delay(2);
}
CS_1;
delay(2);
}
void HT1621_Display(void)
{
unsigned char i;
CS_0; //片选CS
delay(2);
WR_0;
delay(2);
for(i=0;i<3;i++) //写命令
{
if((0x05<<i)&0x04) DA_1;
else DA_0;
delay(2);
WR_0;
delay(2);
WR_1;
delay(2);
}
for(i=0;i<6;i++) //写地址
{
if((20<<i)&0x20) DA_1; //20对应 SEG地址
else DA_0;
delay(2);
WR_0;
delay(2);
WR_1;
delay(2);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[5]<<i)&0x80) DA_1;
else DA_0;
delay(2);
WR_0;
delay(2);
WR_1;
delay(2);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[4]<<i)&0x80) DA_1;
else DA_0;
delay(2);
WR_0;
delay(2);
WR_1;
delay(2);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[3]<<i)&0x80) DA_1;
else DA_0;
delay(2);
WR_0;
delay(2);
WR_1;
delay(2);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[2]<<i)&0x80) DA_1;
else DA_0;
delay(2);
WR_0;
delay(2);
WR_1;
delay(2);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[1]<<i)&0x80) DA_1;
else DA_0;
delay(2);
WR_0;
delay(2);
WR_1;
delay(2);
}
for(i=0;i<8;i++) //写数据
{
if((DpyNum[0]<<i)&0x80) DA_1;
else DA_0;
delay(2);
WR_0;
delay(2);
WR_1;
delay(2);
}
CS_1; //释放CS
delay(2);
}
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 AT32_HT1621_Init(void)
{
GPIO_InitType GPIO_InitStructure;
/*Enable the LED Clock*/
RCC_APB2PeriphClockCmd(CS_GPIO_RCC_CLK|WR_GPIO_RCC_CLK|DA_GPIO_RCC_CLK, ENABLE);
/*Configure the LED pin as ouput push-pull*/
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = CS_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_10MHz;
GPIO_Init(CS_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = WR_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_10MHz;
GPIO_Init(WR_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = DA_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_10MHz;
GPIO_Init(DA_GPIO, &GPIO_InitStructure);
}
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Main Function.
* @param None
* @retval None
*/
int main(void)
{
AT32_Board_Init();
AT32_HT1621_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
for(;;)
{
AT32_LEDn_Toggle(LED2);
Delay_ms(1000);
}
}
#ifdef USE_FULL_ASSERT
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{}
}
#endif
/**
* @}
*/
/**
* @}
*/
效果图:
阴天,图片不是很清楚,隐隐约约可以看到。
|