/************************************************************************************
* Copyright (c), 2006-2007, C8051F单片机网络
* All rights reserved.
*
* Http: www.c8051f.com
* Email: web@c8051f.com
*
* File name: lcd12864.h
* Project : C8051F350DK
* Processor: C8051F350
* Compiler : Keil C51 Compiler
*
* author: glacier
* QQ: 252858144
* date: 2010.04.20
*
* Description: 本文件是LCD12864驱动程序;
*
*
*
* Others: none;
*
* Function List:
* 1.void Clrscr(unsigned char p);
* 2.void Clrscr(unsigned char p,unsigned char pag);
* 3.void InitLCM(void);
* 4.void Display_ASCII(unsigned char Char,unsigned char X,unsigned int Y);
* 5.void Display_Chinese(unsigned int UniCode,unsigned char X,unsigned int Y);
* 6.void Display_String(unsigned char code *p,unsigned char X,unsigned int Y,unsigned char lenth);
* 7.void display_map(unsigned char *p);
* 8.void ShowPicture(unsigned char X_start,unsigned char Y_start,unsigned char Width,unsigned char Hight ,unsigned char code *address);
* 9.void Display_Number(unsigned int Num,unsigned char X,unsigned char Y);
* 10.void Display_char(unsigned char Num,unsigned char X,unsigned char Y);
*************************************************************************************/
#include "..\config\c8051f350.h"
#include "..\config\const.h"
#include "..\config\ascii.h"
#include "..\driver\lcd12864.h"
#include "..\driver\delay.h"
#include "..\driver\spi.h"
#include <ABSACC.H>
#define RS 0x01 // 读写切换
#define WR 0x02 // 写脉冲
#define RD 0x04 // 读脉冲
unsigned int num=0;
unsigned char *p;
unsigned char *s;
unsigned char flag;
/**************************************************************************************
* 函数名称:wdata;
*
* 函数功能描述:LCD12684写数据程序;
*
* 输入参数:dat;
*
* 返回数据:无;
*
**************************************************************************************/
void wdata(unsigned char dat)
{
unsigned char cmd;
unsigned char Cmd_buf[2];
Cmd_buf[1] = 0x00;
cmd = RS|WR|RD;
Cmd_buf[0] = cmd;
SPI_Write(Cmd_buf, 2);
Cmd_buf[1] = dat;
cmd = RS&(~WR)|RD;
Cmd_buf[0] = cmd;
SPI_Write(Cmd_buf, 2);
}
/**************************************************************************************
* 函数名称:w_com;
*
* 函数功能描述:LCD12684写命令程序;
*
* 输入参数:CMD;
*
* 返回数据:无;
*
**************************************************************************************/
void w_com(unsigned char CMD)
{
unsigned char cmd;
unsigned char Cmd_buf[2];
Cmd_buf[1] = 0x00;
cmd = (~RS)|WR|RD;
Cmd_buf[0] = cmd;
SPI_Write(Cmd_buf, 2);
Cmd_buf[1] = CMD;
cmd = (~RS)&(~WR)|RD;
Cmd_buf[0] = cmd;
SPI_Write(Cmd_buf, 2);
}
/**************************************************************************************
* 函数名称:Clrscr;
*
* 函数功能描述:LCD12684清屏程序;
*
* 输入参数:p 清屏数值,pag 位置(写页地址共8页 0xb0----0xb8);
*
* 返回数据:无;
*
**************************************************************************************/
void Clrscr(unsigned char p,unsigned char pag)
{
unsigned char seg;
unsigned char page;
page = pag;
for(page=pag;page<0xb8;page++) //写页地址共8页 0xb0----0xb8
{
w_com(page);
w_com(0x10);
w_com(0x00);
for(seg=0;seg<128;seg++)
{
wdata(p);
}
}
}
/**************************************************************************************
* 函数名称:ReturnBack
*
* 函数功能描述:地址回首行首列;
*
* 输入参数:无;
*
* 返回数据:无;
*
**************************************************************************************/
void ReturnBack(void)
{
w_com(0x40); //起始行
}
/**************************************************************************************
* 函数名称:display_8x8dot_at_xy;
*
* 函数功能描述:LCD12684显示程序;
*
* 输入参数:hang :1--8 lie :1--15 addr :显示数据地址;
*
* 返回数据:无;
*
**************************************************************************************/
void display_8x8dot_at_xy(unsigned char hang,unsigned char lie,unsigned char *addr)
{
unsigned int count_byte;
unsigned char page;
unsigned char row;
row=(lie-1)*8;
page=0xb0+(hang-1);
w_com(page); //选择页
w_com(0x10+((row>>4)&0x0f));
w_com(row&0x0f);
for(count_byte=8;count_byte>0;count_byte--) //写8个字符
{
wdata(*addr++);
}
}
/**************************************************************************************
* 函数名称:displayHZ_at_xyaddr;
*
* 函数功能描述:LCD12684显示程序;
*
* 输入参数:hang :1--8 lie :1--15 addr :显示数据地址;
*
* 返回数据:无;
*
**************************************************************************************/
void displayHZ_at_xyaddr(unsigned char hang,unsigned char lie,unsigned char *addr)
{
display_8x8dot_at_xy(hang,lie,addr);
display_8x8dot_at_xy(hang,lie+1,addr+8);
display_8x8dot_at_xy(hang+1,lie,addr+16);
display_8x8dot_at_xy(hang+1,lie+1,addr+24);
}
/**************************************************************************************
* 函数名称:
*
* 函数功能描述:LCD12684命令;
*
* 输入参数:无;
*
* 返回数据:无;
*
**************************************************************************************/
void outofstandbymode(void)
{
w_com(0xa4);//ALL POINTS ON
w_com(0xaf);//DISPLAY ON
}
void enterstandbymode(void)
{
w_com(0xad);//TURN ON THE STATIC INDICATOR MODE,THIS MODE IS NOT USED IN THIS MODULE;
w_com(0x01);//DOBULE BYTES COMMAND
w_com(0xae);//DISPLAY OFF
w_com(0xa5);//all points off
}
void entersleepmode(void)
{
w_com(0xae); //DISPLAY OFF
w_com(0xa5); //all points off
}
void outofsleepmode(void)
{
w_com(0xa4);//ALL POINTS ON
w_com(0xaf);//DISPLAY ON
}
void ReverseDisplay(unsigned char DIS)
{
if(DIS)
w_com(0xa7); //Reverse Display
else w_com(0xa6);//Normal Display
}
/**************************************************************************************
* 函数名称:InitLCM;
*
* 函数功能描述:LCD12864初始化;
*
* 输入参数:无;
*
* 返回数据:无;
*
**************************************************************************************/
void InitLCM(void)
{
w_com(0xe2); /*软件复位*/
Delay_us(150);
w_com(0xa3); /*LCD BIAS=1/9*/
Delay_us(10);
w_com(0xa0); /*列地址移动方向:ADC=0(SEG1->SEG132)*/
Delay_us(10);
w_com(0xc0); /*行扫描方向:SHL=1(COM64->COM1)*/
Delay_us(10);
w_com(0x2f); /*电源控制模式:VC,VR,VF=111*/
Delay_us(10);
w_com(0x20); /*内部调整电阻比率:R2,R1,R0=111 0x20-0x27*/
Delay_us(10);
w_com(0x81); /*对比度寄存器模式*/
w_com(60); /*对比度寄存器值 修改这个值就可以调节对比度了 0--63*/
w_com(0x40); /*起始行*/
Delay_us(10);
w_com(0xe0); /*写入数据时列地址自动加1,但读时不变*/
Delay_us(10);
// ReverseDisplay(1); /*打开反显 0:正常显示 1:反显*/
Delay_us(10);
w_com(0xaf); /*开显示*/
Delay_us(10);
ReturnBack();
Delay_us(10);//起始行
}
/**************************************************************************************
* 函数名称:Display_ASCII;
*
* 函数功能描述:显示单个字符程序;
*
* 输入参数:Char:字符 X:x轴坐标 Y:y轴坐标
*
* 返回数据:无;
*
**************************************************************************************/
void Display_ASCII(unsigned char Char,unsigned char X,unsigned int Y)
{
unsigned char code * ImgData;
unsigned char add;
if((Char>='0')&(Char<='9'))
{
ImgData=&ASC_MSK[(Char-0x30)*16];
display_8x8dot_at_xy(X+1,Y,ImgData);
ImgData=&ASC_MSK[(Char-0x30)*16+8];
display_8x8dot_at_xy(X+2,Y,ImgDat