微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 基于ATMEGA8515的SPI驱动ST7565P液晶屏的程序

基于ATMEGA8515的SPI驱动ST7565P液晶屏的程序

时间:11-22 来源:互联网 点击:

,0x00,0x00,

0x02,0x02,0x82,0x42,0x32,0x1F,0x0A,0x02,0x02,0x06,0x0B,0x32,0xE2,0x42,0x02,0x00,

0x00,0x08,0x8F,0x89,0x49,0x2B,0x1D,0x0B,0x08,0x08,0x08,0x4A,0x8C,0x7B,0x00,0x00,

0x00,0x7F,0x28,0x24,0x22,0x21,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,0x00,0x00,

0x00,0x00,0x00,0xFF,0x44,0x62,0x55,0x49,0x55,0x43,0x41,0x40,0xFF,0x00,0x00,0x00,

0x40,0x20,0x18,0x07,0x04,0x28,0x63,0x21,0x21,0x3F,0x11,0x15,0x1B,0x30,0x00,0x00},

{0x80,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x00,0xFE,0x02,0x02,0x02,0xFE,0x00,0x00, //却话巴山夜雨时

0x40,0x41,0x4E,0xC4,0x00,0x20,0x24,0x24,0x24,0x24,0xFC,0x22,0x22,0x22,0x20,0x00,

0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x7E,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00,

0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,

0x04,0x04,0x84,0xC4,0x3C,0x14,0x85,0x66,0xBC,0x24,0x24,0x24,0xE4,0x24,0x04,0x00,

0x02,0x02,0xF2,0x32,0x52,0x92,0x12,0xFE,0x32,0x52,0x92,0x12,0xF2,0x02,0x02,0x00,

0x00,0xFC,0x44,0x44,0x44,0xFC,0x10,0x90,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00},

{0x00,0x10,0x3C,0x13,0x10,0x08,0x0A,0x1C,0x08,0xFF,0x00,0x08,0x10,0x0F,0x00,0x00,

0x00,0x00,0x00,0x7F,0x20,0x10,0x00,0x7E,0x22,0x22,0x23,0x22,0x22,0x7E,0x00,0x00,

0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x78,0x20,0x00,

0x00,0x20,0x7F,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x7F,0x00,0x00,

0x02,0x01,0x00,0xFF,0x00,0x82,0x41,0x22,0x14,0x09,0x14,0x23,0x40,0xC0,0x40,0x00,

0x00,0x00,0xFF,0x01,0x02,0x04,0x00,0x7F,0x01,0x02,0x44,0x80,0x7F,0x00,0x00,0x00,

0x00,0x07,0x04,0x04,0x04,0x07,0x00,0x00,0x03,0x40,0x80,0x7F,0x00,0x00,0x00,0x00},

};

////////////////////////////////

//发送一个字节到ST7565P并等待发送完毕

//入口:要发送的字节

//返回值:无

////////////////////////////////

void SPIByte(unsigned char byte)

{

SPDR = byte; //写数据

while(!(SPSR & (1//等待发送完成

}

////////////////////////////////////////////////

//将一个字节发送的ST7565P的函数

//入口参数: select ,data

//select:根据此值确定发送给ST7565P的是数据还是命令

//data: 要发送给ST7565的一个字节

//返回值:无

////////////////////////////////////////////////

void LCD_SPISend(unsigned char select,unsigned char data)

{

PORTC &= ~(1<2); // CS=0 芯片使能信号

if(select == COMMAND) //传输的是命令

{

PORTC &= ~(1<0); // 根据ST7565P的数据手册,传输命令时A0应该是为低电平

SPIByte(data);

PORTC |= 1<0; // A0=1

}

else

{

SPIByte(data);

}

PORTC |= 1<2; //CS= 恢复不使能

}

////////////////////////////////////////////

//写坐标函数

//入口参数:x y

//y: 页面地址,此液晶将显示区域分为9个页面,y的值域0~8

//x: 列地址,值域:0~127

//返回值:无

////////////////////////////////////////////

void LCD_XYSet(unsigned char x,unsigned char y)

{

LCD_SPISend(COMMAND,0xB0|y); //y的值为0~8

LCD_SPISend(COMMAND,0x10|(x>>4));

LCD_SPISend(COMMAND,0x00|(x&0x0F));

}

/////////////////////////////////////

//延时函数

//入口: ms 当延时100毫秒时,ms的值为100即可

//返回值:无

/////////////////////////////////////

void DelayMs(volatile unsigned int ms)

{

volatile unsigned int i;

volatile unsigned int j;

for(i=0;i

{

j=280;

while(j--);

}

}

//////////////////////////////////////////////////////

//初始化SPI及液晶屏的函数

//入口:无

//返回值:无

/////////////////////////////////////////////////////

void LCD_Init(void)

{

SPCR = 0x5C;

SPSR |= 1

//SPI的功能设置解释:使能SPI;采用主机模式;SPI的传输模式为模式3;时钟频率为系统时钟的两分频,即 //3.6864/2M

DelayMs(100);

SPIByte(0xFF); //可发可不发,无意义

PORTC &= ~(1<1); //将复位脚拉低

DelayMs(5); //延时5ms,等待电源稳定

PORTC |= 1<1; //将复位脚拉高

DelayMs(5);

LCD_SPISend(COMMAND,0xAE); //将液晶屏的显示关掉

LCD_SPISend(COMMAND,0xA3); //设置偏压比

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top