LCM12864 C语言驱动程序

]LCM12864 C语言驱动程序。[/b]

下面是一个我写的12864点阵的显示驱动程序(参考PIC自带的字符型液晶驱动的样板例子),在这之前,我一直在网上苦苦搜索,想找到C语言的12864驱动程序,可是不是8051的汇编,就是什么乱七八糟的程序,哎,不得不自已写,找资料,买LCD,现在可以用了,我想大家很多人正在搜索吧!
/*************************************************************************
程序说明:
LCD驱动采用4位元(这个4位元方式,在网上搜索来看,还没有人采用,可以节省4位I/O口),并口方式,晶体4M,注意此LCD有点不同尽量很普通,没有CS1,CS2页选择脚,带串口方式,型号是TS-12864-3。IC 16F877A。
在屏幕上显示“Atilla tester"
"~_~"
RD7----------LCD D7
RD6-----------LCD D6
RD5-----------LCD D5
RD4-----------LCD D4
RD3-----------LCD E
RD2-------- LCD RS
RD1---------R/W
/***********************程序如下**********************************/
#include "pic.h"
#define lcd_cursor(x) lcd_write(((x)&0x7F)|0x80)//Set the cursor position
#define LCD_RS RD2
#define LCD_EN RD3
#define LCD_RW RD1
#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))
void delay_10us(unsigned char x)
{
while(x--);
}
void delay_ms(unsigned char cnt)
{
unsigned char i;
do {
i = 4;
do {
delay_10us(39);
} while(--i);
} while(--cnt);
}
/* write a byte to the LCD in 4 bit mode */
void lcd_write(unsigned char c)
{
PORTD = (PORTD & 0x0F) | (c & 0xF0); //先送高位D7 D6 D5 D4
LCD_STROBE;
PORTD = (PORTD & 0x0F) | (c /* Clear and home the LCD */
void lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
delay_ms(2);
}
/* write a string of chars to the LCD */
void lcd_puts(const char * s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}
/* write one character to the LCD */
void lcd_putch(char c)
{
LCD_RS = 1; // write characters
PORTD = (PORTD & 0x0F) | (c & 0xF0); //先送高位
LCD_STROBE;
PORTD = (PORTD & 0x0F) | (c /*Go to the specified position*/
void lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos);
}
/* initialise the LCD - put into 4 bit mode */
//严格按照LCD的复位要求。
void lcd_init(void)
{
LCD_RS = 0; // write control bytes
delay_ms(40); // power on delay,wait time>40ms
PORTD = 0x20; // Function set,set 4 bit mode
LCD_STROBE;
delay_10us(10); //wait time >100us
lcd_write(0x20); // Function set:4 bit mode.
delay_10us(10); //wait time >100us
lcd_write(0x0C); // display ON/OFF control.
delay_10us(10); //wait time >100us
lcd_write(0x01); // display clear
delay_ms(10); //wait time >10ms
lcd_write(0x06); // entry mode set
}
void main(void)
{
TRISD=0X00;
PORTD=0X00;
lcd_init();
lcd_goto(0x00);
lcd_puts("Atilla tester");
lcd_go

to(0x11);
lcd_puts("~_~");
while(1);
}

相关文档
最新文档