- #include <reg52.h>
- #include<stdio.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar lcd_x,lcd_y,data_byte=0,count;
- uint TH_data,TL_data,RH_data,RL_data,CK_data;
- uint TH_temp,TL_temp,RH_temp,RL_temp,CK_temp;
- uchar num,ldata=0,lold=1;
- sbit RS = P2^0;//并行指令,数据选择信号
- sbit RW = P2^1;//读写信号
- sbit EN = P2^2;//并行使能信号
- sbit PSB = P2^3;//并串口选择信号
- sbit RST = P2^5;//复位信号
- sbit key1 = P2^6; //定义按键1
- sbit key2 = P2^7; //定义按键2
- void delay(uint a);//延时函数
- void delay0(unsigned int time);//延时函数
- void LCD_init();//LCD初始化程序
- void write_cmd(uchar cmd);//写指令
- void write_data(uchar dat);//写数据
- bit check_busy();//检测LCD忙信号
- void delay1();//10us延时
- void lcd_dis_code(uint cmd_addr,uchar num,uchar dis[]);//显示函数
- uchar code lcd0[]={" 科协菜单"};
- uchar code lcd1[]={"1:摄像头"};
- uchar code lcd2[]={"2:传感器"};
- uchar code lcd3[]={"3:液晶显示"};
- uchar code lcd4[]={"4:单片机"};
- uchar code lcd5[]={"5:红外传感器"};
- uchar code lcd6[]={"6:MAX232"};
- uchar code lcd7[]={"7:晶振"};
- uchar code lcd8[]={"8:单片机"};
- uchar code lcd9[]={"9:红外传感器"};
- uchar code lcd10[]={"10:MAX232"};
- uchar code lcd11[]={"11:晶振"};
- void main()
- {
- LCD_init();
- while(1)
- { //循环扫描按键及显示
- if(key1==0)
- { //按键1按下
- delay(5);
- if(key1==0)
- { //是否是刚按下,是执行,否则不执行
- ldata=ldata+1; //显示数据加1
- //lold=0; //处理完,将按键视为按下
- }
- }
- else if(key2==0)
- { //按键2按下
- delay(5);
- if(key2==0){ //是否是刚按下,是执行,否则不执行
- ldata--; //显示数据减1
- // lold=0; ////处理完,将按键视为按下
- }
- }
- switch(ldata)
- {
-
- case 0:{
- lcd_dis_code(0x80,10,lcd0);
- lcd_dis_code(0x90,8,lcd1);
- lcd_dis_code(0x88,8,lcd2);
- lcd_dis_code(0x98,12,lcd3);
- break;
- }
- case 1:{
- lcd_dis_code(0x80,8,lcd4);
- lcd_dis_code(0x90,12,lcd5);
- lcd_dis_code(0x88,8,lcd6);
- lcd_dis_code(0x98,5,lcd7);
- break;
- }
- case 2:{
- lcd_dis_code(0x80,8,lcd8);
- lcd_dis_code(0x90,12,lcd9);
- lcd_dis_code(0x88,9,lcd10);
- lcd_dis_code(0x98,12,lcd11);
- break;
- }
- }
-
-
- }
- }
- void delay1()//延时10us
- {
- unsigned char i;
- for(i=0; i<3; i++);
- }
- /**********************12864模块程序**********************/
-
- void lcd_dis_code(uint cmd_addr,uchar num,uchar dis[])
- {
- uint i;
- write_cmd(cmd_addr);
- for(i=0; i<num; i++)
- write_data(dis[i]);
- }
- void LCD_init()
- {
- PSB = 1;
- RST = 0;
- delay(5);
- RST = 1;
- //write_cmd(0x34);//扩充指令
- delay(5);
- write_cmd(0x30);//基本指令
- //delay(5);
- //write_cmd(0x0f);//显示开关光标
- delay(5);
- write_cmd(0x0c);
- delay(10);
- write_cmd(0x01);//清屏
- delay(5);
- write_cmd(0x06);
- delay(20);
- }
- bit check_busy()
- {
- bit temp;
- RS = 0;
- RW = 1;
- EN = 1;
- delay(5);
- temp = (bit)(P0&0x80); //按位与操作
- EN = 0;
- return (temp);
- }
- void write_cmd(uchar cmd)
- {
- while(check_busy());
- RS = 0;
- RW = 0;
- EN = 0;
- delay(5);
- P0 = cmd;
- delay(5);
- EN = 1;
- delay(5);
- EN = 0;
- }
- void write_data(uchar dat)
- {
- while(check_busy());
- RS = 1;
- RW = 0;
- EN = 0;
- P0 = dat;
- delay(5);
- EN = 1;
- delay(5);
- EN = 0;
- }
- void delay(uint a)
- {
- uchar i;
- while(a--)
- {
- for(i=0; i<113; i++);
- }
- }
- void delay0(unsigned int time)
- {
- while(time--);
- }
复制代码
|