Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#42 Strange behaviour of SDCC with strings

closed
nobody
None
5
2006-03-24
2006-03-07
Omar_Espinosa
No

Dear Collegues,
I have been working with SDCC in setting up an LCD in
mode 4 bits. After doing several attempts I realized
that the compiler is having a strange behaviour. I
tried to show a message using the method of array and
pointers without any success. Nevertheles, when I
tried to send the simple character directly to the
subroutine, it works properly.
In order to be short in this, this is the unique part
I changed, but unsuccessfully. I also tried definin
the array and pointers inside the main routine.

unsigned int index;
char men[]="WELCOME TO COFFEE";
char men2[]="ROASTER V1.0";
char* ptr=men;
char* ptr2=men2;
void main (void){
LCD_Init();
espera(10);
espera(2);
while (*ptr)
{
writedata(*ptr,1);
ptr++;

}

Cmndwrite(0xC0,0);
espera(1);
while (*ptr2)
{
writedata(*ptr2,1);
ptr2++;
}
}

Below the first program that works nicely.

//This program is Tested and worked very good.
//LCD Temperature and thermocouple.
//designed, thought and written by Omar Espinosa
//In this first stage I configure the LCD

#include<stdio.h>
#include<922Sdcc.h>

//end of headers

//Define begins

#define low 0
#define high 1
#define LCD_E P0_4 //Register Select of LCD-
Display-RS
#define LCD_RW P0_5 //ENABLE READ/WRITE
#define LCD_RS P0_6 // Enable of LCD-Display
#define LCD_DATA P0 // Dataport of LCD-Display
(D4..D7)=P0...P3
#define Busy_pin P0_3 // Pin de chequeo del LCD, D7
#define Write 0
#define Read 1

//Begin the prototypes
unsigned char _sdcc_external_startup(void);
void LCD_Init(void);
void Cmndwrite(unsigned int a,bit Reg);
void writedata(unsigned char e,unsigned int var);
void espera(unsigned int K);
void CONFIG(int ac);

//End of prototypes
// unsigned char c='A'; //codigo en memoria
programa.
unsigned int index;
//bit CTRL_REG; //0=INSTRUCTION,
1=DATA; bit definition For SDCC

void main (void){
LCD_Init();
espera(10);
espera(2);
writedata('C',1);
writedata('O',1);
writedata('F',1);
writedata('F',1);
writedata('E',1);
writedata('E',1);

Cmndwrite(0xC0,0);
espera(1);
writedata('T',1);
writedata('E',1);
writedata('M',1);
writedata('P',1);
}

//Port mode configurations//

unsigned char _sdcc_external_startup(void){
P0M1=0X00; //Bidirectional mode
P1M2=0X00; //Bidirectional mode
P0=0x00;
return 1; //Ejecuta inmediatamente
el "MAIN"
}

//LCD configuracion//
void LCD_Init(void){
CONFIG(0X03); //modo 8 bits
CONFIG(0X03); //MODO 8 BITS
CONFIG(0X03); //modo 8 bits
CONFIG(0X02); //modo 4 BITS
Cmndwrite(0x28,0); //SECOND time to see
low nibbles
Cmndwrite(0x0E,0); //set cursor on, set
LCD on, not blinking
// espera(5);
Cmndwrite(0x06,0); //increment by 1
// espera(5);
Cmndwrite(0x01,0); //cursor at home and
clean LCD
}

void CONFIG(int ac){
unsigned int index;
LCD_DATA=ac;
LCD_E=1;
LCD_E=0;
index=20;
while(--index);
if (ac<=2)
{
while(--index);
while(--index);
while(--index);
}
}

void Cmndwrite(unsigned int a,bit Reg){
//Se debe enviar el nible más significativo
primero.
//P0.0=D4, P0.1=D5,P0.2=D6,P0.3=D7
LCD_DATA=a>>4; //upper nible
y rota a la derercha 4 posiciones
LCD_RS=Reg;
//Command or DATA. Depende del valor entrante.
LCD_RW=Write;
LCD_E=1;
LCD_E=0;
LCD_DATA=a&0X0F; //low
nible
LCD_E=1;
LCD_E=0;
index=20;
while(--index);
if (a<=2)
{
while(--index);
while(--index);
while(--index);
}
}
void writedata(unsigned char e,unsigned int var){
//Se debe enviar el nible más significativo
primero.
//P0.0=D4, P0.1=D5,P0.2=D6,P0.3=D7
unsigned char t;
t=(e&0XF0);
LCD_DATA=t>>4; //upper nible y rota a
la derercha 4 posiciones
LCD_RS=var;
//Command or DATA. Depende del valor entrante.
LCD_RW=Write;
// espera(1);
LCD_E=1;
// espera(1);
LCD_E=0;
LCD_DATA=e&0X0F; //low
nible
LCD_RS=var;
LCD_RW=Write;
LCD_E=1;
espera(1);
LCD_E=0;
index=40;
while(--index);

}
void espera(unsigned int k){
while(k!=0){
_asm
nop
_endasm;
k--;
}
}

Discussion

  • Maarten Brock
    Maarten Brock
    2006-03-09

    • status: open --> pending
     
  • Maarten Brock
    Maarten Brock
    2006-03-09

    Logged In: YES
    user_id=888171

    Omar,

    char men[]="WELCOME TO COFFEE";

    Defines variable men and aims to initialize it.

    unsigned char _sdcc_external_startup(void){
    ...
    return 1; //Ejecuta inmediatamente el "MAIN"
    }

    However skips initialization, so men will remain
    uninitialized ! The alternative solution does not depend on
    initialization and therefor works.

    Maarten

     
    • status: pending --> closed
     
  • Logged In: YES
    user_id=1312539

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).