Results 1 to 14 of 14

Thread: How to interface lcd to the parallel port

  1. #1
    Join Date
    2008/02
    Posts
    7

    Smile How to interface lcd to the parallel port

    hi i have a problem with my school project, i cannot write to the lcd module....

    i have a downloaded program for writing strings to the lcd....

    pls take a look at this code because when i tried to run this prrogram the lcd was unable to display the string.

    #include <dos.h>
    #include <string.h>


    #define PORTADDRESS 0x378

    #define DATA PORTADDRESS+0
    #define STATUS PORTADDRESS+1
    #define CONTROL PORTADDRESS+2

    void lcd_init(void);
    void lcd_write(char char2write);
    void lcd_puts(char * str2write);
    void lcd_goto(int row, int column);
    void lcd_clear(void);


    void main(void)
    {

    lcd_init();
    lcd_goto(1,1);
    lcd_puts("Welcome To");
    lcd_goto(1,0);
    lcd_puts("My LIFE");

    while(!kbhit() ) //wait until a key is pressed...
    {}

    }

    void lcd_init()
    {

    outportb(CONTROL, inportb(CONTROL) & 0xDF);


    outportb(CONTROL, inportb(CONTROL) | 0x08);


    lcd_write(0x0f);
    delay(20);
    lcd_write( 0x01);
    delay(20);
    lcd_write( 0x38);
    delay(20);

    }

    void lcd_write(char char2write)
    {

    outportb(DATA, char2write);
    outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe */
    delay(2);
    outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe */
    delay(2);

    }



    void lcd_puts(char *str2write)
    {

    outportb(CONTROL, inportb(CONTROL) & 0xF7);

    while(*str2write)
    lcd_write(*(str2write++));

    }

    void lcd_goto(int row, int column)
    {

    outportb(CONTROL, inportb(CONTROL) | 0x08);
    if(row==2) column+=0x40;

    lcd_write(0x80 | column);

    }

    void lcd_clear()
    {

    outportb(CONTROL, inportb(CONTROL) | 0x08);
    lcd_write(0x01);

    }




    pls help me....
    the deadline of our project is this coming feb. 29....pls help me...

    thanks....

  2. #2
    Join Date
    2003/11
    Location
    Western WA, USA
    Posts
    1,146
    Since you don't indicate which port bits are used for what control signals, your
    "outportb(CONTROL, inportb(CONTROL) | 0x08);" type of statements are inscrutable.

    Anyway, your init sequence will never work as is. Try this sequence:
    Code:
    lcd_write(0x30);
    delay(20);
    lcd_write(0x30);
    delay(5);
    lcd_write(0x30);
    delay(2);
    lcd_write(0x38);  // set 8 bit I/F
    delay(2);
    lcd_write(8);   // display off
    delay(2);
    lcd_write(1);   // clear & home
    delay(20);
    lcd_write(6);   // cursor off, increment
    delay(20);
    lcd_write(0xC);   // display on
    Also, you are setting the cursor to the same row for each string, so they would overwrite.
    Infinity or Bust

  3. #3
    Join Date
    2008/02
    Posts
    7

    Thumbs up Thanks

    Thank you cosmicvoid.... i'll try your suggested code this evening.... if ill be having a problem again... ill ask your opinion again if you dont mind...thanks

  4. #4
    Join Date
    2008/02
    Posts
    7

    Unhappy Need help again

    good day to you cosmicvoid.... i already inserted your suggested code last night... unfortunately, still the lcd module wasnt able to display a string... does the parallel port cable needs a driver or do i have to configure it first before applying the program? here is the revised code and my parallel to lcd connection.... pls help me....thanks
    Code:
    #include <dos.h>
    #include <string.h>
    #include <conio.h>
    #include <time.h>
    
    #define PORTADDRESS 0x378 
    
    #define DATA 0x378 
    #define STATUS 0x379 
    #define CONTROL 0x37A
    
    void lcd_init(void);
    void lcd_write(char char2write);
    void lcd_puts(char * str2write);
    void lcd_goto(int row, int column);
    
    
    void main(void)
    {
    
        lcd_init();
        lcd_goto(1,1);
        lcd_puts("Welcome To");
        lcd_goto(1,0);
        lcd_puts("My LIFE");
    
        while(!kbhit() ) //wait until a key is pressed...
        {}
    
    }
    
    void lcd_init()
    {
    
        outportb(CONTROL, inportb(CONTROL) & 0xDF);
        //config data pins as output
    
        outportb(CONTROL, inportb(CONTROL) | 0x08);
        //RS is made high: control (register select)
    
       lcd_write(0x30);
    delay(20);
    lcd_write(0x30);
    delay(5);
    lcd_write(0x30);
    delay(2);
    lcd_write(0x38);  
    delay(2);
    lcd_write(8);   
    delay(2);
    lcd_write(1);   
    delay(20);
    lcd_write(6);   
    delay(20);
    lcd_write(0xC);
    
    }
    
    void lcd_write(char char2write)
    {
    
        outportb(DATA, char2write);
        outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe */
        delay(2);
        outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe */
        delay(2);
    
    }
    
    
    void lcd_puts(char *str2write)
    {
    
        outportb(CONTROL, inportb(CONTROL) & 0xF7);
        //RS=low: data
        while(*str2write)
            lcd_write(*(str2write++));
    
    }
    
    void lcd_goto(int row, int column)
    {
    
        outportb(CONTROL, inportb(CONTROL) | 0x08);
        if(row==2) column+=0x40;
        /* Add these if you are using LCD module with 4 columns
        if(row==2) column+=0x14;
        if(row==3) column+=0x54;
        */
        lcd_write(0x80 | column);
    
    }
    The connection:

    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	picture.jpg 
