马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 sky! 于 2012-7-7 17:00 编辑 #include<iom16v.h>
#include<macros.h>
#define uchar unsigned char
#define uint unsigned int
#define CS_0 PORTC&=~(1<<PC0)
#define CS_1 PORTC|=(1<<PC0)
#define SID_0 PORTC&=~(1<<PC1)
#define SID_1 PORTC|=(1<<PC1)
#define SCLK_0 PORTC&=~(1<<PC2)
#define SCLK_1 PORTC|=(1<<PC2)
#define PSB_0 PORTC&=~(1<<PC3)
#define PSB_1 PORTC|=(1<<PC3)
#define RESET_0 PORTC&=~(1<<PC4)
#define RESET_1 PORTC|=(1<<PC4)
void write(uchar start,unsigned char ddata);
void sendbyte(unsigned char bbyte);
void delaynms(unsigned int di);
void lcdinit(void);
void lcdtest();
void lcdcls();
unsigned char const ma[] ={" FISHC FISHC "};
unsigned char const ma2[]={"FISHC FISHC FISHC"};
unsigned char const ma3[]={"123456789 "};
unsigned char const ma4[]={"fishc fishc fishc"};
void lcdinit(void)
{
delaynms(10);
PSB_0;
RESET_0;
delaynms(1);
RESET_1;
CS_1;
write(0,0x30);
write(0,0x0c);
write(0,0x01);
}
void write(uchar start,uchar ddata)
{
uchar start_data,Hdata,Ldata;
if(!start) start_data=0xf8;
else start_data=0xfa;
Hdata=ddata&0xf0;//取高四位
Ldata=(ddata<<4)&0xf0;//取低四位
sendbyte(start_data);//发送起始信号
delaynms(5);//延时是必须的
sendbyte(Hdata);
delaynms(1);//延时是必须的
sendbyte(Ldata);
delaynms(1);//延时是必须的
}
void sendbyte(uchar bbyte)
{
uchar i;
for(i=0;i<8;i++)
{
if(bbyte&0x80)
{
SID_1;
}
else
{
SID_0;
}
SCLK_1;
asm("nop");
asm("nop");
asm("nop");
asm("nop");//空周期
SCLK_0;
bbyte<<=1;
}
}
void delaynms(uint di)
{
uchar j;
while(di--)
{
for(j=0;j<1576;j++) //11.0592M晶振1ms基准延时程序
{
;
}
}
}
void main()
{
uchar i;
PORTC=0xff;
DDRC=0xff;
lcdinit();
while(1)
{
write(0,0x80);for(i=0;i<16;i++) write(1,ma[i]);
write(0,0x90);for(i=0;i<16;i++) write(1,ma2[i]);
write(0,0x88);for(i=0;i<16;i++) write(1,ma3[i]);
write(0,0x98);for(i=0;i<16;i++) write(1,ma4[i]);
}
}
|