-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
281 changed files
with
124,121 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...ents/10_ADC_Sensor_Display_on_LCD/ADC_Sensor_Display_on_LCD/ADC_Sensor_Display_on_LCD.aps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<AVRStudio><MANAGEMENT><ProjectName>ADC_Sensor_Display_on_LCD</ProjectName><Created>31-Jan-2010 18:33:25</Created><LastEdit>26-Dec-2010 20:18:46</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>31-Jan-2010 18:33:25</Created><Version>4</Version><Build>4, 17, 0, 655</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\ADC_Sensor_Display_on_LCD.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>F:\D Drive\Fire Bird 5\ATMEGA2560\Expirements 14.7456Mhz 2010-12-25\10_ADC_Sensor_Display_on_LCD\ADC_Sensor_Display_on_LCD\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega2560.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>ADC_Sensor_Display_on_LCD.c</SOURCEFILE><OTHERFILE>default\ADC_Sensor_Display_on_LCD.lss</OTHERFILE><OTHERFILE>default\ADC_Sensor_Display_on_LCD.map</OTHERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega2560</PART><HEX>1</HEX><LIST>1</LIST><MAP>1</MAP><OUTPUTFILENAME>ADC_Sensor_Display_on_LCD.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>0</ISDIRTY><OPTIONS/><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -std=gnu99 -DF_CPU=14745600UL -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\WinAVR-20090313\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR-20090313\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><ProjectFiles><Files><Name>F:\D Drive\Fire Bird 5\ATMEGA2560\Expirements 14.7456Mhz 2010-12-25\10_ADC_Sensor_Display_on_LCD\ADC_Sensor_Display_on_LCD\ADC_Sensor_Display_on_LCD.c</Name></Files></ProjectFiles><IOView><usergroups/><sort sorted="0" column="0" ordername="0" orderaddress="0" ordergroup="0"/></IOView><Files><File00000><FileId>00000</FileId><FileName>ADC_Sensor_Display_on_LCD.c</FileName><Status>1</Status></File00000></Files><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio> |
238 changes: 238 additions & 0 deletions
238
...ements/10_ADC_Sensor_Display_on_LCD/ADC_Sensor_Display_on_LCD/ADC_Sensor_Display_on_LCD.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
/******************************************************************************** | ||
Written by: Vinod Desai, NEX Robotics Pvt. Ltd. | ||
Edited by: Sachitanand Malewar, NEX Robotics Pvt. Ltd. | ||
AVR Studio Version 4.17, Build 666 | ||
Date: 26th December 2010 | ||
In this experiment ADC captures the analog sensor values and displays it on the LCD | ||
Concepts covered: ADC, LCD interfacing | ||
LCD Connections: | ||
LCD Microcontroller Pins | ||
RS --> PC0 | ||
RW --> PC1 | ||
EN --> PC2 | ||
DB7 --> PC7 | ||
DB6 --> PC6 | ||
DB5 --> PC5 | ||
DB4 --> PC4 | ||
ADC Connection: | ||
ACD CH. PORT Sensor | ||
0 PF0 Battery Voltage | ||
1 PF1 White line sensor 3 | ||
2 PF2 White line sensor 2 | ||
3 PF3 White line sensor 1 | ||
4 PF4 IR Proximity analog sensor 1***** | ||
5 PF5 IR Proximity analog sensor 2***** | ||
6 PF6 IR Proximity analog sensor 3***** | ||
7 PF7 IR Proximity analog sensor 4***** | ||
8 PK0 IR Proximity analog sensor 5 | ||
9 PK1 Sharp IR range sensor 1 | ||
10 PK2 Sharp IR range sensor 2 | ||
11 PK3 Sharp IR range sensor 3 | ||
12 PK4 Sharp IR range sensor 4 | ||
13 PK5 Sharp IR range sensor 5 | ||
14 PK6 Servo Pod 1 | ||
15 PK7 Servo Pod 2 | ||
***** For using Analog IR proximity (1, 2, 3 and 4) sensors short the jumper J2. | ||
To use JTAG via expansion slot of the microcontroller socket remove these jumpers. | ||
LCD Display interpretation: | ||
**************************************************************************** | ||
*BATTERY VOLTAGE IR PROX.SENSOR 2 IR PROX.SENSOR 3 IR.PROX.SENSOR 4* | ||
*LEFT WL SENSOR CENTER WL SENSOR RIGHT WL SENSOR FRONT SHARP DIS * | ||
**************************************************************************** | ||
Note: | ||
1. Make sure that in the configuration options following settings are | ||
done for proper operation of the code | ||
Microcontroller: atmega2560 | ||
Frequency: 14745600s | ||
Optimization: -O0 (For more information read section: Selecting proper optimization | ||
options below figure 2.22 in the Software Manual) | ||
2. Make sure that you copy the lcd.c file in your folder | ||
3. Distance calculation is for Sharp GP2D12 (10cm-80cm) IR Range sensor | ||
*********************************************************************************/ | ||
|
||
/******************************************************************************** | ||
Copyright (c) 2010, NEX Robotics Pvt. Ltd. -*- c -*- | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of the copyright holders nor the names of | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
* Source code can be used for academic purpose. | ||
For commercial use permission form the author needs to be taken. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. | ||
Software released under Creative Commence cc by-nc-sa licence. | ||
For legal information refer to: | ||
http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode | ||
********************************************************************************/ | ||
|
||
#include <avr/io.h> | ||
#include <avr/interrupt.h> | ||
#include <util/delay.h> | ||
|
||
#include <math.h> //included to support power function | ||
#include "lcd.c" | ||
|
||
unsigned char ADC_Conversion(unsigned char); | ||
unsigned char ADC_Value; | ||
unsigned char sharp, distance, adc_reading; | ||
unsigned int value; | ||
float BATT_Voltage, BATT_V; | ||
|
||
//Function to configure LCD port | ||
void lcd_port_config (void) | ||
{ | ||
DDRC = DDRC | 0xF7; //all the LCD pin's direction set as output | ||
PORTC = PORTC & 0x80; // all the LCD pins are set to logic 0 except PORTC 7 | ||
} | ||
|
||
//ADC pin configuration | ||
void adc_pin_config (void) | ||
{ | ||
DDRF = 0x00; //set PORTF direction as input | ||
PORTF = 0x00; //set PORTF pins floating | ||
DDRK = 0x00; //set PORTK direction as input | ||
PORTK = 0x00; //set PORTK pins floating | ||
} | ||
|
||
//Function to Initialize PORTS | ||
void port_init() | ||
{ | ||
lcd_port_config(); | ||
adc_pin_config(); | ||
} | ||
|
||
//Function to Initialize ADC | ||
void adc_init() | ||
{ | ||
ADCSRA = 0x00; | ||
ADCSRB = 0x00; //MUX5 = 0 | ||
ADMUX = 0x20; //Vref=5V external --- ADLAR=1 --- MUX4:0 = 0000 | ||
ACSR = 0x80; | ||
ADCSRA = 0x86; //ADEN=1 --- ADIE=1 --- ADPS2:0 = 1 1 0 | ||
} | ||
|
||
|
||
|
||
//This Function accepts the Channel Number and returns the corresponding Analog Value | ||
unsigned char ADC_Conversion(unsigned char Ch) | ||
{ | ||
unsigned char a; | ||
if(Ch>7) | ||
{ | ||
ADCSRB = 0x08; | ||
} | ||
Ch = Ch & 0x07; | ||
ADMUX= 0x20| Ch; | ||
ADCSRA = ADCSRA | 0x40; //Set start conversion bit | ||
while((ADCSRA&0x10)==0); //Wait for ADC conversion to complete | ||
a=ADCH; | ||
ADCSRA = ADCSRA|0x10; //clear ADIF (ADC Interrupt Flag) by writing 1 to it | ||
ADCSRB = 0x00; | ||
return a; | ||
} | ||
|
||
|
||
|
||
// This Function prints the Analog Value Of Corresponding Channel No. at required Row | ||
// and Coloumn Location. | ||
void print_sensor(char row, char coloumn,unsigned char channel) | ||
{ | ||
ADC_Value = ADC_Conversion(channel); | ||
lcd_print(row, coloumn, ADC_Value, 3); | ||
} | ||
|
||
|
||
// This Function calculates the actual distance in millimeters(mm) from the input | ||
// analog value of Sharp Sensor. | ||
unsigned int Sharp_GP2D12_estimation(unsigned char adc_reading) | ||
{ | ||
float distance; | ||
unsigned int distanceInt; | ||
distance = (int)(10.00*(2799.6*(1.00/(pow(adc_reading,1.1546))))); | ||
distanceInt = (int)distance; | ||
if(distanceInt>800) | ||
{ | ||
distanceInt=800; | ||
} | ||
return distanceInt; | ||
} | ||
|
||
void init_devices (void) | ||
{ | ||
cli(); //Clears the global interrupts | ||
port_init(); | ||
adc_init(); | ||
sei(); //Enables the global interrupts | ||
} | ||
|
||
|
||
//Main Function | ||
int main(void) | ||
{ | ||
unsigned int value; | ||
init_devices(); | ||
|
||
lcd_set_4bit(); | ||
lcd_init(); | ||
|
||
while(1) | ||
{ | ||
BATT_V = ADC_Conversion(0); | ||
BATT_Voltage = ((ADC_Conversion(0)*100)*0.07902) + 0.7; //Prints Battery Voltage Status | ||
lcd_print(1,1,BATT_Voltage,4); | ||
|
||
//print_sensor(1,1,0); //Prints Battery voltage binary value | ||
|
||
print_sensor(1,6,5); //Prints IR Proximity Sensor 1 | ||
print_sensor(1,10,6); //Prints vlaue of Analog IR Proximity Sensor 2 | ||
print_sensor(1,14,7); //Prints value of Analog IR Proximity Sensor 3 | ||
print_sensor(2,2,3); //Prints value of White Line Sensor1 | ||
print_sensor(2,6,2); //Prints Value of White Line Sensor2 | ||
print_sensor(2,10,1); //Prints Value of White Line Sensor3 | ||
|
||
//print_sensor(2,9,11); //Analog Value Of Front Sharp Sensor | ||
|
||
sharp = ADC_Conversion(11); //Stores the Analog value of front sharp connected to ADC channel 11 into variable "sharp" | ||
value = Sharp_GP2D12_estimation(sharp); //Stores Distance calsulated in a variable "value". | ||
lcd_print(2,14,value,3); //Prints Value Of Distanc in MM measured by Sharp Sensor. | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ents/10_ADC_Sensor_Display_on_LCD/ADC_Sensor_Display_on_LCD/adc_sensor_display_on_lcd.aws
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA2560"/><Files><File00000 Name="E:\docs recevived from sir\FBV2560 bot\Fire Bird V ATMEGA2560 CD 2010-05-04\Copy of Expirements\10_ADC_Sensor_Display_on_LCD\ADC_Sensor_Display_on_LCD\ADC_Sensor_Display_on_LCD.c" Position="5 76 716 737" LineCol="130 40" State="Maximized"/></Files></AVRWorkspace> |
1 change: 1 addition & 0 deletions
1
...ADC_Sensor_Display_on_LCD/ADC_Sensor_Display_on_LCD/default/ADC_Sensor_Display_on_LCD.eep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
:00000001FF |
Binary file added
BIN
+25 KB
...ADC_Sensor_Display_on_LCD/ADC_Sensor_Display_on_LCD/default/ADC_Sensor_Display_on_LCD.elf
Binary file not shown.
Oops, something went wrong.