#include "jm240.h"
#include "ascii0816.h"
const uint add[]={0x0000,0x0F00,0x1E00,0x2D00,0x3C00,0x4B00,0x5A00,0x6900,0x7800,0x9700,0xA600,0xB500,0xC400} ;
JM240 jm ;
void init_jm240()
{
//set the directio of port
DB_DIR=0 ;
ADCON1=0x06 ;
TRISA=TRISA&0xC0 ;
//init global variable
jm.graphic_add=0x0000 ;
jm.graphic_width=30 ;
jm.cur_page=0 ;
jm.offset=0x0000 ;
jm.char_width=8 ;
jm.chn_width=16 ;
//init
rst_lcd() ;
set_graphic(jm.graphic_add,jm.graphic_width) ;
wr_cmd0(0x80) ;// 或模式
wr_cmd0(0x98) ;//note here must start graphic display
clr_ram() ;
}
//restart lcd
void rst_lcd()
{
RST=0 ;
DelayUs(50) ;
RST=1 ;
DelayMs(50) ;
}
//get the currrent state of lcd
uchar ch_status()
{
uchar temp ;
CD=1 ;
WR=1 ;
CE=0 ;
DB_DIR=0x00 ;
DB=0xff ;
RD=0 ;
DB_DIR=0xFF ;
temp=DB ;
RD=1 ;
CE=1 ;
DB_DIR=0x00 ;
return temp ;
}
//check whether lcd is busy or not at present
void ch_busy(uchar flag)
{
uchar temp1,temp2 ;
if(!flag)//one write or read status flag
temp2=0x03 ;
else
{
if(flag==1)// auto write status flag check
temp2=0x08 ;
else//auto read state flag check
temp2=0x04 ;
}
do
{
temp1=ch_status() ;
temp1=temp1&temp2 ;
}while(temp1!=temp2) ;
}
//set graphic mode
void set_graphic(uint ad,uchar width)
{
jm.graphic_add=ad ;
jm.graphic_width=width ;
wr_cmd3(ad,0x42) ;
wr_cmd2(width,0x00,0x43) ;
}
//read a byte from lcd
uchar rd_data()
{
uchar temp ;
ch_busy(0) ;
CD=0 ;
DB=0 ;
CE=0 ;
DB_DIR=0x00 ;
DB=0xff ;
RD=0 ;
DB=0 ;
CE=0 ;
DB_DIR=0xFF ;
temp=DB ;
RD=1 ;
CD=1 ;
return temp ;
}
//send a byte to lcd ram
void send_byte(uchar dat)
{
RD=1 ;
DB_DIR=0x00 ;
CE=0 ;
CD=0 ;
WR=0 ;
DB=dat ;
// DelayUs(2) ;
CE=1 ;
CD=1 ;
WR=1 ;
}
//send a command word to lcd registor
void send_cmd(uchar cmd)
{
RD=1 ;
DB_DIR=0x00 ;
CE=0 ;
CD=1 ;
WR=0 ;
DB=cmd ;
// DelayUs(2) ;
CE=1 ;
CD=1 ;
WR=1 ;
}
//write a byte
void wr_data(uchar data)
{
ch_busy(0) ;
send_byte(data) ;
}
//write a command with no parameter
void wr_cmd0(uchar cmd)
{
ch_busy(0) ;
send_cmd(cmd) ;
}
//write a command with one parametre
void wr_cmd1(uchar para,uchar cmd)
{
ch_busy(0) ;
send_byte(para) ;
ch_busy(0) ;
send_cmd(cmd) ;
}
//write a cammand with two parameters
void wr_cmd2(uchar para1,uchar para2,uchar cmd)
{
ch_busy(0) ;
send_byte(para1) ;
ch_busy(0) ;
send_byte(para2) ;
ch_busy(0) ;
send_cmd(cmd) ;
}
//write a command with a uint parameter
void wr_cmd3(uint para,uchar cmd)
{
uchar temp,temp1 ;
temp=(uchar )para ;
temp1=(uchar)(para>>8) ;
wr_cmd2(temp,temp1,cmd) ;
}
//autowrite
void auto_wr(uchar dat)
{
ch_busy(1) ;
send_byte(dat) ;
}
//autoread
uchar auto_rd()
{
uchar temp ;
ch_busy(2) ;
CD=0 ;
DB=0 ;
CE=0 ;
DB_DIR=0x00 ;
DB=0xff ;
RD=0 ;
DB=0 ;
CE=0 ;
DB_DIR=0xFF ;
temp=DB ;
RD=1 ;
CD=1 ;
return temp ;
}
//enable auto write or not
void enable_autowr(uchar flag)
{
if(flag)
wr_cmd0(0xB0) ;
else
wr_cmd0(0xB2) ;
}
//enable autoread or not
void enable_autord(uchar flag)
{
if(flag)
wr_cmd0(0xB1) ;
else
wr_cmd0(0xB3) ;
}
//define higher function
//current display ram address add add
void add_add(uint ad)
{
uint temp ;
jm.offset+=ad ;
temp=jm.cur_page+jm.offset ;
wr_cmd3(temp,0x24) ;
}
//set addres s pointer
// had better not use this function
void set_add(uint ad)
{
jm.cur_page=ad ;
wr_cmd3(ad,0x24) ;
}
//move address pointer to y row and x column
void add_xy(uchar x,uchar y)
{
uint temp ;
temp=(uint)x+((uint)y)*jm.graphic_width ;
jm.offset=temp ;
temp=temp+jm.cur_page ;
wr_cmd3(temp,0x24) ;
}
void str_disp(const uchar *str,uchar x,uchar y)
{
uint temp1 ;
uchar temp,temp2,j,i ;
// wr_cmd0(0x9F) ;
// wr_cmd0(0x81) ;
// add_xy(1,x,y) ;
// while(*str!='\0')
// {
// temp=*(str++)-0x20 ;
// wr_cmd1(temp,0xC0) ;//address auto add 1
// }
// wr_cmd0(jm.disp_mode)
i=x ;
y=y*16 ;
while(*str!='\0')
{
add_xy(i++,y) ;
temp1=(*(str++)-0x20)*16 ;
for(j=0;j<16;j++)
{
temp2=ascii0816[temp1+j];
wr_cmd1(temp2,0xC4) ;
add_add(30) ;
}
}
}
//here as long as we understand how lcd scan screen,we can
//implement what function we want
//this lcd scan in horizon mode
void show_char( uchar dat ,uchar x,uchar y)
{
uint temp1 ;
uchar i ,j ,temp2;
y=y*16 ;
add_xy(x,y) ;
temp1=(dat-0x20)*16 ;
//for one char is composed of 16*8 dots ,so we need scan 16 times in horizontal way
for(j=0;j<16;j++)
{
temp2=ascii0816[temp1+j];
//one times we write in 8 dots
wr_cmd1(temp2,0xC4) ;
add_add(30) ;
}
}
void show_chn(const uchar *chn,uchar x,uchar y)
{
uchar i ;
// x=x*8;
y=y*16 ;
add_xy(x,y) ;
for(i=0;i<16;i++)
{
wr_cmd1(*chn++,0xC4) ;
add_add(1) ;
wr_cmd1(*chn++,0xC4) ;
add_add(29) ;
}
}
void chns_disp(const uchar *chn,uchar x,uchar y,uchar count)
{
uchar i,j ;
for(i=0;i<count;i++)
{
add_xy(x+i*2,y) ;
for(j=0;j<16;j++)
{
wr_cmd1(*chn++,0xC4) ;
add_add(1) ;
wr_cmd1(*chn++,0xC4) ;
add_add(29) ;
}
// y=y+16 ;
}
}
void show_img(uchar x,uchar y,uchar width,uchar height,const uchar *img)
{
uchar i ,j,temp1,temp2 ;
// set_add(jm.cur_page) ;
// temp1=(x1-x)/8 ;
// temp2=(y1-y) ;
add_xy(0,y) ;
add_add(x) ;
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
wr_cmd1(*img++,0xC4) ;
add_add(1) ;
}
add_add(30-width) ;
}
}
void clr_lcd(uchar x,uchar y,uchar width,uchar height)
{
uchar i,j;
width=width/8 ;
// add_xy(0,x,y) ;
for(i=0;i<height;i++)
{
add_xy(0,y+i) ;//move to the position where you want to clear
add_add(x) ;
enable_autowr(1) ;
for(j=0;j<width;j++)
{
auto_wr(0x00) ;
}
enable_autowr(0) ;
}
}
void clr_ram()
{
uint i ;
set_add(jm.cur_page) ;
enable_autowr(1) ;
for(i=0;i<0xFFFE;i++)
{
auto_wr(0x00) ;
}
enable_autowr(0) ;
set_add(jm.cur_page) ;
}
//this function has some problems
void wr_img(uchar x,uchar y,uchar width,uchar height,const uchar *img)
{
uchar i,j,flag ;
if(jm.offset<0xF00)
flag=0 ;
else
flag=1 ;
width=width/8 ;
for(i=0;i<height;i++)
{
add_xy(x,y+i) ;//move to the position where you want to clear
enable_autowr(1) ;
for(j=0;j<width;j++)
{
auto_wr(*img++) ;
}
enable_autowr(0) ;
}
}
//draw picture
void draw_vline(uchar x,uchar y,uchar height)
{
uchar i ;
add_xy(x,y) ;
for(i=0;i<height;i++)
{
wr_cmd0(0xF8) ;
add_add(30) ;
}
}
void draw_hline(uchar x,uchar y,uchar width)
{
uchar i;
add_xy(x,y) ;
width=width/8 ;
enable_autowr(1) ;
for(i=0;i<width;i++)
auto_wr(0xff) ;
enable_autowr(0) ;
}
void draw_frame(uchar x,uchar y,uchar width,uchar height)
{
uchar i,j ;
width=width/8 ;
//draw two horizon line
add_xy(x,y) ;
enable_autowr(1) ;
for(i=0;i<width;i++)
auto_wr(0xFF) ;
enable_autowr(0) ;
add_xy(x,y+height) ;
enable_autowr(1) ;
for(i=0;i<width;i++)
auto_wr(0xFF) ;
enable_autowr(0) ;
//draw two vertical line
add_xy(x,y) ;
for(i=0;i<height;i++)
{
wr_cmd0(0xFF) ;
add_add(29) ;
wr_cmd0(0xF8) ;
add_add(1) ;
}
}
void draw_point(uchar x,uchar y)
{
uchar temp ;
temp=x%8 ;
x=x/8 ;
add_xy(0,y) ;
add_add(x) ;
temp=7-temp+0xF8 ;
wr_cmd0(temp) ;
}
void draw_page(uchar num)
{
uint temp=jm.cur_page ;
set_add(add[num]) ;
clr_lcd(0,0,239,127) ;
draw_frame(0,0,240,126) ;
draw_hline(1,105,220) ;
draw_vline(1,20,90) ;
// chns_disp(str,8,3,6) ;
// chns_disp(str1,205,102,2) ;
// show_chn(str2,0,2) ;
// show_chn(str2+32,0,3) ;
draw_point(12,3) ;
set_add(temp) ;
}
JM240128A的驱动程序
5星 · 超过95%的资源 需积分: 33 126 浏览量
2009-08-19
13:51:48
上传
评论 1
收藏 126KB RAR 举报
好清闲
- 粉丝: 319
- 资源: 20
最新资源
- 农村信用社联合社计算机信息系统投产与变更管理办.docx
- 农村信用社联合社计算机信息系统数据管理办法.docx
- 利用SPSS作临床效度分析线上计算网站介绍-医学研究部统计谘.(医学PPT课件).ppt
- 利用Zabbix监控mysqldump定时备份数据库状态.docx
- 利用计算机解决问题的基本过程.doc
- 化工铁路通信工程总结.doc
- 北京大学网络教育软件工程作业.docx
- 医药公司(连锁店)计算机操作规程未新系统的自行按照旧制修改-新系统过制的编号加修模版.doc
- 医药公司(连锁店)计算机系统操作规程模版.doc
- 医药连锁门店计算机系统的操作和管理程序未新系统的自行按照旧制修改-新系统过制的编号加修模版.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