rangerskm
Full Member level 4
- Joined
- Jan 23, 2013
- Messages
- 199
- Helped
- 0
- Reputation
- 2
- Reaction score
- 0
- Trophy points
- 1,296
- Activity points
- 2,663
Code:
// Program to interface 16x2 LCD and display single character using PIC18F4550 Microcontroller
// Configuration bits
/* _CPUDIV_OSC1_PLL2_1L, // Divide clock by 2
_FOSC_HS_1H, // Select High Speed (HS) oscillator
_WDT_OFF_2H, // Watchdog Timer off
MCLRE_ON_3H // Master Clear on
*/
//LCD Control pins
#include<pic.h>
#include<stdio.h>
#define rs RB0
#define rw RB1
#define en RB2
//LCD Data pins
#define lcdport PORTD
void lcd_ini();
void lcdcmd(unsigned char);
void lcddata(unsigned char);
unsigned int i=0;
void Delay_ms(unsigned int msec) // Function to provide time delay in msec.
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
void main(void)
{
// ADCON1=0X07;
TRISB=0; // Configure Port A as output port
//PORTB=0;
TRISD=0; // Configure Port B as output port
//PORTD=0;
lcd_ini(); // LCD initialization
lcddata('E'); // Print 'E'
Delay_ms(10);
lcdcmd(0x85); // Position 1st Line, 6th Column
lcddata('G'); // Print 'G'
}
void lcd_ini()
{
Delay_ms(1);
lcdcmd(0x30); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
Delay_ms(10);
lcdcmd(0x30); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
Delay_ms(10);
lcdcmd(0x30); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
Delay_ms(10);
lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
Delay_ms(10);
lcdcmd(0x38); // Configure the LCD in 8-bit mode, 2 line and 5x7 font
Delay_ms(1);
// lcdcmd(0x0F); // Display On and Cursor Off
// Delay_ms(1);
lcdcmd(0x01); // Clear display screen
Delay_ms(1);
lcdcmd(0x06); // Increment cursor
Delay_ms(1);
lcdcmd(0x80); // Set cursor position to 1st line, 1st column
Delay_ms(1);
}
void lcdcmd(unsigned char cmdout)
{
lcdport=cmdout; //Send command to lcdport=PORTB
rs=0;
rw=0;
en=1;
Delay_ms(1);
en=0;
Delay_ms(10);
}
void lcddata(unsigned char dataout)
{
lcdport=dataout; //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
Delay_ms(10);
en=0;
Delay_ms(10);
}
I COMPILED THIS CODE IN MPLAB BY USING HI TECH C COMPILER.
THE CHARACTERS NOT DISPLAYING IN LCD .JUST BLANK .
CAN ANY ONE HELP ME IN THIS.