《LCD1286 4画点画线画圆画正弦波》由会员分享,可在线阅读,更多相关《LCD1286 4画点画线画圆画正弦波(11页珍藏版)》请在金锄头文库上搜索。
1、LCD12864画点画线画圆画正弦波实际效果图如下:C程序如下:#include#include#define uchar unsigned char#define uint unsigned int#define LCD P0uchar chip_select=1;bit color=0;sbit e=P21;sbit rw=P22;sbit rs=P23;sbit cs2=P24;sbit cs1=P25;uchar line=0;uchar select=0;void delay(uint i)while(i-);/* check busy */void checkBusy()/检查LC
2、D是否忙uchar dat;rs=0;/指令操作rw=1;/读出操作do LCD=0xff;/P0设置为输入e=1;/给使能信号dat=0x80&LCD;/只判断DB7位的状态e=0;while(dat=0x80);/忙则继续检测void lcdWrite(bit ml,uchar zifu)checkBusy();rs=ml;rw=0;P0=zifu;e=1;delay(1);e=0;void ClearLCD(uchar zifu)uchar i,j;lcdWrite(0,0x3f);cs1=1;cs2=1;for(i=0;i8;i+)lcdWrite(0,0xb8+i);lcdWrite
3、(0,0xc0);lcdWrite(0,0x40);for(j=0;j64;j+)lcdWrite(1,zifu);void initLCD()/初始化cs1=1;cs2=1;lcdWrite(0,0x3e);/关显示lcdWrite(0,0x3f);/开显示ClearLCD(0x0f);/清屏/*液晶显示函数*/*x和y来控制显示的位置,x为行,y为列,x1和y1为字的像素行数,x2为显示几行,y2为显示几个字数 */void jis(uchar x,uchar y,uchar x1,uchar y1,uchar x2,uchar y2,uchar code *hz)uchar i,j,k,
4、l,a;lcdWrite(0,0x3f);/开显示for(i=0;ix2;i+)for(j=0;jy2;j+)for(k=0;kx1;k+)lcdWrite(0,0xb8+x+i*x1+k);lcdWrite(0,0xc0);lcdWrite(0,0x40+y+j*y1);a=i*x1*y1*y2+j*x1*y1+k*y1;for(l=0;l 3);/计算出属于哪个字节 uchar BX = Y - (DX 63) chip_select=2;X -= 64;else chip_select=1;lcdWrite(0,0xb8+DX);/设行地址lcdWrite(0,0x40+X);/设列地址
5、TempData = ReadData();/读出所画点所在字节的内容switch (Type) /对该字节进行相应操作case 0:TempData &= (1BX);/擦除break;case 1:TempData |= (1 BX);/画点break;case 2: TempData = (1 BX);/反相break; lcdWrite(0,0xb8+DX);/设行地址lcdWrite(0,0x40+X);/设列地址WriteData(TempData);/把修改后的字节送回LCD,达到画点目的/*插值法画任意两点之间直线的函数,函数中只用加减法,程序运行效率很高*/DrawLine(
6、uchar x1,uchar y1,uchar x2,uchar y2)/x1,y1起点坐标;x2,y2终点坐标;uchar x,y;uchar d_x,d_y;char err=0;uchar temp=0;if(y2x2) x=x1;x1=x2;x2=x;for ( x=x1;x=x1)temp=1;d_x=x2-x1;else d_x=x1-x2;x=x1;y=y1;DrawPoint(x,y,1);if(temp&(d_y=d_x)while(x!=x2)if(errd_x)while(y!=y2)d_x=x2-x;d_y=y2-y;if(err0)x=x+1;y=y+1;err=err+d_y-d_x;else y=y+1;err=err-d_x;DrawPoint(x,y,1);else if(!temp&(d_y=d_x)while(x!=x2)d_x=x-x2;d_y=y2-y;if(errd_x)while(y!=y2)d_x=x-x2;d_y=y2-y;if(err0)x=x-1;y=y+1;err=err+d_y-d_x;else