这是用SPI方法来驱动12864液晶的源程序,液晶屏的操控芯片为ST7565P经测验SPI的时钟可到达振动频率的二分频。比用一般IO口模仿串行的方法快多了。。。
下面贴出源代码,有具体注释。。。。
本程序简略有用,可拿去作简略参阅。。。。
编译环境:GCC+AVR STUDIO
单片机:ATMEGA 8515
晶振: 3.6864M
#include<avr/io.h> //包括头文件
#include
#define COMMAND 1
#define DATA 0
/////////////////////////////////////////
//数据线界说:
// SI==========PB5 //
// A0==========PC0
// CS==========PC2
// RES=========PC1
// SCL=========PB7
//
/////////////////////////////////////////
unsigned char gushi[8][112]PROGMEM=
{
{0x10,0x10,0x92,0x92,0x92,0xF2,0x9E,0x92,0x92,0x92,0x92,0x92,0xFE,0x10,0x10,0x00, //君问归期未有期
0x00,0x00,0xF8,0x01,0x06,0xE0,0x22,0x22,0x22,0x22,0xE2,0x02,0x02,0xFE,0x00,0x00,
0x00,0xF8,0x00,0x00,0xFF,0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0xFC,0x00,0x00,
0x00,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,
0x40,0x40,0x48,0x48,0x48,0x48,0xC8,0xFF,0x48,0x48,0x48,0x48,0x48,0x40,0x40,0x00,
0x00,0x04,0x84,0x44,0xE4,0x34,0x2C,0x27,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00,
0x00,0x04,0xFF,0x54,0x54,0x54,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00},
{0x40,0x20,0x10,0x0C,0xFE,0x45,0x44,0x44,0x44,0x44,0x44,0x44,0xFD,0x00,0x00,0x00,
0x00,0x00,0xFF,0x00,0x00,0x03,0x02,0x02,0x02,0x02,0x03,0x40,0x80,0x7F,0x00,0x00,
0x00,0x87,0x40,0x30,0x0F,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x00,0x00,
0x42,0x22,0x1B,0x02,0x02,0x0A,0x33,0x62,0x18,0x07,0x02,0x22,0x42,0x3F,0x00,0x00,
0x20,0x20,0x10,0x10,0x08,0x06,0x01,0xFF,0x01,0x02,0x04,0x08,0x18,0x30,0x10,0x00,
0x02,0x01,0x00,0x00,0xFF,0x09,0x09,0x09,0x29,0x49,0xC9,0x7F,0x00,0x00,0x00,0x00,
0x42,0x22,0x1B,0x02,0x02,0x0A,0x33,0x62,0x18,0x07,0x02,0x22,0x42,0x3F,0x00,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,
0x10,0x61,0x86,0x60,0xF2,0x12,0x12,0x1E,0x80,0xFF,0xA0,0x90,0x88,0x86,0x80,0x00,
0x24,0x24,0xE4,0xFC,0xA2,0x22,0x22,0x80,0x70,0x00,0xFF,0x40,0x20,0x18,0x00,0x00,
0x10,0x60,0x02,0x8C,0x60,0x80,0xF8,0x40,0x40,0xFE,0x20,0x20,0x10,0xF0,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,
0x04,0xFC,0x03,0x00,0x01,0x41,0x81,0x7F,0x00,0xFF,0x42,0x0C,0x30,0x60,0x20,0x00,
0x02,0x01,0x00,0xFF,0x00,0x83,0x40,0x20,0x18,0x07,0x01,0x06,0x18,0xE0,0x40,0x00,
0x08,0x08,0x7C,0x03,0x00,0x00,0x3F,0x40,0x40,0x5F,0x40,0x42,0x44,0x43,0x70,0x00},
{0x80,0x40,0xF0,0x1C,0x07,0xE2,0x24,0x24,0x24,0xE4,0x04,0x04,0xFC,0x04,0x04,0x00, //何当共剪西窗烛
0x00,0x00,0x40,0x42,0x5C,0x48,0x40,0x40,0x7F,0x40,0x50,0x4E,0x44,0xC0,0x00,0x00,
0x00,0x10,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x00,0x00,
0x00,0x04,0xF4,0x54,0x55,0x56,0x54,0xF4,0x04,0x04,0xE6,0x05,0x04,0xF4,0x04,0x00,
0x02,0xF2,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0xF2,0x02,0x00,
0x00,0x4C,0x44,0xE4,0x54,0x44,0x64,0xD5,0x46,0x44,0x4C,0x54,0xD4,0x24,0x2C,0x00,
0x80,0x60,0x00,0xFF,0x20,0x18,0xF0,0x10,0x10,0xFF,0x12,0x10,0xF0,0x10,0x00,0x00},
{0x00,0x00,0x7F,0x00,0x00,0x07,0x02,0x02,0x02,0x07,0x20,0x40,0x3F,0x00,0x00,0x00,
0x00,0x00,0x20,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x7F,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)
{
}
////////////////////////////////////////////////
//将一个字节发送的ST7565P的函数
//进口参数: select ,data
//select:依据此值确认发送给ST7565P的是数据仍是指令
//data: 要发送给ST7565的一个字节
//返回值:无
////////////////////////////////////////////////
void LCD_SPISend(unsigned char select,unsigned char data)
{
}
////////////////////////////////////////////
//写坐标函数
//进口参数:x y
//y: 页面地址,此液晶将显现区域分为9个页面,y的值域0~8
//x: 列地址,值域:0~127
//返回值:无
////////////////////////////////////////////
void LCD_XYSet(unsigned char x,unsigned char y)
{
}
/////////////////////////////////////
//延时函数
//进口: ms 当延时100毫秒时,ms的值为100即可
//返回值:无
/////////////////////////////////////
void DelayMs(volatile unsigned int ms)
{
}
//////////////////////////////////////////////////////
//初始化SPI及液晶屏的函数
//进口:无
//返回值:无
/////////////////////////////////////////////////////
void LCD_Init(void)
{
//SPI的功用设置解说:使能SPI;选用主机形式;SPI的传输形式为形式3;时钟频率为体系时钟的两分频,即 //3.6864/2M
}
////////////////////////////////////////
//清屏函数
//进口:无
//返回值:无
///////////////////////////////////////
void Clear_Display(void)
{
}
////////////////////////////////
//显现一首李商隐的诗篇:
// 君问归期未有期
// 巴山夜雨涨秋池
// 何当共剪西窗烛
// 却话巴山夜雨时
//进口:无
//返回值:无
////////////////////////////////
void Gushi_Display(void)
{
}
int main(void)
{
}
编译成果如下:
AVR Memory Usage
—————-
Device: atmega8515
Program: 1688 bytes (20.6% Full)
(.text + .data + .bootloader)
Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)
Build succeeded with 0 Warnings…
显现作用如下: