我写过ks0108的可以,这个就写不好,哪里错了啊aaaa?
#include <p30f4011.h>
#define RES LATBbits.LATB7
#define A0 LATBbits.LATB6
#define CLK LATBbits.LATB5
#define SDA LATBbits.LATB4
const unsigned char L[8]={0x00,0x42,0x7e,0x82,0x40,0x60,0x00};
//延时
void delay(int x)
{
int y;
for(;x>0;x--)
{
for(y=0;y<1000;y++)
{}
}
}
//写一个字节
void write(unsigned char byte)
{
unsigned char i,data;
CLK=1;
for(i=0;i<8;i++)
{
CLK=0;
data=byte&0x80;
if(data)
{
SDA=1;
}
else
{
SDA=0;
}
asm("nop");
asm("nop");
CLK=1;
asm("nop");
asm("nop");
byte<<=1;
}
}
//写命令
void writecommandlcd(unsigned char byte)
{
A0=0;
write(byte);
}
//写数据
void writebytelcd(unsigned char byte)
{
A0=1;
write(byte);
}
//设置页列
void lcdsetxy(unsigned char x,unsigned char y)
{
unsigned temp;
writecommandlcd(0xb0|x);
temp=y>>4;
writecommandlcd(0x10|temp);
temp=0x0f&y;
writecommandlcd(temp);
}
//显示一个字符
void display88(unsigned char x,unsigned y,const char *p)
{
unsigned i;
lcdsetxy(x,y);
for(i=0;i<8;i++)
{
writebytelcd(*(p++));
}
}
//初始化
void lcdint()
{
RES=0;复位
delay(10);
RES=1;
delay(10);
writecommandlcd(0xe2);内部复位
writecommandlcd(0xaf);开显示
writecommandlcd(0x2f);
writecommandlcd(0x26);
writecommandlcd(0x81);
writecommandlcd(0x0f);
writecommandlcd(0xa0);
writecommandlcd(0xc0);
writecommandlcd(0xa6);
writecommandlcd(0xa4);
writecommandlcd(0xac);
writecommandlcd(0x00);
writecommandlcd(0xf8);
writecommandlcd(0x00);
writecommandlcd(0x40);显示起始行
display88(1,1,L);
}
|