Go Down

Topic: strange behavior on my prog ! (Read 2 times) previous topic - next topic

mrbbp

Mar 17, 2006, 12:26 am Last Edit: Mar 17, 2006, 12:31 am by mrbbp Reason: 1
Hi all,

well i've made a small prog base on the LCD Display tuto.
The soft is quite simple, it's like a calendar.
it write on the LCD a date like "lundi dix-sept janvier deux mille deux" (it's in french, but this is not really important)
strangely, the word "fevrier" doesn't appear in the sentence.
the soft write the month only at "mars" and other month but not february !!!!
if i delete "sAnnee" declaration, the prog doesn't work any more. (it's not in use in the prog)

have you an idea ?
i add a printString() by the serialport  to debugg.
would you try my prog and tell me if there is the same prob (with "fevrier") on your board.
I suppose there is an init prob with the vars... but why ! not enough memory ?
or have made a bad declaration ?

oh, it delete "janvier" too !

best regards

eric
:-[
Code: [Select]

//boolean b;
int RS = 12;
int RW = 11;
int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};
int Enable = 2;

// init poeme
int jour = 0;
int nJour = 17;
int mois = 2;
int an = 2;
char chaine[65] = " ";
char ligne[0x10] = "";
int jMax[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
const char *sNomJour[7] = {"dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"};
const char *sJour[33] = {"", " premier", " deux", " trois", " quatre", " cinq", " six", " sept", " huit", " neuf", " dix", " onze", " douze", " treize", " quatorze", " quinze", " seize", " dix-sept", " dix-huit", " dix-neuf", " vingt", " vingt-et-un", " vingt-deux", " vingt-trois", " vingt-quatre", " vingt-cinq", " vingt-six", " vingt-sept", " vingt-huit", " vingt-neuf", " trente", " trente-et-un", " mille"};
const char *sMois[13] = {"", " janvier", " fevrier", " mars", " avril", " mai", " juin", " juillet", " aout", " septembre", " octobre", " novembre", " decembre"};
const char *sAnnee[8] = {"", ""," deux mille deux", " deux mille trois", " deux mille quatre", " deux mille cinq", " deux mille six"};

void LcdCommandWrite(int value) {
 int i = 0;
 for (i=DB[0]; i <= RS; i++) {
   digitalWrite(i,value & 01);
   value >>= 1;
 }
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);
 // send a pulse to enable
 digitalWrite(Enable,HIGH);
 delayMicroseconds(1);
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);
}

void LcdDataWrite(int value) {
 // poll all the pins
 int i = 0;
 //delay(25);
 //printInteger(value);
 //printNewline();
 digitalWrite(RS, HIGH);
 digitalWrite(RW, LOW);
 for (i=DB[0]; i <= DB[7]; i++) {
   digitalWrite(i,value & 01);
   value >>= 1;
 }
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);
 // send a pulse to enable
 digitalWrite(Enable,HIGH);
 delayMicroseconds(1);
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);
}

void lcdGotoXY (int x, int y) {
 // depend of your LCD datasheet DDRAM adress
 int DDRAMadresses[]={0x80, 0xC0, 0x90, 0xD0}; // it's a 4X16 LCD DISPLAY
 int i, value;
 digitalWrite(RS, LOW);
 digitalWrite(RW, LOW);
 value = DDRAMadresses[x-1]+y;
 for (i=DB[0]; i <= DB[7]; i++) {
   digitalWrite(i,value & 01);
   value >>= 1;
 }
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);
 // send a pulse to enable
 digitalWrite(Enable,HIGH);
 delayMicroseconds(1);
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);
}

void printStringLCD(unsigned char *s)
{
 while (*s)
   LcdDataWrite(*s++);
}

