#define mcu_pic
//单片机品种挑选 mcu_avr mcu_51 mcu_pic mcu_msp430/******************************************/#define uchar unsigned char/**************************************************/#ifdef mcu_avr //单片机品种 avr#include "iom8535v.h" //类型头文件#define PORT PORTC //端口寄存器#define PORT_OUT (DDRC=0XFF) //输出装备#define PORT_IN (DDRC=0X00) //输入装备#define PORT_INT PINC //端口状况#define rs(x) (x?(PORTA|=0x01):(PORTA&=0xfe))#define rw(x) (x?(PORTA|=0x02):(PORTA&=0xfd))#define e(x) (x?(PORTA|=0x04):(PORTA&=0xfb))#define rs_rw_e_output (DDRA = 0X07)//输出装备#endif/**************************************************//**************************************************/#ifdef mcu_51 //单片机品种 51#include "REG51.h" //类型头文件#define PORT P3 //端口寄存器#define PORT_OUT (P3=0X00) //输出装备#define PORT_IN (P3=0XFF) //输入装备#define PORT_INT P3 //端口状况#define rs(x) (x?(P1|=0x20):(P1&=0xDF))#define rw(x) (x?(P1|=0x40):(P1&=0xBF))#define e(x) (x?(P1|=0x80):(P1&=0x7F))#define rs_rw_e_output (P1 = 0XE0)//输出装备//#define PORT P3//sbit rs=P2^0;//sbit rw=P2^1;//sbit e=P2^2;#endif/**************************************************//**************************************************/#ifdef mcu_pic //单片机品种 pic#define _16F877 #include//类型头文件#define PORT PORTD //端口寄存器#define PORT_OUT (TRISD=0X00) //输出装备#define PORT_IN (TRISD=0XFF) //输入装备#define PORT_INT PORTD //端口状况#define rs(x) (x?(PORTC|=0X01):(PORTC&=0XFE))#define rw(x) (x?(PORTC|=0X02):(PORTC&=0XFd))#define e(x) (x?(PORTC|=0X04):(PORTC&=0XFb))#define rs_rw_e_output (TRISC &= 0XF8)//输出装备#endif#ifdef mcu_msp430 #include"msp430x21x1.h"#define PORT P1OUT #define PORT_OUT (P1DIR=0XFF) #define PORT_IN (P1DIR=0X00) #define PORT_INT P1IN #define rs(x) (x?(P2OUT|=0X01):(P2OUT&=0XFE))#define rw(x) (x?(P2OUT|=0X02):(P2OUT&=0XFd))#define e(x) (x?(P2OUT|=0X04):(P2OUT&=0XFb))#define rs_rw_e_output (P2DIR = 0X07)#endif/**************************************************//**************************************00000 5*7 -> 0xff*****0** /5*8 0x40*****0** 0x40 ----> I*****0** 0x40 ---->*****0** 0x40*****0** 0x40***00000 0x1f增加自己的自定义字符***********************************/uchar ziku[]={0x04,0x05,0x06,0x07,0x13,0x16,0X15,0x0C,0xff,0xff,0x55,0xff,0x55,0xff,0xff,0xff};/*************************************函数声明区*************************************/uchar lcd_readcom(void);void check_busy(void);void lcd_writecom(uchar dat);uchar lcd_readdat(void);void lcd_writedat(uchar dat);void lcd_gets(const uchar *dat);void lcd_xy(uchar x,uchar y);void lcd_init(void);/*******************************读取lcd1602状况 *******************************/uchar lcd_readcom(void){uchar temp;e(0);PORT_IN;rs(0);rw(1);e(1);temp=PORT_INT;e(0);PORT_OUT;return temp;}/***************************************检测 lcd 是否繁忙 阿飞天天忙绿***************************************/void check_busy(void){uchar temp;do{temp=lcd_readcom();}while((temp&0x80)==0x80);}