caramoan tour package

caramoan tour package

Author Topic: Using a 4x20 lcd  (Read 9304 times)

Offline sani_figs

  • CR2032 Battery
  • **
  • Posts: 12
  • Pogi/Ganda Points: 0
Using a 4x20 lcd
« on: July 29, 2008, 08:49:28 PM »
Hi mga master, kailangan ko gumamit ng lcd display pero wala akong idea pano. May massuggest ba kayong materials na pwede aralin para makagamit ako ng lcd (meron ako 4x20 lcd)? Links or kahit turuan niyo ko, ayos lang po. Thank you!

Philippine Electronics Forum

Using a 4x20 lcd
« on: July 29, 2008, 08:49:28 PM »

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10729
  • Pogi/Ganda Points: 632
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: Using a 4x20 lcd
« Reply #1 on: July 29, 2008, 09:40:46 PM »
marami tutorial sa net. search for HD44780 based LCD. sa datasheet din ng HD44780 nandun yung instructions. ;)
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Philippine Electronics Forum

Re: Using a 4x20 lcd
« Reply #1 on: July 29, 2008, 09:40:46 PM »

Offline Cute_Worm_1983

  • Size D Battery
  • ******
  • Posts: 418
  • Pogi/Ganda Points: 16
  • Gender: Male
Re: Using a 4x20 lcd
« Reply #2 on: July 29, 2008, 10:02:56 PM »
I love electronicslab.ph

Philippine Electronics Forum

Re: Using a 4x20 lcd
« Reply #2 on: July 29, 2008, 10:02:56 PM »

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: Using a 4x20 lcd
« Reply #3 on: July 29, 2008, 10:04:54 PM »
try using proteus. It simulates MCU + LCD quite nicely  ;)

Here is a pic16f84a + 2x16 LCD



a sample code in hi-tech c

Code: [Select]

/*
LCD interfacing using 4-bit mode
*/

#include <pic.h>
#include "delay.c"

//configuration fuse
__CONFIG(XT & WDTDIS & PWRTDIS & UNPROTECT);

static bit LCD_RS @ ((unsigned)&PORTA*8+0); // Register select
static bit LCD_EN @ ((unsigned)&PORTA*8+1); // Enable

#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))

void lcd_write(unsigned char c)
{
PORTB = (PORTB & 0xF0) |  (c >> 4);
LCD_STROBE;
PORTB = (PORTB & 0xF0) |  (c & 0x0F);
LCD_STROBE;
DelayUs(40);
}

/*
 * Clear and home the LCD
 */

void lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
DelayMs(2);
}

/* write a string of chars to the LCD */

void lcd_puts(const char * s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}

/* write one character to the LCD */

void lcd_putch(char c)
{
LCD_RS = 1; // write characters
PORTB = (PORTB & 0xF0) |  (c >> 4);
LCD_STROBE;
PORTB = (PORTB & 0xF0) |  (c & 0x0F);
LCD_STROBE;
DelayUs(40);
}


/*
 * Go to the specified position
 */

void lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos);
}

/* initialise the LCD - put into 4 bit mode */

void lcd_init(void)
{
LCD_RS = 0; // write control bytes
DelayMs(15); // power on delay
PORTB = 0x03; // attention!
LCD_STROBE;
DelayMs(5);
LCD_STROBE;
DelayUs(100);
LCD_STROBE;
DelayMs(5);
PORTB = 0x02; // set 4 bit mode
LCD_STROBE;
DelayUs(40);
lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font (0010 1000)
lcd_write(0x08); // display off (0000 1000)
lcd_write(0x0F); // display on, blink curson on
lcd_write(0x06); // entry mode
}


void main()
{
TRISA &= ~0x03; //RA2 & RA3 are output
PORTA &= ~0x03;

TRISB &= ~0x0F; //RB<3:0> are output
PORTB &= ~0x0F; //RB<3:0> are low

lcd_init(); //initialize LCD, set to 4-bit mode
lcd_clear(); //clear LCD
lcd_puts("abcde"); //display text in first line
lcd_goto(0x40); //display text in second line
lcd_puts("pogi si paranz");

while(1);

}


PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Philippine Electronics Forum

Re: Using a 4x20 lcd
« Reply #3 on: July 29, 2008, 10:04:54 PM »

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: Using a 4x20 lcd
« Reply #4 on: July 29, 2008, 10:10:14 PM »
another sample code in CCS C

