change LCD port for microcontroller

This is a discussion on change LCD port for microcontroller within the C Programming forums, part of the General Programming Boards category; This is the library coding for LCD display... in this coding..the LCD display is defined to be connected to port ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    2

    change LCD port for microcontroller

    This is the library coding for LCD display...
    in this coding..the LCD display is defined to be connected to port B in a microcontroller,

    anyone knows how to change this coding to make the LCD display connected to port C instead..
    anyone?

    Code:
    #define use_portb_lcd TRUE
             struct lcd_pin_map {
                 BOOLEAN enable;
                 BOOLEAN rs;
                 BOOLEAN rw;
                 BOOLEAN unused;
                 int data: 4;
    }lcd;
    
    #if defined(_PCH_)
    #if defined use_portb_lcd
    #byte lcd = 0xF81
    #else
    #byte lcd = 0xF83
    #endif
    #else
    #if defined use_portb_lcd
    #byte lcd = 6
    #else
    #byte lcd = 8
    #endif
    #endif
    
    #if defined use_portb_lcd
    #define set_tris_lcd(x) set_tris_b(x)
    #else
    #define set_tris_lcd(x) set_tris_d(x)
    #endif
    
    #define lcd_type 2 
    #define lcd_line_two 0x40
    
    BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
    
    struct lcd_pin_map const LCD_WRITE = {0, 0, 0, 0, 0};
    struct lcd_pin_map const LCD_READ = {0, 0, 0, 0, 15};
    
    BYTE lcd_read_byte() {
          BYTE low, high;
          set_tris_lcd(LCD_READ);
          lcd.rw=1;
          delay_cycles(1);
          lcd.enable = 1;
          delay_cycles(1);
          high = lcd.data;
          lcd.enable = 0;
          delay_cycles(1);
          lcd.enable = 1;
          delay_us(1);
          low = lcd.data;
          lcd.enable = 0;
          set_tris_lcd(lCD_WRITE);
          return ( (high<<4) | low);
    
    }
    
    void lcd_send_nibble(BYTE n) {
          lcd.data = n;
          delay_cycles(1);
          lcd.enable = 1;
          delay_us(2);
          lcd.enable = 0;
    }
    
    void lcd_send_byte( BYTE address, BYTE n) {
    
            lcd.rs = 0;
            while ( bit_test(lcd_read_byte(),7) );
            lcd.rw = address;
            delay_cycles(1);
            lcd.rw = 0;
            delay_cycles(1);
            lcd.enable = 0;
            lcd_send_nibble(n >> 4);
            lcd_send_nibble(n & 0xf);
    }
    
    void lcd_init() {
             BYTE i;
             set_tris_lcd(LCD_WRITE);
             lcd.rs = 0;
             lcd.rw = 0;
             lcd.enable = 0;
             delay_ms(15);
             for(i=1;i<=3;++i) {
             lcd_send_nibble(3);
             delay_ms(5);
             }
             lcd_send_nibble(2);
             for (i=0; i<=3;++i)
                lcd_send_byte(0,LCD_INIT_STRING[i]);
    }
    
    void lcd_gotoxy(BYTE x, BYTE y) {
    BYTE address;
    
    if (y!=1)
    address=lcd_line_two;
    else
    address=0;
    address+=x-1;
    lcd_send_byte(0,0x80|address);
    }
    
    void lcd_putc( char c) {
    switch (c) {
    case '\f'   : lcd_send_byte(0,1);
                  delay_ms(2);
                                        break;
    case '\n'   : lcd_gotoxy(1,2);      break;
    case '\b'   :lcd_send_byte(0,0x10); break;
    
    default     : lcd_send_byte(1,c);   break;
    }
    }
    
    char lcd_getc(BYTE x, BYTE y) {
    char value;
    
    lcd_gotoxy(x,y);
    while ( bit_test (lcd_read_byte(), 7) );
    lcd.rs=1;
    value = lcd_read_byte();
    lcd.rs=0;
    return(value);
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    Study all the places in the code which have
    #if defined use_portb_lcd

    First question being, which port is being used when the #else option is taken, is that port C

    If it isn't, then you need to add
    #elif defined use_portc_lcd
    in all the appropriate places, and insert appropriate lines of code which are specific to port C.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Firstly you have to be familiar with device programming,
    This should help you: http://electrosofts.com/parallel/
    If you read that, you *should* have the knowledge to do what Salem said.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Concurrent chat, Sockets
    By jakemott in forum Linux Programming
    Replies: 6
    Last Post: 11-29-2008, 04:41 PM
  2. Segmentation Fault - Trying to access parallel port
    By tvsinesperanto in forum C Programming
    Replies: 3
    Last Post: 05-24-2006, 03:28 AM
  3. Sending through serial port to LCD
    By SlimDady in forum C Programming
    Replies: 1
    Last Post: 06-03-2002, 03:51 AM
  4. laptop lcd screen
    By skyline in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-15-2001, 11:23 PM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21