?? lcd128645zk.c
字號(hào):
//writed by mengx 2001.7.27
#include "common.h"
#ifndef _UPSD_H_
#include <at89x52.h>
#endif
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include <string.h>
#include <intrins.h>
#include <absacc.h>
/* define uchar,uint*/
#define LCD_RST_HI PSD8xx_reg.DATAOUT_B|=0x20
#define LCD_RST_LO PSD8xx_reg.DATAOUT_B&=~0x20
#define uchar unsigned char
#define uint unsigned int
#define lcd_buff_size 16
#define lcd_refresh_time_set 50 //300ms刷新一次
/*定義lcd命令字和lcd數(shù)據(jù)輸出口*/
#define cls 0x1 /*清屏*/
#define home 0x2 /*光標(biāo)回原點(diǎn)*/
#define cursor_rr 0x6 /*顯示不動(dòng),光標(biāo)右移,DDRAM+1*/
#define cursor_rl 0x4 /*顯示不動(dòng),光標(biāo)左移,DDRAM-1*/
#define disp_on 0xf /*打開(kāi)顯示*/
#define disp_off 0xb /*關(guān)閉顯示*/
#define cursor_on 0xc /*關(guān)閉光標(biāo)顯示*/
#define cursor_off 0xe /*關(guān)閉光標(biāo)閃爍*/
#define cursor_ctrl 0x14 /*光標(biāo)向右移動(dòng)*/
#define ddram_ac 0x80 /*設(shè)定光標(biāo)AC位置*/
#define funcset 0x38 /*設(shè)定功能:8位接口,2行顯示,5*7點(diǎn)陣*/
#define BG_LIGHT 0x80; //LCD背光燈控制 P0 bit7 0=off 1=on
//unsigned char idata lcd_buff[2][lcd_buff_size];
unsigned char idata cursor_position=0; //光標(biāo)位置
unsigned char idata lcd_refresh_time;
uchar idata last_row=0x53;
//lcd 并行接口以外設(shè)模式訪問(wèn) wr、rd合成出E信號(hào)
#define DATA_RD_PORT XBYTE [0x030f] //數(shù)據(jù)讀端口
#define DATA_WR_PORT XBYTE [0x030e] //數(shù)據(jù)寫(xiě)端口
#define COMD_RD_PORT XBYTE [0x030d] //命令讀端口
#define COMD_WR_PORT XBYTE [0x030c] //命令寫(xiě)端口
#define data_port P0 //P1
sbit RS=P2^0; //P3^2
sbit RW=P2^1; //P3^3
sbit E=P2^2; //P3^4
//char xdata ___scr_buffer[MAX_ROW * MAX_COL+20];
#if(0)
//讀取忙標(biāo)志和ac值
unsigned char lcd_read_busy(void)
{unsigned char data busy;
data_port=0xff; //置P0口位高阻輸入狀態(tài)
RS=0;RW=1;E=1;
busy=data_port;
E=0;
return (busy);
}
//寫(xiě)命令到lcd
void lcd_write_command(unsigned char data_com)
{ unsigned char i=120;
ET0 = 0;
data_port=data_com;
RS=0;RW=0;E=1;
E=0;
ET0 = 1;
while(lcd_read_busy()&0x80&&i)i--;
}
//寫(xiě)數(shù)據(jù)到lcd
void lcd_write_data(unsigned char data_com)
{ unsigned char i=120;
ET0 = 0;
data_port=data_com;
RS=1;RW=0;E=1;
E=0;
ET0 = 1;
while(lcd_read_busy()&0x80&&i)i--;
}
#else
/*讀取忙標(biāo)志和ac值*/
unsigned char lcd_read_busy(void)
{unsigned char data busy;
busy=COMD_RD_PORT;
return (busy);
}
//寫(xiě)命令到lcd
void lcd_write_command(unsigned char data_com)
{ unsigned char i=120;
while(lcd_read_busy()&0x80&&i)i--;
COMD_WR_PORT=data_com;
}
//寫(xiě)數(shù)據(jù)到lcd
void lcd_write_data(unsigned char data_com)
{ unsigned char i=120;
while(lcd_read_busy()&0x80&&i)i--;
DATA_WR_PORT=data_com;
}
#endif
/*設(shè)定ddram ac位置,在該位置寫(xiě)入、顯示數(shù)據(jù)*/
void set_ddram_ac(unsigned char ac)
{
lcd_write_command(ac|ddram_ac);
}
void lcd_init(void)
{
LCD_RST_LO;
LCD_RST_HI;
lcd_write_command(funcset);
lcd_refresh_time=0x10;
// while(lcd_refresh_time);
lcd_write_command(funcset);
lcd_refresh_time=0x10;
// while(lcd_refresh_time);
lcd_write_command(disp_on);
lcd_refresh_time=0x1;
// while(lcd_refresh_time);
lcd_write_command(cursor_rr);
lcd_refresh_time=0x1;
// while(lcd_refresh_time);
lcd_write_command(cls);
lcd_refresh_time=0x10;
// while(lcd_refresh_time);
lcd_write_command(cursor_on);
lcd_refresh_time=0x5;
// while(lcd_refresh_time);
lcd_write_command(0x0f);
lcd_refresh_time=0x5;
// while(lcd_refresh_time);
// lcd_write_command(cursor_on);
lcd_refresh_time=0x5;
// while(lcd_refresh_time);
lcd_write_command(disp_off);
lcd_refresh_time=0x5;
// while(lcd_refresh_time);
lcd_write_command(disp_on);
lcd_refresh_time=0x5;
// while(lcd_refresh_time);
/*
lcd_write_command(0x34); //8bit 擴(kuò)充指令
lcd_refresh_time=0x1;
while(lcd_refresh_time);
lcd_write_command(0x06); //反白顯示
lcd_refresh_time=0x1;
while(lcd_refresh_time);
lcd_write_command(0x30); //8bit 擴(kuò)充指令
lcd_refresh_time=0x1;
while(lcd_refresh_time);
*/
memset(&___scr_buffer,' ',sizeof(___scr_buffer));
}
/***********反白顯示某行******************/
void invert_line(uchar row)
{
if(last_row!=row){
lcd_write_command(cls);
lcd_write_command(0x34); //8bit 擴(kuò)充指令
lcd_write_command(0x04|(row&0x03)); //反白顯示
lcd_write_command(0x38); //8bit 基本指令
last_row=row;
}
}
/*顯示數(shù)據(jù),在主程序中調(diào)用*/
void lcd_disp(void)
{unsigned char xdata *ptr,*ptr1;
unsigned char i;
if(RunSta.lcd_timer==0){
if(Msgbuff.delay && RunSta.debug_fg==0){
ptr=&Msgbuff.buff;
}else{
ptr=&___scr_buffer;
}
ptr1=ptr;
// cursor_position=lcd_read_busy(); //保存光標(biāo)位置
lcd_write_command(home);
for(i=0;i<64;i++){
if(i==16){
ptr1=ptr+32;
}
else{
if(i==32){
ptr1=ptr+16;
}
else{
if(i==48){
ptr1=ptr+48;
}
}
}
if(*ptr1==0x00){
*ptr1=0x20;
}
lcd_write_data(*ptr1++);
}
RunSta.lcd_timer=lcd_refresh_time_set;
if(___cursor_on){ //如果光標(biāo)顯示功能打開(kāi)
switch(wherey()&0x03){
case 0:i=0;break;
case 1:i=16;break;
case 2:i=8;break;
case 3:i=24;break;
}
set_ddram_ac(i+wherex()/2); //設(shè)定光標(biāo)位置
}
}
// set_ddram_ac(cursor_position&0x7f); //恢復(fù)光標(biāo)位置
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -