STC 12864显示程序.doc_第1页
STC 12864显示程序.doc_第2页
STC 12864显示程序.doc_第3页
STC 12864显示程序.doc_第4页
STC 12864显示程序.doc_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

#include #include #include #include #define uchar unsigned char / 8bit, 0 255#define uint unsigned int / 16bit, 0 65,535#define ulong unsigned long / 32bit, 0 4,294,967,295/*-建立自定义演示用字符库-*/uchar code CCTAB=/*- 文字: 实 -*/*- 仿宋_GB231212; 此字体下对应的点阵为:宽x高=16x16 -*/0x02,0x00,0x01,0x00,0x7F,0xFE,0x48,0x02,0x86,0x84,0x02,0x80,0x10,0x80,0x0C,0x80, 0x04,0x84,0xFF,0xFE,0x01,0x00,0x01,0x40,0x02,0x20,0x04,0x10,0x18,0x0C,0x60,0x04,/*- 文字: 验 -*/*- 仿宋_GB231212; 此字体下对应的点阵为:宽x高=16x16 -*/0x08,0x40,0xFC,0x40,0x08,0xA0,0x48,0xA0,0x49,0x10,0x4A,0x0E,0x4D,0xF4,0x48,0x00, 0x7C,0x48,0x06,0x48,0x05,0x48,0x1D,0x50,0xE5,0x10,0x44,0x24,0x17,0xFE,0x08,0x00,/*- 文字: 中 -*/*- 仿宋_GB231212; 此字体下对应的点阵为:宽x高=16x16 -*/0x01,0x00,0x01,0x00,0x01,0x04,0x7F,0xFE,0x41,0x04,0x41,0x04,0x41,0x04,0x41,0x04, 0x7F,0xFC,0x41,0x04,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00;uchar code symbo=/*- 调入了一幅图像:D:guoq filestechnic supportpic128x32 Symbo.bmp -*/*- 宽度x高度=128x32 -*/0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x1F,0xC0,0x00,0x1F,0xC0,0x03,0xE0,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x00,0x20,0x40,0x04,0x10,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x00,0x40,0x40,0x08,0x08,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x08,0x00,0x80,0x40,0x08,0x08,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x04,0x01,0x00,0x40,0x08,0x08,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x02,0x02,0x00,0x40,0x08,0x08,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x01,0x04,0x00,0x40,0x08,0x08,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x88,0x00,0x80,0x04,0x10,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x50,0x01,0x00,0x03,0xE0,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x20,0x02,0x00,0x00,0x00,0x00,0x1F,0xFC,0x01,0xFF,0xDF,0xFF,0xFF,0xFF,0xC1,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x80,0x00,0x08,0x1F,0xFF,0xFF,0xF8,0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x40,0x00,0x10,0x10,0x00,0x00,0x08,0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x20,0x00,0x20,0x10,0x00,0x00,0x08,0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x10,0x00,0x40,0x10,0x00,0x00,0x08,0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x08,0x00,0x80,0x10,0x00,0x00,0x08,0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x10,0x00,0x40,0x10,0x00,0x00,0x08,0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x20,0x00,0x20,0x10,0x00,0x00,0x08,0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x40,0x00,0x10,0x10,0x00,0x00,0x08,0x10,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x40,0x80,0x00,0x08,0x1F,0xFF,0xFF,0xF8,0x1F,0xFC,0x01,0xFF,0xDF,0xFF,0xFF,0xFF,0xC1,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x20,0x02,0x00,0x00,0x00,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x50,0x01,0x00,0x03,0xE0,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x88,0x00,0x80,0x04,0x10,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x01,0x04,0x00,0x40,0x08,0x08,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x02,0x02,0x00,0x40,0x08,0x08,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x04,0x01,0x00,0x40,0x08,0x08,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x08,0x00,0x80,0x40,0x08,0x08,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x00,0x40,0x40,0x08,0x08,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x20,0x00,0x20,0x40,0x04,0x10,0x00,0x00,0x07,0xFF,0x00,0x00,0x00,0x00,0x00,0x1F,0xC0,0x00,0x1F,0xC0,0x03,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00;/-/ Delay Routine/-void delay100us(void) /delay TIMER1*1 ms for 12MHz uchar data i; for(i=0;i=10*7;i+) _nop_(); _nop_(); void delayms( uint m ) / 12MHz Xtal, close to ms value uint j; uint i; for(i=0; im*7; i+) for(j=0; j109*7; j+) _nop_();/-/直接访问方式驱动子程序/-/*void SdCmd(uchar Command) /send command uchar xdata *wcom_addr; uchar xdata *rcom_addr; uchar busy; do rcom_addr=0x8200; busy = *rcom_addr&0x80; while (busy=0x80); wcom_addr=0x8000; *wcom_addr = Command;void SdData(uchar DData) /send display data uchar xdata *wdata_addr; uchar xdata *rcom_addr; uchar busy; do rcom_addr=0x8200; busy = *rcom_addr&0x80; while (busy=0x80); wdata_addr =0x8100; *wdata_addr = DData;uchar RdData() uchar xdata *rcom_addr; uchar xdata *rdata_addr; uchar busy,DData; do rcom_addr=0x8200; busy = *rcom_addr&0x80; while (busy=0x80); rdata_addr =0x8300; DData =*rdata_addr; return(DData);*/-/ 串行通讯方式驱动子程序/-/uchar bdata transdata; /该变量可为位操作之变量/sbit transbit = transdata7;/sbit SCLK = P36;/sbit SID = P37;/sbit CS = P31;/-/*void SdCmd(uchar Command) /send command uchar i,j,buffur3; SCLK = 0; CS = 1; buffur0=0xf8; buffur1=Command&0xf0; buffur2=(Command&0x0f)4; for(i=0;i3;i+) transdata=buffuri; for(j=0;j8;j+) SID=transbit; SCLK=1; SCLK=0; transdata=transdata1; CS=0; delayms(100);/void SdData(uchar DData) /send display data uchar i,j,buffur3; SCLK = 0; CS = 1; buffur0=0xfa; buffur1=DData&0xf0; buffur2=(DData&0x0f)4; for(i=0;i3;i+) transdata=buffuri; for(j=0;j8;j+) SID=transbit; SCLK=1; SCLK=0; transdata=transdata1; CS=0; delayms(100);*/-/ 间接控制方式驱动子程序/-#define LCDBUS P2sbit RS = P02;sbit RW = P03;sbit E = P04;sbit PSB = P05;sbit RST = P15;/-void SdCmd(uchar Command) /send command/ uchar busy; RS = 0;/* RW = 1; do LCDBUS=0xff; E = 1; busy = LCDBUS&0x80; E = 0; while (busy=0x80);*/ RW=0; LCDBUS = Command; E = 1; E = 0; delay100us();void SdData(uchar DData) /send display data/ uchar busy; RS = 0;/* RW = 1; do LCDBUS=0xff; E = 1; busy = LCDBUS&0x80; E = 0; while (busy=0x80);*/ RS=1; RW=0; LCDBUS = DData; E = 1; E = 0; delay100us();uchar RdData()/ uchar busy; uchar DData; RS = 0; RW = 1;/* do LCDBUS=0xff; E = 1; busy = LCDBUS&0x80; E = 0; while (busy=0x80);*/ RS=1; LCDBUS=0xff; E=1; DData = LCDBUS; E = 0; return(DData);/-西文写入函数-void PrintASCII(uint x,y,uchar *pstr) /通用函数 uint addr; y=y0) SdData(*pstr+); /-中文写入函数-void PrintGB(uchar x,y,uchar *pstr) uint addr; y=y0) SdData(*pstr+); delayms(300); /演示用 /-初始化函数-void initLCM() RST=0; delayms(5); RST=1; delayms(800); SdCmd(0x30); /* 设置工作方式(8位总线) */ SdCmd(0x06); /* 设置输入方式 */ SdCmd(0x0f); /* 设置显示方式 */ SdCmd(0x01); /* 清屏 */ delayms(2);/-清屏函数-void ClearRAM() uchar i,j;/ SdCmd(0x01);/ delayms(2); SdCmd(0x34); for(i=0;i32;i+) SdCmd(i|0x80); SdCmd(0x80); for(j=0;j16;j+) SdData(0x00);/ SdData(0x00); SdCmd(0x30);/- 画图函数-void ShowBmp(uchar x,y, width,high,uchar *bmp) uchar i,j; SdCmd(0x34); SdCmd(0x36); for(i=y;i(y+high);i+) if (i32) SdCmd(0x80|i); SdCmd(0x80|x); else SdCmd(0x80|(i-32); SdCmd(0x80|(x+8); for(j=0;j=32) y=y-32; x=x+128; SdCmd(y|0x80); k=x/16; SdCmd(k|0x80); k=0x8000; k=kx%16; m=RdData(); m=RdData()|k8; n=RdData()|k; k=x/16; SdCmd(y|0x80); SdCmd(k|0x80); SdData(m); SdData(n);/- 画线函数-void Draw_Line(uint x1,y1,x2,y2) uint temp; int dalt_x,dalt_y,err=0; if (y1y2) temp=x1; x1=x2; x2=temp; temp=y1; y1=y2; y2=temp; Draw_Dot(x1,y1); dalt_x=x2-x1; dalt_y=y2-y1; if(dalt_x=0) if(dalt_ydalt_x)/k1 while(y1y2) if(err0) x1=x1+1; y1=y1+1; err=err+dalt_y-dalt_x; else y1=y1+1; err=err-dalt_x; Draw_Dot(x1,y1); else / 0=k=1 if (dalt_y=0) y1=y1-1; while(x1x2) if(errdalt_x)/k-1 while(y1y2) if(errk=-1 if (dalt_y=0) y1=y1-1; while(x1x2) if(err0) x1=x1-1; err=err+dalt_y; else x1=x1-1; y1=y1+1; err=err+dalt_y-dalt_x; Draw_Dot(x1,y1); /-自建字库函数-void Set_CGRAM(uint num,uchar *pstr)/ num 汉字个数;pstr:汉字数组名 uchar i; SdCmd(0x40); for(i=0;inum*32;i+)/ 计算数据量 SdData(*pstr+); /-功能演示函数-void quxian1() SdCmd(0x06); PrintGB( 0,0,画面不动光标地址加1 指令代码为06); delayms(3000); SdCmd(0x01); delayms(2); SdCmd(0x04); PrintGB( 15,0,画面不动光标地址减1 指令代码为04); delayms(3000); SdCmd(0x01); delayms(2); SdCmd(0x07); PrintGB( 0,0,画面整体左移1 位指令代码为07); delayms(3000); SdCmd(0x01); delayms(2); SdCmd(0x05); PrintGB( 15,0,画面整体右移1 位指令代码为05); delayms(3000); SdCmd(0x06);/-做图演示函数-void quxian2() uint code data148=88,89,85,87,89,90,89,89, 88,86,87,86,88,89,90,94, 95,96,96,97,99,99,101,103, 101,101,100,103,105,113,113, 117,117,116,114,107,110,114, 113,112,115,112,113,119,120, 125,124,128; uint a1,b1,a2,b2,i; SdCmd(0x01); delayms(2); SdCmd(0x0c); PrintASCII(0,0, Time); PrintASCII(14,1,Temp); SdCmd(0x34); SdCmd(0x36); Draw_Line(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论