/*!
* @file jlx12864g_091.c
* @version 2.0
* @author foundkey
* @date 2014-8-8
* @brief jxl12864g_091驱动程序
* @muc TM4C123GH6PM
* 加入了绘图函数,需要1K字节作为绘图寄存器
*/
#ifndef PART_TM4C123GH6PM
#define PART_TM4C123GH6PM
#endif
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "LCD_Resource.h"
#include "jlx12864g_091.h"
#include "driverlib/ssi.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "inc/hw_ints.h"
/* _________
* |
* PC6|-->SCK 串行时钟
* PC7|-->SDA 数据传输
* TIVA PB1|-->CS 低电平片选
* PD1|-->CD 数据/指令寄存器
* PE5|-->RST 低电平复位
* _________|
*/
//绘图用寄存器
static unsigned char CGRAM[8][128] = {0};
//内部函数声明
static void LCD_PinConfigure(void);
static void LCD_Delay(unsigned int time);
static void LCD_Display_Error(unsigned char num);
/********引脚操作********/
// 低电平片选
#define setCS() ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_PIN_1) //PB1
#define rstCS() ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, 0)
// 寄存器选择信号
#define setCD() ROM_GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, GPIO_PIN_6) //PC6
#define rstCD() ROM_GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6, 0)
// 低电平复位,复位完成后,回到高电平,液晶模块开始工作
#define setRES() ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_PIN_5) //PE5
#define rstRES() ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, 0)
//宏定义
#define ABS(x) ((x) > 0) ? (x) : -(x);
/***********************************
* @brief 对LCD用到的引脚进行配置
* @param none
* @return none
*************************************/
static void LCD_PinConfigure(void)
{
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_1);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_6);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
ROM_GPIOPinConfigure(GPIO_PD0_SSI3CLK);
ROM_GPIOPinConfigure(GPIO_PD3_SSI3TX);
ROM_GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_3);
ROM_SSIConfigSetExpClk(SSI3_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
SSI_MODE_MASTER, 50000, 8);
ROM_SSIEnable(SSI3_BASE);
}
/**********************************************
* @brief 简单延时
* @param time:延时的时间长度
* @return none
************************************************/
static void LCD_Delay(unsigned int time)
{
unsigned int i, j;
for(i = 0; i < time; i++)
for(j = 0; j < 990;j++)
;
}
/**********************************************
* @brief 向LCD发送一条指令
* @param com:发送的指令
* @return none
************************************************/
void LCD_TransferCommand(unsigned char com)
{
rstCS();
rstCD();
while(ROM_SSIBusy(SSI3_BASE))
;
ROM_SSIDataPut(SSI3_BASE, com);
while(ROM_SSIBusy(SSI3_BASE))
;
}
/**********************************************
* @brief 向LCD发送一字节的数据
* @param data:发送的数据
* @return none
************************************************/
void LCD_TransferData(unsigned char data)
{
rstCS();
setCD();
while(ROM_SSIBusy(SSI3_BASE))
;
ROM_SSIDataPut(SSI3_BASE, data);
while(ROM_SSIBusy(SSI3_BASE))
;
}
/**********************************************
* @brief 设置显示的位置
* @param page:页数(0~7)(8行为一页)
* @parem col: 列数(0~127)
* @return none
************************************************/
void LCD_SetAddress(unsigned char page, unsigned char col)
{
rstCS();
LCD_TransferCommand(0xb0 + page);
LCD_TransferCommand(0x10 + ((col >> 4) & 0x0f));
LCD_TransferCommand(col & 0x0f);
}
/**********************************************
* @brief LCD初始化
* @param none
* @return none
************************************************/
void LCD_Initial(void)
{
LCD_PinConfigure();
rstCS();
rstRES();
LCD_Delay(50); //delay
setRES();
LCD_Delay(50); //delay
LCD_TransferCommand(0xe2); /*软复位*/
LCD_TransferCommand(0x2c); /*升压步聚1*/
LCD_TransferCommand(0x2e); /*升压步聚2*/
LCD_TransferCommand(0x2f); /*升压步聚3*/
LCD_TransferCommand(0x23); /*粗调对比度,可设置范围20~27*/
LCD_TransferCommand(0x81); /*微调对比度*/
LCD_TransferCommand(0x28); /*微调对比度的值,可设置范围0~63*/
LCD_TransferCommand(0xa2); /*1/9 偏压比(bias)*/
LCD_TransferCommand(0xc8); /*行扫描顺序:从上到下c0 c8 */
LCD_TransferCommand(0xa0); /*列扫描顺序:从左到右 a0 a1*/
LCD_TransferCommand(0xa6); /*正显 0xa6,反显 0xa7*/
LCD_TransferCommand(0x40); /*起始行开始显示*/
LCD_TransferCommand(0xaf); /*开显示*/
LCD_ClearScreen(); //清屏
}
/**********************************************
* @brief LCD清屏
* @param none
* @return none
************************************************/
void LCD_ClearScreen(void)
{
unsigned char page, col;
for(page = 0; page < LCD_MAX_PAGE; page++){
LCD_SetAddress(page, 0);
for(col = 0; col < LCD_MAX_COL; col++){
LCD_TransferData(0x00);
CGRAM[page][col] = 0x00; //同步刷新绘图寄存器
}
}//for
}
/**********************************************
* @brief 写满LCD
* @param none
* @return none
************************************************/
void LCD_FullDisplay(void)
{
unsigned char page, col;
for(page = 0; page < LCD_MAX_PAGE; page++){
LCD_SetAddress(page, 0);
for(col = 0; col < LCD_MAX_COL; col++){
LCD_TransferData(0xFF);
CGRAM[page][col] = 0xFF;
}//for
}//for
}
/**********************************************
* @brief 输出一副128*64的图片
* @param index:保存图片数组
* @return none
************************************************/
void LCD_Display_128x64(unsigned char *index)
{
unsigned char page, col;
for(page = 0; page < LCD_MAX_PAGE; page++){
LCD_SetAddress(page, 0);
for(col = 0; col < LCD_MAX_COL; col++){
LCD_TransferData(*index);
CGRAM[page][col] = *index++;
}
}//for
}
/**********************************************
* @brief 输出16*16的点阵图示
* @param x :输出起始的行坐标(0~6,单位长度8个像素)
* @param y :输出起始的列坐标(0~111,单位长度1个像素)
* @param index:数据
* @return none
0 1 2 3 ...111
--|--------------->y
0|
1|
2|
.|
.|
6| x
v
************************************************/
void LCD_Display_16x16(unsigned char x, unsigned char y, unsigned char *index)
{
unsigned char page, col;
if(x > LCD_MAX_X_16x16 || y > LCD_MAX_Y_16x16)
LCD_Display_Error(1);
for(page = x; page - x < 2; page++){
LCD_SetAddress(page, y);
for(col = 0; col < 16; col++){
LCD_TransferData(*index);
CGRAM[page][y+col] = *index++;
}
}//for
}
/**********************************************
* @brief 清空或填满16*16的点阵图示
* @param x :输出起始的行坐标(0~6,单位长度8个像素)
* @param y :输出起始的列坐标(0~111,单位长度1个像素)
* @param isfull:为ture时,填满此区域;为false时,清空此区域
* @return none
0 1 2 3 ...111
--|--------------->y
0|
1|
2|
.|
.|
6| x
v
************************************************/
void LCD_ClearOrFull_16x16(unsigned char x, unsigned char y, bool isfull)
{
unsigned char page, col;
unsigned char data;
if(x > LCD_MAX_X_16x16 || y > LCD_MAX_Y_16x16)
LCD_Display_Error(1);
if(isfull)
data = 0xff;
else
data = 0x00;
for(page = x; page - x < 2; page++){
LCD_SetAddress(page, y);
for(col = 0; col < 16; col++){
LCD_TransferData(data);
CGRAM[page][y+col] = data