shubham kumar
Member level 3
- Joined
- Sep 11, 2014
- Messages
- 59
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 8
- Location
- bangalore
- Activity points
- 511
I am using PIC18F452 and MikroC
I have tried numerous ways to initialize LCD without using the inbuilt functions of MikroC, but can't get through.
I came up to this solution from a very old post on the forum
(https://www.edaboard.com/threads/259769/),
but I am not getting the correct output. It is showing some characters on LCD but not exactly what I sent
I tried like, giving ASCII value directly, 4bit mode/8bit mode/ defining like #define DISPLAY PORTB
#define LCD_RS PORTD.B6
#define LCD_EN PORTD.B7
but I think it was just permutation-combination, I might be missing some basic concept.
I have tried numerous ways to initialize LCD without using the inbuilt functions of MikroC, but can't get through.
I came up to this solution from a very old post on the forum
(https://www.edaboard.com/threads/259769/),
but I am not getting the correct output. It is showing some characters on LCD but not exactly what I sent
Code:
#define LCDP PORTB
sbit LCD_RS at LATD6_bit;
sbit LCD_EN at LATD7_bit;
sbit LCD_D4 at LATB4_bit;
sbit LCD_D5 at LATB5_bit;
sbit LCD_D6 at LATB6_bit;
sbit LCD_D7 at LATB7_bit;
sbit LCD_RS_Direction at TRISD6_bit;
sbit LCD_EN_Direction at TRISD7_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
void cmd(void);
void lcd_dat(void);
void LCD_ini(void);
void main(){
int j=0;
char ldg[6]="MiKroC";
TRISD=0X00;
PORTD=0X00;
TRISB=0X00;
PORTD=0X00;
LCD_init();
for(j=0;j<=5;j++)
{
LCDP=ldg[j];
lcd_dat();
}
while(1){
}
}
void LCD_ini(void){
LCDP=0X28; //using5*8dots
cmd();
LCDP=0X0C; //display ON
cmd();
LCDP=0X01; //clear lcd//
cmd();
LCDP=0X86; //intial cursor position//
cmd();
}
void cmd(void){
LCD_RS=0;
LCD_EN=1;
delay_us(500);
LCD_EN=0;
delay_us(500);
}
void lcd_dat(void){
LCD_RS=1;
LCD_EN=1;
delay_us(500);
LCD_EN=0;
delay_us(500);
}
I tried like, giving ASCII value directly, 4bit mode/8bit mode/ defining like #define DISPLAY PORTB
#define LCD_RS PORTD.B6
#define LCD_EN PORTD.B7
but I think it was just permutation-combination, I might be missing some basic concept.