LCD12864详细C程序 lcd12864显示c程序

山东建筑大学 锐思实验室函数名称:LCD12864程序 CPU型号:STC89C52晶振参数:12MHZ 联系方式:QQ:610949704程序作者:2009级机械2班 许方超请点击 程序模块中看最新的一篇里面有下载链接,注释一发表就自动没有了http://blog.sina.com.cn/s/articlelist_1730310191_9_1.htmlLCD12864.C#include "LCD12864.h"void Delay_40US() //误差 0us{ unsigned char a,b; for(b=1;b>0;b--) for(a=10;a>0;a--);}code unsigned int LcdMaskTab[]={0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000};void LCD12864_checkbusy(void){ unsigned charBusy,num;num=100;LcdData=0xff; LCD12864_RS=0; LCD12864_RW=1; LCD12864_EN=1; Delay_40US(); Busy=LcdData&0x80; LCD12864_EN=0; while(Busy&&num--);}
void LCD12864_writedata(unsigned char Data){ LCD12864_checkbusy();LCD12864_RS=1;LCD12864_RW=0;LCD12864_EN=0;Delay_40US();LcdData=Data;LCD12864_EN=1;Delay_40US();LCD12864_EN=0;}
unsigned char LCD12864_readdata(void){unsigned char Temp;LCD12864_checkbusy(); LcdData=0xff; LCD12864_RS=1;LCD12864_RW=1;LCD12864_EN=1;Delay_40US(); Temp=LcdData; LCD12864_EN=0; return Temp;}
void LCD12864_writecommand(unsigned char CmdCode){ LCD12864_checkbusy(); LCD12864_RS=0; LCD12864_RW=0; LCD12864_EN=0; Delay_40US() ; LcdData=CmdCode; Delay_40US() ; LCD12864_EN=1; LCD12864_EN=0;}void LCD12864_setplace(uchar X,ucharY){ uchar pos;if (X==1){X=0x80;}else if(X==2){X=0x90;} elseif(X==3){X=0x88;}else if(X==4){X=0x98;}pos=X+Y;LCD12864_writecommand(pos);}void LCD12864_graphsetmode(unsigned char Select){LCD12864_writecommand(LCD_EXTEND_FUNCTION);if(Select){LCD12864_writecommand(LCD_GRAPH_ON);}else {LCD12864_writecommand(LCD_GRAPH_OFF);} }void LCD12864_displaystring(unsigned char x,unsigned chary,unsigned char *Str){ if((y>4)||(x>8)) return;LCD12864_setplace(x,y);while(*Str>0){ LCD12864_writedata(*Str); Str++;}}void LCD12864_displaypage( uchar code *adder1){ unsigned char i; LCD12864_writecommand(0x80);for(i=0;i<32;i++){LCD12864_writedata(*adder1);adder1++;}LCD12864_writecommand(0x90);for(i=32;i<64;i++){LCD12864_writedata(*adder1);adder1++;}
}void LCD12864_sendascii(uchar hang,uchar lie,charsign){
LCD12864_setplace(hang,lie); LCD12864_writedata(sign); }void LCD12864_sendgb2312(uchar hang,uchar lie,unsigned intsign){unsigned char templ, temph;templ=sign&0x00ff;temph=sign>>8 ;LCD12864_writecommand(0x30);LCD12864_setplace(hang,lie); LCD12864_writedata(temph);Delay_40US();LCD12864_writedata(templ); }void LCD12864_writepixel(unsigned char x,unsigned chary,unsigned char color){unsigned char row,collum,cbite;unsigned char tempH,tempL;LCD12864_graphsetmode(0);collum=x>>4;cbite=x&0x0f;if(y<32)row=y;else{row=y-32;collum+=8;}LCD12864_writecommand(0x80+row);LCD12864_writecommand(0x80+collum);LCD12864_readdata();tempH=LCD12864_readdata();tempL=LCD12864_readdata();LCD12864_writecommand(0x80+row);LCD12864_writecommand(0x80+collum);if (color){if(cbite<8){tempH|=(1<<(7-cbite));}else{tempL|=(1<<(15-cbite));}}else{if(cbite<8){tempH&=~(1<<(7-cbite));}else{tempL&=~(1<<(15-cbite));}}LCD12864_writedata(tempH);LCD12864_writedata(tempL);LCD12864_graphsetmode(1);LCD12864_writecommand(0x30);}void LCD12864_cleardram(void){ unsigned char i,j; LCD12864_writecommand(0x34);LCD12864_writecommand(0x34);LCD12864_writecommand(0x30);for(i=1;i<5;i++)for(j=1;j<9;j++)LCD12864_sendgb2312(i,j,0xB0A0); LCD12864_writecommand(0x34); LCD12864_writecommand(0x36);
}void LCD12864_cleargram(unsigned char Mode){unsigned char x,y,ii;unsigned char Temp;if(Mode%2==0)Temp=0x00;else Temp=0xff;LCD12864_writecommand(0x36);//扩充指令 绘图显示for(ii=0;ii<9;ii+=8)for(y=0;y<0x20;y++) for(x=0;x<8;x++){LCD12864_writecommand(y+0x80); //行地址LCD12864_writecommand(x+0x80+ii); //列地址 LCD12864_writedata(Temp); //写数据 D15-D8LCD12864_writedata(Temp); //写数据 D7-D0}LCD12864_writecommand(0x30);}void LCD12864_cleargdram(void){LCD12864_cleardram();LCD12864_cleargram(0);}void LCD12864_displaypicture_up(unsigned char *img){ unsigned char i,j; LCD12864_graphsetmode(0); for(j=0;j<32;j++) { for(i=0;i<8;i++) { LCD12864_writecommand(0x34); LCD12864_writecommand(0x80+j); LCD12864_writecommand(0x80+i); LCD12864_writecommand(0x30); LCD12864_writedata(img[j*16+i*2]); LCD12864_writedata(img[j*16+i*2+1]); } } LCD12864_graphsetmode(1);}void LCD12864_displaypicture_down(unsigned char *img){ unsigned char i,j; LCD12864_graphsetmode(1); for(j=0;j<32;j++) { for(i=0;i<8;i++) { LCD12864_writecommand(0x34); LCD12864_writecommand(0x80+j); LCD12864_writecommand(0x80+(i+8)); LCD12864_writecommand(0x30); LCD12864_writedata(img[j*16+i*2]); LCD12864_writedata(img[j*16+i*2+1]); } } LCD12864_graphsetmode(1);}
void LCD12864_displaypicture_all(unsigned char *img){ unsigned char i,j; LCD12864_graphsetmode(1); for(j=0;j<32;j++) { for(i=0;i<8;i++) { LCD12864_writecommand(0x34); LCD12864_writecommand(0x80+j); LCD12864_writecommand(0x80+i); LCD12864_writecommand(0x30); LCD12864_writedata(img[j*16+i*2]); LCD12864_writedata(img[j*16+i*2+1]); } } for(j=32;j<64;j++) { for(i=0;i<8;i++) {LCD12864_writecommand(0x34); LCD12864_writecommand(0x80+j-32); LCD12864_writecommand(0x80+(i+8)); LCD12864_writecommand(0x30); LCD12864_writedata(img[j*16+i*2]); LCD12864_writedata(img[j*16+i*2+1]); } } LCD12864_graphsetmode(1);}

unsigned char LCD12864_readpixel(unsigned char x,unsigned chary){unsigned char z,w;unsigned int Temp;if(x>=128||y>=64) return0;w=15-x; //确定对这个字的第多少位进行操作x=x/16; //确定为一行上的第几字if(y<32)z=0x80; //如果为上页else z=0x88; //否则如果为下页y=y2;LCD12864_writecommand(0x36);LCD12864_writecommand(y+0x80); //行地址LCD12864_writecommand(x+z); //列地址Temp=LCD12864_readdata(); //先空读一次Temp=(unsignedint)LCD12864_readdata()<<8;//再读出高8位Temp|=(unsigned int)LCD12864_readdata();//再读出低8位if((Temp&&LcdMaskTab[w])==0)return0;else return 1;}
void LCD12864_drawline_H(unsigned char x,unsigned chary,unsigned char Length,unsigned char Color){unsigned char count;if(Length==0)return;for(count=0;count<Length;count++){LCD12864_writepixel(x+count,y,Color);}}void LCD12864_whiteback(uchar x,uchar y,uchar width)//反白,X值为0-7,Y值为0-3,width为行反白格数{ uchar i,j,flag=0x00; uchar ii,jj; LCD12864_writecommand(0x34); //写数据时,关闭图形显示 for(ii=0;ii<32;ii++) { LCD12864_writecommand(0x80+ii); //先写入水平坐标值 LCD12864_writecommand(0x80); //写入垂直坐标值 for(jj=0;jj<16;jj++) //再写入两个8位元的数据 LCD12864_writedata(0x00); } for(ii=0;ii<32;ii++) { LCD12864_writecommand(0x80+ii); LCD12864_writecommand(0x88); for(jj=0;jj<16;jj++) LCD12864_writedata(0x00); } LCD12864_writecommand(0x36); //写完数据,开图形显示 if(y>1) { flag=0x08; y=y-2; } LCD12864_writecommand(0x34); LCD12864_writecommand(0x34); //写数据时,关闭图形显示,且打开扩展指令集for(i=0;i<16;i++){LCD12864_writecommand(0x80+(y<<4)+i);LCD12864_writecommand(0x80+flag+x);for(j=0;j<width;j++){LCD12864_writedata(0xff);LCD12864_writedata(0xff);}Delay_40US();}LCD12864_writecommand(0x36); //写完数据,开图形显示LCD12864_writecommand(0x30); //从扩展指令到基本指令}void LCD12864_drawline_V(unsigned char x,unsigned chary,unsigned char Length,unsigned char Color){unsigned char count;if(Length==0) return;for(count=0;count<Length;count++){LCD12864_writepixel(x,y+count,Color);}}void LCD12864_drawline_R(unsigned char x1,unsigned chary1,unsigned char x2,unsigned char y2,unsigned char Color){unsigned int x,y;unsigned int d_x,d_y;int err=0;unsigned char temp=0;if(y2<y1){x=x1;y=y1;x1=x2;y1=y2;x2=x;y2=y;}d_y=y2-y1;if (d_y==0){if (x1>x2){x=x1;x1=x2;x2=x;}for (x=x1;x<=x2;x++)LCD12864_writepixel(x,y1,Color);}else{if(x2>=x1){temp=1;d_x=x2-x1;}else {d_x=x1-x2;}x=x1;y=y1;LCD12864_writepixel(x,y,1);if(temp&&(d_y<=d_x))while(x!=x2){if(err<0){x=x+1;err=err+(y2-y);}else{ x=x+1;y=y+1;err=err+(y2-y)-(x2-x);}LCD12864_writepixel(x,y,Color);}
LCD12864详细C程序 lcd12864显示c程序
elseif(temp&&(d_y>d_x))while(y!=y2){ d_x=x2-x;d_y=y2-y;if(err<0){ x=x+1;y=y+1;err=err+d_y-d_x;}else{ y=y+1;err=err-d_x;}LCD12864_writepixel(x,y,Color);}
elseif(!temp&&(d_y<=d_x))while(x!=x2){ d_x=x-x2;d_y=y2-y;if(err<0){ x=x-1;err=err+d_y;}else{ x=x-1;y=y+1;err=err+d_y-d_x;}LCD12864_writepixel(x,y,Color);}
else if(!temp&&(d_y>d_x))while(y!=y2){d_x=x-x2; d_y=y2-y;if(err<0){x=x-1;y=y+1;err=err+d_y-d_x;}else{y=y+1;err=err-d_x; }LCD12864_writepixel(x,y,Color);}}}
void LCD12864_drawrectangle(unsigned char x0,unsigned chary0,unsigned char x1,unsigned char y1,unsigned char Color){unsigned char Temp;if(x0>x1) {Temp=x0;x0=x1;x1=Temp;}if(y0>y1) {Temp=y0;y0=y1;y1=Temp;}LCD12864_drawline_V(x0,y0,y1-y0+1,Color);LCD12864_drawline_V(x1,y0,y1-y0+1,Color);LCD12864_drawline_H(x0,y0,x1-x0+1,Color);LCD12864_drawline_H(x0,y1,x1-x0+1,Color);}void LCD12864_drawcircledot(unsigned char x,unsigned chary,char xx,char yy,unsigned char Color)//内部函数,对称法画圆的8个镜像点{LCD12864_writepixel((x+yy),(y+xx),Color);//第 1 个 8 分圆LCD12864_writepixel((x+xx),(y+yy),Color);//第 2 个 8 分圆LCD12864_writepixel((x-xx),(y+yy),Color);//第 3 个 8 分圆LCD12864_writepixel((x-yy),(y+xx),Color);//第 4 个 8 分圆LCD12864_writepixel((x-yy),(y-xx),Color);//第 5 个 8 分圆LCD12864_writepixel((x-xx),(y-yy),Color);//第 6 个 8 分圆LCD12864_writepixel((x+xx),(y-yy),Color);//第 7 个 8 分圆LCD12864_writepixel((x+yy),(y-xx),Color);//第 8 个 8 分圆}
void LCD12864_drawcircle(unsigned char x,unsigned chary,unsigned char r,unsigned char Color)//中点法画圆{//中点法画圆unsigned char xx,yy;char deltax,deltay,d;xx=0;yy=r;deltax=3;deltay=2-r-r;d=1-r;LCD12864_drawcircledot(x,y,xx,yy,Color);//对称法画圆的8个镜像点while (xx<yy){if (d<0){ d+=deltax;deltax+=2;xx++;}else{ d+=deltax+deltay; deltax+=2;deltay+=2;xx++;yy--;}LCD12864_drawcircledot(x,y,xx,yy,Color);//对称法画圆的8个镜像点}}


