12232F液晶驱动程序
#include<pic.h>//4MHZ#define CSRC4
#define SCK RC3
#define SDI RC2
#define LCD_COM0xf8
#define LCD_DATA 0xfa
#define nop() asm("nop")
const unsigned char HYSY={0xbb,0xb6,//欢
0xd3,0xad,//迎
0xca,0xb9,//使
0xd3,0xc3,//用
};
//***************12232写函数LCD_COMM指令/ LCD_DATA 数据, 值*********************//
void lcd_comm(unsigned flag,unsigned data)
{
unsigned char count;
CS=1;
for(count=8;count>0;count--)
{
if(flag&0x80)
SDI=1;
else
SDI=0;
SCK=1;
nop();
nop();
SCK=0;
flag=flag<<1;
}
for(count=4;count>0;count--)
{if(data&0x80)
SDI=1;
else
SDI=0;
SCK=1;
nop();
nop();
SCK=0;
data=data<<1;
}
for(count=4;count>0;count--)
{ SDI=0;
SCK=1;
nop();
nop();
SCK=0;
}
for(count=4;count>0;count--)
{
if(data&0x80)
SDI=1;
else
SDI=0;
SCK=1;
nop();
nop();
SCK=0;
data=data<<1;
}
for(count=4;count>0;count--)
{ SDI=0;
SCK=1;
nop();
nop();
SCK=0;
}
CS=0;
}
void lcd_delay(void)
{
unsigned int i=240;
while(--i){;}
}
/********************12232初始化*******************************/
void lcd_init(void)
{
PORTC=0X00;
TRISC=0XE3;
lcd_comm(LCD_COM,0x30);
lcd_delay();
lcd_comm(LCD_COM,0x0c);
lcd_delay();
lcd_comm(LCD_COM,0x01);
lcd_delay();
lcd_comm(LCD_COM,0x02);
lcd_delay();
lcd_comm(LCD_COM,0x80);
lcd_delay();
}
void hysy(void)
{
unsigned char i;
const unsigned char *romp=HYSY;
for(i=0x82;i<0x86;i++)
{
lcd_comm(LCD_COM,i);
lcd_delay();
lcd_comm(LCD_DATA,*romp++);
lcd_delay();
lcd_comm(LCD_DATA,*romp++);
lcd_delay();
}
}
void main(void)
{
lcd_delay();
lcd_delay();
lcd_delay(); //液晶上电延时
lcd_init();
hysy();
while(1);
}
页:
[1]