Forum: Compiler & IDEs Fonts aus FLASH ins EEPROM legen


von Denny D. (denny)


Lesenswert?

Hallo allerseits,

nach Stundenlangen und vielen Recherchen im Netz komme ich an einer 
Stelle einfach nicht weiter.
Ich bin noch ziemlich in den Kinderstuben was WinAVR und AVR
Programmierung in C angeht, und hoffe mir kann hier jemand im Forum 
weiter helfen.

Der unten angefügte Quelltext nutzt den FLASH des Atmel(mega128) um
Fonts für ein LCD Display dort abzulegen.

Ich würde gern die Funktion umschreiben und die Fonts ins EEPROM legen 
um sie dann daraus lesen zu können.

#include <avr/pgmspace.h>
wurde durch
#include <avr/eeprom.h>
ersetzt

Ich habe versucht:
prog_char ascii_7x11[95][14] = {

entsprechend umzuschreiben in:
__attribute__((section(".eeprom"))) unsigned char ascii_7x11[95][14] = {

und die Zeile:
tx = pgm_read_byte(&ascii_7x11[row][m])   ;  //Read data Ascii

in:
tx = eeprom_read_block(&ascii_7x11[row][m])   ;  //Read data Ascii



Der Quelltext ist auf das wesentliche gekürzt:
1
/******************************************************
2
 *       Font 7x11(English)                  *
3
 *                                *
4
 * -ASCII fonts from 0x20 ~ 0x7F(DEC 32 ~ 126)         *
5
 *  composed of following characters             *
6
 *                                                    * 
7
 * -XSize : 7  pixcels                    *
8
 * -YSize : 11 pixcels                       *
9
 *                                 *
10
 *   ....... <- b0, Blank, Not used              *
11
 *   ....... <- b1, Blank, Not used              *
12
 *   ....... <- b2, Blank, Not used              *
13
 *   ....... <- b3, Blank, Not used              *
14
 *   ....... <- b4, Blank, Not used              *
15
 *   ..End.. <- b5(2nd byte)                *
16
 *   ..OO... <- b6(2nd byte)                *
17
 *   ..OO... <- b7(2nd byte)                *
18
 *   ..OO... <- b0(1st byte)                *
19
 *   ..OO... <- b1(1st byte)                *
20
 *   ..OO... <- b2(1st byte)                *
21
 *   ..OO... <- b3(1st byte)                *
22
 *   ..OO... <- b4(1st byte)                 *
23
 *   ..OO... <- b5(1st byte)                *
24
 *   ..OO... <- b6(1st byte)                *
25
 *   .Start..<- b7(1st byte)                *
26
 *                              *
27
 ******************************************************/
28
29
//7x11 ascii font, each character takes 14 bytes, total 1330 bytes, draw from left bottom to left top
30
prog_char ascii_7x11[95][14] = {                                                       
31
  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f}, //0x20 space
32
  {0x00, 0x00, 0x07, 0xc0, 0xdf, 0xe0, 0xdf, 0xe0, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x1f}, //0x21 !
33
.
34
.
35
.
36
  {0x00, 0x00, 0x80, 0x20, 0xe0, 0xe0, 0x7f, 0xc0, 0x04, 0x00, 0x00, 0x00, 0x00, 0x5f}, //0x7d }
37
  {0x00, 0x60, 0x00, 0x20, 0x00, 0x60, 0x00, 0xc0, 0x00, 0x80, 0x00, 0xc0, 0x00, 0x5f}  //0x7e ~
38
};
39
40
//********************************************************************************
41
//**                Function Print Text 1 Charecter size 7x11                   **
42
//********************************************************************************
43
//**    Parameter :                                **
44
//**               row      = Ascii Code (Position buffer keep text)        **
45
//**               adx,ady  = Position X,Y for begin plot text by will       **
46
//**                          begin plot from bottom left to top left       **
47
//**               fg_clr   = Color of text                    **
48
//**               bg_clr   = Color background of text(if bg_clr = no_bg or 1=  **
49
//**                          non color background)                **
50
//********************************************************************************
51
52
53
 void text_7x11(unsigned char row,int adx,int ady,unsigned int fg_clr,unsigned int bg_clr)
54
  {
55
   int ax,ay                   ;
56
   unsigned char m,n,tx        ;
57
     
58
   ax = adx         ;
59
   ay = ady         ; 
60
61
   row = row-0x20   ;
62
63
  //------- Print Text 1 Charecter(data 14 Byte) -------------
64
    
65
    for(m=0;m<14;m++)
66
     {
67
      //---Sent data byte1=8 bit----
68
69
        tx = pgm_read_byte(&ascii_7x11[row][m])   ;  //Read data Ascii
70
  
71
    for(n=0;n<8;n++)           //Loop Sent data  1 byte(8bit)
72
     {
73
        if(tx & 0x80)           //if data bit7 = 1 ,Plot Color area Charecter
74
      {              
75
        gp_wr_cmm(0x20)       ;  //Command Set Adddress Hor(X)
76
              gp_wr_data(ay)        ;  //Sent X_Address CGRAM       
77
              gp_wr_cmm(0x21)       ;  //Command Set Address Ver(Y)
78
              gp_wr_data(ax)        ;  //Sent Y_Address CGRAM
79
        gp_wr_cmm(0x22)       ;  //Command Write data 
80
              gp_wr_data(fg_clr)    ;
81
 
82
      }
83
      else               //if data bit7 = 0 ,Plot Color area back ground Charecter
84
      {
85
        if(bg_clr != 1)     
86
              {
87
         gp_wr_cmm(0x20)       ;  //Command Set Adddress Hor(X)
88
               gp_wr_data(ay)        ;  //Sent X_Address CGRAM  
89
               gp_wr_cmm(0x21)       ;  //Command Set Adddress Ver(Y)
90
               gp_wr_data(ax)        ;  //Sent Y_Address CGRAM
91
         gp_wr_cmm(0x22)       ;  //Command Write data
92
               gp_wr_data(bg_clr)    ;  //Sent Data
93
        }
94
      }
95
96
       tx <<= 1                 ;  //Shift Right data 1 bit
97
       ay   = ay+1              ;  //Increment Y-address
98
     } 
99
100
     m++                        ;  //Increment Next pointter byte Data 
101
102
103
      //------- Sent data byte2=3 bit -----
104
105
     tx = pgm_read_byte(&ascii_7x11[row][m])    ;  //Read data byte2
106
  
107
    for(n=0;n<3;n++)         //Loop sent data byte2 = 3 bit
108
     {                ;
109
        if(tx & 0x80)           //if data bit7 = 1 ,Plot Color area Charecter
110
      {              
111
        gp_wr_cmm(0x20)       ;  //Command Set Adddress Hor(X)
112
              gp_wr_data(ay)        ;  //Sent X_Address CGRAM    
113
              gp_wr_cmm(0x21)       ;  //Command Set Adddress Ver(Y)
114
              gp_wr_data(ax)        ;  //Sent Y_Address CGRAM
115
        gp_wr_cmm(0x22)       ;  //Command Write data
116
              gp_wr_data(fg_clr)    ;
117
 
118
      }
119
      else               //if data bit7 = 0 ,Plot Color area back ground Charecter
120
      {
121
        if(bg_clr != 1)     
122
              {
123
         gp_wr_cmm(0x20)       ;  //Command Set Adddress Hor(X)
124
               gp_wr_data(ay)        ;  //Sent X_Address CGRAM       
125
               gp_wr_cmm(0x21)       ;  //Command Set Adddress Ver(Y)
126
               gp_wr_data(ax)        ;  //Sent Y_Address CGRAM
127
         gp_wr_cmm(0x22)       ;  //Command Write data
128
               gp_wr_data(bg_clr)    ;
129
        }
130
      }
131
132
       tx <<= 1                 ;  //Shift Right data 1 bit
133
       ay = ay+1                ;  //Increment Y-address
134
     } 
135
136
    ax = ax+1                   ; //Complet sent data 2 byte(11bit) Increment X-Address
137
    ay = ady                    ; //Set Position Y-address old
138
 
139
    }  
140
141
142
   //----Fill Back ground Color Position space between Charecter 1 Colum -------
143
 
144
     if(bg_clr != 1)     
145
     {
146
    for(n=0;n<11;n++)
147
    {
148
      gp_wr_cmm(0x20)            ;  //Command Set Adddress Hor(X)
149
        gp_wr_data(ay)             ;  //Sent X_Address CGRAM       
150
        gp_wr_cmm(0x21)            ;  //Command Set Adddress Ver(Y)
151
        gp_wr_data(ax)             ;  //Sent Y_Address CGRAM
152
      gp_wr_cmm(0x22)            ;  //Command Write data
153
        gp_wr_data(bg_clr)         ;
154
    ay = ay+1                  ;  //Increment Y-Address
155
    }
156
     }
157
  }

von Karl H. (kbuchegg)


Lesenswert?

Denny D. schrieb:
> Hallo allerseits,
>
> nach Stundenlangen und vielen Recherchen im Netz komme ich an einer
> Stelle einfach nicht weiter.

Und das heißt jetzt konkret was?

> Ich würde gern die Funktion umschreiben und die Fonts ins EEPROM legen
> um sie dann daraus lesen zu können.

oooo kay

> #include <avr/pgmspace.h>
> wurde durch
> #include <avr/eeprom.h>
> ersetzt

klingt gut

> Ich habe versucht:
> prog_char ascii_7x11[95][14] = {
>
> entsprechend umzuschreiben in:
> __attribute__((section(".eeprom"))) unsigned char ascii_7x11[95][14] = {


ist auch nicht schlecht. Mit dem vordefinierten Makro EEMEM kann man das 
noch kürzer schreiben, aber prinzipiell ist es ok.

>
> und die Zeile:
> tx = pgm_read_byte(&ascii_7x11[row][m])   ;  //Read data Ascii
>
> in:
> tx = eeprom_read_block(&ascii_7x11[row][m])   ;  //Read data Ascii
>

eeprom_read_byte

Aber abgesehen davon ... ja, klingt gut

> Der Quelltext ist auf das wesentliche gekürzt:

Und deine Frage ist jetzt genau was?

(Hast du vielleicht vergessen das entstehende EEP File auch ins EEPROM 
zu brennen? Irgendwie müssen die Werte da ja auch reinkommen.)

http://www.mikrocontroller.net/articles/AVR-GCC-Tutorial#EEPROM

von Denny D. (denny)


Lesenswert?

Hallo Karl-Heinz,

vielen dank für deine Hilfe.

eeprom_read_byte war des Rätsels Lösung!!

Ich habe die ganze Zeit versucht mittels eeprom_read_block die Fonts zu 
lesen, was natürlich falsch war...
...aber wie das manchmal so ist, "Man sieht den Wald vor lauter Bäumen 
nicht"

WinAVR meckerte beim kompilieren über "too few arguments to function 
'__eerd_block_m128'.

Nachdem ich nun eeprom_read_byte anstatt eeprom_read_block verwendet 
hatte,
kompilierte WinAVR ohne Fehler das HEX und EEP File.

Vielen Dank nochmal
Gruß Denny

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.