void setup (void) {
 int i = 0;
 beginSerial(115200);
 for (i=Enable; i <= RS; i++) {
   pinMode(i,OUTPUT);
 }
 delay(100);
 LcdCommandWrite(0x30);
 delay(64);                      
 LcdCommandWrite(0x30);
 delay(50);                      
 LcdCommandWrite(0x30);
 delay(20);                      
 LcdCommandWrite(0x38);
 delay(20);                      
 LcdCommandWrite(0x6);
 //LcdCommandWrite(0x07);
 delay(20);                      
 LcdCommandWrite(0xE);
 delay(20);                      
 LcdCommandWrite(0x1);
 delay(100);                      
 LcdCommandWrite(0x80);
 delay(20);                      
}
void loop (void) {
 int i = 0;
 int j = 0;
 delay(4000);
 LcdCommandWrite(0x1);
 delay(10);
 LcdCommandWrite(0x2);
 delay(10);
 if (jour > 6) {jour = 0;}
 if (nJour > jMax[mois]) {nJour = 1; mois++;}
 if (mois == 2 && an == 3) { jMax[2] = 29;} else { jMax[2] = 28;}
 if (mois > 12) {mois = 1; an++;}

 // concatenation des chaines
 chaine[64] = " ";
 strcpy(chaine, sNomJour[jour]); // dimanche
 strcat(chaine, sJour[nJour]); // dix-sept
 strcat(chaine, sMois[mois]); // Février
 strcat(chaine, sJour[2]); // deux
 strcat(chaine, sJour[32]);// mille
 strcat(chaine, sJour[an]); // deux
 printString(chaine);
 printNewline();

 jour++;
 nJour++;
 // ecriture des lignes
 lcdGotoXY(1, 0);
 strncpy(ligne,chaine,16);
 if (strlen(ligne) >= 16) {
   ligne[16] = '\0';
 }
 // ecrit la ligne
 printStringLCD(ligne);
 delay(100);
 /*printInteger(an);
 printNewline();*/
 *ligne=" ";
 for (i=2; i<=4;i++) {
   lcdGotoXY(i, 0);
   strncpy(ligne,&chaine[16*(i-1)],16);
   if (strlen(ligne) >= 16) {
     ligne[16] = '\0';
   }
   // ecrit la ligne
   printStringLCD(ligne);
   delay(100);
   *ligne=" ";
 }
}

mellis

You may be running out of RAM on the ATmega8 (it only has 1KB).  Since your strings never change, you could try storing them only in program Flash memory (instead of RAM).  See:
http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_rom_array

mrbbp

Thank you Mellis...

i'll try your link.

a question: can we change the atmega16 for an atmega32 :
in the datasheet, the pin are the same... with 2K ram ?
have to burn the bootloader...

regards

eric

mrbbp

oops sorry.

it's atmega8 only 20 pins no 40 pins...
i suppose this is complex but can we add more ram :-? to the avr or do we need to change the microcontroler ?
i'm a bit confuse between the ram, the eeprom and the flash
the flash is to store the prog, the ram to store the vars and the eeprom ?

have you a link to help ? :-[

regards

eric

admin

hello

just to clarify a bit. There are three types of memory in the atmega8:
* Flash memory: it's a rewritable non-volatile memory. this means that its content will still be there if you turn off the power. it's a bit like the hard disk on the arduino board. your program is stored here.

* RAM: it's like the ram in your computer.its content disappears when you turn of the power but it can be read and writter really fast.

* EEPROM: it's an older technology to implement rewritable non-volatile memory. it's normally used to store settings and other parametres.

remember that only a few years ago flash memory was expensive and very few microcontroller had one. it was common to use OTP memory, which is a type of memory that can ony be written once and can't be reporgrammed anymore. in this situation if you want to store settings or parametres you need an EEPROM.

Lastly when you desing  a product, let's say an egg timer, that you manufacture in large quantity it is normal to buy the processors pre programmed (masked) by the factory. in this case not even a nuclear explosion will change the content of the program and the eeprom comes handy.

The link that mellis sent you allows you to use the program memory to store arrays which is very useful. We're using this technique to store strings for a UI prototype we're building for an appliance manufacturer.

hope this cleared the air a bit :)

Go Up