My experiement with PIC18F2550 and Character Type LCD, using MikroC Pro for PIC

This weekend i wanted to test a character type LCD library supplied with MikroC Pro for PIC. I ran the LCD code on PIC18F2550 device. I ran my PIC18F2550 Device using internal oscillator. To correctly run PIC on internal oscillator, i selected oscillator to INTOSC:USB+HS or INTOSC:USB+XT from the Project Settings Dialog box (which can be accessed by pressing CTRL+SHIF+E in MikroC). To run the microcontroller on internal 8.000mhz clock i also added following statement to my C code:

OSCCON = 0x70; // configures oscillator divider for 8MHz int. oscillator

Schematics:

Picture of my assembled circuit:



MikroC Project Settings

Source Code:



// LCD module connections

sbit LCD_RS at RB4_bit;

sbit LCD_EN at RB5_bit;

sbit LCD_D4 at RB0_bit;

sbit LCD_D5 at RB1_bit;

sbit LCD_D6 at RB2_bit;

sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;

sbit LCD_EN_Direction at TRISB5_bit;

sbit LCD_D4_Direction at TRISB0_bit;

sbit LCD_D5_Direction at TRISB1_bit;

sbit LCD_D6_Direction at TRISB2_bit;

sbit LCD_D7_Direction at TRISB3_bit;

// End LCD module connections

char txt1[] = "mikroElektronika";

char txt2[] = "EasyPIC6";

char txt3[] = "Lcd4bit";

char txt4[] = "example";

char i; // Loop variable

void Move_Delay() { // Function used for text moving

Delay_ms(250); // You can change the moving speed here

}

void main(){

CMCON = 0x07; // Disable comparators

ADCON1 = 0x0F; // Disable Analog functions

OSCCON = 0x70; // configures oscillator divider for 8MHz int. oscillator

Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear display

Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

Lcd_Out(1,6,txt3); // Write text in first row

Lcd_Out(2,6,txt4); // Write text in second row

Delay_ms(2000);

Lcd_Cmd(_LCD_CLEAR); // Clear display

Lcd_Out(1,1,txt1); // Write text in first row

Lcd_Out(2,5,txt2); // Write text in second row

Delay_ms(2000);

// Moving text

for(i=0; i<4; i++) { // Move text to the right 4 times

Lcd_Cmd(_LCD_SHIFT_RIGHT);

Move_Delay();

}

while(1) { // Endless loop

for(i=0; i<8; i++) { // Move text to the left 7 times

Lcd_Cmd(_LCD_SHIFT_LEFT);

Move_Delay();

}

for(i=0; i<8; i++) { // Move text to the right 7 times

Lcd_Cmd(_LCD_SHIFT_RIGHT);

Move_Delay();

}

}

}

Conclusion: Using MikroC built-in LCD library it is very quick and easy to run character type LCDs.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s