#define mcu_pic//單片機(jī)種類選擇 mcu_avr mcu_51 mcu_pic mcu_msp430/******************************************/#define uchar unsigned char/**************************************************/#ifdef mcu_avr //單片機(jī)種類 avr#include "iom8535v.h" //型號(hào)頭文件#define PORT PORTC //端口寄存器#define PORT_OUT (DDRC=0XFF) //輸出配置#define PORT_IN (DDRC=0X00) //輸入配置#define PORT_INT PINC //端口狀態(tài)#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 //單片機(jī)種類 51#include "REG51.h" //型號(hào)頭文件#define PORT P3 //端口寄存器#define PORT_OUT (P3=0X00) //輸出配置#define PORT_IN (P3=0XFF) //輸入配置#define PORT_INT P3 //端口狀態(tài)#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 //單片機(jī)種類 pic#define _16F877 #include //型號(hào)頭文件#define PORT PORTD //端口寄存器#define PORT_OUT (TRISD=0X00) //輸出配置#define PORT_IN (TRISD=0XFF) //輸入配置#define PORT_INT PORTD //端口狀態(tài)#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};/*************************************函數(shù)聲明區(qū)*************************************/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狀態(tài) *******************************/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);}
評(píng)論