上次搞了一下HT1621,这次是另一种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)
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() { PAout(4)=0;} // define P2.2 ---> CS
void Ht1621_CS_1() { PAout(4)=1;}
void Ht1621_WR_0() { PAout(2)=0;} // define P2.1 ---> WR
void Ht1621_WR_1() { PAout(2)=1;}
void Ht1621_DO_0() { PAout(0)=0;} // define P2.0 ---> DAT
void Ht1621_DO_1() { PAout(0)=1;}
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<ims;i++)
for(j=0;j<65;j++) { Delay(1); }
}
//-----------------------------------------------------------------------------------------
//Ht1621Wr_Data()
//-----------------------------------------------------------------------------------------
void Ht1621Wr_Data(unsigned char Data,unsigned char cnt)
{
unsigned char i;
for (i=0;i<cnt;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,6); //??????
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,6); //??????
for (i=0;i<cnt;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=tmp%100;
n3=tmp/10;
tmp=tmp%10;
n2=tmp;
// 4
n1=10; //display "C"
}
/**
* 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);
counter = 235;
Ht1621_Init(); //?????LCD
Delay(100); //??????
Ht1621WrAllData(0,Ht1621Tab,16);// Clear LCD display
Ht1621_Init();
while (1)
{
data_convertor(counter);
Display();
Display_lcd_dot();
//Delayms(1000);
counter++;
LED = !LED;
mdelay(1000);
}
}
效果图:
|
共1人点赞
|