Code: [Select]

#include <16f84a.h>
#use delay (clock = 4000000)
#fuses XT, NOWDT, NOPUT, NOPROTECT

#define LCD_RS    PIN_A0
#define LCD_EN    PIN_A1

#define LCD_STROBE   (output_high(LCD_EN), output_low(LCD_EN))

void lcd_write(unsigned char c)
{
    output_b((c >> 4) & 0x0F);
    LCD_STROBE;
    output_b(c & 0x0F);
    LCD_STROBE;
    delay_us(40);   
}

void lcd_clear(void)
{
    output_low(LCD_RS);
    lcd_write(0x01);
    delay_ms(2);
}

void lcd_puts( char * string)
{
    output_high(LCD_RS);
    while(*string)
        lcd_write(*string++);
}

void lcd_putch(char c)
{
    output_high(LCD_RS);
    output_b((c >> 4) & 0x0F);
    LCD_STROBE;
    output_b(c & 0x0F);
    LCD_STROBE;
    delay_us(40); 
}

void lcd_goto(unsigned char pos)
{
    output_low(LCD_RS);
    lcd_write(0x80+pos);
}


void lcd_init(void)
{
   output_low(LCD_RS);      // write control bytes
   delay_ms(15);            // power on delay
   output_b(0x03);          // attention!
    LCD_STROBE;
   delay_ms(5);

    LCD_STROBE;
   delay_us(100);
    LCD_STROBE;
   delay_ms(5);
   output_b(0x02);          // set 4 bit mode
    LCD_STROBE;
   delay_us(40);
    lcd_write(0x28);        // 4 bit mode, 1/16 duty, 5x8 font
    lcd_write(0x08);        // display off
    lcd_write(0x0F);        // display on, blink curson on
    lcd_write(0x06);        // entry mode
}

void main()
{
    unsigned char a[] = "pogi si paranz";   
   
    set_tris_a(0x00);
    set_tris_b(0x00);
   
    lcd_init();                  //initialize LCD, set to 4-bit mode
    lcd_clear();                 //clear LCD

    lcd_putch('a');              //display chars in first line
    lcd_putch('b');
    lcd_putch('c');
    lcd_putch('d');
    lcd_putch('e');

    lcd_goto(0x40);             //display text in second line
   
    lcd_puts(a);                //display text in a[] array

}



PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Philippine Electronics Forum

Re: Using a 4x20 lcd
« Reply #4 on: July 29, 2008, 10:10:14 PM »

Offline Cute_Worm_1983

  • Size D Battery
  • ******
  • Posts: 418
  • Pogi/Ganda Points: 16
  • Gender: Male
Re: Using a 4x20 lcd
« Reply #5 on: July 29, 2008, 10:12:39 PM »

nice one daddy paranz.  ;D

my pogi pa  :D :D :D
I love electronicslab.ph

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Using a 4x20 lcd
« Reply #6 on: July 29, 2008, 10:50:38 PM »
nice sir paranz...  naexplain mo kaagad kung papano ang gagawin at mga kailangan sa pagiinterface ng LCD. ganda ng example mo.
pwede pa kopya...?
gagawin ko na tong include file para di na ako gumawa.
syempre, papalitan ko na lang dun sa main.
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: Using a 4x20 lcd
« Reply #7 on: July 29, 2008, 10:54:04 PM »
nice one daddy paranz.  ;D

my pogi pa  :D :D :D

hehe


nice sir paranz...  naexplain mo kaagad kung papano ang gagawin at mga kailangan sa pagiinterface ng LCD. ganda ng example mo.
pwede pa kopya...?
gagawin ko na tong include file para di na ako gumawa.
syempre, papalitan ko na lang dun sa main.

sure you can use it naman..

yung sa hi-tech C code, meron na yan sample program sa sample folder ng hitech C installation folder.. tapos pinort ko lang sa CCS C when a forum member asked for a similar sample program on LCD
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline RaffT

  • Technical People
  • Hydroelectric
  • *****
  • Posts: 3440
  • Pogi/Ganda Points: 103
  • Gender: Male
  • more on R-n-D
    • MY Bots
Re: Using a 4x20 lcd
« Reply #8 on: July 29, 2008, 10:58:29 PM »

@paranz,

