|
发表于 2015-8-2 10:15:23
|
显示全部楼层
void LCD_WRClk(void)//1个写入时钟
{
PD_BAK=PD_BAK&(~L_WR);PD_ODR=PD_BAK;
DelayXus(2);
PD_BAK=PD_BAK|(L_WR);PD_ODR=PD_BAK;
DelayXus(2);
}
void LCD0_CS(void)
{
PD_BAK=PD_BAK&(~L_CS0);PD_ODR=PD_BAK;//片选置低
DelayXus(2);
}
void LCD0_NCS(void)
{
PD_BAK=PD_BAK|(L_CS0);PD_ODR=PD_BAK;//片选置高
DelayXus(2);
}
void LCD1_CS(void)
{
PD_BAK=PD_BAK&(~L_CS1);PD_ODR=PD_BAK;//片选置低
DelayXus(2);
}
void LCD1_NCS(void)
{
PD_BAK=PD_BAK|(L_CS1);PD_ODR=PD_BAK;//片选置高
DelayXus(2);
}
void LCD_Command(unsigned char cmd) //发送一字节数据
{
unsigned char i;
PC_BAK=PC_BAK|(L_DATA);PC_ODR=PC_BAK; //100
LCD_WRClk();
PC_BAK=PC_BAK&(~L_DATA);PC_ODR=PC_BAK;
LCD_WRClk();
PC_BAK=PC_BAK&(~L_DATA);PC_ODR=PC_BAK;
LCD_WRClk();
for(i=0;i<8;i++)
{
if(cmd&B10000000){PC_BAK=PC_BAK|(L_DATA);}
else{PC_BAK=PC_BAK&(~L_DATA);}
PC_ODR=PC_BAK;
LCD_WRClk();
cmd=cmd<<1;
}
PC_BAK=PC_BAK|(L_DATA);PC_ODR=PC_BAK;
LCD_WRClk();
}
void LCD_Init(void)//HT1621初始化
{
LCD0_CS();LCD1_CS();
LCD_Command(B00000000); //SYS DIS
LCD0_NCS();LCD1_NCS();
LCD0_CS();LCD1_CS();
LCD_Command(B00000001); //SYS EN
LCD0_NCS();LCD1_NCS();
LCD0_CS();LCD1_CS();
LCD_Command(B00011000); //RC 256K
LCD0_NCS();LCD1_NCS();
LCD0_CS();LCD1_CS();
LCD_Command(B00000100); //TIMER DIS
LCD0_NCS();LCD1_NCS();
LCD0_CS();LCD1_CS();
LCD_Command(B00000101); //WDT DIS
LCD0_NCS();LCD1_NCS();
LCD0_CS();LCD1_CS();
LCD_Command(B00001000); //TONE OFF
LCD0_NCS();LCD1_NCS();
LCD0_CS();LCD1_CS();
LCD_Command(B00101001); //4COM,1/3BIAS
LCD0_NCS();LCD1_NCS();
LCD0_CS();LCD1_CS();
LCD_Command(B00000010); //LCD OFF
LCD0_NCS();LCD1_NCS();
LCD0_CS();LCD1_CS();
LCD_Command(B00000011); //LCD ON
LCD0_NCS();LCD1_NCS();
}
void LCD_DISPLAY(unsigned char LCDset) //显示,发送全部显示缓存
{
unsigned char i,k,dat;
if(LCDset==0){LCD0_CS();}else{LCD1_CS();}
PC_BAK=PC_BAK|(L_DATA);PC_ODR=PC_BAK; //101
LCD_WRClk();
PC_BAK=PC_BAK&(~L_DATA);PC_ODR=PC_BAK;
LCD_WRClk();
PC_BAK=PC_BAK|(L_DATA);PC_ODR=PC_BAK;
LCD_WRClk();
for(k=0;k<6;k++) //六位地址000000
{
PC_BAK=PC_BAK&(~L_DATA);PC_ODR=PC_BAK;
LCD_WRClk();
}
for(k=0;k<16;k++)
{
if(LCDset==0){dat=disbuf0[k];}else{dat=disbuf1[k];}
for(i=0;i<8;i++)
{
if(dat&B00000001){PC_BAK=PC_BAK|(L_DATA);}
else{PC_BAK=PC_BAK&(~L_DATA);}
PC_ODR=PC_BAK;
LCD_WRClk();
dat=dat>>1;
}
}
PC_BAK=PC_BAK|(L_DATA);PC_ODR=PC_BAK;
LCD_WRClk();
if(LCDset==0){LCD0_NCS();}else{LCD1_NCS();}
}
我这是控制两片1621,CS信号分开。供参考 |
|