LCD12864画点,画线,定点写入等子函数

define LCD12864_GLOBAL#include"lcd12864.h"void delay_10us(unsigned char del){ while(del--){ _nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_(); }}///////////////////////////////////////读忙函数//操作方式 RS>L RW>H E>低脉冲//输入://输出:忙标志 1:忙 0:闲/////////////////////////////////////void Lcd12864_ChkBusy(void){ RS = 0; RW = 1; E = 1; L_PORT = 0XFF; while((L_PORT & 0X80) == 0X80); //忙了,则等待 E = 0;}///////////////////////////////////////写指令//操作方式 RS>L RW>H E>高电平//输入://输出://///////////////////////////////////void Lcd12864_WrCom(uchar com){ Lcd12864_ChkBusy(); RS = 0; RW = 0; E = 1; L_PORT = com; delay_10us(1); E = 0; }///////////////////////////////////////写数据//操作方式 RS>L RW>H E>高电平//输入:写入数据//输出://///////////////////////////////////void Lcd12864_WrData(uchar dat){ Lcd12864_ChkBusy(); RS = 1; RW = 0; E = 1; L_PORT = dat; delay_10us(1); E = 0; }///////////////////////////////////////字库初始化函数//输入://输出://///////////////////////////////////void Lcd12864_WordInit(void){ PSB = 1; //8位并行数据传输方式 RET = 0; //复位函数 delay_10us(1); //延时下 RET = 1; //复位无效 Lcd12864_WrCom(0x30); Lcd12864_WrCom(0x30); Lcd12864_WrCom(0x0c); Lcd12864_WrCom(0x01); Lcd12864_WrCom(0x06);}///////////////////////////////////////定位写入字符串函数//输入:参数1:行(1~4),参数2:列(0~7)参数3,字符串 参数4,写入字节数//输出://///////////////////////////////////void Lcd12864_WrString(uchar x,uchar y,uchar *str,uchar num){ uchar i; y = y % 7 ; //舍去大于八的数据 switch(x){ case 1: Lcd12864_WrCom(0x80 + y); break; case 2: Lcd12864_WrCom(0x90 + y); break; case 3: Lcd12864_WrCom(0x88 + y); break; case 4: Lcd12864_WrCom(0x98 + y); break; default: Lcd12864_WrCom(0x80 + y); } for(i = 0;i < num;i ++) { Lcd12864_WrData(*str++); //写入对应点的数据 }}///////////////////////////////////////图片初始化函数//输入://输出://///////////////////////////////////void Lcd12864_PhotoInit(void){ PSB = 1; //8位并行数据传输方式 RET = 0; //复位函数 delay_10us(1); //延时下 RET = 1; //复位无效 Lcd12864_WrCom(0x36); Lcd12864_WrCom(0x36); Lcd12864_WrCom(0x3e); Lcd12864_WrCom(0x01); }///////////////////////////////////////图片打印函数//输入:图片数组的指针//输出://///////////////////////////////////void Lcd12864_PhotoPrint(uchar *photo){ uchar i,j,k; for(i = 0;i < 2;i ++) for(j = 0;j < 32;j ++) { Lcd12864_WrCom(0x80 + j); //纵坐标 if(i == 0) { Lcd12864_WrCom(0x80); //上半屏 } else { Lcd12864_WrCom(0x88); //下半屏 } for(k = 0;k < 16;k ++) { Lcd12864_WrData(*photo ++ ); } }}///////////////////////////////////////清楚GDRAM函数//输入://输出://///////////////////////////////////void Lcd12864_ClrGdRam(void){ uchar x,y; for(y = 0;y < 64;y ++) for(x = 0;x < 16;x ++) { Lcd12864_WrCom(0x34); //开指令扩充 Lcd12864_WrCom(0x80 + y); //行坐标 Lcd12864_WrCom(0x80 + x); //列坐标 Lcd12864_WrCom(0x30); //关指令扩充 Lcd12864_WrData(0x00); //高字节 Lcd12864_WrData(0x00); //低字节 }}///////////////////////////////////////读出数据函数//输入://输出:读出的数据/////////////////////////////////////uchar Lcd12864_ReData(void){ uchar Temp; Lcd12864_ChkBusy(); RS = 1; RW = 1; L_PORT = 0XFF; //准备读入数据 E = 1; Temp = L_PORT; //读出数据 E = 0; return Temp;}///////////////////////////////////// 0 63------------------------- 127 63//画对应点函数 | |//输入:参数1:列(0 ~ 127)参数2:行(0~63)参数3:改点的颜色 | |//输出: | |///////////////////////////////////// 0 0------------------------- 127 0void Lcd12864_DrawPoint(uchar x,uchar y,uchar color){ uchar Row,Tier,TierBit; uchar ReadDatH,ReadDatL; Lcd12864_WrCom(0x36); Tier = x >> 4; //取出对应层数 TierBit = x & 0x0f; //取出对应层数的位 if(y < 32) { Row = ((~y) & 0x1f); //取32的补码 Tier += 8; //下半屏 } else { Row = ((~(y - 32)) & 0x1f); } //选取位置读出数据 Lcd12864_WrCom(Row + 0x80); // 行 Lcd12864_WrCom(Tier + 0x80); // 列 Lcd12864_ReData(); ReadDatH = Lcd12864_ReData(); //读取高八位 ReadDatL = Lcd12864_ReData(); //读取低八位 //定位位置准备写入数据 Lcd12864_WrCom(Row + 0x80); // 行 Lcd12864_WrCom(Tier + 0x80); // 列 if(TierBit < 8) { switch(color) { case 0: ReadDatH &= (~(0x01 << (7 - TierBit))); //置零 break; case 1: ReadDatH |= (0x01 << (7 - TierBit)); //置一 break; case 2: ReadDatH ^= (0x01 << (7 - TierBit)); //异或取反 break; } } else { switch(color) { case 0: ReadDatL &= (~(0X01 << (15 - TierBit))); break; case 1: ReadDatL |= (0x01 << (15 - TierBit)); break; case 2: ReadDatL ^= (0x01 << (15 - TierBit)); } } Lcd12864_WrData(ReadDatH); //先写高位字节 Lcd12864_WrData(ReadDatL); }///////////////////////////////////////画水平直线函数//输入:参数1:起始横坐标 参数2:终止横坐标 参数3:纵坐标 参数4:显示状态//输出://///////////////////////////////////void Lcd12864_DrawLine_Level(uchar x0,uchar x1,uchar y,uchar color){ uchar i,Temp; if(x0 > x1) //保证x1 > x0 { Temp = x0; x0 = x1; x1 = Temp; } for(i = x0;i < x1;i ++) { Lcd12864_ChkBusy(); Lcd12864_DrawPoint(i,y,color); }}///////////////////////////////////////画垂直线函数///输入:参数1:定位横坐标 参数2:起始纵坐标 参数3:终止纵坐标 参数4:显示状态//输出:///////////////////////////////////// void Lcd12864_DrawLine_Vertical(uchar x,uchar y0,uchar y1,uchar color){ uchar i,Temp; if(y0 > y1) //保证x1 > x0 { Temp = y0; y0 = y1; y1 = Temp; } for(i = y0;i < y1;i ++) { Lcd12864_ChkBusy(); Lcd12864_DrawPoint(x,i,color); } }///////////////////////////////////////画垂直线函数///输入:参数1, 参数2:起始横纵坐标 参数3:参数4:终止横纵坐标 参数5:显示状态//输出:///////////////////////////////////// void Lcd12864_DrawLine_Arbitrary(uchar x0,uchar y0,uchar x1,uchar y1,uchar color){ int i,Distance; int x = 0,y = 0,DeltaX,DeltaY; char IncX,IncY; //取出斜率 DeltaX = x1 - x0; DeltaY = y1 - y0; if(DeltaX > 0) { IncX = 1; } else { IncX = -1; DeltaX = -DeltaX; } if(DeltaY > 0) { IncY = 1; } else { IncY = -1; DeltaY = -DeltaY; } if(DeltaX > DeltaY) { Distance = DeltaX; } else { Distance = DeltaY; } Lcd12864_DrawPoint(x0,y0,color); for(i = 0;i <= Distance + 1;i ++) { Lcd12864_DrawPoint(x0,y0,color); x += DeltaX; y += DeltaY; if(x > Distance) { x -= Distance; x0 += IncX; } if(y > Distance) { y -= Distance; y0 += IncY; } }}///////////////////////////////////////点位花图片函数(图片格式为横坐标32纵坐标30) ///输入:参数1,图片指针,参数2,定位显示 (固定)//输出:///////////////////////////////////// void Lcd12864_PosDrawPhoto(uchar *photo,uchar pos){ uchar Temp; uchar i,j; switch(pos) { case 1: Temp = 0x80; break; case 2: Temp = 0x83; break; case 3: Temp = 0x86; break; case 4: Temp = 0x88; break; case 5: Temp = 0x8b; break; case 6: Temp = 0x8e; break; } for(i = 1;i < 31;i ++) { Lcd12864_WrCom(0x80 + i); //纵坐标 Lcd12864_WrCom(Temp); //横坐标 for(j = 0;j < 4;j ++) { Lcd12864_WrData(*photo ++); } }}。