parang nakita ko na yan "somewhere" na pogi sa LCD.... di ko lang maremember kung saan ;D
Learning is CooL! BEAM robotics/DIY UCD180/PSP/AC wtmtr/digiESRmtr/PICkit™2 clone/SGTC/SSTC/DR-SSTC

Never argue with an idiot... They'll take you down to their level and beat you with experience

Offline sani_figs

  • CR2032 Battery
  • **
  • Posts: 12
  • Pogi/Ganda Points: 0
Re: Using a 4x20 lcd
« Reply #9 on: July 29, 2008, 11:02:09 PM »
Wow! Ang bilis ng mga solusyon ah! :) Iintindihin ko na lang to pero malamang ayos na ayos na to.
Thanks mga master! Lalo na kay master "POGI"! (DragonBol?) Hehe.

Add: Nga pala sir paranz, free ba idownload yang proteus? If ever, anong whole name nung program/app. Salamat!

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Using a 4x20 lcd
« Reply #10 on: July 29, 2008, 11:04:43 PM »
sure you can use it naman..

yung sa hi-tech C code, meron na yan sample program sa sample folder ng hitech C installation folder.. tapos pinort ko lang sa CCS C when a forum member asked for a similar sample program on LCD

ah ganun ba... bumalik kasi ako sa CCS, gawa ng medyo late na ako sa project ko. obvious naman na medyo madali sa CCS gawa ng IDE nila. pero babalik din ako sa hitech c, matapos lang tong ginagawa ko. kaya yan, di ko na masyado na explore ang ccs...
salamat pa din.

Wow! Ang bilis ng mga solusyon ah! :) Iintindihin ko na lang to pero malamang ayos na ayos na to.
Thanks mga master! Lalo na kay master "POGI"! (DragonBol?) Hehe.
oo nga, kailangan nalang maintindihan yung mga subroutines... and we're save! hehehe
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: Using a 4x20 lcd
« Reply #11 on: July 29, 2008, 11:07:58 PM »
@paranz,

parang nakita ko na yan "somewhere" na pogi sa LCD.... di ko lang maremember kung saan ;D

saan nga ba?   ::) ::) ::)  ;D


Wow! Ang bilis ng mga solusyon ah! :) Iintindihin ko na lang to pero malamang ayos na ayos na to.
Thanks mga master! Lalo na kay master "POGI"! (DragonBol?) Hehe.

welcome  ;)
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: Using a 4x20 lcd
« Reply #12 on: July 29, 2008, 11:11:26 PM »
@sani

check this link for LCD interfacing tutorial

PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline Shey

  • Administrator
  • Gas Turbine
  • *****
  • Posts: 2004
  • Pogi/Ganda Points: 154
  • Gender: Female
  • "E tangi ana koe Hine e hine, E hine e Hoki maira"
    • Elab.PH
Re: Using a 4x20 lcd
« Reply #13 on: July 29, 2008, 11:33:28 PM »
PIC Basic fan kasi ako kaya eto naman ang link na suggested ko for LCD tutorial using PIC.. dito sa site na ito ako natuto sa PIC kaya higly recommended ko siya..

http://www.mikroe.com/en/books/picbasicbook/07.htm#7.3

sa simulation naman always use Proteus kahit na shareware fully functional yun kaya lang hindi ka makakapag-save..

I wish for this night-time to last for a lifetime
The darkness around me
Shores of a solar sea
Oh how I wish to go down with the sun
Sleeping
Weeping
With you

I walk alone
Every step I take
I walk alone
My winter storm
Holding me awake
It’s never gone

I fear that soon you'll reveal
Your dangerous mind
As your true colours show
A dangerous sign

Offline marcelino

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Using a 4x20 lcd
« Reply #14 on: July 30, 2008, 12:00:04 AM »
ayos na ako... hehehe... salamat uli sir paranz. siguro babasahin ko nalang yung tutorial. pati na yung pinost ni bulate....
very helpful!

painaglaruan ko na yung code... i made a simple sweet message to my wife. talgang nilagay ko pa sa breadboard ha... sabi naman sakin, "yan lang ba?" hehehe
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline sani_figs

  • CR2032 Battery
  • **
  • Posts: 12
  • Pogi/Ganda Points: 0
Re: Using a 4x20 lcd
« Reply #15 on: July 30, 2008, 11:34:39 AM »
Followup:

