#include <pic.h>
#define uchar unsigned char
#define BIAS 0x24
#define SYSEN 0x01
#define LCDOFF 0x02
#define LCDON 0x03
#define SDA_LCD1621 RC1 //数据线
#define SCL_LCD1621 RC0 //时钟线
#define CS1_LCD1621 RC5
#define CS2_LCD1621 RC4
#define T_SDA_LCD1621 TRISC1
#define T_SCL_LCD1621 TRISC0
#define T_CS1_LCD1621 TRISC5
#define T_CS2_LCD1621 TRISC4
bank1 const unsigned char HALLO_data[16]={0x0e,0x34,0x0F,0xc5,0x0b,0x01,0x0b,0x01,0x0b,0xf1,0x00,0x00,0x00,0x00,0x00,0x00}; //HELLO
void __ht1621Sendbit(unsigned char a,unsigned char i)
{
if (i == 0) {
return;
}
while(i--)
{
if(a&0x01)
{
SDA_LCD1621=1; //?í "1"
}
else
{
SDA_LCD1621=0; //?í"0"
}
SCL_LCD1621=0; //ê±??
_nop();
SCL_LCD1621=1;
_nop();
SCL_LCD1621=0; //ê±??
_nop();
a=a>>1;
}
}
void SendBit_1621(uchar data,uchar cnt) //data的高cnt位写入HT1621,高位在前
{
uchar i;
for(i =0; i <cnt; i ++){
if((data&0x80)==0) SDA_LCD1621=0;
else SDA_LCD1621=1;
SCL_LCD1621=0;
_nop();
SCL_LCD1621=1;
data<<=1;
}
}
void SendDataBit_1621(uchar data,uchar cnt) //data的低cnt位写入HT1621,低位在前
{
uchar i;
for(i =0; i <cnt; i ++)
{
if((data&0x01)==0) SDA_LCD1621=0;
else SDA_LCD1621=1;
SCL_LCD1621=0;
_nop();
SCL_LCD1621=1;
data>>=1;
}
}
void SendCmd(uchar command)
{
CS1_LCD1621=0; //ê1?ü
CS2_LCD1621=0;
SendBit_1621(0x80,3); //写入标志码"100"
SendBit_1621(command,9); //写入9位数据,其中前8位为command命令,最后1位任意
CS1_LCD1621=1; //ê1?ü
CS2_LCD1621=1;
}
void Write_1621(uchar addr,uchar data)
{
CS1_LCD1621=0; //ê1?ü
CS2_LCD1621=0;
SendBit_1621(0xa0,3); //写入标志码"101"
SendBit_1621(addr<<2,6); //写入6位addr
SendDataBit_1621(data,4); //写入data的低4位
CS1_LCD1621=1; //ê1?ü
CS2_LCD1621=1;
}
void WriteAll_1621(uchar addr,uchar *p,uchar cnt)
{
uchar i;
CS1_LCD1621=0; //ê1?ü
CS2_LCD1621=0;
SendBit_1621(0xa0,3); //写入标志码"101"
SendBit_1621(addr<<2,6); //写入6位addr
for(i =0; i <cnt; i ++,p++) //连续写入数
{
SendDataBit_1621(*p,8);
}
CS1_LCD1621=1; //ê1?ü
CS2_LCD1621=1;
}
void lcdInit()
{
unsigned char i=3;
TRISC &= ~(1 << 0); /* CLK */
TRISC &= ~(1 << 1); /* DATA */
TRISC &= ~(1 << 4); /* CS2 */
TRISC &= ~(1 << 5); /* CS1 */
CS1_LCD1621=0; //ê1?ü
CS2_LCD1621=0;
__ht1621Sendbit(0x01,8);
__ht1621Sendbit(0x4,4);
CS1_LCD1621=1; //ê1?ü
CS2_LCD1621=1;
CS1_LCD1621=0; //ê1?ü
CS2_LCD1621=0;
__ht1621Sendbit(0x1,8);
__ht1621Sendbit(0x6,4);
CS1_LCD1621=1; //ê1?ü
CS2_LCD1621=1;
CS1_LCD1621=0; //ê1?ü
CS2_LCD1621=0;
__ht1621Sendbit(0xa1,8);
__ht1621Sendbit(0x4,4);
CS1_LCD1621=1; //ê1?ü
CS2_LCD1621=1;
CS1_LCD1621=0;
CS2_LCD1621=0;
__ht1621Sendbit(0x5,9);
for(i=0;i<16;++i) {
__ht1621Sendbit(0x0,8);
}
CS1_LCD1621=1; //ê1?ü
CS2_LCD1621=1;
}
void lcdDispPowerUp()
{
unsigned char i=0;
CS1_LCD1621=0;
CS2_LCD1621=0;
__ht1621Sendbit(0x5,9);
for(i=0;i<16;++i) {
__ht1621Sendbit(HALLO_data[i],8); /* 显示HELLo */
}
CS1_LCD1621=1;
CS2_LCD1621=1;
}
void main()
{
TRISC=0xC0;
PORTC=0x00;
TRISB=0X00;
PORTB=0x00;
//T_SDA_LCD1621 = 0;
//T_SCL_LCD1621 = 0;
//T_CS1_LCD1621 = 0;
uchar a[10];
a[0]=0x21;a[1]=0x43;a[2]=0x65;a[3]=0x87;a[4]=0xa9;
//SDA_LCD1621=0; //将端口设为输出
//SendCmd(BIAS); //设置偏压和占空比
//SendCmd(SYSEN); //打开系统振荡器
//SendCmd(LCDON); //打开LCD偏压发生器
lcdInit();
RB3=1;
//Write_1621(0x09,0x01); //在地址0x09处写入数据0x01
//WriteAll_1621(0,a,5); //在起始地址为0处连续写入5个字节数据 //a为写入数据的起始地址,5为写入的字节数
//SendCmd(LCDOFF); //关闭LCD显示
lcdDispPowerUp();
} |