资源描述:
《单片机C语言按键显示打包.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#include#defineucharunsignedchar#defineunitunsignedintconstunsignedcharlcd_ex[16]={0x53,0x68,0x65,0x7a,0x68,0x69,0x20,0x30,0x30,0x2e,0x30,0x20,0x6e,0x2f,0x73,0x20};constunsignedcharlcd_ed[16]={0x53,0x68,0x69,0x6a,0x69,0x20,0x20,0x30,0x30,0x2e,0x30,0x20,
2、0x6e,0x2f,0x73,0x20};ucharjp_shuju[3]={0,0,0};ucharxs_shuju[3]={0,0,0};sbitjp_d=P1^0;sbitjp_clk=P1^1;sbitjp_h1=P1^2;sbitjp_h2=P1^3;sbitlcd_2=P1^6;sbitlcd_1=P1^5;sbitlcd_0=P1^4;bitjp_jiananzhe=0;bitjp_huoqujianzhi=0;bith1=0;bith2=0;bitjpc_quedingshezhi=0;bitjp_shuru;uchar*jp_p;ucha
3、r*xs_p;ucharjp_judge=0;ucharjp_judge2=0;uniti;//1ms的延时子程序---------------------voidmdelay(unitdelay){unitw;for(;delay>0;delay--){for(w=0;w<124;w++){;}}}//40us的延时子程序---------------------voidudelay(unitdelay2){unitw2;for(;delay2>0;delay2--){for(w2=0;w2<5;w2++){;}}}//液晶写的子程序----------
4、-----------voidlcd_write(){lcd_2=1;lcd_2=0;udelay(7);}//液晶初始化子程序voidlcd_chushihua(){lcd_0=0;lcd_1=0;lcd_2=0;P2=0;mdelay(16);P2=0x30;_nop_();_nop_();lcd_write();mdelay(5);P2=0x30;lcd_write();udelay(3);P2=0x30;_nop_();_nop_();lcd_write();_nop_();udelay(1);/*2,功能设定38h的含义是dl置1-8位、将N位置
5、1-双行,将f位置0-5x7*/P2=0x38;//;lcd_write();udelay(2);/*3模式设定06h的含义是i/d=1,地址递增,s=0,显示屏不移动*/P2=0x06;//;lcd_write();udelay(3);/*4显示器清屏01h的是显示器清屏指令*/P2=0x01;//;lcd_write();mdelay(2);/*5显示器开启关闭//0eh的含义是d为1-显示开启*/P2=0x0e;//;lcd_write();_nop_();udelay(1);/*6,开始写数据*/P2=0x80;//80的含义是地址是00,是ram
6、的地址lcd_write();udelay(1);lcd_0=1;//开始写for(i=0;i<16;i++){P2=lcd_ex[i];lcd_write();}lcd_0=0;//结束写P2=0xc0;//80的含义是地址是40,是ram的地lcd_write();lcd_0=1;//开始写for(i=0;i<16;i++){P2=lcd_ed[i];lcd_write();}lcd_0=0;//结束写}//键盘的初始化-------------------------------voidchushihua(){jp_jiananzhe=0;jp_hu
7、oqujianzhi=0;jp_judge=0;jp_clk=0;jp_d=0;for(i=0;i<16;i++){//循环两次产生一个脉冲,这样就可以给8个脉冲if(jp_clk)jp_clk=0;elsejp_clk=1;}}//接下来是键盘按键判断的子程序----------------jp_scan(){if(jp_jiananzhe==1)//当键按着的时候不会扫描键盘gotojp_over;if(jp_h1==0)//要是第一行的键按下,则为0{jp_jiananzhe=1;//将键按着的标志位置一jp_huoqujianzhi=0;//将获取
8、键值的标志位清0jp_judge=0;//判断按键的寄寸器清零jp