Views:	4566 
Size:	64.6 KB 
ID:	1336  

  5. #5
    Join Date
    2003/11
    Location
    Western WA, USA
    Posts
    1,146
    The Crystalfontz recommended parallel port connection http://www.crystalfontz.com/software...p-hd44780.html
    has RS connected to pin 16, you have it connected to pin 17. I don't know if that is important or not.

    It seems that your code is running under DOS (MSDOS?), is that correct? If not, what operating system are you using. What is the cpu hardware, a PC motherboard, or a SBC? Are you sure that the port address is right? Printer ports could be on 0x278, 0x378, or 0x3BC on the old hardware.

    Have you tried making a test program, to be sure that you are actually outputting to the port? For example, loops that toggle the state of each control signal or data bit, with delays, so that you can see the voltage change with a meter or LED.
    Infinity or Bust

  6. #6
    Join Date
    2008/02
    Posts
    7

    Smile Reply

    my os is windows xp and im using c in dos base.... im sure that the port address of my parallel port is 378 because i saw it in the parallel port properties... can you give me a code in viewing the output using the leds because i really dont have an idea about that.... thank you very much

  7. #7
    Join Date
    2001/03
    Location
    Spokane, Washington
    Posts
    4,092
    Well, first please try CFAH_WinTest, which is known good software:

    http://www.crystalfontz.com/software...est/index.html

    I am not completely sure a program in a DOS box under XP is going to have access to the printer port. CFAH_WinTest must use a library to get access, and it is an "native" windows application.

  8. #8
    Join Date
    2003/11
    Location
    Western WA, USA
    Posts
    1,146
    A raw DOS program will never work under XP, since direct I/O port access is not permitted from user programs. The last version of windows that allowed direct I/O was win98, I believe.

    You will need to install the kernel driver, and use the dll, in order to do printer port I/O. Look at the page that CF Tech linked, and try the CFAH Wintest program. Look at the source code as well, to see how the port I/O is done, and also notice that the pin connections for Wintest don't match your hookup.

    If you want to write LCD code to run under XP, you will have to use different programming methods than a DOS program.
    Infinity or Bust

  9. #9
    Join Date
    2008/02
    Posts
    7

    Smile Questions

    what programming language do u prefer, vb or vc++? do i still have to install libraries for the vb or vc++ even if i already have installed the kernel drivers? Pls give me a link for the kernel drivers and the libraries also.... thank you very much!

  10. #10
    Join Date
    2008/02
    Posts
    7

    Questions

    i think kernel is only for linux

  11. #11
    Join Date
    2003/11
    Location
    Western WA, USA
    Posts
    1,146
    I prefer vc++, and don't like vb, but that is irrelevant.

    The link that CF Tech posted to the CFAH WinTest page contains everything you need. There is a link to the kernel driver, port95nt, on that page. The zip of the source file contains the dlportio.dll, which interfaces to the kernel driver, and the dlportio.h has the declarations for the I/O functions. You should also look into the WinTest source files to see the port pin macros, since some of the signals are inverted at the pin, and some aren't.

    In fact, just for laffs, you could actually install the CFAH_WinTest executable, to verify that your display works with known good code.
    Infinity or Bust

  12. #12
    Join Date
    2008/02
    Posts
    7

    Talking thanks

    thank you very much.....

    if my projects will not work.... i'll ask your opinions again....

    thanks alot

  13. #13
    Join Date
    2008/05
    Posts
    3

    LCD interface to parallel port using VB6

    You can also try interfacing using VB6 as it has GUI.I want to display CPU fan speed on LCD using VB6.Can you help me ?

  14. #14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •