Pages: [1]   Go Down
Author Topic: strange behavior on my prog !  (Read 2045 times)
0 Members and 1 Guest are viewing this topic.
Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
//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=" ";
  }
}
« Last Edit: March 16, 2006, 06:31:43 pm by mrbbp » Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Forum Administrator
Offline Offline
Newbie
*****
Karma: 3
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged

Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well thanks for helps...

i've try this code... from your link

Code:
#include <avr/pgmspace.h>

PGM_P array[2] PROGMEM = {
    "Foo",
    "Bar"
};

void loop ()
{
    char buf[32];
    strcpy_P (buf, array[1]);
    return 0;
}

and have received this error ;
"unexpected token:array" :-/

don't know !

i've tried the second exemple, same result :
"unexpected token:const"

do i need to add pgmspace.h somewhere ?

regards

eric
Logged

Forum Administrator
Offline Offline
God Member
*****
Karma: 52
Posts: 639
I find plain exciting
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hmm it's a tricky issue

it's a problem with include files and the rest

I have to do some tests with C files before..
I need a few days because we are very very very busy at the moment..


massimo
Logged

Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No prob massimo :-[
take your time.
I'll be patient.

thanks for your help

eric
Logged

berlin
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi guys,

i'm wondering if you figured this out in the meantime!?

as documented in another thread, i am interfacing a graphical LCD.
The original code (threw in by massimo) defines the ASCII characters in pixels.

like that:

Code:
static const byte FontLookup [][5] =
{
  {
    0x7E, 0x11, 0x11, 0x11, 0x7E     }
  ,   // A
  {
    0x7F, 0x49, 0x49, 0x49, 0x36     }
  ,   // B
  {
    0x3E, 0x41, 0x41, 0x41, 0x22     }
  ,   // C
  {
    0x7F, 0x41, 0x41, 0x22, 0x1C     }
     //D
//...
}
using this code the array is stored in RAM right? or is it in the flash memory??? (BTW what does the "static const" declaration do exactly?)

since every character takes 5 Bytes of memory and there are 95 printable ascii characters, i'm constantly running out of memory when working on the code. those 512 bytes of eeprom would come very handy!

is there a way to put all those pixel bytes into the eeprom using the ide? if i understand it right, the bootloader just copies the program into the flash-memory. is the bootloader able to write into eeprom at all?

i know i could copy the bytes from the RAM to the EEPROM using eeprom_write_byte(adr,val); but as it looks i'm not even able to get the program up running with *every* ascii character describe. :-(

another question:

is the eeprom used for anything when doing *normal* arduino stuff (no fancy c)? as a buffer for serial communication or something? or some debugging data maybe? just because it wasn't empty when i first accessed it for testing.


hope to hear from you.
i whish you all a nice easter weekend.

kuk

Logged

Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
BTW what does the "static const" declaration do exactly?

"static const byte FontLookup [][5] ="

static : that mean the compiler attribute a fixed adress in ram
constant : that doesn't vary along the prog !
byte : this is the type of your constant...

i think the solution of your prob, is the same of mine...
we have to wait a bit more for a solution.
put your patience under your foot and wait :smiley

my two pences...

eric
« Last Edit: April 14, 2006, 12:02:02 pm by mrbbp » Logged

Forum Administrator
Offline Offline
God Member
*****
Karma: 52
Posts: 639
I find plain exciting
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Eric


can you try this code??

Code:

const char *sNomJour[7]   __attribute__((section(".eeprom"))) = {"dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"};

void setup() {
 beginSerial(9600);
}


void loop() {


   printString(sNomJour[2]);


}




not sure it's going to work but I forced the program to store the array in the eeprom

can you try this technique with your code?

see if it solves the problem

massimo



Logged

Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i've tried this :
Code:
const char *sNomJour[7] = {"dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"};
const char *sJour[33]   __attribute__((section(".eeprom"))) = {"", " 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"};
and have as result
Quote
mercrediü fevrierüü
jeudir fevrierüü
vendredi¨ fevrierüü
samedi fevrierüü
dimanche fevrierüü

i've tried this :
Code:
const char *sNomJour[7] __attribute__((section(".eeprom"))) = {"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"};

result :
Quote
ç dix-sept fevrier deux mille deux
t dix-huit fevrier deux mille deux
ü dix-neuf fevrier deux mille deux
 vingt fevrier deux mille deux
 vingt-et-un fevrier deux mille deux

i think this not the good solution :'(

regards

eric
Logged

berlin
Offline Offline
Sr. Member
****
Karma: 0
Posts: 293
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i can't get it work neither.

Code:
const char *sNomJour[7]   __attribute__((section(".eeprom"))) = {"dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"};
i don't think that this line writes anything to eeprom

i read out the eeprom in the main loop function afterwards but it always showed the values that i put there the run before.
Code:
      int EEadr;
      
      for ( EEadr=0;  EEadr<512;  EEadr++){

        value1 = eeprom_read_byte(EEadr);

        printInteger(EEadr);
        printByte(62); //">"
        printHex(value1);
        
        printNewline();
     // eeprom_write_byte(EEadr,0xDD); //uncommented in the second run
      }
is giving out 0xDD for all addresses.  :-/
« Last Edit: April 14, 2006, 06:01:07 pm by leKuk » Logged

Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,

i've find in avrfreak forum a thread about how to put cosntant in flash...

http://www.avrfreaks.com/index.php?name=PNphpBB2&file=viewtopic&t=36339&highlight=enough+ram+var&sid=ac0aaea81038b29246ff1a3bb17834a7

but i'm not sure to understand with my poor knowledge... :-[ do you think it works ?
and what code do the trick :-/

sorry...
any help will be cool... :-*

eric
« Last Edit: May 04, 2006, 04:50:54 pm by mrbbp » Logged

Pages: [1]   Go Up
Jump to: