• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

switch() always deault?

Status
Not open for further replies.

johnl69

Member
Im trying to make a function to call an exact address on an LCD but the switch() constantly defers to default.

C:
#include <xc.h>
#include "lcd.h"
#include  "lcd_extra.h"

// These are the line addresses for most 4x20 LCDs. 
#define LCD_LINE_1_ADDRESS 0x00 
#define LCD_LINE_2_ADDRESS 0x40 
#define LCD_LINE_3_ADDRESS 0x14 
#define LCD_LINE_4_ADDRESS 0x54 

//---------------------------- 

void lcd_gotoxy(unsigned int row, unsigned int column) {
    unsigned int address;


    switch (row) {
        case 1:
            address = LCD_LINE_1_ADDRESS;
            break;

        case 2:
            address = LCD_LINE_2_ADDRESS;
            break;

        case 3:
            address = LCD_LINE_3_ADDRESS;
            break;

        case 4:
            address = LCD_LINE_4_ADDRESS;
            break;

        default:
            address = LCD_LINE_1_ADDRESS;
            break;

    }
   
    column -= 1;
    address = (row + column);
    SetDDRamAddr(address);
   
}
It should take the Row address from the switch() table and then add the column number to it and then goto that address.
 

NorthGuy

Well-Known Member
I guess, instead of

C:
address = (row + column);
you want

C:
address += column;
Otherwise, the whole switch statement doesn't produce any effect and compiler is likely to eliminate it completely.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top