void LCD12864_setstatus(unsigned char cmd){ LCD12864_writecommand(0x34);LCD12864_writecommand(cmd);
}void LCD12864_init(){ LCD12864_PSB=1;LCD12864_writecommand(0x34);LCD12864_writecommand(0x34);LCD12864_writecommand(0x30); //选择基本指令集LCD12864_writecommand(0x0c); //开显示(无游标、不反白)LCD12864_writecommand(0x01); //清除显示,并且设定地址指针为00HLCD12864_writecommand(0x06); //指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位}LCD12864.H#ifndef __lcd12864_H__#define __lcd12864_H__#include "Reg52.h"#include "intrins.h"#define Delay2US _nop_();_nop_();sbit LCD12864_RS=P2^5; //并行的指令/数据选择信号, H数据, L命令sbit LCD12864_RW=P2^6; //并行读写选择信号, H读, L写sbit LCD12864_EN=P2^7; //并行使能端, H有效, L无效sbit LCD12864_PSB=P2^3; //并/串接口选择,H并,L串//sbit LCD12864_RET=P2^5; //复位, L有效本指令集预定义#define LCD_CLEAR_SCREEN 0x01 //清屏#define LCD_ADDRESS_RESET 0x02 //地址归零#define LCD_BASIC_FUNCTION 0x30//基本指令集#define LCD_EXTEND_FUNCTION 0x34//扩充指令集//扩展指令集预定义#define LCD_AWAIT_MODE 0x01 //待命模式#define LCD_ROLLADDRESS_ON 0x03 //允许输入垂直卷动地址#define LCD_IRAMADDRESS_ON 0x02 //允许输入IRAM地址#define LCD_SLEEP_MODE 0x08 //进入睡眠模式#define LCD_NO_SLEEP_MODE 0x0c //脱离睡眠模式#define LCD_GRAPH_ON 0x36 //打开绘图模式#define LCD_GRAPH_OFF 0x34 //关闭绘图模式#ifndef LCD_COLOR#define LCD_COLOR_BLACK 1#define LCD_COLOR_WHITE#define LcdData P0#define uchar unsigned charvoid LCD12864_checkbusy(void);void LCD12864_writedata(unsigned charData);uchar LCD12864_readdata(void);void LCD12864_writecommand(unsigned charCmdCode);void LCD12864_writepixel(unsigned charx,unsigned char y,unsigned char Color);uchar LCD12864_readpixel(unsigned char x,unsigned chary);void LCD12864_drawline_H(unsigned charx,unsigned char y,unsigned char Length,unsigned char Color);void LCD12864_drawline_V(unsigned charx,unsigned char y,unsigned char Length,unsigned char Color);void LCD12864_drawline_R(unsigned charx1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned charColor);void LCD12864_displaypicture_all(unsignedchar *img);void LCD12864_displaypicture( uchar code*adder);void LCD12864_sendascii(uchar hang,ucharlie,char sign);void LCD12864_sendgb2312(uchar hang,ucharlie,unsigned int sign);void LCD12864_whiteback(uchar x,uchary,uchar width);void LCD12864_startprobar(unsigned charx,unsigned char speed);void LCD12864_cleardram(void);void LCD12864_drawrectangle(unsigned charx0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned charColor);void LCD12864_drawcircle(unsigned charx,unsigned char y,unsigned char r,unsigned char Color);void LCD12864_cleargram(unsigned charMode);void LCD12864_displaystring(unsigned charx,unsigned char y,unsigned char *Str);void LCD12864_drawcircledot(unsigned charx,unsigned char y,char xx,char yy,unsigned char Color);void LCD12864_init(void);void LCD12864_setstatus(unsigned charcmd);
#endif

  

爱华网本文地址 » http://www.413yy.cn/a/25101017/359097.html

更多阅读

LCD12864详细C程序 lcd12864显示c程序

山东建筑大学 锐思实验室函数名称:LCD12864程序 CPU型号:STC89C52晶振参数:12MHZ 联系方式:QQ:610949704程序作者:2009级机械2班 许方超请点击 程序模块中看最新的一篇里面有下载链接,注释一发表就自动没有了http://blog.sina.com.cn/s/art

12864简单显示程序 lcd12864显示汉字程序

下午没事,就搜了一些12864的参考程序,然后结合自己前一阶段卖家给的12864说明书,写了一个简单的显示程序,在此把代码附上。其实这款LCD功能很强大,本身带有字库,而且可以显示图形,改天再写个显示图形的程序供大家参考。此程序可以直接下载

图文解说网吧最新版Pubwin2009破解方法 pubwin2015网吧破解

网吧最新版Pubwin2009破解方法30秒破解最新版pubwin2009,吧台不显示非法程序,显示关机状态,永久免费上网需要的工具有,网吧幽灵辅助工具4.2,金山卫士,操作步骤1、在网上下载一个网吧幽灵辅助工具4.2版本2、打开网吧幽灵辅助程序.再点系

程序流程图的画法 word流程图制作视频

1、程序流程图的作用程序流程图的作用程序流程图的作用程序流程图的作用 程序流程图是人们对解决问题的方法、思路或算法的一种描述。流程图的优点:(a)采用简单规范的符号,画法简单;(b)结构清晰,逻辑性强;(c)便于描述,容易理解。2、流程图

企业内部决策程序 企业决策论证程序

决策体系建设属于企业制度建设,它可能帮助企业进行决策规范,但不能代替任何具体决策产生。决策体系建设解决的是决策种类的划分和责任划分,是企业管理的基础工作,也可以集中在一个时段完成。而企业决策却可能经常产生,是持续不断的工作

声明:《LCD12864详细C程序 lcd12864显示c程序》为网友机车人分享!如侵犯到您的合法权益请联系我们删除