paralell port: I have got few errors on this piece of code below, please help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • afshana
    New Member
    • Feb 2007
    • 6

    paralell port: I have got few errors on this piece of code below, please help

    Code:
    #include <dos.h>
    #include <string.h>
    #include <conio.h>
    #include <time.h>
    
    #define PORTADDRESS 0x378 /* Enter Your Port Address Here */
    
    #define DATA PORTADDRESS+0
    #define STATUS PORTADDRESS+1
    #define CONTROL PORTADDRESS+2
    
    void lcd_init(void);
    void lcd_write(char char2write);
    void lcd_putch(char char2write);
    void lcd_puts(char * str2write);
    void lcd_goto(int row, int column);
    void lcd_clear(void);
    void lcd_home(void);
    void lcd_cursor(int cursor);
    void lcd_entry_mode(int mode);
    
    
    void main(void)
    {
    lcd_init();
    lcd_goto(1,1);
    lcd_puts("Welcome To");
    lcd_goto(1,0);
    lcd_puts("electroSofts.com");
    
    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(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_putch(char char2write)
    {
    
    outportb(CONTROL, inportb(CONTROL) & 0xF7);
    //RS=low: data
    lcd_write(char2write);
    
    }
    
    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);
    
    }
    
    void lcd_clear()
    {
    
    outportb(CONTROL, inportb(CONTROL) | 0x08);
    lcd_write(0x01);
    
    }
    
    void lcd_home()
    {
    
    outportb(CONTROL, inportb(CONTROL) | 0x08);
    lcd_write(0x02);
    
    }
    
    void lcd_entry_mode(int mode)
    {
    
    /*
    if you dont call this function, entry mode sets to 2 by default.
    mode: 0 - cursor left shift, no text shift
    1 - no cursor shift, text right shift
    2 - cursor right shift, no text shift
    3 - no cursor shift, text left shift
    */
    outportb(CONTROL, inportb(CONTROL) | 0x08);
    lcd_write(0x04 + (mode%4));
    
    }
    
    void lcd_cursor(int cursor)
    {
    
    /*
    set cursor: 0 - no cursor, no blink
    1 - only blink, no cursor
    2 - only cursor, no blink
    3 - both cursor and blink
    */
    
    
    outportb( CONTROL, inportb(CONTROL) | 0x08 );
    lcd_write( 0x0c + (cursor%4));
    
    }
    
    --------------------------------------------------------------------------------
    Last edited by horace1; Mar 16 '07, 06:49 PM. Reason: added code tags
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    using Turbo C V3.0 this code compiles and links OK

    Have not tried to run it!

    what is your problem?

    Comment

    Working...