C Anzeigeroutine LED Matrix

Janiiix3

Aktives Mitglied
28. Sep. 2013
1.333
10
38
Hannover
Sprachen
  1. ANSI C
  2. C#
Hallo Leute,

ich habe mal wieder folgendes Problem...

Und zwar möchte ich diese Routine umschreiben, so das sie mit "Variablen" Strings arbeiten kann.
Ist das überhaupt möglich?

Hier die Routine die mit statischen Strings arbeitet z.B "Hallo Welt"...

Code:
void scroll_display(const char *s,uint8_t speed) {
    // clear display
    ledarray_blank();
    int8_t offset = 0 , next_offset = 0;
    uint8_t is_started = 0;
    uint8_t y=0;
    char x=' ';
    if(speed==0)
    speed=90;
    
    // begin loop and continue until nul character at end of string
    while(pgm_read_byte(s) != 0x00){
        
        // have we read a character?
        if(is_started) {
            // if so, place and shift the character until it is clear of column (COLS-1)
            while(next_offset>(COLS-1)){
                delay_ms(speed);
                // shift the display one place
                ledarray_left_shift();
                // check the end of the currently displayed characters if it's greater than zero, decrement
                // both the offset (character display position), and next_offset(character end position)
                if(next_offset > 0) {
                    offset -= 1;
                    next_offset -= 1;
                }
                // display the character at the new position
                font_display(x, offset);
            }
            } else {
            // if not, set offset to # of columns -1 ((COLS-1))
            offset = COLS-1;
        }
        // read the next character in the string
        x = pgm_read_byte(s++);
        
        // if we have already started, set the current display position to where the last character ended
        if(is_started)
        offset = next_offset;
        // display the character
        font_display(x, offset);
        // create the new character end position
        next_offset = offset + font_width(x)+1;
        // set Enable_DCF77_Scan to show we have been through the loop
        is_started = 1;
    }
    // Process the last character.  This is neccessary since the while bails as soon as it reads
    // the null character.  At that point, the last read character has not yet shifted into full
    // view.  The following while loop shifts the final string character into full view.
    while(next_offset>(COLS-1)){
        delay_ms(speed);
        ledarray_left_shift();
        if(next_offset > 0) {
            offset -= 1;
            next_offset -= 1;
        }
        font_display(x, offset);
    }
    
    delay_ms(speed);
    // this final loop shifts the display all the way off.
    for(y=0;y<COLS;y++){
        ledarray_left_shift();
        delay_ms(speed);
    }
    
    return;
}
 
Hi
Da mein C mangelhaft ist, könnt ich mich irren, aber übergib doch der Routine einfach mal "Guten Morgen" statt "Hallo Welt". So wie ich das sehe, ist in der Variablen s der String, aus dem dann in der Schleife Zeichen für Zeichen herausgelesen wird, bis ein 0-zeichen kommt. Das ist das Ende-Zeichen des String.
Gruß oldmax
 
Im vorliegendem Code-Fragment werden die darzustellenden Bytes (Chars) mit "pgm_read_byte(Adresse)" gelesen und zugewiesen. Offensichtlich also aus dem Program-Flash.
Für Dich als C-Programmierer sollte es doch kein Ding sein, das auf den SRAM umzustricken. Müßte auf'ne Zuweisung wie "x=Array(Adresse)" raus laufen, wobei ein String ja so was wie ein Array oft Char ist.

Irgendwo ausserhalb dieses Codes dann den Text ins SRAM knallen, wie auch immer Du das willst.
 
Du meinst einen String im SRAM verwenden, nicht im FlashMemory?

Zum Beispiel prinzipiell so ...
[CCODE]void meineroutine (char *s)
{
char x;

while (*s) // solange Inhalt der Adresse (Pointer) ungleich '\0'
{
x = (char)*s;
s++; // Pointer inkrementieren

// ... mit x irgendwas machen

}
}
[/CCODE]
 
Hallo :)

ich habe die Funktion ein bisschen angepasst (laut Dirk)... hoffentlich habe ich das richtig gedeuetet und umgesetzt...

So sieht meine aktuelle Routine aus...

