/****************************************************************************
*
*
*
*
*
*
****************************************************************************/
#include <intrins.h>
#include "STC15F2K60S2.h"
#include "LCD_drive.h"
#include "ASCII8X16.h"
//==========================================================================
// 函数功能: LCD的接口信号(逻辑管脚与物理管脚的对应表)
//==========================================================================
sbit LCD_BL = P2^7;
sbit LCD_RST = P2^6;
sbit LCD_CS2 = P2^5;
sbit LCD_CS1 = P2^4;
sbit LCD_E = P2^3;
sbit LCD_RW = P2^2;
sbit LCD_RS = P2^1;
#define LCD_DATA P0
//==========================================================================
// 函数功能: 本地变量及常量的定义
//==========================================================================
#define NOP delay_us(5)
//==========================================================================
// 函数功能: 1微秒延时函数
//==========================================================================
#ifndef delay_us
void delay_us(unsigned char us_value)
{//IRC @ 24.000MHz
unsigned char i;
while(us_value--)
{
_nop_();
_nop_();
i = 3;
while (--i);
}
}
#endif /*delay_us*/
//==========================================================================
// 函数功能: 1毫秒延时函数
//==========================================================================
#ifndef delay_ms
void delay_ms(unsigned int ms_value)
{ //IRC @ 24.000MHz
unsigned char i, j;
while(ms_value--)
{
i = 24;
j = 85;
do
{
while (--j);
} while (--i);
}
}
#endif /*delay_ms*/
//==========================================================================
// 函数功能: 检测是否空闲
//==========================================================================
void LCD_BusyChk(void)
{
unsigned int timeout = 0;
LCD_E = 0;
LCD_RS = 0;
LCD_RW = 1;
LCD_E = 1;
while((LCD_DATA & 0x80) && ++timeout != 0); //忙状态检测, 等待超时时间为60ms
LCD_E = 0;
}
//==========================================================================
// 函数功能: 往12864读数据
//==========================================================================
unsigned char LCD_RdData(void)
{
unsigned char temp;
LCD_BusyChk();
LCD_E = 0;
LCD_DATA = 0xFF; //IO口置高电平, 以便读引脚
LCD_RS = 1;
LCD_RW = 1;
LCD_E = 1;
NOP; //使能延时, 如果是较快的CPU应该延时久一些
NOP;
NOP;
temp = LCD_DATA;
return temp;
}
//==========================================================================
// 函数功能: 往12864写命令
//==========================================================================
void LCD_WrCmd(unsigned char cmd)
{
LCD_RS = 0;
LCD_RW = 0;
LCD_DATA = cmd;
LCD_E = 1;
NOP;
LCD_E = 0;
}
//==========================================================================
// 函数功能: 往12864写数据
//==========================================================================
void LCD_WrData(unsigned char wdata)
{
LCD_RS = 1;
LCD_RW = 0;
LCD_DATA = wdata;
LCD_E = 1;
NOP;
LCD_E = 0;
}
//==========================================================================
// 函数功能: 地址转换
//==========================================================================
void LCD_Select(unsigned char x, unsigned char y)
{
if( y>=64 )
{
LCD_CS2 = 1; //选中左屏
LCD_CS1 = 0;
}
else
{
LCD_CS1 = 1; //选中右屏
LCD_CS2 = 0;
}
LCD_WrCmd(0xC0);
LCD_WrCmd(0x40 + (y&0x3F)); //列地址
LCD_WrCmd(0xB8 + (x&7)); //行
}
//==========================================================================
// 函数功能: LCD满屏
// 函数接口: void LCD_Full(void);
//==========================================================================
void LCD_Full(void)
{
unsigned char i, x=0;
for(x=0; x<8; x++)
{
LCD_Select(x, 0); //选中左屏
for(i=0; i<64; i++)
{
LCD_WrData(0xFF);
}
LCD_Select(x, 64); //选中右屏
for(i=0; i<64; i++)
{
LCD_WrData(0xFF);
}
}
}
//==========================================================================
// 函数功能: LCD显示一行
// 函数接口: void LCD_DispOneRow(unsigned char x, unsigned char y, unsigned char *buf, unsigned char len);
// 出口参数: unsigned char x, unsigned char y, unsigned char *buf, unsigned char len
// x-显示行, 0~7(一行宽度为8个点)
// y-显示起始列, 0~127, 超过列显示无效
//==========================================================================
void LCD_DispOneRow(unsigned char x, unsigned char y, unsigned char *buf, unsigned char len)
{
x = x&7;
LCD_Select(x, y);
while(len--)
{
LCD_WrData(*buf);
buf++;
y++;
if( y == 64 )
{
LCD_Select(x, y); //选中右屏
}
}
}
//==========================================================================
// 函数功能: LCD画点
// 函数接口: void DrawDot_12864(unsigned char x, unsigned char y, unsigned char type);
// 出口参数: unsigned char x, unsigned char y, unsigned char type
// x-显示行, 0~63
// y-显示起始列, 0~127, 超过列显示无效
//==========================================================================
void DrawDot_12864(unsigned char x, unsigned char y, unsigned char type)
{
unsigned char X, Y; //X存储行地址, Y存储列地址
unsigned char dat, temp;
if( x >= 0 && x < 64 )
{
X = x/8;
Y = y;
}
LCD_Select(X, Y); //地址转换
dat = LCD_RdData(); //假读
dat = LCD_RdData();
temp = x % 8; //余数为点在字中的位置
switch(type) //画点类型, 0白, 1黑, 2取反
{
case 0:
dat &= ~(0x01 << temp);; //修改该点同时保持其他位不变
break;
case 1:
dat |= (0x01 << temp); //修改该点同时保持其他位不变
break;
case 2:
dat ^= (0x01 << temp);; //修改该点同时保持其他位不变
break;
default:
break;
}
LCD_Select(X, Y);
LCD_WrData(dat); //将字节数据写回
}
//==========================================================================
// 函数功能: LCD清屏
// 函数接口: void LCD_Clr(void);
//==========================================================================
void LCD_Clr(void)
{
unsigned char i, x=0;
for(x=0; x<8; x++)
{
LCD_Select(x, 0); //选中左屏
for(i=0; i<64; i++)
{
LCD_WrData(0);
}
LCD_Select(x, 64); //选中右屏
for(i=0; i<64; i++)
{
LCD_WrData(0);
}
}
}
//==========================================================================
// 函数功能: LCD初始化
// 函数接口: void LCD_Init(void);
//==========================================================================
void LCD_Init (void)
{
LCD_BL = 0; //打开背光
LCD_RST = 0;
delay_ms(100);
LCD_RST = 1;
delay_ms(1);
LCD_CS1 = 1;
LCD_CS2 = 1;
LCD_WrCmd(0xC0); //设置显示起始行
LCD_WrCmd(0x3F); //显示打开
LCD_Clr(); //清屏
}
/************************************
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
舵机.rar (32个子文件)
舵机
duoji.uvgui.hunagshunxing 137KB
photosensitive.h 242B
PCF8591.h 826B
Objects
duoji.lnp 201B
photosensitive.obj 8KB
time.obj 2KB
duoji.build_log.htm 2KB
duoji.hex 19KB
PCF8591.obj 17KB
LCD_drive.obj 22KB
duoji 59KB
main.obj 13KB
key.h 2KB
LCD_drive.c 13KB
11 2KB
ASCII8X16.h 16KB
duoji.uvopt 7KB
Listings
PCF8591.lst 10KB
duoji.m51 49KB
photosensitive.lst 2KB
main.lst 8KB
time.lst 2KB
LCD_drive.lst 22KB
LCD_drive.h 5KB
PCF8591.c 6KB
photosensitive.c 512B
time.h 141B
stdint.h 2KB
time.c 369B
duoji.uvgui.14744 92KB
main.c 3KB
duoji.uvproj 15KB
共 32 条
- 1
资源评论
超级努力刘
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功