今晚搞了一下HT1621.
代码:
#include "ac78xx_gpio.h"
#include "ac78xx_debugout.h"
#include "ac78xx.h"
#define uchar unsigned char
#define uint unsigned int
/* makesure n < 16 */
#define PAout(n) BIT_ADDR(GPIOA_ODR_ADDR, n)
#define PAin(n) BIT_ADDR(GPIOA_IDR_ADDR, n)
#define PBout(n) BIT_ADDR(GPIOB_ODR_ADDR, n)
#define PBin(n) BIT_ADDR(GPIOB_IDR_ADDR, n)
#define PCout(n) BIT_ADDR(GPIOC_ODR_ADDR, n)
#define PCin(n) BIT_ADDR(GPIOC_IDR_ADDR, n)
#define PDout(n) BIT_ADDR(GPIOD_ODR_ADDR, n)
#define PDin(n) BIT_ADDR(GPIOD_IDR_ADDR, n)
#define PEout(n) BIT_ADDR(GPIOE_ODR_ADDR, n)
#define PEin(n) BIT_ADDR(GPIOE_IDR_ADDR, n)
/* gpio bit-band control */
#define LED PAout(0)
#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 PAout(0)=0
#define CS_1 PAout(0)=1
#define WR_0 PAout(2)=0
#define WR_1 PAout(2)=1
#define DA_0 PAout(4)=0
#define DA_1 PAout(4)=1
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(uchar x)
{
for(i=0;i<x;i++);
}
void COMMAND_HT1621(unsigned char comm)
{
unsigned char i;
CS_0;
delay(5);
WR_0;
delay(5);
for(i=0;i<3;i++) //???
{
if((0x04<<i)&0x04) DA_1; //100
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<9;i++) //?????
{
if((comm<<i)&0x80) DA_1; //100
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
CS_1;
delay(5);
}
void HT1621_Display(void)
{
unsigned char i;
CS_0; //??CS
delay(5);
WR_0;
delay(5);
for(i=0;i<3;i++) //???
{
if((0x05<<i)&0x04) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<6;i++) //???
{
if((20<<i)&0x20) DA_1; //20?? SEG??
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //???
{
if((DpyNum[5]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //???
{
if((DpyNum[4]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //???
{
if((DpyNum[3]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //???
{
if((DpyNum[2]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //???
{
if((DpyNum[1]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
for(i=0;i<8;i++) //???
{
if((DpyNum[0]<<i)&0x80) DA_1;
else DA_0;
delay(5);
WR_0;
delay(5);
WR_1;
delay(5);
}
CS_1; //??CS
delay(5);
}
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
}
/**
* main
*
* @param[in] none
* @return none
*
* @brief entry
*
*/
int main(void)
{
InitDebug(); //´òÓ¡³õʼ»¯
InitDelay(); //ÑÓʱº¯Êý³õʼ»¯
GPIO_SetDir(GPIO_PA0, 1);
GPIO_SetDir(GPIO_PA2, 1);
GPIO_SetDir(GPIO_PA4, 1);
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)
{
LED = !LED;
mdelay(500);
}
}
效果图:
|