Академический Документы
Профессиональный Документы
Культура Документы
BRiCS
Process : Create a new folder. Copy lcd_lib.h & lcd_lib.c from CD-ROM>Sample Code>LCD to this new Folder. Open MFile Generator and save the MakeFilefile to your new folder. Open MakeFile with programmers notepad and make the 5 changes in Makefile as told earlier. Source list will be SRC= $(TARGET).c lcd_lib.c Open a new file in programmers notepad and save it in your folder as main.c Write the above code in main.c Compile the code Tools >Make All. If successful, transfer it to your kit Tools > Program Connect LCD and IR sensor on the kit. LCD displays the o/p of sensor as 0 or 1. Move the sensor over black and white surfaces and see the change.
2. IR Sensor with ADC Now we are going to connect IR sensors through ADC. Thus the analog O/p of IR Sensor is converted to a digital value in the range 0-1023. The digital value will change linearly as the sensor is moved away from the surface or put on different colors. There is no need to declare port A as input because when ADC is enabled, MCU automatically configures that pin of port A as input
Code : #include <avr/io.h> #include lcd_lib.h #include <util/delay.h> #include adc_lib.h #include<stdio.h> void main ( ) { int x; char a[15]; LCDinit(); LCDclr( ); ADCinit(10); while (1) { x = read_adc(0); sprintf(a,Value = %d LCDclr(); LCDstring(a,10); _delay_ms(300); } }
// Initializes ADC in 10 bit mode // returns the digital value of the analog i/p connected to pin 0 of port A ,x);
3. Making a Digital voltmeter A voltmeter is required to print the value of the voltage and not the digital value corresponding to it. Therefore we need to get back the value of applied voltage from the digital o/p using the fundamental equation of ADC. The final equation to convert ADC o/p x to analog voltage is given below. V = (x * Vref / 1023); ask ur mentor to get Multimeter and measure the exact value of Vref on pin 32
Code : #include <avr/io.h> #include lcd_lib.h #include <util/delay.h> #include adc_lib.h #include <stdio.h> void main ( ) { int x;
BRiCS
IR sensor & ADC float v; char a[15]; LCDinit(); LCDclr( ); ADCinit(10); while (1) { x = read_adc(0); v = (x*5.0 / 512) ; sprintf(a,Voltage = %f LCDclr(); LCDstring(a,15); _delay_ms(300); } }
// Initializes ADC in 10 bit mode // returns the digital value of the voltage at pin 0 // substitute the 5.0 with exact value of Vref measured above ,v);
Process :
To you floating point numbers u need to generate the make file with some modification. Open mFile generator (Programs > WinAVR>mFile). Goto MakeFile > printf () options. Select floating point. Save this file in your New Folder. File > Save As. Rest steps same as before .Same as above program 2. After transferring the program, connect the given batterys +ve to pin 0 and ve to GND of the ADC connector on board.
A C file with some pre-written code opens. To use delay in your code you need to include delay.h. Write #include <delay.h>
BRiCS
IR sensor & ADC Code : // this line is automatically generated by CVAVR #include <mega16.h> #include <lcd.h> // this line is automatically generated by CVAVR #include <delay.h> #include <stdio.h> // some code generated by CVAVR comes here void main() { int x; char a[15]; // some code generated by CVAVR comes here lcd_init(16); // this is automatically generated by CVAVR while(1) { x=read_adc(0); sprintf(a,value =%d ,x); lcd_clear(); lcd_puts(a); lcd_gotoxy(0,1); if (x<512) lcd_putsf(Color : White); else lcd_putsf(Color : Black); } } Write the code in main method. When you are finished with writing the code, compile it by clicking Projects>>Compile or press F9 Errors, if any, are displayed in the message window at bottom and navigator window at the left. 4 After correcting the errors, re-compile and then make the code- Projects>>Make or press SHIFT + F9 Now you will have your hex file in your project folder. Connect your kit and transfer the code using AVRDude GUI. Connect the IR sensor and LCD and see the o/p.
BRiCS