Nakaka-display na po ako ng text ("Hello World!", "Pogi rin ako", etc.  ;D) kaya nga lang, yung application ko needs to show through the lcd the data which is computed every certain period e.g. every 2secs.

Dun sa mga code na nakita ko, isa-isa sinesend yung characters:
                while(*s)
      lcd_write(*s++);

at yung input ay predefined:
                lcd_puts("pogi si paranz");

Kaya, paano ko po babaguhin yung code para magprint ng real time data (int or float) data every 2secs? Yung parang printf lang: printf("Reading: %d",data);

Thank you!

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: Using a 4x20 lcd
« Reply #16 on: July 30, 2008, 11:45:36 AM »
^ kulang pa po yung code.. if you want to display an integer data, you need to convert it to character/string first.. use the itoa() function, meron example code sa hi-tech C sample folder
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline RaffT

  • Technical People
  • Hydroelectric
  • *****
  • Posts: 3440
  • Pogi/Ganda Points: 103
  • Gender: Male
  • more on R-n-D
    • MY Bots
Re: Using a 4x20 lcd
« Reply #17 on: July 30, 2008, 11:49:35 AM »
Followup:

Nakaka-display na po ako ng text ("Hello World!", "Pogi rin ako", etc.  ;D) kaya nga lang, yung application ko needs to show through the lcd the data which is computed every certain period e.g. every 2secs.

Dun sa mga code na nakita ko, isa-isa sinesend yung characters:
                while(*s)
      lcd_write(*s++);

at yung input ay predefined:
                lcd_puts("pogi si paranz");

Kaya, paano ko po babaguhin yung code para magprint ng real time data (int or float) data every 2secs? Yung parang printf lang: printf("Reading: %d",data);

Thank you!


hmmmm hulaan ko.. digital therm?? or sonething needing updated display every 2secs ?? :)
Learning is CooL! BEAM robotics/DIY UCD180/PSP/AC wtmtr/digiESRmtr/PICkit™2 clone/SGTC/SSTC/DR-SSTC

Never argue with an idiot... They'll take you down to their level and beat you with experience

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: Using a 4x20 lcd
« Reply #18 on: July 30, 2008, 12:58:04 PM »
@sani_figs

try this sample code. Inedit ko lang yung nasa taas, i added an itoa() and delay()function.

It will display an initial text, then start displaying counter values from 0 to 255

Code: [Select]

/*
LCD interfacing using 4-bit mode
*/

#include <pic.h>
#include "delay.c"

//configuration fuse
__CONFIG(XT & WDTDIS & PWRTDIS & UNPROTECT);

#define LCD_RS RA0
#define LCD_EN RA1

#define LCD_STROBE ((LCD_EN = 1),(LCD_EN=0))

void lcd_write(unsigned char c)
{
PORTB = (PORTB & 0xF0) |  (c >> 4);
LCD_STROBE;
PORTB = (PORTB & 0xF0) |  (c & 0x0F);
LCD_STROBE;
DelayUs(40);
}

/*
 * Clear and home the LCD
 */

void lcd_clear(void)
{
LCD_RS = 0;
lcd_write(0x1);
DelayMs(2);
}

/* write a string of chars to the LCD */

void lcd_puts(const char * s)
{
LCD_RS = 1; // write characters
while(*s)
lcd_write(*s++);
}

/* write one character to the LCD */

void lcd_putch(char c)
{
LCD_RS = 1; // write characters
PORTB = (PORTB & 0xF0) |  (c >> 4);
LCD_STROBE;
PORTB = (PORTB & 0xF0) |  (c & 0x0F);
LCD_STROBE;
DelayUs(40);
}


/*
 * Go to the specified position
 */

void lcd_goto(unsigned char pos)
{
LCD_RS = 0;
lcd_write(0x80+pos);
}

/* initialise the LCD - put into 4 bit mode */

void lcd_init(void)
{
LCD_RS = 0; // write control bytes
DelayMs(15); // power on delay
PORTB = 0x03; // attention!
LCD_STROBE;
DelayMs(5);
LCD_STROBE;
DelayUs(100);
LCD_STROBE;
DelayMs(5);
PORTB = 0x02; // set 4 bit mode
LCD_STROBE;
DelayUs(40);
lcd_write(0x28); // 4 bit mode, 1/16 duty, 5x8 font (0010 1000)
lcd_write(0x08); // display off (0000 1000)
lcd_write(0x0F); // display on, blink curson on
lcd_write(0x06); // entry mode
}

