Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

function of pgm_read_byte() in Adafruit_GFX.cpp
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

function of pgm_read_byte() in Adafruit_GFX.cpp

by jimwang90 on Fri Jan 29, 2016 4:00 pm

what is this function for? where I can find the code? thank you

jimwang90
 
Posts: 41
Joined: Sat Jan 23, 2016 10:13 pm

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by adafruit_support_rick on Sat Jan 30, 2016 12:37 pm

That function is part of AVR LibC: http://nongnu.org/avr-libc/user-manual/ ... space.html

The AVR processor architecture splits program and data into two separate address spaces. The pgmspace library allows you to read program space as if it were data space.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by jimwang90 on Sat Jan 30, 2016 6:25 pm

what is return of this function ? AVR memory address? thanks

jimwang90
 
Posts: 41
Joined: Sat Jan 23, 2016 10:13 pm

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by adafruit_support_rick on Sun Jan 31, 2016 9:51 am

It returns the value of a byte stored in program space.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by jimwang90 on Mon Feb 01, 2016 10:15 am

Thank you,
I use ILI9341 LCD, there is a the source code " line = pgm_read_byte(font+(c*5)+i); " in the DrawChar() function , I think there is a data set which are saved in AVR memory. I also found there is another file glcdfont.c that define a data array Font[], I guess the code of " line = pgm_read_byte(font+(c*5)+i); " will read the value from Font[]. right?

jimwang90
 
Posts: 41
Joined: Sat Jan 23, 2016 10:13 pm

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by adafruit_support_rick on Mon Feb 01, 2016 11:43 am

That's right. The data memory on the AVR 328 and 32U4 chips is very small, and is not able to hold the entire font. So the font is stored in program space, where there is more room. pgm_read_byte is used to retrieve the font data from program space.

You can read more about Arduino memories here:
https://learn.adafruit.com/memories-of-an-arduino

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by jimwang90 on Mon Feb 01, 2016 5:11 pm

thanks,
delay(200) defined in Arduino.h, how long it will be delay ? I have UNO board.
maybe based on main clock ? 200 main clock time?
what is UNO board main clock?

jimwang90
 
Posts: 41
Joined: Sat Jan 23, 2016 10:13 pm

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by adafruit_support_rick on Tue Feb 02, 2016 9:19 am

delay(200) will wait for 200 milliseconds

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by jimwang90 on Tue Feb 02, 2016 1:30 pm

what is follow code do? what is value of _reset? where can find the code of function digitalWrite(_reset, LOW);

#ifdef USE_ADAFRUIT_SHIELD_PINOUT
digitalWrite(5, LOW);
delay(2);
digitalWrite(5, HIGH);
#else
if(_reset) {
digitalWrite(_reset, LOW);
delay(2);
digitalWrite(_reset, HIGH);
}
#endif

thanks a lots

jimwang90
 
Posts: 41
Joined: Sat Jan 23, 2016 10:13 pm

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by adafruit_support_rick on Wed Feb 03, 2016 9:45 am

That code is not part of the Adafruit_GFX library. What library are you using?

_reset is a member variable of the library's class. You will find it in the class declaration in the library's .h file.
It contains a pin number passed by the class constructor call in your sketch. The pin should be connected to to reset line of the device you're using.

If you are using a shield deice, the reset line is automatically connected, and the reset operation is performed. If you are using a breakout device, it is possible to operate the device without the reset line connected. In that case the value of _reset would be -1.

So the code performs the reset if you are using a shield. If you are using a breakout, the reset is only performed if you specify a reset pin in the constructor.

The reset itself is done by setting the reset pin LOW for 2 milliseconds, and then setting it back to HIGH.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by jimwang90 on Wed Feb 03, 2016 4:01 pm

Actually I use a breakout Board, I connect it with my design,which is MSP430 board, by parallel port. I am trying to use this ILI9341 LCD in my system, I already copy and modify some code from your library, but its is not work.
may be I disable the follow code, because I can not find this function: digitalWrite()
because I use a breakout, based on your instruction, there is no any connection to RST pin of LCD, how they reset it?
like you said, can I use one of my microprocessor pin to control the RST pin ? put LOW for 2ms then put it high back.

thank you for so much help ! I still need your more help in order to use this LCD, actually, my project is for our new products that may be 10000 per year.

jimwang90
 
Posts: 41
Joined: Sat Jan 23, 2016 10:13 pm

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by jimwang90 on Wed Feb 03, 2016 4:07 pm

it is a part of Adafruit_GFX library, this function found in Adafruit_TFTLCD.cpp, source code as follow:

void Adafruit_TFTLCD::reset(void) {

CS_IDLE;
// CD_DATA;
WR_IDLE;
RD_IDLE;

#ifdef USE_ADAFRUIT_SHIELD_PINOUT
digitalWrite(5, LOW);
delay(2);
digitalWrite(5, HIGH);
#else
if(_reset) {
digitalWrite(_reset, LOW);
delay(2);
digitalWrite(_reset, HIGH);
}
#endif

// Data transfer sync
CS_ACTIVE;
CD_COMMAND;
write8(0x00);
for(uint8_t i=0; i<3; i++) WR_STROBE; // Three extra 0x00s
CS_IDLE;
}

jimwang90
 
Posts: 41
Joined: Sat Jan 23, 2016 10:13 pm

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by jimwang90 on Wed Feb 03, 2016 4:19 pm

I disable these code in UNO board, it is no problem. So this is not the reason why my msp430 can not run.

jimwang90
 
Posts: 41
Joined: Sat Jan 23, 2016 10:13 pm

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by adafruit_support_rick on Thu Feb 04, 2016 10:54 am

digitalWrite and delay are not C library functions. They are part of the Arduino runtime library.
You will have to write your own versions of these functions. The documentation on the Arduino runtime functions is here:
https://www.arduino.cc/en/Reference/HomePage

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: function of pgm_read_byte() in Adafruit_GFX.cpp

by jimwang90 on Thu Feb 04, 2016 2:43 pm

OK, my modified code is work now, thank you very much.
I will looking the touch screen function next.

jimwang90
 
Posts: 41
Joined: Sat Jan 23, 2016 10:13 pm

Please be positive and constructive with your questions and comments.