虫虫首页|资源下载|资源专辑|精品软件|心愿单
m 登录|注册

自己做的单片机Proteus仿真实例

源代码在线查看: main.c

软件大小: 16559 K 下载次数: 2
上传用户: ingtak
关键词: Proteus 单片机 仿真实例
下载地址: 电信下载 网通下载 移动下载 联通下载 VIP VIP

相关代码

					/************http://hi.baidu.com/echoas***************
					程序:LCD12864自定义显示字符(最多显示4个)
					内容:ASCII码显示、自带字库显示(8192个)、自定义显示字符(4个)。
					软件:keil uVision4
					液晶:QYLCD12864HZ1(带字库) 
					作者:大海橡树 
					整理日期:2010-11-28  11:00
					修改:无 
					
					备注:有什么错误的地方,欢迎网友们到空间留言
					
										O(∩_∩)O~
					
					************http://hi.baidu.com/echoas*****************/
					#include
					#define uchar unsigned char
					#define uint  unsigned int		//定义一下,方便使用 
					
					sbit RS=P2^5;
					sbit RW=P2^6;
					sbit EN=P2^7;	//液晶的三个控制端 
					
					//sbit PSB=P2^4;//1---8位或4位并口方式;0---串口方式。单片机上电高电平,选择的是并口方式 
					
					//繁体中文字“龍”	
					uchar table[]={0x10,0x80,0x08,0x80,0x7E,0xFC,0x24,0x80,0x18,0xFC,0xFF,0x04,0x00,0xFC,0x3E,0x80,
					0x22,0xF8,0x3E,0x80,0x22,0xF8,0x3E,0x80,0x22,0xFA,0x22,0x82,0x2A,0x82,0x24,0x7E}; 
					
					//一个星星、一个月亮 
					unsigned char code zk[]={0x08,0x20,0x1c,0x10,0x1c,0x1c,0xff,0x9e,0x7f,0x1e,0x1c,0x1f,0x3e,0x1f,
					0x3e,0x1f, 0x77,0x1f,0x41,0x3f,0x00,0x7e,0x00,0xfe,0x83,0xfc,0x7f,0xf8,0x3f,0xf0,0x0f,0xc0, 
					}; 
					
					//小人 
					uchar code table2[]={0x03,0xC0,0x04,0x20,0x04,0x20,0x03,0xC0,0x0C,0x30,0x14,0x28,0x14,0x28,0x14,0x28,
					0x14,0x28,0x17,0xE8,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x0E,0x70,0x0E,0x70}; 
					
					//喇叭 
					uchar code table3[]={0x00,0x39,0x00,0x6A,0x00,0xA8,0x01,0x29,0x7E,0x2A,0xFC,0x28,0xFC,0x29,0xCC,0x2A,
					0xCC,0x28,0xFC,0x29,0xFC,0x2A,0x7E,0x28,0x01,0x29,0x00,0xAA,0x00,0x68,0x00,0x38};
					
					uchar code table4[]="LCD12864";
					uchar code table5[]="自定义显示字符";
					uchar code table6[]="大海橡树";
					
					void delay(uint i)	//延时函数 
					{
						while(--i);
					}
					
					void read_busy()	//读忙标志 最高位为1则busy,不能进行读写操作 
					{
						RS=0;
						RW=1;
						EN=1;	//看时序 
						while(P0 & 0x80); 
						EN=0;
					}
					
					void write_LCD_command(uchar value) //写命令函数 
					{
						read_busy();	//每次读写都要进行读忙标志 
						RS=0;
						RW=0;
						delay(200);
						EN=1;		//EN从1--0锁存数据 
						P0=value;
						delay(200);
						EN=0;
					}
					
					void write_LCD_data(uchar value)	//写数据函数 
					{
						read_busy();
						RS=1;
						RW=0;
						delay(200);
						EN=1;		//EN从1--0锁存数据 
						P0=value;
						delay(200);
						EN=0;
					}
					
					void init_LCD()				//8位并口方式LCD1864初始化函数 
					{
						delay(4000);			//等待时间>40ms 
						write_LCD_command(0x30);//功能设定:8位数据、基本指令操作 
						delay(100);				//等待时间>100us 
						write_LCD_command(0x30);//功能设定:8位数据、基本指令操作 
						delay(37);				//等待时间>37us 
						write_LCD_command(0x0C);//显示设定:整体显示、游标关、不反白 
						delay(100);				// 等待时间>100us 
						write_LCD_command(0x01);//清屏指令 
						delay(10000);			//等待时间>10ms 
						write_LCD_command(0x06);//进入点设定:地址指针加1 
					}
					
					/*=============================================
					自定义汉字函数:CGRAM自定义显示字符
					地址		显示编码
					0x40		0x0000
					0x50		0x0002
					0x60		0x0004
					0x70		0x0006
					共可显示四个自定义字符! 
					显示自定义字符前,先要设定显示的位置,否则会乱码 
					==============================================*/
					void CGRAM()
					{
						uchar i;
						write_LCD_command(0x30);//基本指令操作 
						write_LCD_command(0x40);//设定CGRAM字符的位置 
						for(i=0;i						{
							write_LCD_data(table[i*2]);
							write_LCD_data(table[i*2+1]);//送显示数据到CGRAM区中 
						}
						write_LCD_command(0x50);
						for(i=0;i						{
							write_LCD_data(zk[i*2]);
							write_LCD_data(zk[i*2+1]);
						}
						write_LCD_command(0x60);
						for(i=0;i						{
							write_LCD_data(table2[i*2]);
							write_LCD_data(table2[i*2+1]);
						}
					
						write_LCD_command(0x70);
						for(i=0;i						{
							write_LCD_data(table3[i*2]);
							write_LCD_data(table3[i*2+1]);
						}
						
					}
					
					void main()
					{
						uchar num;
						init_LCD();
						
						while(1)
						{
							write_LCD_command(0x80);
							for(num=0;num							{
								write_LCD_data(table6[num]);
							}
							write_LCD_command(0x84);
							for(num=0;num							{
								write_LCD_data(table4[num]);
							}
					
							write_LCD_command(0x90);
							for(num=0;num							{
								write_LCD_data(table5[num]);
							}
							
							CGRAM();
							write_LCD_command(0x98);
							write_LCD_data(0x00);
							write_LCD_data(0x00);//第一个自定义显示字符编码为:0x0000 
							
							write_LCD_command(0x99);
							write_LCD_data(0x00);
							write_LCD_data(0x02);//第一个自定义显示字符编码为:0x0002
					
							write_LCD_command(0x9A);
							write_LCD_data(0x00);
							write_LCD_data(0x04);//第一个自定义显示字符编码为:0x0004
					
							write_LCD_command(0x9B);
							write_LCD_data(0x00);
							write_LCD_data(0x06);//第一个自定义显示字符编码为:0x0006
						}
					}
									

相关资源