void delay(void) //software delay
{
int i,j;
for(i=0;i<0xFF;i++)
for(j=0;j<0xFF;j++)
;
}

/* Convert integer 'i', radix 10 to a string */
void itoa(unsigned char *buf, int i) {
unsigned int rem;
unsigned char *s,length=0;

s = buf; //<points to address of buf
if (i == 0) //if i is 0, buf is 0
*s++ = '0';
else {
if (i < 0) {
*buf++ = '-';
s = buf;
i = -i;
}
while (i) {
++length;
rem = i % 10;
*s++ = rem + '0';
i /= 10;
}
for(rem=0; ((unsigned char)rem)<length/2; rem++) {
*(buf+length) = *(buf+((unsigned char)rem));
*(buf+((unsigned char)rem)) = *(buf+(length-((unsigned char)rem)-1));
*(buf+(length-((unsigned char)rem)-1)) = *(buf+length);
}
}
*s=0;
}

void main()
{
unsigned char value = 0x00; //counter value
unsigned char string_value[5]; //hold 5 strings

TRISA &= ~0x03; //RA2 & RA3 are output
PORTA &= ~0x03;

TRISB &= ~0x0F; //RB<3:0> are output
PORTB &= ~0x0F; //RB<3:0> are low

lcd_init(); //initialize LCD, set to 4-bit mode
lcd_clear(); //clear LCD
lcd_puts("abcde"); //display text in first line
lcd_goto(0x40); //display text in second line
lcd_puts("pogi si paranz");

delay(); //delay

lcd_clear(); //remove previous display

while(1)
{
itoa(string_value, value); //convert value to string,
//then assign to string_value
lcd_goto(0x00); //goto first line
lcd_puts(string_value); //display value to LCD
value++; //increment value

delay(); //delay
}
}


PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline Cute_Worm_1983

  • Size D Battery
  • ******
  • Posts: 418
  • Pogi/Ganda Points: 16
  • Gender: Male
Re: Using a 4x20 lcd
« Reply #19 on: July 30, 2008, 01:00:56 PM »
Another sample code in assembly (20x4)




Code: [Select]
;*************************************************************/07/30/08*****
; File: LCD_20x4_test.asm @ 4Mhz.
; Project name: LCD Test 4x20   
;***************************************************************************   
            LIST     P=16F84
            INCLUDE "P16F84.INC"
            __CONFIG H'3FF1'
            RADIX HEX
            ERRORLEVEL -302,-202
;***************************************************************************
; Pin configuration for 20x4 LCD 
;*************************************************************************** 
; RB0 = D4
; RB1 = D5
; RB2 = D6
; RB3 = D7
; RB4 = E
; RB5 = RS           
;***************************************************************************                 
LCD_TEMP1   EQU    0X20
LCD_TEMP2   EQU    0X22
LCD_TEMP3   EQU    0X23
COUNT1      EQU    0X24
COUNT2      EQU    0X25
             
#DEFINE     EN     PORTB,4
#DEFINE     RS     PORTB,5       
;***************************************************************************   
            ORG    0X00
           
            BSF    STATUS,RP0
            MOVLW  0X00
            MOVWF  TRISB
            BCF    STATUS,RP0
           
            CLRF   PORTB
            CALL   LCD_INIT
            GOTO   MAIN                     
;***************************************************************************
LCD_TABLE:  ADDWF  PCL,F
            RETLW  0X32                ; Set 4-bit mode
            RETLW  0X2C                ; Set 2 lines LCD
            RETLW  0X08                ; Display OFF
            RETLW  0X06                ; Set so cursor addr is incremented
            RETLW  0X0C                ; Display ON, cursor OFF, blink OFF
            RETLW  0X01                ; Clear display
            RETLW  0X02                ; Home cursor, clear RAM
            RETLW  0X00                ; Return zero as end marker
;***************************************************************************
            ORG    0X100
SET_STRING: ADDWF  PCL,F
              ; 01234567890123456789
