📄 lcd.c
字号:
/* * LCD interface example * Uses routines from delay.c * This code will interface to a standard LCD controller * like the Hitachi HD44780. It uses it in 4 bit mode, with * the hardware connected as follows (the standard 14 pin * LCD connector is used): * * PORTD bits 0-3 are connected to the LCD data bits 4-7 (high nibble) * PORTA bit 3 is connected to the LCD RS input (register select) * PORTA bit 1 is connected to the LCD EN bit (enable) * * To use these routines, set up the port I/O (TRISA, TRISD) then * call lcd_init(), then other routines as required. * */#include <pic.h>#include "lcd.h"#include "..\delay.h"/* write a byte to the LCD in 4 bit mode */voidlcd_write(unsigned char c){ DelayUs(40); LCD_DATA = ( ( c >> 4 ) & 0x0F ); LCD_STROBE(); LCD_DATA = ( c & 0x0F ); LCD_STROBE();}/* * Clear and home the LCD */voidlcd_clear(void){ LCD_RS = 0; lcd_write(0x1); DelayMs(2);}/* write a string of chars to the LCD */voidlcd_puts(const char * s){ LCD_RS = 1; // write characters while(*s) lcd_write(*s++);}/* write one character to the LCD */voidlcd_putch(char c){ LCD_RS = 1; // write characters lcd_write( c );}/* * Go to the specified position */voidlcd_goto(unsigned char pos){ LCD_RS = 0; lcd_write(0x80+pos);} /* initialise the LCD - put into 4 bit mode */voidlcd_init(){ char init_value; ADCON1 = 0x06; // Disable analog pins on PORTA init_value = 0x3; //TRISA = 0; //TRISB3 = 0;
//TRISB4 = 0;
//TRISB5 = 0; LCD_RS = 0; LCD_EN = 0; LCD_RW = 0; DelayMs(15); // wait 15mSec after power applied, LCD_DATA = init_value; LCD_STROBE(); DelayMs(5); LCD_STROBE(); DelayUs(200); LCD_STROBE(); DelayUs(200); LCD_DATA = 2; // Four bit mode LCD_STROBE(); lcd_write(0x28); // Set interface length lcd_write(0xF); // Display On, Cursor On, Cursor Blink lcd_clear(); // Clear screen lcd_write(0x6); // Set entry Mode}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -