控制器ST7565S,可以选择并口通信或者串口通信,8080接口和6800接口可选。
ST7565S是一颗支持串行SPI的LCD 芯片,其使用方法比较简单,只需要驱动程序包括写入指令和写入数据操作即可。
#include<REG52.H>
#include<INTRINS.H>
#include<PIC.C> //1100
#define VC_ON 0x2C //1010
#define VR_ON 0x2A
#define VF_ON 0x29 //1001
#define NOP _nop_();_nop_();_nop_();_nop_()
#define data P0
sbit CS = P2^7;
sbit RES = P2^6;
sbit RS = P2^5;
sbit RW = P2^4;
sbit Read = P2^3;
/******************************delay time***********************************/
void delay_ms(unsigned int ms)
{
unsigned int n ;
while(ms--)
{
n = 86;
while(n--);
}
}
/****************************reset IC for start****************************/
void LCD_Reset()
{
IE = 0x00;
RES = 0;
delay_ms(50);
RES = 1;
delay_ms(50);
}
/*******************************write data to IC**************************/
void w_dat(unsigned char dat)
{
data = dat;
NOP;
RS = 1;
RW = 0;
Read = 1;
NOP;
CS = 1;
_nop_();
CS = 0;
}
/******************************write Command to IC***********************/
void w_cmd(unsigned char cmd)
{
data = cmd;
NOP;
RS = 0;
RW = 0;
Read = 1;
NOP;
CS = 1;
_nop_();
CS = 0;
}
/***************************display picture *****************************/
void Display(unsigned char *p)
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page); //set page address
w_cmd(0x10); //set Column address MSB
w_cmd(0x00); //set column address LSB
for(column=0;column<128;column++)
{
w_dat(*p++);
}
}
}
void Display_fill(unsigned char fill)
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page); //set page address
w_cmd(0x10); //set Column address MSB
w_cmd(0x00); //set column address LSB
for(column=0;column<131;column++)
{
w_dat(fill);
}
}
}
void Grid_white()
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page);
w_cmd(0x10);
w_cmd(0x00);
for(column=0;column<65;column++)
{
w_dat(0xFF);
w_dat(0x00);
}
}
}
void Grid_Black()
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page);
w_cmd(0x10);
w_cmd(0x00);
for(column=0;column<65;column++)
{
w_dat(0x00);
w_dat(0xFF);
}
}
}
void Grid_Line1()
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page);
w_cmd(0x10);
w_cmd(0x00);
for(column=0;column<131;column++)
{
w_dat(0xAA);
}
}
}
void Grid_Line2()
{
unsigned char page,column;
for(page=0xB7;page>=0xB0;page--)
{
w_cmd(page);
w_cmd(0x10);
w_cmd(0x00);
for(column=0;column<131;column++)
{
w_dat(0x55);
}
}
}
void Init_IC()
{
CS = 0;
P3 = 0xFF;
LCD_Reset();
w_cmd(0xA2); //LCD Bias selection(1/65 Duty,1/9Bias)
w_cmd(0xA0); //ADC selection(SEG0->SEG128)
w_cmd(0xC0); //SHL selection(COM0->COM64)
w_cmd(0x26); //Regulator Resistor Selection
delay_ms(5);
w_cmd(0x81); //Electronic Volume
w_cmd(0x8); //Reference Register selection Vo=(1+Rb/Ra)(1+a)*2.1=10
w_cmd(VC_ON); //Power Control(Vc=1;Vr=0;Vf=0)
delay_ms(10);
w_cmd(VC_ON|VR_ON);
delay_ms(10);
w_cmd(VC_ON|VR_ON|VF_ON);
delay_ms(10);
w_cmd(0xF8);
w_cmd(0x00);
delay_ms(5);
w_cmd(0xAF); //Display on
}
void main()
{
while(1)
{
Init_IC();
Display_fill(0xFF);
delay_ms(1000);
Grid_white();
delay_ms(1000);
Grid_Black();
delay_ms(1000);
Grid_Line1();
delay_ms(1000);
Grid_Line2();
delay_ms(1000);
Display_fill(0x00);
delay_ms(5); ;
Display(deep);
delay_ms(3000);
}
}
unsigned char code deep[] = {
0x00,0x00,0x00,0x00,0x0E,0x03,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7C,0x23,0x1F,
0x00,0x00,0x01,0x01,0x03,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0x07,0x06,0x06,0x06,
0x06,0x06,0x06,0x1F,0x31,0x0E,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x3F,
0x00,0x00,0x00,0x00,0x7F,0x27,0x18,0x00,
0xFF,0x2E,0x10,0x01,0x03,0x00,0x00,0x00,
0x00,0x2F,0x39,0x05,0x0A,0x00,0x00,0x00,
0x7F,0x27,0x18,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7F,0x37,0x0C,0x00,0x00,
0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x17,0x38,0x07,0x0D,0x00,0x03,0x03,
0x03,0x03,0x03,0x03,0x0F,0x1E,0x01,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xF0,0x8F,0x7F,
0x20,0x38,0x28,0x2F,0x29,0x28,0xEF,0xE9,
0x28,0x28,0x68,0x88,0x78,0x08,0x00,0x00,
0x00,0x00,0x00,0xFF,0xFD,0x05,0x05,0x05,
0x05,0x05,0x05,0xFD,0xFF,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
0x03,0x77,0x70,0x60,0xFF,0xFF,0x60,0x60,
0xFF,0xFF,0x60,0xE0,0x20,0xE0,0x00,0x00,
0x00,0x55,0xFF,0x2A,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x00,0x00,0x00,0x07,0x01,0x00,
0x00,0x00,0x00,0x00,0x00,0x30,0x38,0x30,
0x30,0x30,0x30,0xFF,0xFF,0x30,0x30,0x30,
0x70,0x90,0xF0,0x10,0x00,0x00,0x00,0x00,
0x00,0x75,0x8A,0x75,0x5A,0x00,0x80,0x80,
0x00,0x01,0x0E,0x71,0x9E,0xE0,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x0C,0x1B,0x06,0x01,0x00,0x03,
0x3F,0x00,0x7F,0x9F,0x60,0x81,0xFE,0x3F,
0xC3,0x03,0x1F,0x14,0x03,0x00,0x00,0x00,
0x00,0x00,0x00,0xDF,0xFE,0x02,0x02,0x02,
0x02,0x02,0x02,0xFE,0xFF,0x00,0x00,0x00,
0x00,0x00,0x80,0xE0,0xC0,0xC7,0xF8,0xFF,
0xC0,0xC0,0x40,0x7F,0xDF,0xD8,0x18,0x18,
0xD8,0x98,0x7F,0x1E,0x00,0x00,0x04,0x07,
0x06,0x56,0xFF,0x86,0x16,0xBE,0xE2,0xC0,
0xFF,0xFF,0xC0,0xC0,0xC0,0xFF,0x7F,0x80,
0x00,0x00,0x00,0x38,0x28,0x28,0x28,0x28,
0x2B,0x29,0x28,0xE8,0xE8,0x2F,0x29,0x28,
0x28,0x28,0x2B,0xCD,0x36,0x0C,0x00,0x0C,
0x0E,0x7D,0x8A,0x65,0xBE,0x7C,0x14,0x05,
0x3F,0xD8,0x60,0xA0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xC0,0x3E,0xFF,0x03,0xFF,
0x81,0x1E,0xF3,0xCC,0x03,0xFE,0x78,0x9F,
0x02,0x11,0xFE,0xAB,0x00,0x00,0x00,0x00,
0x07,0x02,0x00,0xF8,0xF8,0x87,0x81,0x80,
0x80,0x83,0x80,0xF0,0x20,0xC0,0x03,0x07,
0x00,0x00,0x00,0x00,0x0F,0xF1,0x0F,0xFF,
0x7F,0x0F,0x00,0xFF,0xEF,0x28,0x28,0x28,
0x28,0x28,0xEF,0xFB,0x00,0x00,0x00,0x00,
0x00,0xAA,0xFF,0xAA,0x00,0x00,0x00,0x00,
0xFF,0xFF,0x00,0x00,0x00,0xFF,0xFF,0x03,
0x00,0x00,0x00,0x00,0x00,0x03,0x01,0x00,
0xE0,0x9F,0x7F,0x00,0x00,0xFF,0x7F,0x80,
0x00,0x70,0xF0,0x80,0x00,0x00,0x00,0x00,
0x00,0x55,0xAA,0x55,0x96,0x20,0xEC,0xD8,
0x37,0x38,0x3D,0x33,0x3C,0x3F,0x30,0xDF,
0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,
0xFC,0x60,0xFF,0x03,0xFC,0xE0,0x7F,0xC1,
0x3C,0xFE,0x3B,0x80,0x00,0x00,0x00,0x00,
0x6A,0xFF,0xC1,0xC0,0xC0,0xFF,0xBF,0x40,
0x00,0xFF,0xFF,0xC0,0xC0,0xC0,0xFF,0x9F,
0x60,0x00,0x00,0x1F,0xFF,0xE0,0xFF,0xFF,
0xC0,0xF0,0x00,0xFF,0xFE,0x30,0x3F,0x3F,
0x30,0x31,0xFF,0xFC,0x00,0x00,0x00,0x00,
0x00,0xAA,0xFF,0xB2,0x20,0x38,0x30,0x30,
0xFF,0xFF,0x3F,0x33,0x30,0xF0,0xF0,0x90,
0xF0,0x10,0x00,0x00,0x00,0x80,0x7C,0xC3,
0x3F,0x00,0x80,0x00,0x01,0xFF,0xFC,0x00,
0x00,0x00,0x00,0x01,0x03,0x00,0x00,0x00,
0x00,0x55,0xAA,0x4A,0xB5,0x03,0x06,0x0F,
0xF1,0x7E,0x80,0xF7,0x7F,0x80,0x07,0xF8,
0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3C,0x17,0xF0,0xFF,0xC0,
0x00,0x00,0xFF,0x80,0x00,0x00,0xE0,0xFF,
0xFF,0x7C,0x80,0x00,0x00,0x00,0x00,0x00,
0xDA,0xFF,0x1C,0x18,0x18,0xFF,0xFF,0x00,
0x00,0xFF,0xFF,0x18,0x18,0x18,0xFF,0xFF,
0x00,0x00,0x3C,0xF0,0xC0,0x00,0xFF,0xFF,
0x10,0x1C,0x18,0x18,0x18,0x1F,0xF3,0xFF,
0x1B,0x18,0x18,0x78,0xC8,0x38,0x01,0x03,
0x04,0xAD,0xFA,0xA6,0x28,0x58,0x60,0x1F,
0xEF,0xF0,0xFC,0xFB,0x07,0x00,0x00,0x00,
0x00,0x00,0x20,0x38,0x30,0x30,0x30,0xF0,
0xB0,0x30,0x30,0x37,0xF9,0xFE,0x30,0x30,
0x30,0x30,0x30,0xF0,0xF0,0x10,0x00,0x01,
0x06,0x58,0xA7,0x1C,0xF1,0xC2,0x17,0x7C,
0xC0,0x0F,0xF3,0x3C,0xC0,0x00,0xFF,0x07,
0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0x00,0xFF,0x00,
0x00,0x00,0xFF,0x00,0x00,0x07,0x39,0xDE,
0xE8,0x67,0x11,0x0C,0x03,0x01,0x00,0x00,
0xAA,0xFF,0x23,0x03,0x03,0xFF,0xFF,0x00,
0x00,0xFF,0xFF,0x03,0x03,0x03,0xFF,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
0x00,0x00,0x00,0x03,0x1F,0xEC,0xF0,0x80,
0xFC,0x33,0x0E,0x01,0x01,0x00,0x60,0x90,
0x50,0xA0,0x80,0x00,0x03,0x1D,0xE6,0x78,
0x80,0x00,0x00,0xC0,0x38,0xE7,0x18,0x06,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x1F,0x6C,0xB0,0xC0,0xC0,0xB0,0x48,
0x46,0x31,0x08,0x07,0x01,0x00,0x00,0xD0,
0x78,0xA0,0x80,0x40,0xB0,0xE0,0x80,0x07,
0x7E,0xB0,0xC7,0x02,0x02,0x03,0xFE,0xFF,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xE0,0x10,0xF0,0x00,
0x00,0x7C,0xE8,0x1C,0x70,0xE0,0x80,0x00,
0x00,0x00,0xC0,0x30,0xD0,0x40,0x00,0x00,
0xD8,0xE8,0x00,0x00,0x00,0xF0,0xC0,0x00,
0x00,0xF8,0xE0,0x00,0x00,0x00,0xF0,0xF0,
0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xF8,
0x14,0x38,0xF0,0xC0,0x00,0x00,0x00,0x00,
0x00,0x40,0xE0,0x10,0x38,0xC0,0x00,0x00,
0x00,0x08,0x38,0xA0,0x40,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x18,
0x60,0xC0,0x00,0x1C,0x18,0x30,0x70,0xB0,
0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x80,0x60,0x18,0xF8,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x28,0x38,0xC0,0x80,
0x00,0x00,0x00,0x80,0x78,0x0C,0x70,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
用户325238 2010-10-9 11:59