Difference between revisions of "AVR C Library"
Line 126: | Line 126: | ||
#define BlankSpace ' ' | #define BlankSpace ' ' | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | ==LCD_Init()== | ||
+ | *''description :This function is used to initialize the lcd in 8-bit mode'' | ||
+ | *''Function name: LCD_Init()'' | ||
+ | *''I/P Arguments: none.'' | ||
+ | *''Return value : none'' | ||
+ | |||
+ | |||
+ | <syntaxhighlight lang="c"> | ||
+ | void LCD_Init() | ||
+ | { | ||
+ | _delay_ms(50); | ||
+ | databus_direction = 0xff; // Configure both databus and controlbus as output | ||
+ | controlbus_direction = 0xff; | ||
+ | LCD_CmdWrite(0x38); // LCD 2lines, 5*7 matrix | ||
+ | LCD_CmdWrite(0x0E); // Display ON cursor ON | ||
+ | LCD_CmdWrite(0x01); // Clear the LCD | ||
+ | LCD_CmdWrite(0x80); // Move the Cursor to First line First Position | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 15:56, 22 October 2013
Contents
Introduction
Overview:
This manual is designed to help embedded programmers and students, rapidly exploit the Avr(Atmega)-Controller for embedded applications. This manual has been targeted at embedded systems programmers and Students who have basic knowledge of Avr(Atmega32/Avr) architecture and C-Language.
This manual provides the reference to all the library functions which are grouped under respective .c file.
The .c files convention is as per the peripherals. The peripherals (lcd, keypad..) are connected to default PORTs which can be connect to required PORTs by changing the #defines .
Reference:
It is recommended to go through the below reference documents and datasheets before interfacing any peripherals.
1. The Avr Microcontroller and Embedded Systems by Muhammad Ali Mazidi. 2. Atmega32 DataSheet. 3. Embedded C by Michael J Pont . 4. Any of the 16x2 lcd datasheet. 5. RTC-DS1307 from Dallas Semiconductors.
Feedback:
Suggestions for additions and improvements in code and documentation are always welcome. Please send your feedback via e-mail to feedback@xplorelabz.com
Disclaimer:
The libraries have been tested for Atmega16 on different development boards. We strongly believe that the library works on any Atmega boards. However, Xplore Labz disclaims any kind of hardware failure resulting out of usage of libraries, directly or indirectly. Documentation may be subject to change without prior notice.
The usage of tools and software demonstrated in the document are for educational purpose only, all rights pertaining to these belong to the respective owners. Users must ensure license terms are adhered to, for any use of the demonstrated software.
GNU GENERAL PUBLIC LICENSE: The library code in this document is licensed under GNU General Public License (GPL) Copyright (C) 2012.
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Since the library is licensed free of charge, there is no warranty for the libraries and the entire risk of the quality and performance is with the user.
Errors and omissions should be reported to feedback@xplorelabz.com
ADC
Avr ADC library
- Filename: adc.c
- Controller: Atmega8/16/32/128
- Oscillator: 11.0592 MHz
- Author: XploreLabz
- website: www.xplorelabz.com
- Reference:Atmega32 dataSheet
#include<avr/io.h> #include <util/delay.h> #include "adc.h"
ADC_Init()
- Description :This function initializes the ADC control registers
- I/P Arguments: none
- Return value: none
void ADC_Init() { ADCSRA=0x81; //Enable ADC , sampling freq=osc_freq/2 ADMUX=0x00; //Result right justified, select channel zero }
ADC_StartConversion()
- Description :This function does the ADC conversioin for the Selected Channel and returns the converted 10bit result
- I/P Arguments: char(channel number)
- Return value : int(10 bit ADC result)
unsigned int ADC_StartConversion(unsigned char channel) { ADMUX=channel; _delay_ms(5); ADCSRA=0xc1; while((ADCSRA & (1<<ADIF)==0); return(ADCW); }
LCD_8_bit Mode
AVR LCD library for 8-bit mode
- Filename: lcd_8_bit.c
- Controller: Atmega Family(8,16,32,64,128)
- Oscillator: 11.0592 MHz
- Author: XploreLabz
- website: www.xplorelabz.com
Note:
- Pin connection for LCD display in 8-bit mode is as shown below.By default the LCD is connected to PORTB(databus) and PORTD(controlbus).
- The code can be modified to connect the LCD to any of the PORTs by changing the "#define".
- io.h contains the defnition of all ports and SFRs delay.h contains the in built delay routines(us and ms routines).
#include <avr\io.h> #include <util\delay.h> #include "lcd.h" #define databus_direction DDRC // LCD databus Direction Configuration #define controlbus_direction DDRD // LCD Control bus Direction Configuration #define databus PORTC // LCD databus connected to PORTB #define control_bus PORTD // LCD Control bus connected to PORTD #define rs 5 // Register select pin connected 6th bit(D5) Control bus #define rw 6 // Read Write pin connected to 7th bit(D6) Control bus #define en 7 // Enable pin connected to 8th bit(D7) Control bus /* 16x2 LCD Specification */ #define LCDMaxLines 2 #define LCDMaxChars 16 #define LineOne 0x80 #define LineTwo 0xc0 #define BlankSpace ' '
LCD_Init()
- description :This function is used to initialize the lcd in 8-bit mode
- Function name: LCD_Init()
- I/P Arguments: none.
- Return value : none
void LCD_Init() { _delay_ms(50); databus_direction = 0xff; // Configure both databus and controlbus as output controlbus_direction = 0xff; LCD_CmdWrite(0x38); // LCD 2lines, 5*7 matrix LCD_CmdWrite(0x0E); // Display ON cursor ON LCD_CmdWrite(0x01); // Clear the LCD LCD_CmdWrite(0x80); // Move the Cursor to First line First Position }