avr c library
TRANSCRIPT
-
8/22/2019 AVR C Library
1/501 | Page Avr C-Library Reference Manual www.xplorelabz.com
AVR C-Library Reference Manual
-
8/22/2019 AVR C Library
2/502 | Page Avr C-Library Reference Manual www.xplorelabz.com
-
8/22/2019 AVR C Library
3/503 | Page Avr C-Library Reference Manual www.xplorelabz.com
Contents
Introduction ...................................................................................................................................................................
ADC................................................................................................................................................................................
ADC_Init() ..............................................................................................................................................................................................
ADC_StartConversion()......................................................................................................................................................................
LCD_8_bit Mode .............................................................................................................................................................
LCD_Init() ..............................................................................................................................................................................................
LCD_Clear() ............................................................................................................................................................................................
LCD_GoToLineOne()...............................................................................................................................................................................
LCD_GoToLineTwo()...............................................................................................................................................................................
LCD_GoToXY()..........................................................................................................................................................................................
LCD_CmdWrite() .....................................................................................................................................................................................
LCD_DataWrite() ...................................................................................................................................................................................
LCD_DisplayString()..........................................................................................................................................................................
LCD_DisplayNumber() ..........................................................................................................................................................................
LCD_ScrollMessage() ..........................................................................................................................................................................
LCD_DisplayRtcTime()........................................................................................................................................................................
LCD_DisplayRtcDate()........................................................................................................................................................................
LCD_4_bit Mode .............................................................................................................................................................
LCD_Init() ..............................................................................................................................................................................................
LCD_Clear() ............................................................................................................................................................................................
LCD_GoToLineOne()...............................................................................................................................................................................
LCD_GoToLineTwo()...............................................................................................................................................................................
LCD_GoToXY()..........................................................................................................................................................................................
LCD_CmdWrite() .....................................................................................................................................................................................
LCD_DataWrite() ...................................................................................................................................................................................
LCD_DisplayString() ..........................................................................................................................................................................
LCD_DisplayNumber() ..........................................................................................................................................................................
LCD_ScrollMessage() ..........................................................................................................................................................................
LCD_DisplayRtcTime()........................................................................................................................................................................
LCD_DisplayRtcDate()........................................................................................................................................................................
Keypad...........................................................................................................................................................................
KEYPAD_Init()........................................................................................................................................................................................
KEYPAD_WaitForKeyRelease() ..........................................................................................................................................................
KEYPAD_WaitForKeyPress()...............................................................................................................................................................
KEYPAD_ScanKey().................................................................................................................................................................................
KEYPAD_GetKey() ...................................................................................................................................................................................
UART..............................................................................................................................................................................
UART_Init() ............................................................................................................................................................................................
-
8/22/2019 AVR C Library
4/504 | Page Avr C-Library Reference Manual www.xplorelabz.com
UART_RxChar()........................................................................................................................................................................................
UART_TxChar()........................................................................................................................................................................................
UART_TxString() ...................................................................................................................................................................................
UART_RxString() ...................................................................................................................................................................................
UART_TxNumber() ...................................................................................................................................................................................
I2C..................................................................................................................................................................................
I2C_Init() ..............................................................................................................................................................................................
I2C_Start()............................................................................................................................................................................................
I2C_Stop() ..............................................................................................................................................................................................
I2C_Write() ............................................................................................................................................................................................
I2C_Read() ..............................................................................................................................................................................................
RTC_DS1307...................................................................................................................................................................
DS1307_Init()........................................................................................................................................................................................
DS1307_SetTime().................................................................................................................................................................................
DS1307_SetDate().................................................................................................................................................................................
DS1307_GetTime().................................................................................................................................................................................
DS1307_GetDate().................................................................................................................................................................................
EEPROM .........................................................................................................................................................................
EEPROM_WriteByte() ............................................................................................................................................................................
EEPROM_ReadByte()...............................................................................................................................................................................
EEPROM_WriteNBytes()........................................................................................................................................................................
EEPROM_ReadNBytes() ..........................................................................................................................................................................
EEPROM_WriteString()........................................................................................................................................................................
EEPROM_ReadString() ..........................................................................................................................................................................
EEPROM_Erase() .....................................................................................................................................................................................
Library usage guide ........................................................................................................................................................
Flashing the hex file into the controller.........................................................................................................................
-
8/22/2019 AVR C Library
5/505 | Page Avr C-Library Reference Manual www.xplorelabz.com
Introduction
Overview:
This manual is designed to help embedded programmers and students, rapidly exploit the Avr(Atmega)-Contro
for embedded applications. This manual has been targeted at embedded systems programmers and Students who hav
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 c
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 you
feedback via e-mail [email protected]
Disclaimer:The libraries have been tested for Atmega16 on different development boards. We strongly believe that the lib
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
pertaining to these belong to the respective owners. Users must ensure license terms are adhered to, for any use
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 [email protected]
mailto:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected] -
8/22/2019 AVR C Library
6/506 | Page Avr C-Library Reference Manual www.xplorelabz.com
ADC/*----------------------------------------------------------------------------------
Avr ADC library.
Filename: adc.cController: Atmega8/16/32/128Oscillator: 11.0592 MHzAuthor: XploreLabzwebsite: www.xplorelabz.comReference:Atmega32 dataSheet----------------------------------------------------------------------------------*/
#include#include #include "adc.h"
/*----------------------------------------------------------------------------------
ADC_Init()
-----------------------------------------------------------------------------------* I/P Arguments: none.* Return value : none
* description :This function initializes the ADC control registers-----------------------------------------------------------------------------------*/
voidADC_Init(){ADCSRA=0x81; //Enable ADC , sampling freq=osc_freq/2ADMUX=0x00; //Result right justified, select channel zero}
/*----------------------------------------------------------------------------------
ADC_StartConversion()-----------------------------------------------------------------------------------* I/P Arguments: char(channel number).* Return value : int(10 bit ADC result)
* description :This function does the ADC conversioin for the Selected Channeland returns the converted 10bit result
------------------------------------------------------------------------------------*/
unsignedint ADC_StartConversion(unsignedcharchannel){
ADMUX=channel; //Select a channel for which the conversion needs to be done_delay_ms(5); //Wait till the channel is selected
ADCSRA=0xc1; //Start the ADC conversion by setting ADSC bit
while((ADCSRA& (1
-
8/22/2019 AVR C Library
7/507 | Page Avr C-Library Reference Manual www.xplorelabz.com
LCD_8_bit Mode
/*---------------------------------------------------------------------------------AVR LCD library for 8-bit mode
Filename: lcd_8_bit.cController: Atmega Family(8,16,32,64,128)Oscillator: 11.0592 MHzAuthor: XploreLabzwebsite: www.xplorelabz.com----------------------------------------------------------------------------------
Note:1.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).2.The code can be modified to connect the LCD to any of the PORTsby changing the "#define ".
-----------------------------------------------------------------------------------*/
/* io.h contains the defnition of all ports and SFRsdelay.h contains the in built delay routines(us and ms routines)*/
#include #include
#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 b#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 ' '
http://www.xplorelabz.com/http://www.xplorelabz.com/ -
8/22/2019 AVR C Library
8/508 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*---------------------------------------------------------------------------------
LCD_Init()
----------------------------------------------------------------------------------* Function name: LCD_Init()* I/P Arguments: none.* Return value : none
* description :This function is used to initialize the lcd in 8-bit mode
-----------------------------------------------------------------------------------*/
voidLCD_Init(){
_delay_ms(50);databus_direction =0xff; // Configure both databus and controlbus as outputcontrolbus_direction =0xff;LCD_CmdWrite(0x38); // LCD 2lines, 5*7 matrixLCD_CmdWrite(0x0E);// Display ON cursor ONLCD_CmdWrite(0x01);// Clear the LCDLCD_CmdWrite(0x80);// Move the Cursor to First line First Position
}
/*---------------------------------------------------------------------------------
LCD_Clear()
----------------------------------------------------------------------------------* I/P Arguments: none.* Return value : none
* description :This function clears the LCD and moves the cursor to first Position
-----------------------------------------------------------------------------------*/
voidLCD_Clear(){
LCD_CmdWrite(0x01);// Clear the LCD and go to First line First PositionLCD_CmdWrite(LineOne);
}
/*---------------------------------------------------------------------------------
LCD_GoToLineOne()----------------------------------------------------------------------------------* I/P Arguments: none.* Return value : none
* description :This function moves the Cursor to First line First Position
-----------------------------------------------------------------------------------*/
voidLCD_GoToLineOne(){
LCD_CmdWrite(LineOne); // Move the Cursor to First line First Position}
-
8/22/2019 AVR C Library
9/509 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*---------------------------------------------------------------------------------
LCD_GoToLineTwo()
----------------------------------------------------------------------------------* I/P Arguments: none.* Return value : none
* description :This function moves the Cursor to Second line First Position
-----------------------------------------------------------------------------------*/
voidLCD_GoToLineTwo
()
{LCD_CmdWrite(LineTwo); // Move the Cursor to Second line First Position
}
/*---------------------------------------------------------------------------------
LCD_GoToXY()
----------------------------------------------------------------------------------* I/P Arguments: char row,char colrow -> line number(line1=0, line2=1),
For 2line LCD the I/P argument should be either 0 or 1.col -> char number.
For 16-char LCD the I/P argument should be betwen 0-15.* Return value : none
* description :This function moves the Cursor to specified position
-----------------------------------------------------------------------------------*/
voidLCD_GoToXY(charrow,charcol){
charpos;
if(row
-
8/22/2019 AVR C Library
10/5010 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*---------------------------------------------------------------------------------
LCD_CmdWrite()
* ---------------------------------------------------------------------------------* I/P Arguments: 8-bit command supported by LCD.* Return value : none
* description :This function sends a command to LCD in the following steps.step1: Send the I/P command to LCD.step2: Select the Control Register by making RS low.step3: Select Write operation making RW low.step4: Send a High-to-Low pulse on Enable PIN with some delay_us.
----------------------------------------------------------------------------------*/
voidLCD_CmdWrite(charcmd){
databus=cmd; // Send the command to LCDcontrol_bus &=~(1
-
8/22/2019 AVR C Library
11/5011 | Page Avr C-Library Reference Manual www.xplorelabz.com
LCD_DisplayString()
----------------------------------------------------------------------------------* I/P Arguments: String(Address of the string) to be displayed.* Return value : none
* description :This function is used to display the ASCII string on the lcd.1.The string_ptr points to the first char of the string
and traverses till the end(NULL CHAR).2.Each time a char is sent to LCD_DataWrite funtion to display.
-----------------------------------------------------------------------------------*/
voidLCD_DisplayString(char*string_ptr){while(*string_ptr)LCD_DataWrite(*string_ptr++);
}
/*---------------------------------------------------------------------------------
LCD_DisplayNumber()
----------------------------------------------------------------------------------* Function name: LCD_DisplayNumber()* I/P Arguments: unsigned int.
* Return value : none
* description :This function is used to display a 5-digit integer(0-65535).ex: if the number is 12345 then 12345 is displayed.
if the number is 123 then 00123 is displayed.
__________Take 1 by dividing by 10000 and add 0X30 to obtain the ASCII value,| then take the 4-digit remainder(2345).|| _________Take 2 by dividing by 1000 and add 0X30 to obtain the ASCII value,|| then take the 3-digit remainder(345)|||| ________Take 3 by dividing by 100 and add 0X30 to obtain the ASCII value,||| then take the 2-digit remainder(45).|||||| _______Take 4 by dividing by 10 and add 0X30 to obtain the ASCII value,|||| ______Take 5 the remainder of 45 and add 0X30 to obtain the ASCII value,.|||||12345-----------------------------------------------------------------------------------*/
voidLCD_DisplayNumber(unsignedint num){
LCD_DataWrite((num/10000)+0x30);num=num%10000;
LCD_DataWrite((num/1000)+0x30);
num=num%1000;
LCD_DataWrite((num/100)+0x30);num=num%100;
LCD_DataWrite((num/10)+0x30);
LCD_DataWrite((num%10)+0x30);
}
-
8/22/2019 AVR C Library
12/5012 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*---------------------------------------------------------------------------------
LCD_ScrollMessage()
----------------------------------------------------------------------------------* I/P Arguments: char *msg_ptr
msg_ptr -> pointer to the string to be scrolled
* Return value : none
* description :This function scrolls the given message on the first line.1.16 chars are displayed at atime.2.Pointer is incremented to skip a char each time to give the illusion of
moving chars3.If the chars are less than 16, then the BlankSpaces are displayed.
-----------------------------------------------------------------------------------*/
voidLCD_ScrollMessage(char*msg_ptr){unsignedchari,j;LCD_CmdWrite(0x0c); //Disable the Cursorfor(i=0;msg_ptr[i];i++) //Loop to display the complete string
{ //each time 16 chars are displayed and//pointer is incremented to point to next char
LCD_GoToLineOne(); //Move the Cursor to first line
for(j=0;j
-
8/22/2019 AVR C Library
13/5013 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*---------------------------------------------------------------------------------
LCD_DisplayRtcTime()
----------------------------------------------------------------------------------* I/P Arguments: char hour,char min,char sec
hour,min,sec should be packed BCD format, as read from DS1307
* Return value : none
* description :This function display hour,min,sec read from DS1307.
___________ Display the higher nibble of hour after adding 0x30(ASCII conversion)| Display the lower nibble of hour after adding 0x30(ASCII conversion)|| ________ Display the higher nibble of min after adding 0x30(ASCII conversion)| | Display the lower nibble of min after adding 0x30(ASCII conversion| || | _____ Display the higher nibble of sec after adding 0x30(ASCII conversion)| | | Display the lower nibble of sec after adding 0x30(ASCII conversion)| | |
10;10;40
-----------------------------------------------------------------------------------*/
voidLCD_DisplayRtcTime(charhour,charmin,charsec){
LCD_DataWrite(((hour>>4)&0x0f)+0x30);LCD_DataWrite((hour&0x0f)+0x30);LCD_DataWrite(':');
LCD_DataWrite(((min>>4)&0x0f)+0x30);LCD_DataWrite((min &0x0f)+0x30);
LCD_DataWrite(':');
LCD_DataWrite(((sec>>4)&0x0f)+0x30);LCD_DataWrite((sec &0x0f)+0x30);
}
-
8/22/2019 AVR C Library
14/5014 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*---------------------------------------------------------------------------------
LCD_DisplayRtcDate()
----------------------------------------------------------------------------------* I/P Arguments: char day,char month,char year
day,month,year should be packed BCD format, as read from DS1307
* Return value : none
* description :This function display day,month,year read from DS1307.
___________ Display the higher nibble of day after adding 0x30(ASCII conversion)| Display the lower nibble of day after adding 0x30(ASCII conversion)|| ________ Display the higher nibble of month after adding 0x30(ASCII conversion)| | Display the lower nibble of month after adding 0x30(ASCII conversion)| || | _____ Display the higher nibble of year after adding 0x30(ASCII conversion| | | Display the lower nibble of year after adding 0x30(ASCII conversion)| | |01/01/12 (1st-Jan 2012)
-----------------------------------------------------------------------------------*/voidLCD_DisplayRtcDate(charday,charmonth,charyear){
LCD_DataWrite(((day>>4)&0x0f)+0x30);LCD_DataWrite((day&0x0f)+0x30);LCD_DataWrite('/');
LCD_DataWrite(((month>>4)&0x0f)+0x30);LCD_DataWrite((month &0x0f)+0x30);
LCD_DataWrite('/');
LCD_DataWrite(((year>>4)&0x0f)+0x30);
LCD_DataWrite((year&0x0f)+0x30);
}
-
8/22/2019 AVR C Library
15/5015 | Page Avr C-Library Reference Manual www.xplorelabz.com
LCD_4_bit Mode/*----------------------------------------------------------------------------------
AVR LCD library for 4-bit modeFilename: lcd_4_bit.cController: Atmega Family(8,16,32,64,128)Oscillator: 11.0592 MHzAuthor: XploreLabzwebsite: www.xplorelabz.com
----------------------------------------------------------------------------------Note:1.Pin connection for LCD display in 4-bit mode.2.By default the LCD is connected to PORTB.3.The code can be modified to connect the LCD to any of the PORTs by changing the"#define databus PORTB".
----------------------------------------------------------------------------------*/
/* io.h contains the defnition of all ports and SFRsdelay.h contains the in built delay routines(us and ms routines)*/
#include #include
#include "lcd.h"
#define databus_direction DDRB // LCD data and Control bus Direction Configurati
#define databus PORTB // LCD databus connected to PORTB#define control_bus PORTB // LCD Control bus connected to PORTB
#define rs 0 // Register select pin connected 1st bit(D0) Control b#define rw 1 // Read Write pin connected to 2nd bit(D1) Control bus#define en 2 // Enable pin connected to 3rd bit(D2) Control bus
/* 16x2 LCD Specification */
#define LCDMaxLines 2#define LCDMaxChars 16#define LineOne 0x80#define LineTwo 0xc0
#define BlankSpace ' '
http://www.xplorelabz.com/http://www.xplorelabz.com/ -
8/22/2019 AVR C Library
16/5016 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*----------------------------------------------------------------------------------
LCD_Init()
----------------------------------------------------------------------------------* Function name: LCD_Init()* I/P Arguments: none.* Return value : none
* description :This function is used to initialize the lcd in 4-bit mode----------------------------------------------------------------------------------*/
voidLCD_Init(){_delay_ms(50);databus_direction =0xff; // Configure both databus and controlbus as outputLCD_CmdWrite(0x02); //Initilize the LCD in 4bit ModeLCD_CmdWrite(0x28);LCD_CmdWrite(0x0E); // Display ON cursor ONLCD_CmdWrite(0x01); // Clear the LCDLCD_CmdWrite(0x80); // Move the Cursor to First line First Position
}
/*----------------------------------------------------------------------------------
LCD_CmdWrite()
------------------------------------------------------------------------------------* I/P Arguments: 8-bit command supported by LCD.* Return value : none
* description :This function sends a command to LCD in the following steps.step1: Send the Higher Nibble of the I/P command to LCD.step2: Select the Control Register by making RS low.step3: Select Write operation making RW low.step4: Send a High-to-Low pulse on Enable PIN with some delay_us.
step5: Send the Lower Nibble of the I/P command to LCD.step6: Select the Control Register by making RS low.step7: Select Write operation making RW low.step8: Send a High-to-Low pulse on Enable PIN with some delay_us.
----------------------------------------------------------------------------------*/
voidLCD_CmdWrite(charcmd){
databus=(cmd&0xf0); // Send the Higher Nibble of the command to LCDcontrol_bus &=~(1
-
8/22/2019 AVR C Library
17/5017 | Page Avr C-Library Reference Manual www.xplorelabz.com
_delay_ms(1);}
/*---------------------------------------------------------------------------------
LCD_DataWrite()
----------------------------------------------------------------------------------* Function name: LCD_DataWrite()
* I/P Arguments: ASCII value of the char to be displayed.* Return value : none
* description :This function sends a character to be displayed on LCD in the following steps.
step1: Send the higher nibble of the character to LCD.step2: Select the Data Register by making RS high.step3: Select Write operation making RW low.step4: Send a High-to-Low pulse on Enable PIN with some delay_us.
step5: wait for some time
step6: Send the lower nibble of the character to LCD.step7: Select the Data Register by making RS high.
step8: Select Write operation making RW low.step9: Send a High-to-Low pulse on Enable PIN with some delay_us.
----------------------------------------------------------------------------------*/
voidLCD_DataWrite(chardat){
databus=(dat &0xf0); // Send the Higher Nibble of the Data to LCDcontrol_bus |=1
-
8/22/2019 AVR C Library
18/5018 | Page Avr C-Library Reference Manual www.xplorelabz.com
Keypad
/*----------------------------------------------------------------------------------Avr 4x4 Keypad Library
Filename: keypad.cController:Atmega8/16/32/128Oscillator: 11.0592 MHzAuthor: XploreLabzwebsite: www.xplorelabz.com----------------------------------------------------------------------------------Note:
1.Rows are connected to lower 4-bits of PORTC1.Cols are connected to higher 4-bits of PORTC
----------------------------------------------------------------------------------*/
#include #include #include "keypad.h"
#include "lcd.h"
#define RowColDirection DDRB //Data Direction Configuration for keypad#define ROW PORTB //Lower four bits of PORTC are used as ROWs#define COL PINB //Higher four bits of PORTC are used as COLs
/*---------------------------------------------------------------------------------
KEYPAD_Init()
----------------------------------------------------------------------------------
* I/P Arguments:none* Return value : none
* description : This function the rows and colums for keypad scan1.ROW lines are configured as Output.2.Column Lines are configured as Input.
-----------------------------------------------------------------------------------*/
voidKEYPAD_Init(){
RowColDirection=0xf0; // Configure Row lines as O/P and Column lines as I/P}
http://www.xplorelabz.com/http://www.xplorelabz.com/ -
8/22/2019 AVR C Library
19/5019 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*---------------------------------------------------------------------------------
KEYPAD_WaitForKeyRelease()
----------------------------------------------------------------------------------* I/P Arguments:none
* Return value : none
* description : This function waits till the previous key is released.1.All the ROW lines are pulled low.2.Column Lines are read to check the key press.3.If all the Keys are released then Column lines will remain high(0x0f)
-----------------------------------------------------------------------------------*/
voidKEYPAD_WaitForKeyRelease(){
unsignedcharkey;do{
ROW=0x0f; // Pull the ROW lines to low and Column high low.key=COL &0x0f; // Read the Columns, to check the key press
}while(key!=0x0f); // Wait till the Key is released,// If no Key is pressed, Column lines will remain high (0x0
}
/*---------------------------------------------------------------------------------
KEYPAD_WaitForKeyPress()
----------------------------------------------------------------------------------* I/P Arguments:none
* Return value : none
* description : This function waits till a new key is pressed.1.All the ROW lines are pulled low.
2.Column Lines are read to check the key press.3.If any Key is pressed then corresponding Column Line goes low.4.Wait for Some time and perform the above operation to ensurethe True Key Press before decoding the KEY.
-----------------------------------------------------------------------------------*/
voidKEYPAD_WaitForKeyPress(){unsignedcharkey;do{
do{
ROW=0x0f; // Pull the ROW lines to low and Column lines high.
key=COL &0x0F; // Read the Columns, to check the key press
}while(key==0x0f);// Wait till the Key is pressed,// if a Key is pressed the corresponding Column line go low
_delay_ms(1); // Wait for some time(debounce Time);
ROW=0x0f; // After debounce time, perform the above operationkey=COL &0x0F; // to ensure the Key press.
}while(key==0x0f);
}
-
8/22/2019 AVR C Library
20/5020 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*---------------------------------------------------------------------------------
KEYPAD_ScanKey()
----------------------------------------------------------------------------------* I/P Arguments:none
* Return value : char--> Scancode of the Key Pressed
* description : This function scans all the rows to decode the key pressed.1.Each time a ROW line is pulled low to detect the KEY.2.Column Lines are read to check the key press.3.If any Key is pressed then corresponding Column Line goes low.
4.Return the ScanCode(Combination of ROW & COL) for decoding the key.-----------------------------------------------------------------------------------*/
unsignedcharKEYPAD_ScanKey(){
unsignedcharScanKey=0xe0,i, key;
for(i=0;i
-
8/22/2019 AVR C Library
21/5021 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*---------------------------------------------------------------------------------
KEYPAD_GetKey()
----------------------------------------------------------------------------------* I/P Arguments: none
* Return value : char--> ASCII value of the Key Pressed
* Description: This function waits till a key is pressed and returns its ASCII Value
1. Wait till the previous key is released..2. Wait for the new key press.3. Scan all the rows one at a time for the pressed key.4. Decode the key pressed depending on ROW-COL combination and returns itsASCII value.
-----------------------------------------------------------------------------------*/
unsignedcharKEYPAD_GetKey(){
unsignedcharkey;
KEYPAD_WaitForKeyRelease(); // Wait for the previous key release_delay_ms(1);
KEYPAD_WaitForKeyPress(); // Wait for the new key presskey=KEYPAD_ScanKey(); // Scan for the key pressed.
switch(key) // Decode the key{
case0xe7: key='0';break;case0xeb: key='1';break;case0xed: key='2';break;case0xee: key='3';break;
case0xd7: key='4';break;case0xdb: key='5';break;case0xdd: key='6';break;case0xde: key='7';break;case0xb7: key='8';break;case0xbb: key='9';break;case0xbd: key='A';break;case0xbe: key='B';break;case0x77: key='C';break;case0x7b: key='D';break;case0x7d: key='E';break;
case0x7e: key='F';break;default: key='z';
}return(key); // Return the key
}
-
8/22/2019 AVR C Library
22/5022 | Page Avr C-Library Reference Manual www.xplorelabz.com
UART/*--------------------------------------------------------------------------------
AVR UART library for Serial Communication for 9600 baud rate at 11.0592MhzFilename: uart.cController: Atmega8/16/32/128Oscillator: 11.0592 MHzAuthor: XploreLabz
website: www.xplorelabz.com---------------------------------------------------------------------------------*/
#include
/*-------------------------------------------------------------------------------
UART_Init()
----------------------------------------------------------------------------------* I/P Arguments: none.* Return value : none* description :This function is used to initialize the UART at 9600 baud rate
by below configuration.
------------------------------------------------------------------------------------*/voidUART_Init(){
UCSRB=0x18; // Enable Receiver and TransmitterUCSRC=0x86; // Asynchronous mode 8-bit data and 1-stop bitUCSRA=0x00; // Normal Baud rate(no doubling), Single processor commnUBRRH=0;UBRRL=71; // 9600 Baud rate at 11.0592MHz
}
/*----------------------------------------------------------------------------------
UART_RxChar()----------------------------------------------------------------------------------
* I/P Arguments: none.* Return value : char* description :This function is used to receive a char from UART module.
It waits till a char is received ie.till RXC is set,RXC will be set once a CHAR is received.Finally returns the received char.
------------------------------------------------------------------------------------*/
charUART_RxChar(){
while((UCSRA& (1
-
8/22/2019 AVR C Library
23/5023 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*----------------------------------------------------------------------------------
UART_TxChar()
------------------------------------------------------------------------------------* I/P Arguments: char--> data to be transmitted.* Return value : none.* description :This function is used to transmit a char through UART module.
It waits till previous char is transmitted ie.till UDRE is set.UDRE will be set once a CHAR is transmitted ie UDR becomes empty.Finally the new Char to be transmitted is loaded into UDR.
------------------------------------------------------------------------------------*/
voidUART_TxChar
(charch)
{while((UCSRA& (1
-
8/22/2019 AVR C Library
24/5024 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*---------------------------------------------------------------------------------
UART_RxString()
----------------------------------------------------------------------------------* I/P Arguments: *string_ptr
Address of the string where the received data needs to be stored* Return value : none
* description :1.This function is used to receive a ASCII string through UARTtill the carriage_return/New_line
2.The string_ptr points to the begining of the string and eachtime UART_RxChar() function is called to receive a char and copyit into the buffer(STRING) and incrment string_ptr.
3.Once the carriage_return/New_line is encountered the loopis breaked and the String is NULL terminated.
*****NOTE*******:1.The received char is ECHOED back,if not required then comment UART_TxChar(ch) in the code.
2.BackSlash is not taken care.----------------------------------------------------------------------------------_*/
voidUART_RxString(char*string_ptr){
charch;while(1){
ch=UART_RxChar(); //Reaceive a charUART_TxChar(ch); //Echo back the received char
if((ch=='\r')||(ch=='\n'))//read till enter key is pressed{ //once enter key is pressed
*string_ptr=0; //null terminate the stringbreak; //and break the loop
}
*string_ptr=ch; //copy the char into string.string_ptr++; //and increment the pointer
}}
-
8/22/2019 AVR C Library
25/5025 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*----------------------------------------------------------------------------------
UART_TxNumber()
------------------------------------------------------------------------------------* I/P Arguments: unsigned int.* Return value : none
* description :This function is used to transmit a 5-digit integer(0-65535).ex: if the number is 12345 then 12345 is transmitted.
if the number is 123 then 00123 is transmitted.
----------Take 1 by dividing by 10000 and add 0X30 to obtain the ASCII value,| then take the 4-digit remainder(2345).|| ---------Take 2 by dividing by 1000 and add 0X30 to obtain the ASCII value,|| then take the 3-digit remainder(345)|||| --------Take 3 by dividing by 100 and add 0X30 to obtain the ASCII value,||| then take the 2-digit remainder(45).|||||| -------Take 4 by dividing by 10 and add 0X30 to obtain the ASCII value,|||| ------Take 5 the remainder of 45 and add 0X30 to obtain the ASCII value,.|||||
12345------------------------------------------------------------------------------------*/
voidUART_TxNumber(unsignedint num){
UART_TxChar((num/10000)+0x30);num=num%10000;
UART_TxChar((num/1000)+0x30);num=num%1000;
UART_TxChar((num/100)+0x30);num=num%100;
UART_TxChar((num/10)+0x30);
UART_TxChar((num%10)+0x30);}
-
8/22/2019 AVR C Library
26/5026 | Page Avr C-Library Reference Manual www.xplorelabz.com
I2C/*---------------------------------------------------------------------------------*
Avr I2C libraryFilename: I2C.cController: Atmega8/16/32/128Oscillator: 11.0592 MHzAuthor: XploreLabzwebsite: www.xplorelabz.com
Refer Atmega32 for register description.----------------------------------------------------------------------------------*/
#include#include#include "i2c.h"
/*---------------------------------------------------------------------------------
I2C_Init()
----------------------------------------------------------------------------------* I/P Arguments: none.* Return value : none
* description :This function is used to initialize the I2c Module.
------------------------------------------------------------------------------------*/
voidI2C_Init(){TWSR=0x00;//set presca1er bits to zeroTWBR=0x46;//SCL frequency is 100K for XTAL = 7.3728MTWCR=0x04;//enab1e TWI module
}
/*---------------------------------------------------------------------------------*
I2C_Start()----------------------------------------------------------------------------------** I/P Arguments: none.* Return value : none
* description :This function is used to generate I2C Start Condition.Start Condition: SDA goes low when SCL is High.
____________SCL: | |
________| |_______________
SDA: | |
____| |____________
-----------------------------------------------------------------------------------*/
voidI2C_Start(){TWCR =((1
-
8/22/2019 AVR C Library
27/5027 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*-----------------------------------------------------------------------------------
I2C_Stop()
------------------------------------------------------------------------------------* I/P Arguments: none.* Return value : none* description :This function is used to generate I2C Stop Condition.
Stop Condition: SDA goes High when SCL is High.____________
SCL: | |________| |______
_________________SDA: |
__________|------------------------------------------------------------------------------------*/
voidI2C_Stop(void){TWCR =((1
-
8/22/2019 AVR C Library
28/5028 | Page Avr C-Library Reference Manual www.xplorelabz.com
RTC_DS1307/*--------------------------------------------------------------------------------
DS1307 libraryFilename: DS1307.cController: Atmega8/16/32/128Oscillator: 11.0592 MHzAuthor: XploreLabz
website: www.xplorelabz.com
---------------------------------------------------------------------------------*/
#include #include
#include "ds1307.h"#include "i2c.h"
/* Below values are fixed and should not be changed.Refer Ds1307 DataSheet for more info*/
#define DS1307_ID 0xD0 // DS1307 ID
#define SEC_ADDRESS 0x00 // Address to access Ds1307 SEC register#define DATE_ADDRESS 0x04 // Address to access Ds1307 DATE register#define CONTROL 0x07 // Address to access Ds1307 CONTROL register
/*---------------------------------------------------------------------------------
DS1307_Init()
----------------------------------------------------------------------------------* I/P Arguments: none.* Return value : none
* description :This function is used to initialize the Ds1307 RTC.Ds1307 ic is enabled by sending the DS1307 id on the I2C bus.After selecting DS1307, write 0x00 into Control register of Ds1307
------------------------------------------------------------------------------------*/
voidDS1307_Init()
{I2C_Init(); // Initilize the I2c module.I2C_Start(); // Start I2C communication
I2C_Write(DS1307_ID); // Connect to DS1307 by sending its ID on I2c BusI2C_Write(CONTROL); // Select the Ds1307 ControlRegister to configure Ds1307
I2C_Write(0x00); // Write 0x00 to Control register to disable SQW-Out
I2C_Stop(); // Stop I2C communication after initilizing DS1307}
http://www.xplorelabz.com/http://www.xplorelabz.com/ -
8/22/2019 AVR C Library
29/5029 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*----------------------------------------------------------------------------------
DS1307_SetTime()
-----------------------------------------------------------------------------------* I/P Arguments: char,char,char-->hh,mm,ss to initilize the time into DS1307.* Return value : none
* description :This function is used to set Time(hh,mm,ss) into the Ds1307 RTC.Ds1307 ic is enabled by sending the DS1307 id on the I2C bus.After selecting DS1307, select the RAM address 0x00 to point to secInitilze Sec, MIN, Hour one after the other.Stop the I2c communication.
-----------------------------------------------------------------------------------*/
voidDS1307_SetTime(unsignedcharhh,unsignedcharmm,unsignedcharss){
I2C_Start(); // Start I2C communication
I2C_Write(DS1307_ID); // connect to DS1307 by sending its ID on I2c Bus
I2C_Write(SEC_ADDRESS);// Select the SEC RAM address
I2C_Write(ss); // Write sec on RAM address 00HI2C_Write(mm); // Write min on RAM address 01HI2C_Write(hh); // Write hour on RAM address 02H
I2C_Stop(); // Stop I2C communication after Setting the Time}
/*---------------------------------------------------------------------------------
DS1307_SetDate()
----------------------------------------------------------------------------------* I/P Arguments: char,char,char-->day,month,year to initilize the Date into DS1307.* Return value : none
* description :This function is used to set Date(dd,mm,yy) into the Ds1307 RTC.Ds1307 ic is enabled by sending the DS1307 id on the I2C bus.After selecting DS1307, select the RAM address 0x04 to point to dayInitilze Day,Month and Year one after the other.Stop the I2c communication.
----------------------------------------------------------------------------------*/
voidDS1307_SetDate(unsignedchardd,unsignedcharmm,unsignedcharyy)
{I2C_Start(); // Start I2C communication
I2C_Write(DS1307_ID); // connect to DS1307 by sending its ID on I2c BusI2C_Write(DATE_ADDRESS); // Request DAY RAM address at 04H
I2C_Write(dd); // Write date on RAM address 04HI2C_Write(mm); // Write month on RAM address 05HI2C_Write(yy); // Write year on RAM address 06h
I2C_Stop(); // Stop I2C communication after Setting the Date}
-
8/22/2019 AVR C Library
30/5030 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*----------------------------------------------------------------------------------
DS1307_GetTime()
-----------------------------------------------------------------------------------* I/P Arguments: char *,char *,char *-->pointers to get the hh,mm,ss.* Return value : none
* description :This function is used to get the Time(hh,mm,ss) from Ds1307 RTC.Ds1307 ic is enabled by sending the DS1307 id on the I2C bus.After selecting DS1307, select the RAM address 0x00 to point to secGet Sec, MIN, Hour one after the other.Stop the I2c communication.
-----------------------------------------------------------------------------------*/voidDS1307_GetTime(unsignedchar*h_ptr,unsignedchar*m_ptr,unsignedchar*s_ptr)
{I2C_Start(); // Start I2C communication
I2C_Write(DS1307_ID); // connect to DS1307 by sending its ID on I2c BusI2C_Write(SEC_ADDRESS);// Request Sec RAM address at 00H
I2C_Stop(); // Stop I2C communication after selecting Sec Register
I2C_Start(); // Start I2C communicationI2C_Write(0xD1); // connect to DS1307( under Read mode)
//by sending its ID on I2c Bus
*s_ptr=I2C_Read(1); // read second and return Positive ACK*m_ptr=I2C_Read(1); // read minute and return Positive ACK*h_ptr=I2C_Read(0); // read hour and return Negative/No ACK
I2C_Stop(); // Stop I2C communication after reading the Time}
-
8/22/2019 AVR C Library
31/5031 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*----------------------------------------------------------------------------------
DS1307_GetDate()
-----------------------------------------------------------------------------------* I/P Arguments: char *,char *,char *-->pointers to get the y,m,d.* Return value : none
* description :This function is used to get the Date(y,m,d) from Ds1307 RTC.Ds1307 ic is enabled by sending the DS1307 id on the I2C bus.After selecting DS1307, select the RAM address 0x00 to point to DAYGet Day, Month, Year one after the other.Stop the I2c communication.
-----------------------------------------------------------------------------------*/voidDS1307_GetDate(unsignedchar*d_ptr,unsignedchar*m_ptr,unsignedchar*y_ptr)
{I2C_Start(); // Start I2C communication
I2C_Write(DS1307_ID); // connect to DS1307 by sending its ID on I2c BusI2C_Write(DATE_ADDRESS); // Request DAY RAM address at 04H
I2C_Stop(); // Stop I2C communication after selecting DAY Register
I2C_Start(); // Start I2C communicationI2C_Write(0xD1); // connect to DS1307( under Read mode)
// by sending its ID on I2c Bus
*d_ptr=I2C_Read(1); // read Day and return Positive ACK*m_ptr=I2C_Read(1); // read Month and return Positive ACK*y_ptr=I2C_Read(0); // read Year and return Negative/No ACK
I2C_Stop();
// Stop I2C communication after reading the Time
}
-
8/22/2019 AVR C Library
32/5032 | Page Avr C-Library Reference Manual www.xplorelabz.com
EEPROM
/*--------------------------------------------------------------------------------------Avr Eeprom library
Filename: eeprom.c
Controller: Atmega8/16/32/128Oscillator: 11.0592 MHzAuthor: XploreLabzwebsite: www.xplorelabz.comReference: Atmega8/16/32 dataSheet for Control register description.---------------------------------------------------------------------------------------
#include#include
/*The below value should be set depending on the controllerby refering the respective data sheet*/
#define MaxEepromSize 1024
/*--------------------------------------------------------------------------------------
EEPROM_WriteByte()
---------------------------------------------------------------------------------------* I/P Arguments: int,char-->eeprom_address at which eeprom_data is to be written.* Return value : none
* description:This function is used to write the data at specified EEPROM_address..1. Wait till previous write operation is completed(ie wait till EEWE becomes zer2.Load the eeprom address into EEAR at which the data has to be stored.3.Load the data into EEDR which has to be stored in Eeprom.4.Set the EEMWE(Eeprom Master Write Enable) and within four clock cycles
set EEWE(Eeprom Write Enable) to trigger the Eeprom Write Opeartion.----------------------------------------------------------------------------------------
voidEEPROM_WriteByte(unsignedint eeprom_Address,unsignedchareeprom_Data){while(EECR &(1
-
8/22/2019 AVR C Library
33/5033 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*--------------------------------------------------------------------------------------
EEPROM_ReadByte()
---------------------------------------------------------------------------------------* I/P Arguments: int-->eeprom_address from where eeprom_data is to be read.* Return value : char-->data read from Eeprom.
* description: This function is used to read the data from specified EEPROM_address.1.WAit for completion of previous Write operation.2.EEWE will be cleared once EEprom write is completed.3.Load the eeprom address into EEAR from where the data needs to be read.4.Trigger the eeprom read operation by setting EERE(Eeprom Read Enable).5.Wait for some time and collect the read data from EEDR.
----------------------------------------------------------------------------------------
unsignedcharEEPROM_ReadByte(unsignedint eeprom_Address){while(EECR &(1
-
8/22/2019 AVR C Library
34/5034 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*--------------------------------------------------------------------------------------
EEPROM_ReadNBytes()
---------------------------------------------------------------------------------------* I/P Arguments: int,-->eeprom_address from where the N-bytes is to be read.
char*-->Pointer into which the N-bytes of data is to be read.char --> Number of bytes to be Read
* Return value : none
* description:This function is used to Read N-bytes of data from specified EEPROM_addressEEPROM_ReadByte() func is called to read a byte at a time.Source(RAM) and destination(EEPROM) address are incremented each time.NoOfBytes is Decemented after a byte is read.Above Operation is carried out till all the bytes are read(NoOfBytes!=0)
---------------------------------------------------------------------------------------*voidEEPROM_ReadNBytes(unsignedint EepromAddr,unsignedchar*RamAddr,charNoOfBytes)
{while(NoOfBytes != 0)
{*RamAddr=EEPROM_ReadByte(EepromAddr);//Read a byte from EEPROM to RAM
EepromAddr++; //Incerement the Eeprom AddressRamAddr++; //Increment the RAM Address
NoOfBytes--; //Decrement NoOfBytes after Reading each By
}}
/*--------------------------------------------------------------------------------------
EEPROM_WriteString()
---------------------------------------------------------------------------------------* I/P Arguments: int,-->eeprom_address where the String is to be written.
char*-->Pointer to String which has to be written.
* Return value : none
* description:This function is used to Write a String at specified EEPROM_address.EEPROM_WriteByte() function is called to write a byte at a time.Source(RAM) and destination(EEPOM) address are incremented each time.Above Operation is carried out till Null char is identified.
NOTE: Null char is also written into the eeprom.---------------------------------------------------------------------------------------*
voidEEPROM_WriteString(unsignedint eeprom_address,unsignedchar* source_addre{
do{EEPROM_WriteByte(eeprom_address,*source_address);//Write a byte from RAM to Esource_address++; //Increment the RAM Addresseeprom_address++; //Increment the Eeprom Address
} while(*(source_address-1) !=0);}
-
8/22/2019 AVR C Library
35/5035 | Page Avr C-Library Reference Manual www.xplorelabz.com
/*--------------------------------------------------------------------------------------
EEPROM_ReadString()
---------------------------------------------------------------------------------------* I/P Arguments: int,-->eeprom_address from where the String is to be read.
char*-->Pointer into which the String is to be read.
* Return value : none
* description:This function is used to Read a String from specified EEPROM_address.EEPROM_ReadByte() function is called to read a byte at a time.Source(EEPROM) and destination(RAM) address are incremented each time.Above Operation is carried out till Null char is identified.
---------------------------------------------------------------------------------------*voidEEPROM_ReadString(unsignedint eeprom_address,unsignedchar* destination_address
{chareeprom_data;
do
{eeprom_data =EEPROM_ReadByte(eeprom_address);//Read a byte from EEPROM to RAM*destination_address =eeprom_data; //Copy the data into String Buffdestination_address++; //Increment the RAM Addresseeprom_address++; //Increment the Eeprom Address}while(eeprom_data!=0);
}
/*--------------------------------------------------------------------------------------
EEPROM_Erase()
---------------------------------------------------------------------------------------* I/P Arguments: none
* Return value : none
* description:This function is used to erase the entire Eeprom memory.Eeprom is filled with 0xFF to accomplish the Eeprom Erase.EEPROM_WriteByte() function is called to write a byte at a time.Whole memory(0-MaxEepromSize) is traversed and filled with 0xFF
----------------------------------------------------------------------------------------
voidEEPROM_Erase()
{unsignedint eeprom_address;
for(eeprom_address=0;eeprom_address
-
8/22/2019 AVR C Library
36/5036 | Page Avr C-Library Reference Manual www.xplorelabz.com
Library usage guideBelow example demonstrates the step by step procedure to include the libraries into any applications.
Step 1: Open the Avr AtmelStudio-6 and select the New project from File Menu as shown below.
-
8/22/2019 AVR C Library
37/5037 | Page Avr C-Library Reference Manual www.xplorelabz.com
Step 2: Browse to your project folder and provide the project name and click on Ok.
-
8/22/2019 AVR C Library
38/5038 | Page Avr C-Library Reference Manual www.xplorelabz.com
Step 3: Once the project is saveda new dialog box Device Selection opens, Select Atmega32 and click OK.
Step 4:Once the project is successfully created the below window opens with the initil .c file .
-
8/22/2019 AVR C Library
39/5039 | Page Avr C-Library Reference Manual www.xplorelabz.com
Note:The initial file name will be same as project name.
Step 5: Write your program using the library functions and save it.
Note: Include the respective header files before calling any library functions.
-
8/22/2019 AVR C Library
40/5040 | Page Avr C-Library Reference Manual www.xplorelabz.com
Step 6:Add the library files(.c,.h) to the project as shown below.
Note: Copy the library files into the project folder before including them into the project.
Step 7:Add the Source(.c) and header( .h) files by browsing to the project folder.
-
8/22/2019 AVR C Library
41/5041 | Page Avr C-Library Reference Manual www.xplorelabz.com
Step 8: The included library files can be seen in Solution Explorer on the right side.
Step 9: Compile the project by clicking on Build Solution from Build menu (or press F7). Project complies if there are no
errors. If there are any errors fix them and re-compile.
-
8/22/2019 AVR C Library
42/5042 | Page Avr C-Library Reference Manual www.xplorelabz.com
Step 10: Configure the Controller Freq by selecting the project properties from Project menu.
Note:As the Inbuilt delay routines as used the freq needs to be specified to generate accurate delays.
-
8/22/2019 AVR C Library
43/5043 | Page Avr C-Library Reference Manual www.xplorelabz.com
Step 11: Select the Symbols from Tool Chain menu and Click on Add Item in Defined Symbols(-D) box.
Step 12: Provide the Controller (Target Board)frequency as F_CPU=xxx Hz .In this case it is 11.0592Mhz.
-
8/22/2019 AVR C Library
44/5044 | Page Avr C-Library Reference Manual www.xplorelabz.com
Step 13: Configuring the optimization levels: Select the Optimization from ToolChain menu. Select the required optim
level from drop down. Refer WinAvr/Gcc documents for more optimization details.
Step 14: Seletcting the targed tool chain : Select the Advanced option on the left side, now click the link shown in blue
colourTools->Options->Toochain ->Flavour Configuretion.
-
8/22/2019 AVR C Library
45/5045 | Page Avr C-Library Reference Manual www.xplorelabz.com
Step 15: From the drop down select WinAVR and set it as Defaulttoolchain by clicking on Set As Default.
Note:
Above two Steps( 14 & 15) needs to be performed for the first time, ie till the WinAVR is configured as default Toolch
Step 14: Finally recompile after all configurations. Hex file will be generated with the project name in the selected
Project->Debug folder.
-
8/22/2019 AVR C Library
46/5046 | Page Avr C-Library Reference Manual www.xplorelabz.com
-
8/22/2019 AVR C Library
47/5047 | Page Avr C-Library Reference Manual www.xplorelabz.com
Flashing the hex file into the controllerStep 1: Run the Khazama Avr Programmer. The software can be downloaded form
www.khazama.com/project/programmer
Step 2: Connect the usb isp programmer to the targed device and select the required ic from the drop down menu.
Step 3:Configuring the fuse and lock bits : Select the Fuses and Lock bits from the Command menu.
f
http://www.khazama.com/project/programmerhttp://www.khazama.com/project/programmerhttp://www.khazama.com/project/programmer -
8/22/2019 AVR C Library
48/5048 | Page Avr C-Library Reference Manual www.xplorelabz.com
Step 4:A new window opens to read/write the fuse bits. Now read the fuse bits of the target. If the below window doe
open then double check the connection(six pin connector). Still the problem persists then remove the usb cable and
reconnect it.
Step 5: Mode1: No memory lock Feature should be selected else the controller gets lockedand cannot be reprogramm
Step5: the Source of the clock should be selected from the drop down menu as shown below. In this the external high
frequency is selected as the target device is running at 11.0592Mhz freq.
-
8/22/2019 AVR C Library
49/5049 | Page Avr C-Library Reference Manual www.xplorelabz.com
Step6: After configuring the lock and fuse bits, write them back into the target controller. Double check the memory lo
and crystal features as shown in step 4 and 5 before writing the fuse bits.
Note: Step 4,5,6 needs to be performed only once, once the fuse bits are written they will be saved.
Step 7: Browse and select the hex file that needs to be flashed into the target device.
-
8/22/2019 AVR C Library
50/50
Step8: Click the flash option as show below to program the target device.
Step9: Once the target is programmed a new pop up window will be displayed to notify the same. And the controller s
executing and no external hard reset is required.