Pages: [1]   Go Down
Author Topic: How to get Font from EEPROM  (Read 1140 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 Hello every boby.

Code:
for (byte c=0; c<8; ++c) {          
     for (byte y=0; y<8; ++y) {
            byte data = (byte) pgm_read_byte (&myfont[disp[line][c]][y]);   // fetch data from program memory
              for (byte x=0; x<8; ++x) {
                if (data & (1<<x)) {
                   // on is off
                   int color = 2;
                   if (line > 1)
                     color = 1;
                    
                   set_pixel((7-x) + (line * 8),y + (c*8),color);
                } else {
                    //set_pixel(x,y,1);
                }
            }
        }
}

}

This is available code ,which i downloaded ,but i don't know how to use detail this syntax :
data = (byte) pgm_read_byte (&myfont[disp[line][c]][y])
This code is so complex ,can you give me some codes simpler ,because i search on Google serveral days ,but difficult to found  smiley-cry smiley-cry

Thanks
« Last Edit: October 02, 2012, 07:25:16 am by taipscode » Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

EEPROM != PROGMEM

It's difficult to help with just a code snipped. Please post all the info you have, especially what you're trying to achieve.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes,this is a full source.pde
http://www.mediafire.com/?1o5eptd3avscb61
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice!

Have you noticed this line in font.h ?

Code:
const prog_uint8_t PROGMEM BitMap[8] = {                                   // Store in program memory to save RAM

PROGMEM is where the program(!) is stored. RAM and EEPROM are other two types of memory you find in Arduino (well, inside the Atmega328P, actually).

pgm_read_byte is a special function that reads a byte from PROGMEM and brings it into RAM, so it can be used by the program.

I won't repeat here with my own (poor) words what has already been written elsewhere in great detail. Search for PROGMEM.

smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I only want how to use this syntax
data = (byte) pgm_read_byte (&myfont[disp[line][c]][y])

not const prog_uint8_t PROGMEM BitMap[8] = {

Thanks             

Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please read my previous reply.

Also, I don't find it clear what you're trying to do...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 Yes, i hope you don't reply with not useful  smiley-mad

Thanks
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's the wrong smiley to use when asking for FREE help.

Good luck with your project.

(edit: maybe you misunderstood my previous answer: what I meant is that I don't understand what you're trying to achieve; it wasn't a judgement about your project (which I don't know))
« Last Edit: October 02, 2012, 08:01:23 am by tuxduino » Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 142
Posts: 5296
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I only want how to use this syntax
data = (byte) pgm_read_byte (&myfont[disp[line][c]][y])

not const prog_uint8_t PROGMEM BitMap[8] = {


pgm_read_byte() is a function in the Arduino library.


Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think it is general avr-libc, rather that Arduino specific.

http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

data = (byte) pgm_read_byte (&myfont[disp[line][c]][y])

data = (get 8 pixels ) from (a font-character[pointed to by disp[currentline][current_character][current_character_pixel_line].

Which is a complicated way of Saying

if disp[line] = "A simple test"
then disp[line][0] = "A"
       disp[line][1] = " "
       disp[line][2] = "s"
       ... etc

then &myfont[] returns the address of a character inside a font array which holds the (8 x 8 pixels) character.
So &myfont[disp[line][0]] would return the address to the letter "A" in the font array.

&myfont[disp[line][0]][y] would return 8 pixels of row [y] of the letter "A"
This technique is used to convert a letter to pixels. e.g. (8x8 pixel font)


.  .  .  .  .  .  .  .
.  .  .  X  .  .  .  .
.  .  X  .  X  .  .  .
.  X  .  .  .  X  .  .       =>  A
.  X  X  X  X  X  .  .
X  .  .  .  .  .  X  .
X  .  .  .  .  .  X  .
.  .  .  .  .  .  .  .


It's reading 8 pixels as a byte.
Your code then loops through this code with for (byte x=0; x<8; ++x)
And draws a pixel on the screen if it found a pixel in the font.

Thats about it.
Logged

Pages: [1]   Go Up
Jump to: