#include "SC_Init.h" //MCU Init header,Include all IC resource headers
#include "SC_it.h"
#include "..\Drivers\SCDriver_list.h"
#include "HeadFiles\SysFunVarDefine.h"
/**************************************Generated by EasyCodeCube*************************************/
#define uchar unsigned char
#define uint unsigned int
#define CS_0 GPIO_WriteLow(GPIO2, GPIO_PIN_7)
#define CS_1 GPIO_WriteHigh(GPIO2, GPIO_PIN_7)
#define WR_0 GPIO_WriteLow(GPIO0, GPIO_PIN_0)
#define WR_1 GPIO_WriteHigh(GPIO0, GPIO_PIN_0)
#define DA_0 GPIO_WriteLow(GPIO0, GPIO_PIN_1)
#define DA_1 GPIO_WriteHigh(GPIO0, GPIO_PIN_1)
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
unsigned char DispTab[]={0x7B,0x12,0x67,0x57,0x1E,0x5D,0x7D,0x13,0x7F,0x5F,0x3F,0x7C,0x69,0x76,0x6D, 0x2D};
// 0 1 2 3 4 5 6 7 8 9 A b C d E F
#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() { CS_0;} // define P2.2 ---> CS
void Ht1621_CS_1() { CS_1;}
void Ht1621_WR_0() { WR_0;} // define P2.1 ---> WR
void Ht1621_WR_1() { WR_1;}
void Ht1621_DO_0() { DA_0;} // define P2.0 ---> DAT
void Ht1621_DO_1() { DA_1;}
unsigned int counter;
void BSP_Configuration(void);
//-----------------------------------------------------------------------------------------
//????: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();
Delay(10);
if((Data & 0x80)==0x80) {Ht1621_DO_1();Delay(100);}
else {Ht1621_DO_0();Delay(100);}
Ht1621_WR_1();
Delay(10);
Data<<=1;
}
}
//-----------------------------------------------------------------------------------------
//void Ht1621WrCmd(uchar Cmd)
//-----------------------------------------------------------------------------------------
void Ht1621WrCmd(unsigned char Cmd)
{
Ht1621_CS_0();
Delay(10);
Ht1621Wr_Data(0x80,4); //??????100
Ht1621Wr_Data(Cmd,8); //??????
Ht1621_CS_1();
Delay(10);
}
//-----------------------------------------------------------------------------------------
//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/1000;
n3=tmp%1000/100;
n2=tmp%100/10;
// 4
n1=tmp%10; //display "C"
}
/*************************************.Generated by EasyCodeCube.************************************/
/*****************************************************************************************************
* Function Name: main
* Description : This function implements main function.
* Arguments : None
* Return Value : None
******************************************************************************************************/
void main(void)
{
/*<Generated by EasyCodeCube begin>*/
/*<UserCodeStart>*//*<SinOne-Tag><3>*/
SC_Init(); /*** MCU init***/
/*<UserCodeEnd>*//*<SinOne-Tag><3>*/
/*<UserCodeStart>*//*<SinOne-Tag><4>*/
/*****MainLoop*****/
counter = 235;
Ht1621_Init(); //?????LCD
Delay(100); //??????
Ht1621WrAllData(0,Ht1621Tab,16);// Clear LCD display
Ht1621_Init();
data_convertor(counter);
Display();
while(1)
{
/*<UserCodeStart>*//*<SinOne-Tag><5>*/
/*****User program*****/
/*<UserCodeEnd>*//*<SinOne-Tag><5>*/
/*<Begin-Inserted by EasyCodeCube for Condition>*/
}
/*<UserCodeEnd>*//*<SinOne-Tag><4>*/
/*<Generated by EasyCodeCube end>*/
}
效果图