各位大佬,画的HT1621B驱动板驱动液晶,烧录程序后液晶不显示,程序如下。
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define uint32 unsigned long int
#define CKSEL (*(uchar volatile xdata *)0xfe00)
#define CLKDIV (*(uchar volatile xdata *)0xfe01)
#define IRC24MCR (*(uchar volatile xdata *)0xfe02)
sfr P1M0=0x92;
sfr P1M1=0x91;
sfr P_SW2 = 0xba;
sbit _DAT=P1^6; //HT1621数据引脚
sbit _CS=P1^0; //HT1621使能引脚
sbit _WR=P1^1; //HT1621时钟引脚
sbit _Vlcd=P1^7;//液晶/背光电源控制引脚,低电平有效
void delay_ms(uint z) //主时钟频率24MHz
{
uchar i=11, j=190;
_nop_();
_nop_();
_nop_();
while(z--)
{
do
{
while (--j);
} while (--i);
}
}
void WriteBitR(uchar dat,uchar m)
{
uchar i;
for (i=0;i<m;i++)
{
_WR=0;
_nop_();
_DAT=dat&0x80;
_nop_();
_WR=1;
_nop_();
dat<<=1;
}
}
void Write_cmd(uchar Cmd)
{
_CS=0;
_nop_();
WriteBitR(0x80,4); //写入命令标志100
WriteBitR(Cmd,8); //写入命令数据
_CS=1;
_nop_();
}
void WriteOneData(uchar Addr,uchar Data)
{
_CS=0;
WriteBitR(0xa0,3); //写入数据标志101
WriteBitR(Addr<<2,6); //写入地址数据
WriteBitR(Data,8); //写入数据
_CS=1;
_nop_();
}
void LCD_Init(void)
{
_CS=1;
_WR=1;
_DAT=1;
Write_cmd(0x52); //0b1000 0101 0010 1/3duty 4com
Write_cmd(0X30); //0b1000 0011 0000 内部时钟
Write_cmd(0x00); //0b1000 0000 0000 关振系统荡器和LCD偏压发生器
Write_cmd(0X0A); //0b1000 0000 1010 禁止看门狗
Write_cmd(0X02); //0b1000 0000 0010 打开系统振荡器
Write_cmd(0X06); //0b1000 0000 0110 打开LCD偏压
}
void display1()
{
uchar m1;
for(m1=0;m1<30;m1=m1+2)
WriteOneData(m1,0xff);
}
void Init()
{
P_SW2=0x80;
CKSEL=0x00;
P_SW2=0x00;
P1M0=0x00;
P1M1=0x00;
_Vlcd=0;
LCD_Init();
}
void main()
{
Init();
while(1)
{
display1();
delay_ms(1);
}
}
|