hemnath
Advanced Member level 3
Hardware: PIC18F2520
Microcontroller pins B0 to B3 connected LCD DB4 to DB7;
A2 connected to RS
A1 connected to Enable
CCS C compiler program:
But the display shows nothing. Voltages are +5V. Please help .
Microcontroller pins B0 to B3 connected LCD DB4 to DB7;
A2 connected to RS
A1 connected to Enable
CCS C compiler program:
Code:
#include "18F2520.h"
#fuses INTRC_IO
#use delay(clock=4000000)
#define EN PIN_A1
#define RS PIN_A2
void lcd_init();
void lcd_cmd(unsigned char );
void lcd_data(unsigned char );
void disp_cmd(unsigned char );
void disp_data(unsigned char );
void main()
{
delay_ms(100);
lcd_init();
delay_ms(100);
while(1)
{
disp_cmd(0x80);
printf(disp_data, "TESTING ");
delay_ms(100);
}
}
void lcd_init()
{
disp_cmd(0x02); // To initialize LCD in 4-bit mode.
disp_cmd(0x20); // To initialize LCD in 1 lines, 5x7 dots and 4bit mode.
disp_cmd(0x0C);
disp_cmd(0x01);
disp_cmd(0x06);
disp_cmd(0x80);
}
void lcd_cmd(unsigned char c)
{
output_b(c);
output_low(RS);
output_high(EN);
delay_ms(15);
output_low(EN);
}
void lcd_data(unsigned char z)
{
output_b(z);
output_high(RS);
output_high(EN);
delay_ms(15);
output_low(EN);
}
void disp_cmd(unsigned char cmd_value)
{
unsigned char cmd_value1;
cmd_value1 = ((cmd_value>>4) & 0x0F); // Shift 4-bit and mask
lcd_cmd(cmd_value1); // Send to LCD
cmd_value1=(cmd_value & 0x0F);
lcd_cmd(cmd_value1); // Send to LCD
}
void disp_data(unsigned char data_value)
{
unsigned char data_value1;
data_value1 = ((data_value>>4) & 0x0F);
lcd_data(data_value1);
data_value1=(data_value & 0x0F);
lcd_data(data_value1);
}
But the display shows nothing. Voltages are +5V. Please help .