MSG_L1:     DT "       I love       ",0
MSG_L2:     DT "   electronicslab   ",0
MSG_L3:     DT "         by:        ",0
MSG_L4:     DT "     bulate1983     ",0
;***************************************************************************         
MAIN:       CALL   LCD_LINE_1
            MOVLW  MSG_L1
            CALL   STRING_OUT
           
            CALL   LCD_LINE_2
            MOVLW  MSG_L2
            CALL   STRING_OUT
           
            CALL   LCD_LINE_3
            MOVLW  MSG_L3
            CALL   STRING_OUT
             
            CALL   LCD_LINE_4
            MOVLW  MSG_L4
            CALL   STRING_OUT
            GOTO   MAIN
;***************************************************************************
STRING_OUT: MOVWF  LCD_TEMP1         ; Save the string
            DECF   LCD_TEMP1,F       ; Subract 1 to string.
LOOP01:     MOVLW  0X01
            MOVWF  PCLATH
            MOVF   LCD_TEMP1,W   
            CALL   SET_STRING        ; Add the Count text to PCL
            XORLW  0X00
            BTFSC  STATUS,Z          ; String = 0?
            GOTO   CLR_PCL
            CALL   LCD_CHAR          ; display to LCD
            INCF   LCD_TEMP1,F       ; Point to next character
            GOTO   LOOP01            ; Keep checking
CLR_PCL:    CLRF   PCLATH
            RETURN   
;***************************************************************************
; LCD Subroutine 20x4 Display
;***************************************************************************
LCD_INIT:   CALL   DELAY_5           ; Wait to Initialize the LCD
            CLRF   LCD_TEMP2
SET_LCD:    MOVF   LCD_TEMP2,W
            CALL   LCD_TABLE
            XORLW  0X00
            BTFSC  STATUS,Z
            RETURN
            CALL   LCD_CMD
            INCF   LCD_TEMP2,F
            CALL   DELAY_5
            GOTO   SET_LCD 
;***************************************************************************         
LCD_LINE_1: MOVLW  0X80             ; Go to start of line 1   
            CALL   LCD_CMD          ; Yes call Command Display
            RETURN
LCD_LINE_2: MOVLW  0XC0             ; Go to start of line 2   
            CALL   LCD_CMD          ; Yes call Command Display 
            RETURN
LCD_LINE_3: MOVLW  0X94             ; Go to start of line 3       
            CALL   LCD_CMD          ; Yes call Command Display
            RETURN
LCD_LINE_4: MOVLW  0XD4             ; Go to start of line 4   
            CALL   LCD_CMD          ; Yes call Command Display
            RETURN
;***************************************************************************           
PULSE_EN:   BSF    EN 
            NOP
            BCF    EN 
            RETURN
;***************************************************************************
LCD_CMD:    MOVWF  LCD_TEMP3
            SWAPF  LCD_TEMP3,W       ; Send the upper nibble
            ANDLW  B'00001111'       ; Clear the upper 4-bit of W
            MOVWF  PORTB 
            BCF    RS         
            CALL   PULSE_EN
            MOVF   LCD_TEMP3,W       ; Send the lower nibble
            ANDLW  B'00001111'       ; Clear the upper 4-bit of W
            MOVWF  PORTB
            BCF    RS   
            CALL   PULSE_EN
            CALL   DELAY_1
            RETURN         
;*************************************************************************** 
LCD_CHAR:   MOVWF  LCD_TEMP3
            SWAPF  LCD_TEMP3,W       ; Send the upper nibble
            ANDLW  B'00001111'       ; Clear the upper 4-bit of W
            MOVWF  PORTB
            BSF    RS
            CALL   PULSE_EN
            MOVF   LCD_TEMP3,W       ; Send the lower nibble
            ANDLW  B'00001111'       ; Clear the upper 4-bit of W
            MOVWF  PORTB
            BSF    RS   
            CALL   PULSE_EN
            CALL   DELAY_1
            RETURN         
;***************************************************************************           
; Delay Subroutine @ 4Mhz.
;***************************************************************************
DELAY_1:    MOVLW .200
            MOVWF COUNT1
LOOP1:      NOP
            NOP
            DECFSZ COUNT1,F
            GOTO LOOP1
            RETURN
             
DELAY_5:    MOVLW .5
            MOVWF COUNT2
LOOP2:      CALL DELAY_1 
            DECFSZ COUNT2,F
            GOTO LOOP2
            RETURN           
;***************************************************************************             
            END




I love electronicslab.ph

Philippine Electronics Forum

Re: Using a 4x20 lcd
« Reply #19 on: July 30, 2008, 01:00:56 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com