專注差異化嵌入式產(chǎn)品解決方案 給智能產(chǎn)品定制注入靈魂給予生命
提供開發(fā)工具、應(yīng)用測試 完善的開發(fā)代碼案例庫分享
從全面的產(chǎn)品導(dǎo)入到強大技術(shù)支援服務(wù) 全程貼心伴隨服務(wù),創(chuàng)造無限潛能!
128x64 LCD圖形顯示程序例子
這是一個在LCD128*64上顯示圖形的一個程序,一直以來都總是不知道怎么搞,現(xiàn)在終于都通了,想當(dāng)初在網(wǎng)上總找,要不是程序不全,就是無法運行,或者是C51匯編語言,讓人不爽,這樣的痛苦不可以再讓別人難受了。在LCD上顯示一幅圖,是“我的電腦,我的文檔”。IC用PIC16F877A,晶振4MHZ,采用并行8線,LCD:TS12864-3,接法在程序中有定義,只要將此程序COPY到你的PICC里編譯下載后,在目標板上即可以看到圖畫了!
不知道可不可以加酷?
#i nclude "pic.h"
#define RS RC0
#define RW RC1
#define E RC2
#define PSB RC3
#define RST RC4
//PORTD=DATA;
unsigned char COUNT3,COUNT2,COUNT1,COUNT,LCD_X,LCD_Y,LCD_DATA1,LCD_DATA2,LCD_DATA,F3,R1,F0;
const unsigned char TU_TAB1[]={
// 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xF0,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x18,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,0xFF,0xDC,0x00,0x01,
0x80,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,0xFF,0xBC,0x00,0x01,
0x80,0x00,0x30,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x7F,0xFF,0xB8,0x00,0x01,
0x80,0x00,0x30,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x01,0x7F,0xFF,0x78,0x00,0x01,
0x80,0x00,0x19,0xFF,0xFE,0xC0,0x00,0x00,0x00,0x00,0x02,0xFF,0xFF,0x70,0x00,0x01,
0x80,0x00,0x18,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x02,0xFF,0xFE,0xF0,0x00,0x01,
0x80,0x00,0x0C,0x01,0xFF,0x60,0x00,0x00,0x00,0x00,0x05,0xFF,0xFE,0xE0,0x00,0x01,
0x80,0x00,0x0C,0x7F,0xD0,0x20,0x00,0x00,0x00,0x00,0x05,0xFF,0xFD,0xE0,0x00,0x01,
0x80,0x00,0x06,0x00,0x0F,0xB0,0x00,0x00,0x00,0x00,0x0B,0xFF,0xFD,0xC0,0x00,0x01,
0x80,0x00,0x06,0x03,0xFC,0x10,0x00,0x00,0x00,0x00,0x0B,0xFF,0xFB,0xC0,0x00,0x01,
0x80,0x00,0x03,0x1F,0x00,0x18,0x00,0x00,0x00,0x00,0x17,0xFF,0xFB,0x80,0x00,0x01,
0x80,0x00,0x03,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x17,0xFF,0xF7,0x80,0x00,0x01,
0x80,0x00,0x01,0x80,0x00,0x0C,0x00,0x00,0x00,0x00,0x17,0xFF,0xF7,0x00,0x00,0x01,
0x80,0x00,0x01,0x80,0x00,0x04,0x00,0x00,0x00,0x00,0x09,0xFF,0xEF,0x00,0x00,0x01,
0x80,0x00,0x00,0xC0,0x00,0xF6,0x00,0x00,0x00,0x00,0x06,0x7F,0xEE,0x00,0x00,0x01,
0x80,0x00,0x00,0xC0,0x03,0xC2,0x00,0x00,0x00,0x00,0x01,0x9F,0xDE,0x00,0x00,0x01,
0x80,0x00,0x00,0x60,0x00,0x3B,0x00,0x00,0x00,0x00,0x00,0x67,0xDF,0x00,0x00,0x01,
0x80,0x00,0x00,0x60,0x00,0xE3,0x00,0x00,0x00,0x00,0x00,0x19,0xBF,0x00,0x00,0x01,
0x80,0x00,0x00,0x30,0x03,0x8E,0x00,0x00,0x00,0x00,0x00,0x06,0x3F,0x00,0x00,0x01,
0x80,0x00,0x00,0x30,0x06,0x3C,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0x00,0x00,0x01,
0x80,0x00,0x00,0x18,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x01,
0x80,0x00,0x00,0x18,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x0F,0x7F,0x80,0x00,0x01,
0x80,0x00,0x00,0x0C,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x1F,0xC0,0x00,0x01,
0x80,0x00,0x00,0x0C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x07,0xE0,0x00,0x01,
0x80,0x00,0x00,0x06,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x1F,0xE0,0x00,0x01,
0x80,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x3F,0xC0,0x00,0x01,
0x80,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0xFF,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFC,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x05,0x40,0x88,0x04,0x01,0x08,0x00,0x00,0x0A,0x81,0x10,0x04,0x00,0x20,0x01,
0x80,0x79,0x21,0x08,0x02,0x21,0x49,0x00,0x00,0xF2,0x42,0x10,0x04,0x47,0x10,0x01,
0x80,0x09,0x07,0xDF,0x7F,0xF7,0xAA,0x00,0x00,0x12,0x0F,0xBE,0x7F,0xE5,0xFE,0x01,
0x80,0x7F,0xF4,0x51,0x08,0x81,0x2C,0x00,0x00,0xFF,0xE8,0xA2,0x44,0x47,0x00,0x01,
0x80,0x09,0x04,0x61,0x08,0x81,0x7F,0x00,0x00,0x12,0x08,0xC2,0x7F,0xC5,0x4A,0x01,
0x80,0x0B,0x24,0x51,0x08,0x83,0x81,0x00,0x00,0x16,0x48,0xA2,0x44,0x45,0x6A,0x01,
0x80,0x1D,0x47,0xC9,0x05,0x05,0x01,0x00,0x00,0x3A,0x8F,0x92,0x44,0x47,0x52,0x01,
0x80,0x68,0x84,0x49,0x05,0x05,0x7F,0x00,0x00,0xD1,0x08,0x92,0x7F,0xC5,0x6A,0x01,
0x80,0x09,0x94,0x41,0x02,0x01,0x01,0x00,0x00,0x13,0x28,0x82,0x44,0x05,0x4A,0x01,
0x80,0x0E,0x57,0xC1,0x0D,0x81,0x01,0x00,0x00,0x1C,0xAF,0x82,0x04,0x29,0x42,0x01,
0x80,0x38,0x34,0x4E,0x70,0x71,0x7F,0x00,0x00,0x70,0x68,0x9C,0x03,0xEB,0x7E,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
};
//*************delay_ms********************************
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);
}
//***********檢查是否LCD忙碌的子程序**********************
void check_busy(void)
{
TRISD=0xff;//在此處設(shè)為輸入。
PORTD=0xff;
RS=0;
RW=1;
while (1)
{
NOP();NOP();NOP();
E =1;
NOP();NOP();NOP();
if (RD7==0) break;
NOP();NOP();NOP();
E =0;
}
E =0;
TRISD=0X00;//還原為輸出。
RC7=!RC7;
//delay_ms(50);
}
//**********數(shù)據(jù)寫命令***************************
void send_com(unsigned char command )
{
check_busy();
RS=0;
RW=0;
PORTD=command;
E =1;
NOP();
NOP();
E =0;
}
//**********LCD初始化時的送命令******************
void send_com_init(unsigned char command_init )
{
RS=0;
RW=0;
PORTD=command_init;
E =1;
NOP();
NOP();
E =0;
}
//**********寫數(shù)據(jù)***************************
void send_data(unsigned char data )
{
check_busy();
RS=1;
RW=0;
PORTD=data;
E =1;
NOP();
NOP();
E =0;
}
//***********讀數(shù)據(jù)****************************
unsigned char read_data(void)
{
unsigned char read_data;
check_busy();
TRISD=0XFF;
RS=1;
RW=1;
E =1;
NOP();
read_data=PORTD;
E =0;
TRISD=0x00;//還原為輸出。
return (read_data);
}
//***********清屏*****************************
void clear_LCD(void)
{
send_com(0x01);
send_com(0x34);
send_com(0x30);
}
//**********LCD初始化************************
void initial_LCD(void)
{
PSB=1;
RST=0;//Reset.
NOP();
NOP();
RST=1;
NOP();
delay_10us(10);
send_com_init(0x30);//30H--基本指令操作
delay_10us(4);
send_com_init(0x0c);//開顯示,關(guān)光標,不閃爍。
delay_10us(10);
send_com_init(0x01);//清除顯示
delay_ms(10);
send_com_init(0x06);//指定在資料寫入或讀取時,光標的移動方向,DDRAM的地址計數(shù)器(AC)加1。
}
//**********寫準備***************************
void WR_ZB(void)
{
send_com(0x34);
send_com(LCD_Y);
send_com(LCD_X);
send_com(0x30);
}
//*********取數(shù)送顯示******************************
void QUSHU(const unsigned char *shu)
{
for (;COUNT!=0;COUNT--)
{
send_data(*shu++);
delay_ms(80);
}
}
//*********Flash******************************
void flash(void)
{
send_com(0x08);//關(guān)閉顯示
delay_ms(250);
send_com(0x0c);//開顯示,關(guān)光標,不閃爍。
delay_ms(250);
send_com(0x08);//關(guān)閉顯示
delay_ms(250);
send_com(0x0c);//開顯示,關(guān)光標,不閃爍。
delay_ms(250);
send_com(0x08);//關(guān)閉顯示
delay_ms(250);
}
//**********顯示圖形子程序*********************
void PHO_DISP(const unsigned char *s)
{
COUNT3=0X02;
LCD_X=0X80;
for (;COUNT3!=0;COUNT3--)
{
LCD_Y=0X80;
COUNT2=0X20;//32
for (;COUNT2!=0;COUNT2--)
{
COUNT1=0X10;//16
WR_ZB();
for (;COUNT1!=0;COUNT1--)
{
send_data(*s++);
}
LCD_Y+=1;
}
LCD_X=0X88;
}
send_com(0x36);
send_com(0x30);
}
//******************顯示點陣子程序************
void LAT_DISP(void)
{
COUNT3=0X02;
LCD_X=0X80;
for (;COUNT3!=0;COUNT--)
{
LCD_Y=0X80;
F0=0;
COUNT2=0X20;
for (;COUNT2!=0;COUNT--)
{
COUNT1=0X10;
WR_ZB();
if (F0!=0)
{
LCD_DATA=LCD_DATA2;
}
else LCD_DATA=LCD_DATA1;
for (;COUNT1!=0;COUNT1--)
{
send_data(LCD_DATA);
}
LCD_Y+=1;
F0=!F0;
}
LCD_X=0X88;
}
send_com(0x36);
send_com(0x30);
}
void main(void)
{
TRISC=0X00;
TRISD=0X00;
PORTD=0X00;
PORTC=0X00;
initial_LCD();
while (1)
{
clear_LCD();
PHO_DISP(TU_TAB1);//顯示圖形
while (1);
}
}