以下是在AC1090上加HT1621B显示屏,并调试OK的程序。
#define BIAS 0X50 //1/2偏压,4背极 //
//#define BIAS 0X52 //1/3偏压,4背极
#define RC256 0X30 //系统时钟选择为片内RC振荡器
//#define RC256 0X38
#define WDTDIS1 0X0A //禁止WDT溢出标志输出
#define TIMERDIS 0X08 //时基输出禁能
#define SYSEN 0X02 //打开系统时钟
#define SYSDIS 0X00 //关闭系统时钟和偏压发生器
#define LCDON 0X06 //打开偏压发生器
#define LCDOFF 0X04 //关闭LCD偏压发生器
#define LCD1621_GPIO_Init() P1DIR &= ~(BIT(3)|BIT(4)|BIT(5)); P1 |=(BIT(3)|BIT(4)|BIT(5));
#define LCD1621_DIO P13
#define LCD1621_CE P15
#define LCD1621_CLK P14
/*----------------------------------------------------------------------------*/
uint8 LCD_CODE[]=
{
//F(0x20) E (0x40) G(0x02) D(0x80) C(0x04) B(0x01) A(0x10)
0xf5, //0
0x05, //1
0xd3, //2
0x97, //3
0x27, //4
0xb6, //5
0xF6, //6
0x15, //7
0xf7, //8
0xb7, //9
0XFF
};
/*********************************************************/
//送 d_count 位数据 d;从低位开始送
/*********************************************************/
void HT1621_Send_Bits(uint8 d, uint8 d_count)
{
uint8 j;
for (j=0; j
{
LCD1621_CLK = 0; //wr 置低;
//HT1621_Delay(50);
if ((d & 0x80)==0) //置数据位;
{
LCD1621_DIO= 0; //data 置 0
}
else
{
LCD1621_DIO= 1; //data 置 1
}
LCD1621_CLK = 1;; //wr 置高;
//HT1621_Delay(50);
d =(d<<1); //右移位
}
}
u8 Read_LCD1621_Byte()AT(LED_5X7_CODE)
{
u8 i,k=0;
LCD1621_CE =0;
for(i=0;i<8;i++)
{
LCD1621_CLK=0;
//delayus();
k>>=1;
LCD1621_CLK=1;
//delayus();
if(LCD1621_DIO==1)
{
k|=0x80;
}
// else k&=0x7f;
}
LCD1621_CE =1;
return (k);
}
void START_HT1621(void)
{
LCD1621_GPIO_Init();
LCD1621_CE =0;
_nop_();
_nop_();
LCD1621_CE =1;
}
void WR_LCD1621_BYTE(uint8 cmd)
{
HT1621_Send_Bits(cmd,8);
}
/**-------------------------------------------------------------------------
Name: SendCmd(送命令)
---------------------------------------------------------------------------*/
void SendCmd_1621(uint8 command)
{
/*LCD1621_CE =0;
HT1621_Send_Bits(0x80,4); //写入标志码“100”和9 位command 命令,由于
HT1621_Send_Bits(command,8); //没有使有到更改时钟输出等命令,为了编程方便
LCD1621_CE =1; //直接将command 的最高位写“0”
*/
uint8 i,k;
LCD1621_CE =0;
k = 0x80;
for(i=0;i<3;i++)
{
if((k&0x80)==0)
LCD1621_DIO = 0;
else
LCD1621_DIO = 1;
LCD1621_CLK = 0;
LCD1621_CLK = 1;
k=k<<1;
}
k=command;
for(i=0;i<9;i++)
{
if((k&0x80)==0)
LCD1621_DIO = 0;
else
LCD1621_DIO = 1;
LCD1621_CLK = 0;
LCD1621_CLK = 1;
k=k<<1;
}
LCD1621_CE = 1;
}
/**-------------------------------------------------------------------------
Name: Write_1621(送数据和命令程序)
---------------------------------------------------------------------------*/
void Write_1621(uint8 addr,uint8 sdata)
{
/*addr<<=2;
LCD1621_CE =0;
HT1621_Send_Bits(0xa0,3); //写入标志码“101”
HT1621_Send_Bits(addr,6); //写入addr 的高6位
HT1621_Send_Bits(sdata,8); //写入data 的8位
LCD1621_CE =1;*/
uint8 i,k;
LCD1621_CE =0;
k = 0xa0;
for(i=0;i<3;i++)
{
if((k&0x80)==0)
LCD1621_DIO = 0;
else
LCD1621_DIO = 1;
LCD1621_CLK = 0;
LCD1621_CLK = 1;
k=k<<1;
}
k=addr<<2;
for(i=0;i<6;i++)
{
if((k&0x80)==0)
LCD1621_DIO = 0;
else
LCD1621_DIO = 1;
LCD1621_CLK = 0;
LCD1621_CLK = 1;
k=k<<1;
}
k=sdata<<4;
for(i=0;i<6;i++)
{
if((k&0x80)==0)
LCD1621_DIO = 0;
else
LCD1621_DIO = 1;
LCD1621_CLK = 0;
LCD1621_CLK = 1;
k=k<<1;
}
LCD1621_CE = 1;
}
/*******************************************************************/
/*
com: com0-->4;com1-->3;com2-->2;com3-->1;
num: num =1 ;显示0x10-->USB; 0x20-->FM; 0x40--> 蓝牙; 0x80-->MHZ
num =0 显示无符号的4*7 "8"数字
dat: dat-->0x80;com=4-->SD; com=3-->:;com=2-->.;com=1-->MHZ;
*/
/*******************************************************************/
void DISP_NUM(uint8 com,uint8 num,uint8 dat)
{
uint8 i,j;
uint8 udat;
udat = dat>>4;
//if(udat&0x0f)
{
for(i=(8-com*2);i<(10-com*2+num);i++) //com口选择0,1,2,3,4
{
//Write_1621(i,dat<<4);
j=i;
Write_1621(++j,dat); //显示低4位
Write_1621(i++,udat); //显示高4位
}
}
}
/*******************************************************************/
void DISP_Icon(uint8 com,uint8 dat)
{
uint8 i,j;
uint8 udat;
udat = dat>>4;
//if(udat&0x0f)
{
for(i=(8-com*2);i<9;i++) //com口选择0,1,2,3,4
{
//Write_1621(i,dat<<4);
j=i;
Write_1621(++j,dat); //显示低4位
Write_1621(i++,udat); //显示高4位
}
}
}
void DISP(uint8 dat)
{
uint8 i;
for(i=0;i<9;i++)
Write_1621(i,dat);
}
/*************************HT1621B初始化设置*************************/
void SETUP_HT1621(void) //HT1621偏压、背极、工作方式设置
{
START_HT1621();
/*SendCmd_1621(BIAS);
SendCmd_1621(RC256);
SendCmd_1621(SYSEN);
SendCmd_1621(LCDON);
SendCmd_1621(WDTDIS1);
SendCmd_1621(TIMERDIS); */
SendCmd_1621(0x01); //Enable system
SendCmd_1621(0x18); //CLOCK SOURCE IS 256K ON CHIP
SendCmd_1621(0x29); //BIAS =1/3 DUTY=1/4
SendCmd_1621(0x02); //Display off
LCD1621_POWER_OUT;
LCDBL_CONTROL_OUT;
LCD1621_POWER_ON;
LCDBL_CONTROL_ON;
//HT1621_all_on();
SendCmd_1621(0x03); //Display on
DISP(0x00);
}
阅读(1977) | 评论(0) | 转发(0) |