Code:
void scroll_display(const char *s,uint8_t speed) {
    // clear display
    ledarray_blank();
    int8_t offset = 0 , next_offset = 0;
    uint8_t is_started = 0;
    uint8_t y=0;
    char x=' ';
    if(speed==0)
    speed=90;
    
    // begin loop and continue until nul character at end of string
    while(*s){
        
        // have we read a character?
        if(is_started) {
            // if so, place and shift the character until it is clear of column (COLS-1)
            while(next_offset>(COLS-1)){
                delay_ms(speed);
                // shift the display one place
                ledarray_left_shift();
                // check the end of the currently displayed characters if it's greater than zero, decrement
                // both the offset (character display position), and next_offset(character end position)
                if(next_offset > 0) {
                    offset -= 1;
                    next_offset -= 1;
                }
                // display the character at the new position
                font_display(x, offset);
            }
            } else {
            // if not, set offset to # of columns -1 ((COLS-1))
            offset = COLS-1;
        }
        // read the next character in the string
        x = (char)*s;
        s++;
        
        // if we have already started, set the current display position to where the last character ended
        if(is_started)
        offset = next_offset;
        // display the character
        font_display(x, offset);
        // create the new character end position
        next_offset = offset + font_width(x)+1;
        // set Enable_DCF77_Scan to show we have been through the loop
        is_started = 1;
    }
    // Process the last character.  This is neccessary since the while bails as soon as it reads
    // the null character.  At that point, the last read character has not yet shifted into full
    // view.  The following while loop shifts the final string character into full view.
    while(next_offset>(COLS-1)){
        delay_ms(speed);
        ledarray_left_shift();
        if(next_offset > 0) {
            offset -= 1;
            next_offset -= 1;
        }
        font_display(x, offset);
    }
    
    delay_ms(speed);
    // this final loop shifts the display all the way off.
    for(y=0;y<COLS;y++){
        ledarray_left_shift();
        delay_ms(speed);
    }
    
    return;
}

In einer ISR zähle ich eine Variable hoch... diese wollte ich (zum Test erstmal) auf meinem Display als Laufschrift darstellen.
Dort kommen meist nur Sonderzeichen...

so rufe ich die Funktion auf...

Code:
scroll_display(&ms_counter,20);

ist es denn richtig, dass ich der Funktion die Adresse von der Variable übergebe?
 
Ja du übergibst die Adresse.

mscounter ist ja ein String, ein char array.

Die Startadresse des Arrays (Adresse des ersten Elements) erhältst du einfach durch den Bezeichner der Variable, also einfach

mscounter

oder auch durch den & Operator wenn du das array mit index=0 adressierst ...

&mscounter[0]
 
Okay...

Wenn ich jetzt eine Variable ausgeben will kommen immer nur "Sonderzeichen"...

z.B...

Code:
uint8_t Variable = 12;

gebe ich sie jedoch so an...

Code:
uint8_t Variable = "12";

kommt meine Zahl... Muss ich es evtl. vorher noch in ASCII umrechnen?
 
Ich komme irgendwie nicht ganz mit dem "struct" klar...
Kann evtl. jemand einen Blick in meinen Header "RX8564.h" werfen?

Bekomme ständig die Warnung

Code:
Warning    1    useless storage class specifier in empty declaration [enabled by default]    C:\Users\Hm\Desktop\DaJa_Clock_Deluxe\DaJa_Clock_Deluxe\RX8564.h    53    16    DaJa_Clock_Deluxe
 

Anhänge

  • RX8564.zip
    985 Bytes · Aufrufe: 1
Hat sich erledigt... Die initalisierung war nicht richtig...

Code:
/* hours, minutes, secounds, day, month, year, day_name */
rtc rx8564 = {12,00,00,01,01,15,01};

so klappts ;)
 

Über uns

  • Makerconnect ist ein Forum, welches wir ausschließlich für einen Gedankenaustausch und als Diskussionsplattform für Interessierte bereitstellen, welche sich privat, durch das Studium oder beruflich mit Mikrocontroller- und Kleinstrechnersystemen beschäftigen wollen oder müssen ;-)
  • Dirk
  • Du bist noch kein Mitglied in unserer freundlichen Community? Werde Teil von uns und registriere dich in unserem Forum.
  •  Registriere dich

User Menu

 Kaffeezeit

  • Wir arbeiten hart daran sicherzustellen, dass unser Forum permanent online und schnell erreichbar ist, unsere Forensoftware auf dem aktuellsten Stand ist und der Server regelmäßig gewartet wird. Auch die Themen Datensicherheit und Datenschutz sind uns wichtig und hier sind wir auch ständig aktiv. Alles in allem, sorgen wir uns darum, dass alles Drumherum stimmt :-)

    Dir gefällt das Forum und unsere Arbeit und du möchtest uns unterstützen? Unterstütze uns durch deine Premium-Mitgliedschaft!
    Wir freuen uns auch über eine Spende für unsere Kaffeekasse :-)
    Vielen Dank! :ciao:


     Spende uns! (Paypal)