1 / 5

avr-libc provides a subset of the standard C library for AVR microcontrollers.

Using avr-libc. avr-libc provides a subset of the standard C library for AVR microcontrollers. avr-libc also provides necessary startup code for most applications. Details (oh, are there details) are linked from the class web page at:

porter
Télécharger la présentation

avr-libc provides a subset of the standard C library for AVR microcontrollers.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using avr-libc avr-libc provides a subset of the standard C library for AVR microcontrollers. avr-libc also provides necessary startup code for most applications. Details (oh, are there details) are linked from the class web page at: Many categories of libc modules to make embedded programming easier: -Delay loops -EEPROM access -character operations -integer conversions -math operations -string operations -interrupts http://www.nongnu.org/avr-libc/user-manual/index.html

  2. Using avr-libc More examples using avr-libc Character operations... #include <string.h> //right justify results on the LCD for(i=0; i<=(14–(strlen(lcd_str) + strlen(lcd_str1))); i++) char2lcd(‘ ‘); Fake floating point math and print results #include <stdlib.h> div_t fp_adc_result, fp_low_result; //double fp_adc_result; fp_adc_result = div(adc_result, 205); //should be 204.8 to be exact low = fp_adc_result.rem; high = fp_adc_result.quot; fp_low_result = div((low*100), 205); //set decimal fraction itoa(fp_low_result.quot, lcd_str, 10); //convert to ascii string itoa(high, lcd_str1, 10); //convert to ascii string Convert integers to ascii scring

  3. Using avr-libc Examples using avr-libc Character conversion: Setup a interrupt service routine. The ISR created will save registers for you and will disable interrupts when entering the ISR. #include <stdlib.h> itoa(frequency, lcd_freq_str, 10); //convert integer to ASCII string #include <avr/interrupt.h> /***********************************************************************/ // timer/counter 1 ISR //When the TCNT1 compare1A interrupt occurs, port F bit 4 is toggled. //This creates the alarm sound from the clock. /***********************************************************************/ ISR(TIMER1_COMPA_vect){ if (alarm_enable == 1) //toggle port F bit 4 if valid button pushed PORTF ^= 0x10; }//ISR

  4. Using avr-libc Examples using avr-libc Generating timing delays: Note: compiler optimizations must be enabled and the delay time must be an expression that is a known constant at compile-time. #defineF_CPU must be defined as a constant. It defines the CPU clock frequency (in Hertz). The maximal possible delay is 262.14 ms / F_CPU in MHz. If the user requests more delay, resolution is limited to 0.1mS and user will not be notified. See avr-libc Function Documentation for details. There is also a _delay_us function for smaller delays. #define F_CPU 16000000UL //16Mhz #include <util/delay.h> for(i=0; i<=3; i++) {_delay_ms(250);} //delay for 1 sec

  5. Using avr-libc Examples using avr-libc Accessing EEPROM memory: #include <avr/eeprom.h> /***********************************************************************/ // save_settings //Saves user settings into EEPROM when power is going down. void save_settings(){ eeprom_write_byte(&eeprom_alarm_volume, alarm_volume); eeprom_write_byte(&eeprom_alarm_level, alarm_level); }//save_settings /***********************************************************************/

More Related