标题:
无控制器12864lcd仿真小设计(汉字,图片,画直线,画圆)
[打印本页]
作者:
70599
时间:
2018-4-8 10:56
标题:
无控制器12864lcd仿真小设计(汉字,图片,画直线,画圆)
一个无控制器12864lcd小设计。包括显示ASCII字符,汉字,图片,画直线,画圆。
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
0.png
(12.93 KB, 下载次数: 34)
下载附件
2018-4-8 15:20 上传
0.jpg
(45.62 KB, 下载次数: 29)
下载附件
2018-4-8 15:20 上传
单片机源程序如下:
#include<reg51.h>
#include<intrins.h>
#include<stdlib.h>
#include<math.h>
#include "ziku.h"
#include "bmp.h"
//***************************
#define LCD P2;
sbit RS=P3^0;
sbit RW=P3^1;
sbit EN=P3^2;
sbit CS1=P3^4;
sbit CS2=P3^3;
//***************************
sbit button1=P1^0;
sbit button2=P1^1;
sbit button3=P1^2;
sbit button4=P1^3;
sbit button5=P1^4;
sbit button6=P1^5;
//*****************************
unsigned char code huan[]= // 欢
{0x04,0x24,0x44,0x84,0x64,0x9C,0x40,0x30,0x0F,0xC8,0x08,0x08,0x28,0x18,0x00,0x00,
0x10,0x08,0x06,0x01,0x82,0x4C,0x20,0x18,0x06,0x01,0x06,0x18,0x20,0x40,0x80,0x00};
unsigned char code ying[]= //迎
{0x40,0x40,0x42,0xCC,0x00,0x00,0xFC,0x04,0x02,0x00,0xFC,0x04,0x04,0xFC,0x00,0x00,
0x00,0x40,0x20,0x1F,0x20,0x40,0x4F,0x44,0x42,0x40,0x7F,0x42,0x44,0x43,0x40,0x00};
//**************************
/*void busy()
{
P0=0x00;
RS=0;
RW=1;
EN=1;
while(P2&0x80);
EN=0;
} */
//**************************
void delay(unsigned int t)
{
unsigned int t1;
for(t1=0;t1<t;t1++);
}
//**********************
void write_cmd(unsigned char com)//写指令
{
//busy();
RS=0;RW=0;EN=0;
P2=com;
delay(5);
EN=1;
delay(5);
EN=0;
}
//***************************
void write_dat(unsigned char dat)//写数据
{
//busy();
RS=1;RW=0;EN=0;
P2=dat;
delay(5);
EN=1;
delay(5);
EN=0;
}
//*****************
void set_page(unsigned char page)//设置页,12864LCD共有8页,每页有8行点阵点。
{
page=0xb8|page; //首页地址为0XB8
write_cmd(page); //page取值范围为0~7,表示第1到8页
}
//***************
void set_line(unsigned char line)//设置显示的起始行,共有0——63行,一般从0行开始显示
{
line=0xc0|line; //起始行地址0XC0
write_cmd(line); //line取值范围为0~63,表示第1到64行
}
//***********************
void set_column(unsigned char column)//设置显示的列
{
column=0x40|column; //列的首地址为0X40,
write_cmd(column); //column的取值范围为0~63,共64列
}
//***********************
void set_onoff(unsigned char onoff)//设置显示开关,onoff取值为0或1
{
onoff|=0x3e;//0X3E是关显示,0X3F是开显示
write_cmd(onoff);//所以若onoff为0,则表示关显示,onoff为1,则表示开显示
}
//********************
void select_screen(unsigned char screen)
{
switch(screen)
{
case 0:CS1=0;CS2=0;break; //全屏
case 1:CS1=0;CS2=1;break; //左半屏
case 2:CS1=1;CS2=0;break; //右半屏
default:break;
}
}
//***********************
void intialize() //12864初始化
{
//busy();
RS=0;RW=0;EN=0;P2=0xff;
write_cmd(0x30); //基本指令集*
write_cmd(0x0c); //开显示关光标
write_cmd(0x01); //清屏
}
//**********************
void clear()
{
unsigned char i,j;
select_screen(0);//先选屏
for(i=0;i<8;i++)//控制页数0——7,共8页
{
set_page(i);//设置页
set_column(0); //设置列,每页都从第1列开始,共64列
for(j=0;j<64;j++)//控制列数0——63,共64列
write_dat(0x00);//写入0,列地址指针会自动加1
}
}
//*********************************
void writechar(unsigned char screen,unsigned char page,unsigned char column,unsigned char *p)//显示一个汉字(16*16)共8列4行(1~2屏,1~4行,1~4列)
{
unsigned char i;
select_screen(screen);
set_page(2*(page-1));
set_column((column-1)*16);
for(i=0;i<16;i++)
write_dat(p[i]);
set_page(2*(page-1)+1);
set_column((column-1)*16);
for(i=0;i<16;i++)
write_dat(p[i+16]);
}
//*****************************
void writeasc(unsigned char screen,unsigned char page,unsigned char column,unsigned char asc)//显示一个ASC(8*16)共16列8行(1~2屏,1~4行,1~8列)
{
unsigned char i;
select_screen(screen);
set_page(2*(page-1));
set_column(8*(column-1));
for(i=0;i<8;i++)
write_dat(asctab[(asc-32)*16+i]);
set_page(2*(page-1)+1);
set_column(8*(column-1));
for(i=0;i<8;i++)
write_dat(asctab[(asc-32)*16+8+i]);
}
//*****************************
void writestring(unsigned char screen,unsigned char page,unsigned char column,unsigned char *string)
{
unsigned char i=0;
while(screen==1&&string[i]!='\0'&&i<(17-column))
{
if(i<8){writeasc(screen,page,column+i,string[i]);i++;}
else{writeasc(screen+1,page,column+i,string[i]);i++;}
}
while(screen==2&&string[i]!='\0'&&i<(17-column))
{writeasc(screen,page,column+i,string[i]);i++;}
}
//*****************************
void drawbmp(unsigned char page,unsigned char column,unsigned char *pic)
{
unsigned char j=0,i=0;
CS1=0;CS2=1;
for(j=0;j<8;j++)
{
write_cmd(0xb8+page-1+j);
write_cmd(0x40+column-1);
for(i=0;i<64;i++)
write_dat(pic[128*j+i]);
}
CS1=1;CS2=0;
for(j=0;j<8;j++)
{
write_cmd(0xb8+page-1+j);
write_cmd(0x40+column-1);
for(i=64;i<128;i++)
write_dat(pic[128*j+i]);
}
}
//***********************
unsigned char ReadData()
{
unsigned char dsp_data;
P2=0xff;
RW=1;
RS=1;
EN=1;
delay(5);
EN=0;
delay(5);
EN=1;
delay(5);
dsp_data=P2;
delay(5);
EN=0;
return(dsp_data);
}
void Pixel(unsigned char X,unsigned char Y)//横纵坐标
{
unsigned char DX = (Y >> 3);
unsigned char BX = Y - (DX << 3);
unsigned char TempData = 0;
if (X > 63) { CS1=1;CS2=0; X -= 64; }
else { CS1=0;CS2=1; }
write_cmd(0xb8+DX);
write_cmd(0x40+X);
TempData = ReadData();
TempData |= (1 << BX); //TempData |= (1 << BX);TempData &= ~(1<<BX);TempData ^= (1 << BX);
write_cmd(0xb8+DX);
write_cmd(0x40+X);
write_dat(TempData);
}
//*********************
void drawline(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2)//起点终点横纵坐标
{
char dx,dy;
char inc_x,inc_y;
int xerr = 0,yerr = 0; //初始化变量
unsigned char i,ds;
dx = x2 - x1; //计算坐标增量
dy = y2 - y1;
if(dx > 0)
inc_x = 1; //设置单步方向
else
{
if(dx == 0)
{inc_x = 0;} //垂直线
else
{inc_x = -1; dx = -dx;}
}
if(dy > 0)
inc_y = 1; //设置单步方向
else
{
if(dy == 0)
{inc_y = 0;} //水平线
else
{inc_y = -1; dy = -dy;}
}
if(dx > dy)
ds = dx; //选取基本增量坐标轴
else
ds = dy;
for(i = 0; i <= ds+1; i++) //画线输出
{
Pixel(x1, y1); //画点
xerr += dx;
yerr += dy;
if(xerr > ds)
{xerr -= ds;x1 += inc_x;}
if(yerr > ds)
{yerr -= ds;y1 += inc_y;}
}
}
//***********************
void drawcircle(unsigned char x0 , unsigned char y0 , unsigned char r)//横纵坐标,半径
{
char a , b;
char di;
if(r > 31 || r == 0)//画不下
return;
a = 0;
b = r;
di = 3 - 2 * r;//下一个点
while(a <= b)
{
Pixel( x0 - b , y0 - a);
Pixel( x0 + b , y0 - a);
Pixel( x0 - a , y0 + b);
Pixel( x0 - b , y0 - a);
Pixel( x0 - a , y0 - b);
Pixel( x0 + b , y0 + a);
Pixel( x0 + a , y0 - b);
Pixel( x0 + a , y0 + b);
Pixel( x0 - b , y0 + a);
a ++;
//***bresenham********/
if(di < 0)
di += 4 * a + 6;
else
{
di += 10 + 4 * (a - b);
}
Pixel( x0 + a , y0 + b);
}
}
//*************************
void main()
{
intialize();
clear();
while(1)
{
if(button1==0)
{
delay(3000);
if(button1==0)
{
clear();writechar(1,4,4,huan);writechar(2,1,1,ying);
while(!button1);
}
}
if(button2==0)
{
delay(3000);
if(button2==0)
{
clear();writestring(1,1,1,"A Beast of Prey");
while(!button2);
}
}
if(button3==0)
{
delay(3000);
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
12864.rar
(75.6 KB, 下载次数: 44)
2018-4-8 10:48 上传
点击文件名下载附件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1