1602的驱动没有问题,编译以后提示 1602.C(112): warning C182: pointer to different objects 有问题吗?如果有怎末改呢?
#include <reg51.h> #include <absacc.h> #include <INTRINS.h>
#define LINE1 0 #define LINE2 1 #define LINE1_HEAD 0x80 #define LINE2_HEAD 0xC0 #define LCD_DELAY_TIME 40 #define DATA_MODE 0x38 #define OPEN_SCREEN 0x0C #define DISPLAY_ADDRESS 0x80 #define CLEARSCREEN LCD_en_command(0x01)
#define HIGH 1 #define LOW 0 #define TRUE 1 #define FALSE 0 #define ZERO 0 #define MSB 0x80 #define LSB 0x01
#define Null 0 #define LCDIO P2
#define UP '3' #define Down '7' #define Esc 'B' #define Enter 'F'
sbit LCD1602_RS=P0^7; //data command select 1 data 0 command pin 4 sbit LCD1602_RW=P0^6; //read write select 1 read 0 write pin 5 sbit LCD1602_EN=P0^5; //LCD enable signal pin 6
/********************************************************************/
void LCD_delay(void);//lcd delay function void LCD_en_command(unsigned char command);//write command function void LCD_en_dat(unsigned char temp);//write data function void LCD_set_xy( unsigned char x, unsigned char y );//set display address function void LCD_write_char( unsigned x,unsigned char y,unsigned char dat);//write lcd a character function LCD_write_char (列,行,'字符') void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);//write lcd string function LCD_write_string(列,行,"字符串") void LCD_init(void);//lcd initize function
void delay_nms(unsigned int n);//delay function
void ShowMenu(void);
void Menu_Change(unsigned char KeyNum);
/**************************************************************/
struct MenuItem
{ unsigned char MenuCount; //当前层节点数 unsigned char *DisplayString; //菜单标题
struct MenuItem *ChildrenMenus; //子节点 struct MenuItem *ParentMenus; //父节点
void (*Subs)(); //节点函数
};
/*********************************************************************/
void TimeSet(void) { LCD_write_string(0,0,"1.Time Set"); }
void DateSet(void) { //put_s("DateSet"); LCD_write_string(0,0,"Date Set"); }
void AlertSet (void) { //put_s("AlertSet"); LCD_write_string(0,0,"Alert Set"); }
void NullSubs(void) { }
struct MenuItem TimeMenu [4]; struct MenuItem MainMenu [5];
struct MenuItem TimeMenu[4]=
{ // MenuCount DisplayString Subs ChildrenMenus ParentMenus {4, "1.Time Set", TimeSet, Null, MainMenu}, {4, "2.Date Set", DateSet, Null, MainMenu}, {4, "3.AlertSet", AlertSet, Null, MainMenu}, {4, "4.Back", NullSubs, MainMenu, MainMenu}, };
/*****************************************************************/ //结构体指针,指向结构体后由内部函数指针指向功能函数
struct MenuItem (*MenuPoint) = MainMenu; unsigned char DisplayStart = 0; //显示时的第一个菜单项 unsigned char UserChoose = 0; //用户所选菜单项 unsigned char DisplayPoint = 0; //显示指针 unsigned MaxItems; //同级最大菜单数 unsigned char ShowCount = 2; //同屏显示菜单数
void ShowMenu(void)
{ unsigned char n;
MaxItems = MenuPoint[0].MenuCount;//定义最大同级菜单
DisplayPoint = DisplayStart;
for(n=0;DisplayPoint<MaxItems&&n<ShowCount;n++)
{ if(DisplayPoint==UserChoose)
LCD_write_string(0,n,"->");
LCD_write_string(2,n,MenuPoint[DisplayPoint++].DisplayString); }
}
/******************************************************************/ void LCD_en_command(unsigned char command)
{ LCDIO=command; LCD1602_RS=LOW; LCD1602_RW=LOW; LCD1602_EN=LOW; LCD_delay(); LCD1602_EN=HIGH; }
/********************************************************************/
void LCD_en_dat(unsigned char dat)
{ LCDIO=dat; LCD1602_RS=HIGH; LCD1602_RW=LOW; LCD1602_EN=LOW; LCD_delay(); LCD1602_EN=HIGH; }
/********************************************************************/
void LCD_set_xy( unsigned char x, unsigned char y )
{ unsigned char address; if (y == LINE1) address = LINE1_HEAD + x; else address = LINE2_HEAD + x; LCD_en_command(address); }
/********************************************************************/
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
{ LCD_set_xy( x, y ); LCD_en_dat(dat); }
/********************************************************************/
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{ LCD_set_xy( X, Y ); //set address
while (*s) // write character { LCDIO=*s; LCD_en_dat(*s); s ++; } }
/********************************************************************/
void LCD_init(void) { CLEARSCREEN;//clear screen LCD_en_command(DATA_MODE);//set 8 bit data transmission mode LCD_en_command(OPEN_SCREEN);//open display (enable lcd display) LCD_en_command(DISPLAY_ADDRESS);//set lcd first display address CLEARSCREEN;//clear screen }
/*********************** OTHER PART *********************************/
void delay_nms(unsigned int n) { unsigned int i=0,j=0; for (i=n;i>0;i--) for (j=0;j<1140;j++);
}
/*****************************************************************************/
void Menu_Change(unsigned char KeyNum) { //if(KeyNum) // { switch(KeyNum) { case UP: UserChoose --; if (UserChoose ==255) { UserChoose = 0;//上翻截至,如果要回滚赋值MaxItems-1 } break;
case Esc: if (MenuPoint[UserChoose].ParentMenus != Null) { MenuPoint = MenuPoint[UserChoose].ParentMenus; UserChoose = 0; DisplayStart = 0; } break;
case Down: UserChoose ++; if (UserChoose == MaxItems) { UserChoose = MaxItems-1;//下翻截至,如要回滚赋值为0 } break;
case Enter: if (MenuPoint[UserChoose].Subs != NullSubs) { (*MenuPoint[UserChoose].Subs)(); } else if (MenuPoint[UserChoose].ChildrenMenus != Null) { MenuPoint = MenuPoint[UserChoose].ChildrenMenus; UserChoose = 0; DisplayStart = 0; } break; default:break; } if (UserChoose%ShowCount==0) //一屏只能显示ShowCount行 DisplayStart = UserChoose; else if(UserChoose==1||UserChoose== 3) DisplayStart = UserChoose-1; //实现滚屏的关键 LCD_en_command(0x01); //液晶清屏,根据不同液晶函数自行修改 delay_nms(5); //液晶为慢速器件 ShowMenu(); } //}
/*******************************************************************************************************************************/
void main()
{ LCD_init(); // Init_Menu(); ShowMenu(); //欢迎界面显示 while(1) { // Menu_Change(get_key()); } }
|
|