/** * Waits until busy flag of LCD is cleared */ static void lcdBusyWait() { LCD_RW(1); LCD_RS(0); LCD_DATA_DDR = 0x00; /* input */ delay_us(LCD_DELAY_SHORT); /* RS, RW Setup Time (Minimum: 60ns) */ lcdToggleEn(); loop_until_bit_is_clear(LCD_DATA_PIN,LCD_BUSY_FLAG); lcdToggleEn(); }
/** * Writes instructions to the LCD * * Inputs: db LCD instruction * rs for commands, rs = 0 * for sending data, rs = 1 */ static void lcdWrite(BYTE db, BYTE rs) { lcdBusyWait(); LCD_RW(0); LCD_RS(rs); LCD_DATA_DDR = 0xFF; /* output */ LCD_DATA_PORT = db; delay_us(LCD_DELAY_EN); /* RS, RW Setup Time (Minimum: 60ns) */ lcdToggleEn(); }
static void SendStartByte( unsigned char RW, unsigned char RS) { #define LCD_DEV_ID(v) (v<<2) #define LCD_RS(v) (v<<1) #define LCD_RW(v) (v<<0) unsigned char StartByte = 0x70; StartByte |= (LCD_DEV_ID(0) | LCD_RS(RS) | LCD_RW(RW)); SendByte( StartByte); }
//写指令 void WriteCommandLCD(unsigned char WCLCD) //BuysC为0时忽略忙检测 { ReadStatusLCD(); //根据需要检测忙 LCD_RS(0); LCD_RW(0); LCD_EN(0); Delay_us(1); LCD_WriteData(WCLCD); LCD_EN(1); Delay_us(1); LCD_EN(0); }
//写数据 void WriteDataLCD(unsigned char WDLCD) { ReadStatusLCD(); //检测忙 LCD_RS(1); LCD_RW(0); LCD_EN(0); Delay_us(1); LCD_WriteData(WDLCD); LCD_EN(1); Delay_us(1); LCD_EN(0); }
uint8_t LCD_read(uint8_t RS) { volatile uint8_t buf = 0; LCD_DATA_PORT->DIR &= ~(0xF0); LCD_RS(RS); LCD_RW(1); LCD_EN(1); LCD_EN(0); buf = LCD_DATA_PORT->DATA & 0xF0; LCD_EN(1); LCD_EN(0); buf |= LCD_DATA_PORT->DATA >> 4; return buf; }
void __LCD_write(uint8_t RS,uint8_t data,uint8_t wait){ LCD_DATA_PORT->DIR |= 0xF0; LCD_RS(RS); LCD_RW(0); LCD_DATA_PORT->DATA = (LCD_CONTROL_PORT->DATA & ~(0xF0))|(data&0xF0); LCD_EN(1); LCD_EN(0); data <<=4; LCD_DATA_PORT->DATA = (LCD_CONTROL_PORT->DATA & ~(0xF0))|(data&0xF0); LCD_EN(1); LCD_EN(0); if(wait){ while(LCD_read(0) & 0x80); } }
//读状态 void ReadStatusLCD(void) { unsigned char lcd_status; LCD_RS(0); LCD_RW(1); LCD_Data_In(); do { LCD_EN(1); Delay_us(1); lcd_status=GPIO_ReadInputData( LCD12864_GPIO); LCD_EN(0); } while (lcd_status&Busy); //检测忙信号 LCD_Data_Out(); }