今晚捣鼓了一下另一种HT1621。
#include "main.h"
/** @addtogroup Projects_Examples_MD
* @{
*/
/** @addtogroup Examples
* @{
*/
#define uchar unsigned char
#define uint unsigned int
unsigned int tmp;
unsigned int n1, n2, n3, n4;
unsigned char Ht1621Tab[]={0x00,0x00,0x00,0x00};
unsigned char DispTab[]={0x7B,0x12,0x67,0x57,0x1E,0x5D,0x7D,0x13,0x7F,0x5F,0x69,0x45,0x3f, 0x7a, 0x3e};
// 0 1 2 3 4 5 6 7 8 9 C ? A V H
#define BIAS 0x52 //0b1000 0101 0010 1/3duty 4com
#define SYSDIS 0X00 //0b1000 0000 0000 ???????LCD?????
#define SYSEN 0X02 //0b1000 0000 0010 ???????
#define LCDOFF 0X04 //0b1000 0000 0100 ?LCD??
#define LCDON 0X06 //0b1000 0000 0110 ??LCD??
#define XTAL 0x28 //0b1000 0010 1000 ?????
#define RC256 0X30 //0b1000 0011 0000 ????
#define WDTDIS1 0X0A //0b1000 0000 1010 ?????
void Ht1621_CS_0() { md_gpio_set_pin_low(CS_GPIO_PORT,CS_GPIO_PIN);} // define P2.2 ---> CS
void Ht1621_CS_1() { md_gpio_set_pin_high(CS_GPIO_PORT,CS_GPIO_PIN);}
void Ht1621_WR_0() { md_gpio_set_pin_low(WR_GPIO_PORT,WR_GPIO_PIN);} // define P2.1 ---> WR
void Ht1621_WR_1() { md_gpio_set_pin_high(WR_GPIO_PORT,WR_GPIO_PIN);}
void Ht1621_DO_0() { md_gpio_set_pin_low(DA_GPIO_PORT,DA_GPIO_PIN);} // define P2.0 ---> DAT
void Ht1621_DO_1() { md_gpio_set_pin_high(DA_GPIO_PORT,DA_GPIO_PIN);}
unsigned int counter;
//-----------------------------------------------------------------------------------------
//????:Delay()
//? ?:?????
//-----------------------------------------------------------------------------------------
void Delay(unsigned char us) //5,7,9
{
while(--us);
}
//-----------------------------------------------------------------------------------------
//????:Delayms()
//-----------------------------------------------------------------------------------------
void Delayms(unsigned int ims)
{
unsigned int i,j;
for(i=0;i
for(j=0;j<65>
}
//-----------------------------------------------------------------------------------------
//Ht1621Wr_Data()
//-----------------------------------------------------------------------------------------
void Ht1621Wr_Data(unsigned char Data,unsigned char cnt)
{
unsigned char i;
for (i=0;i
{
Ht1621_WR_0();
if((Data & 0x80)==0x80) {Ht1621_DO_1();}
else {Ht1621_DO_0();}
Ht1621_WR_1();
Data<<=1;
}
}
//-----------------------------------------------------------------------------------------
//void Ht1621WrCmd(uchar Cmd)
//-----------------------------------------------------------------------------------------
void Ht1621WrCmd(unsigned char Cmd)
{
Ht1621_CS_0();
Ht1621Wr_Data(0x80,4); //??????100
Ht1621Wr_Data(Cmd,8); //??????
Ht1621_CS_1();
}
//-----------------------------------------------------------------------------------------
//void Ht1621WrOneData(uchar Addr,uchar Data)
//-----------------------------------------------------------------------------------------
void Ht1621WrOneData(unsigned char Addr,unsigned char Data)
{
Ht1621_CS_0();
Ht1621Wr_Data(0xa0,3); //??????101
Ht1621Wr_Data(Addr<<2>
Ht1621Wr_Data(Data,4); //???????? 7 6 5 4
Ht1621_CS_1();
}
//-----------------------------------------------------------------------------------------
//void Ht1621WrAllData()
//-----------------------------------------------------------------------------------------
void Ht1621WrAllData(unsigned char Addr,unsigned char *p,unsigned char cnt)
{
unsigned char i;
Ht1621_CS_0();
Ht1621Wr_Data(0xa0,3); //??????101
Ht1621Wr_Data(Addr<<2>
for (i=0;i
{
Ht1621Wr_Data(*p,8); //????
p++;
}
Ht1621_CS_1();
}
//-----------------------------------------------------------------------------------------
//void Ht1621_Init(void)
//-----------------------------------------------------------------------------------------
void Ht1621_Init(void)
{
Ht1621WrCmd(BIAS);
Ht1621WrCmd(RC256); //???????
//Ht1621WrCmd(XTAL); //???????
Ht1621WrCmd(SYSDIS);
Ht1621WrCmd(WDTDIS1);
Ht1621WrCmd(SYSEN);
Ht1621WrCmd(LCDON);
}
//-----------------------------------------------------------------------------------------
//DISPLAY
//-----------------------------------------------------------------------------------------
void Display(void)
{
unsigned char com;
com = 0;
if((DispTab[n1]&0x01) == 0x01){ com = com + 0x10;}
if((DispTab[n2]&0x01) == 0x01){ com = com + 0x20;}
if((DispTab[n3]&0x01) == 0x01){ com = com + 0x40;}
if((DispTab[n4]&0x01) == 0x01){ com = com + 0x80;}
Ht1621WrOneData(0 , com);
com = 0;
if((DispTab[n1]&0x02) == 0x02){ com = com + 0x10;}
if((DispTab[n2]&0x02) == 0x02){ com = com + 0x20;}
if((DispTab[n3]&0x02) == 0x02){ com = com + 0x40;}
if((DispTab[n4]&0x02) == 0x02){ com = com + 0x80;}
Ht1621WrOneData(1 , com);
com = 0;
if((DispTab[n1]&0x10) == 0x10){ com = com + 0x10;}
if((DispTab[n2]&0x10) == 0x10){ com = com + 0x20;}
if((DispTab[n3]&0x10) == 0x10){ com = com + 0x40;}
if((DispTab[n4]&0x10) == 0x10){ com = com + 0x80;}
Ht1621WrOneData(2 , com);
com = 0;
if((DispTab[n1]&0x40) == 0x40){ com = com + 0x10;}
if((DispTab[n2]&0x40) == 0x40){ com = com + 0x20;}
if((DispTab[n3]&0x40) == 0x40){ com = com + 0x40;}
if((DispTab[n4]&0x40) == 0x40){ com = com + 0x80;}
Ht1621WrOneData(3 , com);
com = 0;
if((DispTab[n1]&0x20) == 0x20){ com = com + 0x10;}
if((DispTab[n2]&0x20) == 0x20){ com = com + 0x20;}
if((DispTab[n3]&0x20) == 0x20){ com = com + 0x40;}
if((DispTab[n4]&0x20) == 0x20){ com = com + 0x80;}
Ht1621WrOneData(4 , com);
com = 0;
if((DispTab[n1]&0x08) == 0x08){ com = com + 0x10;}
if((DispTab[n2]&0x08) == 0x08){ com = com + 0x20;}
if((DispTab[n3]&0x08) == 0x08){ com = com + 0x40;}
if((DispTab[n4]&0x08) == 0x08){ com = com + 0x80;}
Ht1621WrOneData(5 , com);
com = 0;
if((DispTab[n1]&0x04) == 0x04){ com = com + 0x10;}
if((DispTab[n2]&0x04) == 0x04){ com = com + 0x20;}
if((DispTab[n3]&0x04) == 0x04){ com = com + 0x40;}
if((DispTab[n4]&0x04) == 0x04){ com = com + 0x80;}
Ht1621WrOneData(6 , com);
}
//-----------------------------------------------------------------------------------------
//Display_lcd_dot
//-----------------------------------------------------------------------------------------
void Display_lcd_dot(void)
{
Ht1621WrOneData(7 , 0x50);
}
//-----------------------------------------------------------------------------------------
//convertor()
//-----------------------------------------------------------------------------------------
void data_convertor(unsigned long adc_value)
{
tmp=adc_value; //adc
n4=tmp/100;
tmp=tmp0;
n3=tmp/10;
tmp=tmp;
n2=tmp;
// 4
n1=10; //display "C"
}
/**
* @brief This function configures GPIO
* @param None
* @retval None
*/
void config_gpio(void)
{
md_gpio_set_pin_function(DA_GPIO_PORT, DA_GPIO_PIN, GPIO_FUNC_1);
md_gpio_set_pin_push_pull(DA_GPIO_PORT, DA_GPIO_PIN);
md_gpio_set_pin_mode_output(DA_GPIO_PORT, DA_GPIO_PIN);
md_gpio_set_pin_function(WR_GPIO_PORT, WR_GPIO_PIN, GPIO_FUNC_1);
md_gpio_set_pin_push_pull(WR_GPIO_PORT, WR_GPIO_PIN);
md_gpio_set_pin_mode_output(WR_GPIO_PORT, WR_GPIO_PIN);
md_gpio_set_pin_function(CS_GPIO_PORT, CS_GPIO_PIN, GPIO_FUNC_1);
md_gpio_set_pin_push_pull(CS_GPIO_PORT, CS_GPIO_PIN);
md_gpio_set_pin_mode_output(CS_GPIO_PORT, CS_GPIO_PIN);
md_gpio_set_pin_function(LED2_GPIO_PORT, LED2_GPIO_PIN, GPIO_FUNC_1);
md_gpio_set_pin_push_pull(LED2_GPIO_PORT, LED2_GPIO_PIN);
md_gpio_set_pin_mode_output(LED2_GPIO_PORT, LED2_GPIO_PIN);
}
/**
* @brief Test main function
* @retval Status.
*/
int main()
{
md_init_1ms_tick();
config_gpio();
counter = 235;
Ht1621_Init(); //?????LCD
Delay(100); //??????
Ht1621WrAllData(0,Ht1621Tab,16);// Clear LCD display
Ht1621_Init();
while (1)
{
md_delay_1ms(1000);
md_gpio_toggle_pin_output(LED2_GPIO_PORT, LED2_GPIO_PIN);
data_convertor(counter);
Display();
Display_lcd_dot();
counter++;
}
}
代码:
一周热门 更多>