今天搞了一下HT1621.
DA接PC0,WR接PC1,CS接PC2.
主程序代码:
#include "main.h"
/** @addtogroup Examples
@{
*/
#define uchar unsigned char
#define uint unsigned int
/** @addtogroup 425_GPIO_led_toggle GPIO_led_toggle
* @{
*/
#define DA_1 GPIO_SetBit(GPIOC,DA_PIN)
#define DA_0 GPIO_ResetBit(GPIOC,DA_PIN)
#define WR_1 GPIO_SetBit(GPIOC,WR_PIN)
#define WR_0 GPIO_ResetBit(GPIOC,WR_PIN)
#define CS_1 GPIO_SetBit(GPIOC,CS_PIN)
#define CS_0 GPIO_ResetBit(GPIOC,CS_PIN)
#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
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
}
/** @addtogroup GPIO_Toggle
@{
*/
/** @defgroup GPIO_Toggle_Functions Functions
@{
*/
void APM_MINI_HT1621Init(void)
{
GPIO_Config_T configStruct;
/* Enable the GPIO_LED Clock */
RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOC);
/* Configure the GPIO_LED pin */
configStruct.pin = DA_PIN | WR_PIN | CS_PIN;
configStruct.mode = GPIO_MODE_OUT_PP;
configStruct.speed = GPIO_SPEED_50MHz;
GPIO_Config(GPIOC, &configStruct);
}
/*!
* [url=home.php?mod=space&uid=247401]@brief[/url] Main program
*
* @param None
*
* @retval None
*
*/
int main(void)
{
APM_MINI_HT1621Init();
LCD_Init();
DpyNum[0] = Smg_a|Smg_d|Smg_g; //"Èý"
DpyNum[1] = SegCode[2];
DpyNum[2] = SegCode[4];
DpyNum[3] = SegCode[6];
DpyNum[4] = SegCode[8];
DpyNum[5] = SegCode[0];
HT1621_Display(); //Ë¢ÐÂLCD
while (1)
{
}
}
/*!
* @brief Main program
*
* @param None
*
* @retval None
*
*/
void Delay(void)
{
volatile uint32_t delay = 0xffffff;
while(delay--);
}
/**@} end of group GPIO_Toggle_Functions */
/**@} end of group GPIO_Toggle */
/**@} end of group Examples */
初始化代码:
void APM_MINI_HT1621Init(void)
{
GPIO_Config_T configStruct;
/* Enable the GPIO_LED Clock */
RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOC);
/* Configure the GPIO_LED pin */
configStruct.pin = DA_PIN | WR_PIN | CS_PIN;
configStruct.mode = GPIO_MODE_OUT_PP;
configStruct.speed = GPIO_SPEED_50MHz;
GPIO_Config(GPIOC, &configStruct);
}
#define DA_PIN GPIO_PIN_0
#define DA_GPIO_PORT GPIOC
#define DA_GPIO_CLK RCM_APB2_PERIPH_GPIOC
#define WR_PIN GPIO_PIN_1
#define WR_GPIO_PORT GPIOC
#define WR_GPIO_CLK RCM_APB2_PERIPH_GPIOC
#define CS_PIN GPIO_PIN_2
#define CS_GPIO_PORT GPIOC
#define CS_GPIO_CLK RCM_APB2_PERIPH_GPIOC
效果图:
|