找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3909|回复: 3
打印 上一主题 下一主题
收起左侧

高人求解

[复制链接]
跳转到指定楼层
楼主
ID:37070 发表于 2012-3-28 10:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include"reg52.h" #include"string.h" unsigned char table[]={0x00,0x00,0x00,0x3C,0x12,0x11,0x11,0x11,0x11,0x11,0x12,0x3C,0x00,0x00,0x19,0x19,0x06,0x06,0x19,0x19,0x06,0x00,0x06,0x19,0x19,0x06,0x06,0x19,0x19,0x00,0x89,0x89,0x06,0x06,0x89,0x89,0x06,0x00,0x06,0x89,0x89,0x06,0x06,0x89,0x89,0x00}; #define CLEARSCREEN LCD_write_command(0x01) #define LCDIO P0 sbit LCD1602_RS=P2^0; sbit LCD1602_RW=P2^1; sbit LCD1602_EN=P2^2; sbit Key1=P2^3; sbit Key2=P2^4; sbit Key3=P2^5; sbit Key4=P2^6; sbit Key5=P2^7; void LCD_write_command(unsigned char command);//写入指令函数 void LCD_write_dat(unsigned char dat);//写入数据函数 void LCD_set_xy( unsigned char x, unsigned char y );//设置显示位置函数 void LCD_dsp_char( unsigned x,unsigned char y,unsigned char dat);//显示一个字符函数 void LCD_dsp_string(unsigned char X,unsigned char Y,unsigned char *s);//显示字符串函数 void LCD_init(void);//初始化函数 void delay_nms(unsigned int n); void Write_CGRAM(unsigned char *p) { unsigned char i,j,kk; unsigned char tmp=0x40; //操作CGRAM的命令码 kk=0; for(j=0;j<8;j++) //64 字节存储空间,可以生成 8="8" 个自定义字符点阵 { for(i=0;i<8;i++) // 8="8" 个字节生成 1="1" 个字符点阵 { LCD_write_command(tmp+i); //操作CGRAM的命令码+写入CGRAM地址. LCD_write_dat(p[kk]); //写入数据 kk++; } tmp="tmp" += 8; } } void LCD_init(void) { CLEARSCREEN;//clear screen="screen" LCD_write_command(0x38);//set 8="8" bit="bit" data="data" transmission="transmission" mode="mode" LCD_write_command(0x0c);//open display="display" (enable lcd="lcd" display) LCD_write_command(0x80);//set lcd="lcd" first="first" display="display" address="address" CLEARSCREEN;//clear screen } void LCD_write_command(unsigned char="char" command) { lcdio="command; " lcd1602_rs="0;" lcd1602_rw="0; " lcd1602_en="0; " delay_nms(10); lcd1602_en="1; " delay_nms(10); } void LCD_write_dat(unsigned char="char" dat) { LCDIO=dat; LCD1602_RS=1; LCD1602_RW=0; LCD1602_EN=0; delay_nms(10); LCD1602_EN=1; } void LCD_set_xy( unsigned="unsigned" char="char" x, unsigned="unsigned" char="char" y="y" ) { unsigned char="char" address; if (y == 1) { address="address" = 0x80="0x80" + x;} else { address="address" =0xc0+ x;} LCD_write_command(address); } /****************显示一个字符**********************/ void LCD_dsp_char( unsigned="unsigned" x,unsigned char="char" y,unsigned char="char" dat) { LCD_set_xy( x, y="y" ); LCD_write_dat(dat); } /***************显示字符串函数***************/ void LCD_dsp_string(unsigned char="char" X,unsigned char="char" Y,unsigned char="char" *s) { LCD_set_xy( X, Y="Y" ); while="while" (*s) { LCD_write_dat(*s); s="s" ++; } } /***********************************************/ void delay_nms(unsigned int="int" n) { unsigned="unsigned" int="int" i="0,j=0; " for="for" (i=n;i>0;i--) for (j=0;j<10;j++); } void main(void) { int i,aa,bb; delay_nms(5000); LCD_init(); delay_nms(100); Write_CGRAM(table); Key1=0; Key2=0; Key3=0; Key4=0; Key5=0; lable:while(1){ LCD_dsp_string(0,1," welcome ");//显示欢迎界面 LCD_dsp_string(0,2," 2011.05.25 "); if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1){ CLEARSCREEN; while(1){ if(Key1==1){ //显示大写D. CLEARSCREEN; for (i=0;i<1;i++) { LCD_dsp_char( 8+i,1,i); delay_nms(1); } for (i=1;i<2;i++) { LCD_dsp_char( 8+i-1,2,i); delay_nms(1); } aa="0;bb=0; " while(1){ aa++; if(aa==10000) bb++; if(bb==10)goto lable; if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1) { break; } }} if (Key2==1){ CLEARSCREEN; LCD_dsp_string(0,1," D ");delay_nms(100); //显示小写D aa="0;bb=0; " while(1){ aa++; if(aa==10000)bb++;if(bb==10)goto lable; if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1) { break; } }} if (Key3==1){ CLEARSCREEN; LCD_dsp_char( 8,1,2);//显示自己设计好的图案。 LCD_dsp_char( 9,1,4); LCD_dsp_char( 8,2,3); LCD_dsp_char( 9,2,5); delay_nms(100); aa="0;bb=0; " while(1){ aa++; if(aa==10000)bb++;if(bb==10)goto lable; if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1) { break; } } } if (Key4==1){ CLEARSCREEN; LCD_dsp_string(0,1," smile ") ;//显示微笑 LCD_dsp_string(0,2," (^-^) "); delay_nms(100); aa="0;bb=0; " while(1){ aa++; if(aa==10000) bb++; if(bb==10)goto lable; if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1) { break; } }} if (Key5==1){ CLEARSCREEN; LCD_dsp_string(0,1," thankyou byebye ");//显示thankyou byebye. LCD_dsp_string(0,2," 2011.05.25 "); delay_nms(100); aa="0;bb=0; " while(1){ aa++; if(aa==10000) bb++; if(bb==10)goto lable; if(Key1==1||Key2==1||Key3==1||Key4==1||Key5==1) { break; } }} } } } } 为什么下载到单片机里面只有第一行全满,求指教。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:35775 发表于 2012-3-28 12:21 | 只看该作者

看着头好晕

 

回复

使用道具 举报

板凳
ID:37434 发表于 2012-3-30 21:56 | 只看该作者
整理整理再发吗
回复

使用道具 举报

地板
ID:32563 发表于 2012-5-25 22:27 | 只看该作者

太复杂了,我

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表