// 编译版本:0002 如果对本文件的更改会影响全局,请将编译版本号增加,谢谢
//
// 版权所有(C)2005 www.yangchu.com
//
// 文件名称: DrvSED1335.c
//
// 简 介: SED1335驱动程序,仅为黑白显示
//
// 作 者: yangchu 14-September-2005
// yangchu@yangchu.com
//
// ~~~~~~~~~~~~~~~~~~~~~~~ Never try, never know ~~~~~~~~~~~~~~~~~~~~~~~
//
// 状 态: 测试中
//
// 改进纪录:
// 3-November-2005 yangchu
// 1)改写字符显示函数为通用函数
// 2)删除原来的字符显示函数
// 3)修改了注释风格
//
// 12-November-2005 yangchu
// 1)增加2148模式函数接口
//
#include "typedef.h"
#include "lcd.h"
#if (CONTROLLER_TYPE == SED1335)
#include "SED1335Cfg.h"
//
// 数据转换宏定义
//
#define HIBYTE(V1) ((BYTE)((V1) >> 8))
#define LOBYTE(V1) ((BYTE)((V1) & 0xff))
#define MAKEWORD(V1, V2) ((((WORD)(V1)) << 8) + (WORD)(V2))
//
// CPU延时宏定义
//
#define DLY_CPU_CYCLE(x) \
{ \
int i; \
for (i = 0; i < x; i++); \
}
//
// SED1335的命令集
//
#define SYSTEM_SET (0x40)
#define SCROLL (0x44)
#define SLEEP_IN (0x53)
#define DISP_ON (0x59)
#define DISP_OFF (0x58)
#define OVLAY (0x5b)
#define HDOT_SCR (0x5a)
#define CSRFORM (0x5d)
#define CGRAM_ADR (0x5c)
#define CSR_RIGHT (0x4c)
#define CSR_LEFT (0x4d)
#define CSR_UP (0x4e)
#define CSR_DOWN (0x4f)
#define CSRW (0x46)
#define CSRR (0x47)
#define MWRITE (0x42)
#define MREAD (0x43)
//
// 屏幕中,每行可显示的ASC字符数
//
#define AP (40)
//
// LCD初始化所用到的参数
//
#define GRAPHICS_BASE_ADDR 0x1000 // 该地址位于SED1335所使用的32kB SRAM中
static const BYTE SYSTAB[8] = {
0x30, // 0011 0000 B: 1, W/S: 0, M2: 0, M1: 0, M0: 0
0x87, // 1000 0111 WF: 1, FX: 7
0x0f, // 0000 1111 FY: 15
0x27, // 0010 0111 C/R: 39
0x42, // 0100 0010 TC/R: 66
0xf0, // 1111 0000 L/F: 240
0x28, // 0010 1000 APL: 40
0x00 // 0000 0000 APH: 0
};
static const BYTE SCRTAB[10] = {
0x00, // 0000 0000 SAD1L: 0x00
0x00, // 0000 0000 SAD1H: 0x00
0xf0, // 1111 0000 SL1: 240
(BYTE)(GRAPHICS_BASE_ADDR & 0xff), // 0000 0000 SAD2L: 0x00
(BYTE)(GRAPHICS_BASE_ADDR >> 8), // 0001 0000 SAD2H: 0x10
0xf0, // 1111 0000 SL2: 240
0x00, // 0000 0000 SAD3L: 0x00
0x04, // 1000 0000 SAD3H: 0x40
0x00, // 0000 0000 SAD4L: 0x00
0x50 // 0101 0000 SAD4H: 0x50
};
static int _Color; // 前景色
static int _XRefreshLimit; // X方向刷新屏幕最大坐标限制值
//
// Philips LPC2114接口方式(试验用)
//
#if (CPU_TYPE == LPC2114)
#include "LPC2294.h"
/*
Signal cofiguration of LPC2114:
A0 : P0.9
nWR : P0.8
nRD : P0.11
DB0~DB7 : P0.0~P0.7
nCS : P0.10
nRST : nRST from mainboard
SEL1 : Always low (always 8080 mode)
*/
#define BIT_A0 (1 << 9)
#define BIT_nWR (1 << 8)
#define BIT_nRD (1 << 11)
#define BIT_nCS (1 << 10)
//
// 写LCD控制命令
//
static void
_LCDCom(
BYTE com
)
{
IO0CLR = 0xff | BIT_nCS; // Clear DB0~DB7, chip select enable
IO0PIN |= (BIT_A0 | com); // Set A0 and put Data on bus
IO0CLR = BIT_nWR; // Clear nWR
#if DELAY_TIME > 0
DLY_CPU_CYCLE(DELAY_TIME); // Delay for SED1335
#endif
IO0SET = BIT_nWR; // Set nWR
IO0SET = BIT_nCS; // Chip select disable
}
//
// 写LCD控制参数和显示字符数据
//
static void
_LCDData(
BYTE dat
)
{
IO0CLR = 0xff | BIT_A0 | BIT_nCS; // Clear DB0~DB7 and A0, chip select enable
IO0PIN |= dat; // Put Data on bus
IO0CLR = BIT_nWR; // Clear nWR
#if DELAY_TIME > 0
DLY_CPU_CYCLE(DELAY_TIME); // Delay for SED1335
#endif
IO0SET = BIT_nWR; // Set nWR
IO0SET = BIT_nCS; // Chip select disable
}
#if LCD_READ_BACK_ENABLE == TRUE
//
// 读数据
//
static BYTE
_ReadData(void)
{
BYTE dat;
IO0CLR = BIT_nCS; // Clear DB0~DB7, chip select enable
IO0CLR = BIT_nRD; // Clear nRD
#if DELAY_TIME > 0
DLY_CPU_CYCLE(DELAY_TIME); // Delay for SED1335
#endif
dat = (BYTE)(IO0PIN & 0xff); // Get memory data
IO0SET = BIT_nRD; // Set nRD
IO0SET = BIT_nCS; // Chip select disable
return dat;
}
//
// 读显示内存
//
static BYTE
_ReadSram(void)
{
BYTE dat;
_LCDCom(MREAD); // Send command of reading memory
IO0DIR &= ~0xff; // Bit P0.0~P0.7 IO direction: input
IO0SET = BIT_A0; // Set A0
dat = _ReadData();
IO0DIR |= 0xff; // Bit P0.0~P0.7 IO direction: output
return dat;
}
//
// 读状态
//
static BYTE
_ReadState(void)
{
BYTE state;
IO0DIR &= ~0xff; // Bit P0.0~P0.7 IO direction: input
IO0CLR = BIT_A0; // Clear DB0~DB7 and A0, chip select enable
state = _ReadData(); // Get state
IO0DIR |= 0xff; // Bit P0.0~P0.7 IO direction: output
return state;
}
//
// 读光标地址
//
static WORD
_ReadCursorPos(void)
{
WORD state = 0;
_LCDCom(CSRR);
IO0DIR &= ~0xff; // Bit P0.0~P0.7 IO direction: input
IO0SET = BIT_A0; // Set A0
state = _ReadData(); // X position
state |= (_ReadData() << 8); // Y position
IO0DIR |= 0xff; // Bit P0.0~P0.7 IO direction: output
return state;
}
#endif
static void
_LCDPortInit(void)
{
IO0DIR |= (0xff | BIT_A0 | BIT_nWR | BIT_nRD | BIT_nCS);
IO0SET = (BIT_nWR | BIT_nRD | BIT_nCS);
}
#else // If we are not using above CPUs
#error "CPU type not specified or not supported"
#endif
//
// 显示存储器清零
//
// 输入:无
//
// 输出:无
//
static void
_ClearMemory(void)
{
INT32U i;
//
// 光标方向向右,指针指向零地址
//
_LCDCom(CSR_RIGHT);
_LCDCom(CSRW);
_LCDData(0);
_LCDData(0);
//
// 显存中数据全部清零
//
_LCDCom(MWRITE);
for (i = 0; i < 32 * 1024; i++)
{
_LCDData(0x00);
}
}
//
// 设置光标
//
// 输入: x 横坐标
// y 纵坐标
//
// 输出: 无
//
// 注意: 由于只能字节寻址,横坐标必须被8相除
//
void
_SetCursor(
IN INT32U x,
IN INT32U y
)
{
BYTE low, high;
INT32U actualAddr;
x = x / 8;
actualAddr = y * AP + x + GRAPHICS_BASE_ADDR;
low = LOBYTE(actualAddr);
high = HIBYTE(actualAddr);
_LCDCom(CSRW);
_LCDData(low);
_LCDData(high);
}
//
// 固定位置显示字模
//
// 输入: x 横轴坐标
// y 纵轴坐标
// width 字模宽度(单位:8像素)
// hight 字模高度
// p 字模头指针
//
// 输出: 1
//
static int
_FixedDispCode(
IN INT32U x,
IN INT32U y,
IN INT32U width,
IN INT32U hight,
IN const BYTE* p
)
{
int i, j;
const BYTE* pWork;
_LCDCom(CSR_DOWN);
//
// 横轴方向循环
//