完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
怎么没人回复呢
|
|
|
|
自己找找实例吧
|
|
|
|
有个程序可以显示第一个站名为什么后面的就是乱码了呢? 程序如下 #include #include #include #define uint unsigned int #define uchar unsigned char #define Port P0 //LCD12864数据线 ***it EN=P2^6; // 读写使能 ***it RW=P2^5; // 读写 选择 ***it RS=P2^4; // 数据指令 选择 ***it cs2=P2^2; // 片选2 ***it cs1=P2^1; // 片选1 int State_Count = 0 ; int Run_Dir_P_Flag = 1; int Run_Dir_N_Flag = 0; int Next_Stat_Flag = 0 ; ***it Key1 = P1^2; ***it Key2 = P1^3; ***it Key3 = P1^4; /********************************/ /* 定义中文字库 */ /********************************/ uchar code Hzk[]={ /*-- 文字:站名: --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x00,0xC8,0x08,0x09,0x0E,0xE8,0x08,0x00,0x00,0x00,0xFF,0x10,0x10,0x10,0x10,0x00, 0x10,0x30,0x17,0x10,0x0E,0x09,0x08,0xFF,0x41,0x41,0x41,0x41,0x41,0xFF,0x00,0x00, 0x00,0x20,0x20,0x10,0x08,0x14,0x67,0x84,0x44,0x24,0x14,0x0C,0x00,0x00,0x00,0x00, 0x04,0x04,0x04,0x02,0xFE,0x43,0x43,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",1*/ /*-- 文字: 科技大学 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/ 0x24,0x24,0xA4,0xFE,0xA3,0x22,0x00,0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00,0x00, 0x08,0x06,0x01,0xFF,0x00,0x01,0x04,0x04,0x04,0x04,0x04,0xFF,0x02,0x02,0x02,0x00, 0x10,0x10,0x10,0xFF,0x10,0x90,0x08,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x08,0x00, 0x04,0x44,0x82,0x7F,0x01,0x80,0x80,0x40,0x43,0x2C,0x10,0x28,0x46,0x81,0x80,0x00,/*"技",0*/ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00, 0x80,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x80,0x00,/*"大",1*/ 0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00, 0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,0x06,0x05,0x04,0x04,0x04,0x04,0x04,0x00,/*"学",2*/ // 博物馆 0x20,0x20,0xFF,0x20,0x24,0xF4,0x54,0x54,0x54,0xFF,0x54,0x55,0x56,0xF4,0x04,0x00, 0x00,0x00,0xFF,0x00,0x08,0x0B,0x19,0x69,0x09,0x0B,0x49,0x89,0x7D,0x0B,0x08,0x00,/*"博",0*/ 0x40,0x3C,0x10,0xFF,0x10,0x10,0x20,0x10,0x8F,0x78,0x08,0xF8,0x08,0xF8,0x00,0x00, 0x02,0x06,0x02,0xFF,0x01,0x01,0x04,0x42,0x21,0x18,0x46,0x81,0x40,0x3F,0x00,0x00,/*"物",1*/ 0x40,0x30,0x8F,0x28,0x18,0x10,0x0C,0xE4,0x24,0x25,0x26,0x24,0xE4,0x14,0x0C,0x00, 0x00,0x00,0x7F,0x20,0x10,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0xF8,0x00,0x00,/*"馆",2*/ //火车站 0x00,0x00,0xC0,0x38,0x00,0x00,0x00,0xFF,0x00,0x00,0x40,0x20,0x18,0x00,0x00,0x00, 0x80,0x81,0x40,0x20,0x10,0x0C,0x03,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x80,0x00,/*"火",0*/ 0x00,0x08,0x88,0x48,0x28,0x18,0x0F,0xE8,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00, 0x08,0x08,0x09,0x09,0x09,0x09,0x09,0xFF,0x09,0x09,0x09,0x09,0x09,0x08,0x08,0x00,/*"车",1*/ 0x00,0xC8,0x08,0x09,0x0E,0xE8,0x08,0x00,0x00,0x00,0xFF,0x10,0x10,0x10,0x10,0x00, 0x10,0x30,0x17,0x10,0x0E,0x09,0x08,0xFF,0x41,0x41,0x41,0x41,0x41,0xFF,0x00,0x00,/*"站",2*/ }; /****************************************/ /* 定义ASCII字库8列*16行 */ /****************************************/ uchar code Ezk[]={ /*-- 文字: 2 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*"2",0*/ /*-- 文字: 5 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00, /*-- 文字: . --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,/*".",0*/ /*-- 文字: 7 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,/*"7",0*/ /*-- 文字: 摄氏单位 --*/ /*-- 宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/ 0x00,0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,/*"C",0*/ 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",0*/ 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",1*/ 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,/*":",2*/ 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",3*/ 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",4*/ 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,/*":",5*/ 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",6*/ 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",7*/ }; /*状态检查,LCD是否忙*/ void Checkbusy() { uchar dat;//状态信息(判断是否忙) RS=0; // 数据指令选择,D/I(RS)=“L” ,表示 DB7∽DB0 为显示指令数据 RW=1; //R/W=“H” ,E=“H”数据被读到DB7∽DB0 do { Port=0x00; EN=1; //EN下降源 _nop_(); //一个时钟延时 dat=Port; EN=0; dat=(0x80 & dat); } while(!(dat==0x00)); //仅当第7位为0时才可操作(判别busy信号) } /*写命令到LCD中*/ Wcmd(uchar cmd) { Checkbusy();//状态检查,LCD是否忙 RS=0; //向LCD发送命令。RS=0写指令,RS=1写数据 RW=0;//R/W=“L” ,E=“H→L”数据被写到 IR 或 DR Port=cmd; //com :命令 EN=1;//EN下降源 _nop_(); _nop_(); EN=0; } /*设置页 0xb8是页的首地址*/ void Setpage(uchar page) { page=0xb8|page; //1011 1xxx 0<=page<=7 设定页地址--X 0-7,8行为一页64/8=8,共8页 Wcmd(page); } /*设定显示开始行,0xc0是行的首地址*/ void Setx(uchar x) { x=0xc0|x; //1100 0000 Wcmd(x); //设置从哪行开始:0--63,一般从0 行开始显示 } /*设定列地址--Y 0-63 ,0x40是列的首地址*/ void Sety(uchar y) { y=y&0x3f; //column最大值为64,越出 0= Wcmd(y); } /*开关显示,0x3f是开显示,0x3e是关显示*/ void SetOnOff(uchar onoff) { onoff=0x3e|onoff; //0011 111x,onoff只能为0或者1 Wcmd(onoff); } /*写显示数据 */ void Writedata(uchar dat) { Checkbusy();//状态检查,LCD是否忙 RS=1; //RS=0写指令,RS=1写数据 RW=0;////R/W=“L” ,E=“H→L”数据被写到 IR 或 DR Port=dat;//dat:显示数据 EN=1; //EN下降源 _nop_(); _nop_(); EN=0; } /*选择屏幕screen: 0-全屏,1-左屏,2-右屏*/ void SelectScreen(uchar screen) { switch(screen) { case 0: cs1=0;//全屏 _nop_(); _nop_(); _nop_(); cs2=0; _nop_(); _nop_(); _nop_(); break; case 1: cs1=0;//左屏 _nop_(); _nop_(); _nop_(); cs2=1; _nop_(); _nop_(); _nop_(); break; case 2: cs1=1;//右屏 _nop_(); _nop_(); _nop_(); cs2=0; _nop_(); _nop_(); _nop_(); break; } } /*清屏screen: 0-全屏,1-左屏,2-右*/ void ClearScreen(uchar screen) { uchar i,j; SelectScreen(screen); for(i=0;i<8;i++) //控制页数0-7,共8页 { Setpage(i); Sety(0); for(j=0;j<64;j++) //控制列数0-63,共64列 { Writedata(0x00); //写点内容,列地址自动加1 } } } /*延时程序*/ void delay(uint z) { uint i,j; for(i=0; i } /*初始化LCD*/ void InitLCD() { Checkbusy(); SelectScreen(0); SetOnOff(0); //关显示 SelectScreen(0); SetOnOff(1); //开显示 SelectScreen(0); ClearScreen(0);//清屏 Setx(0); //开始行:0 } /*显示全角汉字*/ void Display(uchar ss,uchar page,uchar y,uchar number) { int i; //选屏参数,pagr选页参数,column选列参数,number选第几汉字输出 SelectScreen(ss); y=y&0x3f; Setpage(page); //写上半页 Sety(y); //控制列 for(i=0;i<16;i++) //控制16列的数据输出 { Writedata(Hzk[i+32*number]); //i+32*number汉字的前16个数据输出 } Setpage(page+1); //写下半页 Sety(y); //控制列 for(i=0;i<16;i++) //控制16列的数据输出 { Writedata(Hzk[i+32*number+16]); //i+32*number+16汉字的后16个数据输出 } } /*显示半角汉字和数字和字母*/ void Displayen(uchar ss,uchar page,uchar y,uchar number) { uint i;//选屏参数,pagr选页参数,column选列参数,number选第几汉字输出 SelectScreen(ss); y=y&0x3f; Setpage(page); //写上半页 Sety(y); for(i=0;i<8;i++) { Writedata(Ezk[i+16*number]); } Setpage(page+1); //写下半页 Sety(y); for(i=0;i<8;i++) { Writedata(Ezk[i+16*number+8]); } } //按键扫描及处理 void Key_Process(void) { if(Key1 == 0) { while(Key1==0); Run_Dir_P_Flag = 1; Run_Dir_N_Flag = 0; } if(Key2 == 0) { while(Key2==0); Run_Dir_P_Flag = 0; Run_Dir_N_Flag = 1; } if(Key3== 0) { while(Key3==0); Next_Stat_Flag = 1; } if(Next_Stat_Flag == 1) { Next_Stat_Flag = 0; if(Run_Dir_P_Flag ==1 ) { State_Count ++; if(State_Count>= 3) { State_Count = 0; } } if(Run_Dir_N_Flag ==1 ) { State_Count --; if(State_Count < 0 ) { State_Count = 2; } } } } /*主函数*/ void main() { uint i; InitLCD();//初始12864 ClearScreen(0);//清屏 Setx(0);//显示开始行 while(1) { Key_Process(); //按键扫描及处理 /* 可以多个显示,这里是4个一起显示*/ for(i=0;i<4;i++) { Display(1,0,i*16,i);//Display(选屏参数(cs0,cs1),pagr选页参数,column选列参数,number选第几汉字输出) _nop_(); switch(State_Count) { case 0: Display(2,0,i*16,i+4); break; //河北科技大学 case 1: Display(2,0,i*16,i+17); break; //博物馆 case 2: Display(2,0,i*16,i+21); break; //火车站 default: break; } } } } |
|
|
|
bucuoxuexixuexixuexi
|
|
|
|
额,最近有点忙!
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
6217 浏览 3 评论
7488 浏览 1 评论
7725 浏览 0 评论
Protues中自己封装的芯片元件无Program File、Clock Frequency选项怎么解决,求求大神了!
9530 浏览 1 评论
基于51单片机的车辆倒车雷达报警系统,HC-SR04超声波测距,全套资料
1279 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 23:03 , Processed in 0.522588 second(s), Total 52, Slave 45 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号