PIC单片机12864编程程序
扫描二维码
随时随地手机看文章
IC用PIC16F877A,晶振4MHz,采用并行8线,LCD:TS12864-3,接法在程序中有定义,只要将此程序COPY到你的PICC里编译下载后,在目标板上即可以看到图画了!
#include"pic.h"
#defineRSRC0
#defineRWRC1
#defineERC2
#definePSBRC3
#defineRSTRC4
//PORTD=DATA;
unsignedcharCOUNT3,COUNT2,COUNT1,COUNT,LCD_X,LCD_Y,LCD_DATA1,LCD_DATA2,LCD_DATA,F3,R1,F0;
constunsignedcharTU_TAB1[]={
//16151413121110987654321
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********************************
voiddelay_10us(unsignedcharx)
{
while(x--);
}
voiddelay_ms(unsignedcharcnt)
{
unsignedchari;
do{
i=4;
do{
delay_10us(39);
}while(--i);
}while(--cnt);
}
//***********检查是否LCD忙碌的子程序**********************
voidcheck_busy(void)
{
TRISD=0xff;//在此处设为输入。
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);
}
//**********数据写命令***************************
voidsend_com(unsignedcharcommand)
{
check_busy();
RS=0;
RW=0;
PORTD=command;
E=1;
NOP();
NOP();
E=0;
}
//**********LCD初始化时的送命令******************
voidsend_com_init(unsignedcharcommand_init)
{
RS=0;
RW=0;
PORTD=command_init;
E=1;
NOP();
NOP();
E=0;
}
//**********写数据***************************
voidsend_data(unsignedchardata)
{
check_busy();
RS=1;
RW=0;
PORTD=data;
E=1;
NOP();
NOP();
E=0;
}
//***********读数据****************************
unsignedcharread_data(void)
{
unsignedcharread_data;
check_busy();
TRISD=0XFF;
RS=1;
RW=1;
E=1;
NOP();
read_data=PORTD;
E=0;
TRISD=0x00;//还原为输出。
return(read_data);
}
//***********清屏*****************************
voidclear_LCD(void)
{
send_com(0x01);
send_com(0x34);
send_com(0x30);
}
//**********LCD初始化************************
voidinitial_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);//开显示,关光标,不闪烁。
delay_10us(10);
send_com_init(0x01);//清除显示
delay_ms(10);
send_com_init(0x06);//指定在资料写入或读取时,光标的移动方向,DDRAM的地址计数器(AC)加1。
}
//**********写准备***************************
voidWR_ZB(void)
{
send_com(0x34);
send_com(LCD_Y);
send_com(LCD_X);
send_com(0x30);
}
//*********取数送显示******************************
voidQUSHU(constunsignedchar*shu)
{
for(;COUNT!=0;COUNT--)
{
send_data(*shu++);
delay_ms(80);
}
}
//*********Flash******************************
voidflash(void)
{
send_com(0x08);//关闭显示
delay_ms(250);
send_com(0x0c);//开显示,关光标,不闪烁。
delay_ms(250);
send_com(0x08);//关闭显示
delay_ms(250);
send_com(0x0c);//开显示,关光标,不闪烁。
delay_ms(250);
send_com(0x08);//关闭显示
delay_ms(250);
}
//**********显示图形子程序*********************
voidPHO_DISP(constunsignedchar*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);
}
//******************显示点阵子程序************
voidLAT_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;
}
elseLCD_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);
}
voidmain(void)
{
TRISC=0X00;
TRISD=0X00;
PORTD=0X00;
PORTC=0X00;
initial_LCD();
while(1)
{
clear_LCD();
PHO_DISP(TU_TAB1);//显示图形
while(1);
}
}