本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
我最近在调RA8835控制器的320*240的LCD(蓝底白字),用的单片机是51系类的,可以显示汉字,但是在显示“查”的时候中间的一竖显示不出来,屏下方有一条带状的线2,哪位高手可以帮我看看,以下是我的程序
#include <reg52.h>
#define AP 0x35
/*--------------------------------------------------------------*/
//端口定义
sfr LCD320_BUS = 0x90; //8位数据总线 P2 = 0xa0
sbit LCD320_WR = P2^3; //写信号,低电平有效
sbit LCD320_RD = P2^2; //读信号,低电平有效
sbit LCD320_CD = P2^5; //高:选择指令寄存器;低:选择数据寄存器
//定义命令字
#define systemset 0x40 //初始化设置
unsigned char code parasystable8[]={0x30, 0x85, 0x07, 0x34, 0x4f, 0xef, 0x35, 0x00}; // P1-P8参数
#define scroll 0x44 //显示域设置
#define basepart1 0x00 //第一显示区RAM,高8位地址,10KB
#define basepart2 0x28 //第二显示区RAM,高8位地址,10KB
#define basepart3 0x50 //第三显示区RAM,高8位地址,10KB
#define basepart4 0x00 //第四显示区RAM,高8位地址,32KB
unsigned char code parascrtablea[]={0x00, basepart1, 0xf0, 0x00, basepart2, 0xf0, 0x00,
basepart3, 0x00, basepart4};
#define sleepin 0x53 //休闲模式设置
#define dispon 0x59 //显示状态打开
#define dispoff 0x58 //显示关闭
#define ovlay 0x5b //显示合成设置
#define hdotscr 0x5a //点位移设置
#define csrform 0x5d //光标形状设置
#define cgramadr 0x5c //CGRAM首地址设置
#define csrdirr 0x4c //光标向右方向移
#define csrdirl 0x4d //光标向左方向
#define csrdiru 0x4e //光标向上方向
#define csrdird 0x4f //光标向下方向
#define csrw 0x46 //设置光标地址
#define csrr 0x47 //读出光标地址
#define mwrite 0x42 //显示数据写入
#define mread 0x43 //显示数据读取
#define busy 0x40 //忙信号D6
/*--------------------------------------------------------------*/
//函数声明
//void check_busy(void); //忙状态检测
void write_cmd(unsigned char cmd);
void write_dat(unsigned char dat);
//unsigned char read_dat(void);
void lcd_init(void);
void lcd_cls(void);
void show_on(void);
void show_off(void);
unsigned char code cgtab[][32]= {
0xDF,0xDE,0x01,0xDF,0xAF,0xAF,0x6F,0x02,0xEC,0xEF,0xE3,0x0F,0xEF,0xEF,0xE8,0xEF,
0xFF,0x03,0xF7,0xEF,0xDF,0xAF,0x73,0xFB,0x01,0xDF,0xDF,0xDF,0xDF,0xDF,0x01,0xFF,//轻
};
void delay200ms(void)
{
unsigned char i,j,k;
for(i=201;i>0;i--)
for(j=32;j>0;j--)
for(k=14;k>0;k--);
}
/*--------------------------------------------------------------*/
//检测忙
/*void check_busy(void)
{
unsigned char onbusy;
LCD320_WR = 1;
while(1)
{
LCD320_CD = 0;
LCD320_RD = 0;
onbusy = LCD320_BUS;
LCD320_RD = 1;
if((onbusy&busy)==0) break;
}
}
/*--------------------------------------------------------------*/
//
void write_cmd(unsigned char cmd)
{
LCD320_RD = 1;
LCD320_BUS = cmd;
LCD320_CD = 1; //指令
LCD320_WR = 0; //上升沿写入
LCD320_WR = 1;
}
/*--------------------------------------------------------------*/
//
void write_dat(unsigned char dat)
{
LCD320_RD = 1;
LCD320_BUS = dat;
LCD320_CD = 0; //数据
LCD320_WR = 0; //上升沿写入
LCD320_WR = 1;
}
void lcd_init(void)
{
unsigned char i;
write_cmd(systemset);
for(i=0; i<8; i++)
{
write_dat(parasystable8[i]);
}
write_cmd(scroll);
for(i=0; i<10; i++)
{
write_dat(parascrtablea[i]);
}
write_cmd(hdotscr);
write_dat(0x00);
write_cmd(ovlay);
write_dat(0x00);
show_off();
lcd_cls();
show_on();
}
/*--------------------------------------------------------------*/
//32KB RAM 清零
void lcd_cls(void)
{
unsigned int i = 32768;
write_cmd(csrdirr);
write_cmd(csrw);
write_dat(0x00);
write_dat(0x00);
write_cmd(mwrite);
while(i--)
{
write_dat(0x00);
}
}
/*--------------------------------------------------------------*/
//
void show_on(void)
{
write_cmd(dispon);
write_dat(0x54);
}
/*--------------------------------------------------------------*/
//
void show_off(void)
{
write_cmd(dispoff);
write_dat(0x56);
}
/*--------------------------------------------------------------*/
void locate_xy1(unsigned char x, unsigned char y)
{
unsigned int addr;
addr =(unsigned int)(y) * AP + x;
write_cmd(csrw); //写入光标地址
write_dat((unsigned char)(addr & 0xff)); //先写低八位
write_dat((unsigned char)(addr >> 8)); //后写高八位
}
//加载cgram
void load_cgram(unsigned char m)
{
unsigned char i, j;
write_cmd(cgramadr);
write_dat(0x00);
write_dat(0x50); //cgram起始地址
write_cmd(csrdirr);
write_cmd(csrw);
write_dat(0x00);
write_dat(0x54); //cgram 1K RAM 结束地址
write_cmd(mwrite);
for(j = 0; j < m; j++)
{
for(i = 0; i < 32; i++)
{
if(inverse) write_dat(cgtab[j][i]);
else write_dat(cgtab[j][i]);
}
}
}
/*--------------------------------------------------------------*/
//显示汉字(文本)
//x横坐标: 0~39 320/8=40
//y纵坐标: 0~29 240/8=30
void show_hzt(unsigned char x, unsigned char y, unsigned char n_4)
{
locate_xy1(x, y);
write_cmd(csrdird); //光标向下方向移动
write_cmd(mwrite);
write_dat(n_4);
write_dat(n_4 + 1);
locate_xy1(x + 1, y);
write_cmd(mwrite);
write_dat(n_4 + 2);
write_dat(n_4 + 3);
}
void main(void)
{
lcd_init();
load_cgram(1);
show_hzt(0,2,0x80);
delay200ms();
while(1);
} |
|