In: Electrical Engineering
An LCD 16x2 display is used for PIC16F1619, if Port C is connected to 8 data pins of the LCD. Pin4 and 5 of port A are connected to EN and RS respectively. RW is tied to the ground. Write a C code to set up 2 lines, 5x8 matrix, 8-bit mode and force the cursor to the beginning of the first line.
#define RS RA5
#define EN RA4
#define D0 RC0
#define D1 RC1
#define D2 RC2
#define D3 RC3
#define D4 RC4
#define D5 RC5
#define D6 RC6
#define D7 RC7
unsigned char rw=0;// connected this pin to gnd
void main()
{
TRISA = 0x00;
TRISC = 0x00;// using port c as output
Lcd_init();
while(1)
{
// program to disply string
}
}
void lcd_init()
{
LCD_CmdWrite(0x30); // Configure the LCD in 8-bit mode,
LCD_CmdWrite(0x0C); // Display On and Cursor Off
LCD_CmdWrite(0x01); // Clear display screen
LCD_CmdWrite(0x06); // Increment cursor
LCD_CmdWrite(0x80); // Set cursor position to 1st line, 1st
column
}
void LCD_CmdWrite( char cmd)
{
PORTC = (PORTC & 0xF0) | (cmd >> 4);; // Send the
command to LCD
rs=0; // Select the Command Register by pulling RS LOW
rw=0; // connected to gnd low
en=1; // Send a High-to-Low Pusle at Enable Pin
__delay_ms(10);
en=0;
__delay_ms(200);
}
void _delay_ms(int x)
{
int y = x/15;
while(--y != 0)
continue;
}