AVR ATmega32 Mini Development Board – Interfacing Temperature sensor
AVR mini development board has on board temperature sensor MCP9700. Here in this section, we discuss the interfacing of the same with its host controller ATmega32. ATmega32 has 8 channel 10-bit successive approximation ADC.
On the Mini Development Board the temperature sensor MCP9700 is connected to pin PA1 of the controller i.e, ADC1 via jumper J10. The MCP9700/9700A and MCP9701/9701A family of Linear Active Thermistor™ Integrated Circuit (IC) is an analog temperature sensor that converts temperature to analog voltage. It has an accuracy of ±2°C from 0°C to +70°C (MCP9700A/9701A) ±4°C from 0°C to +70°C (MCP9700/9701) while consuming 6µA (typical) of operating current. Sensitivity is 10mV/°C. At 0°C, the output is 500mV. So that’s the spec and description for MCP9700, now lets see its actual working here below.
Sample code to check the temperature sensor is given below. The output is displayed on LCD.
Note: To use temperature sensor, don’t forget to short jumper J10. Leaving it open frees PA1 and it can be used for any other desired purpose.
Schematic
Sample Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
/************************************************************************************* HEADER FILES **************************************************************************************/ #define F_CPU 8000000UL #include<avr/io.h> #include<util/delay.h> /************************************************************************************* FUNCTION DECLARATIONS **************************************************************************************/ int Adc_Conversion(unsigned char channel); void Int_Asci(int); void Command(unsigned char cmd); void Data(unsigned char dat); void Display(char loc, const char *LCD); /************************************************************************************* VARIABLE DECLARATIONS **************************************************************************************/ int Adc_Check=0,i=0; volatile unsigned char a=0; unsigned char temp[]="Temp:"; /************************************************************************************* MAIN FUNCTION **************************************************************************************/ int main() { DDRA = 0X00; /* Set PA1 PIN as input */ DDRB = 0xFF; /* Set LCD data lines(PORTB) as output */ DDRD = 0X62; /* RS(PD5),EN(PD6) set as Output */ ADCSRA = 0X85; /* ADEN=1,ADPS2=1,ADPS1=0,ADPS0=0 */ _delay_us(15); /* Minimum Delay To Power On LCD To Rx Mode */ Command(0x30); /* LCD Specification Command */ _delay_us(5); Command(0x30); /* LCD Specification Command */ _delay_us(2); Command(0x30); /* LCD Specification Command */ Command(0x38); /* Double Line Display Command */ Command(0x06); /* Auto Increment Location Address Command */ Command(0x0C); /* Display ON Command */ Command(0x01); /* Clear Display Command */ _delay_us(1200); while(1) { Adc_Check = Adc_Conversion(0X41); /* Read sensor out from PA1 pin */ Adc_Check = ((Adc_Check*4.88)-500);/* Convert votage to corresponding temperature */ Adc_Check = (Adc_Check/10); /* 1 degree celsius = 10mV */ Display(0X80,"Temp:"); Command(0X86); Int_Asci(Adc_Check); /* Display temperature */ Data(0xDF); /* notation for degre celcius */ Data('C'); /* notation for degre celcius */ } } /************************************************************************************** * Function : Adc_Conversion * * * * Description : Function to convert analog value to digital * * * * Parameters : channel - channel for ADC conversion * ***************************************************************************************/ int Adc_Conversion(unsigned char channel) { volatile int b; volatile int ad=0; ADMUX = channel; /* Channel selection */ ADCSRA = ADCSRA|0X40; /* ADSC=1,start conversion */ while((ADCSRA & 0x40) == 0x40); /* Check if ADIF is set i.e, conversion is over */ b = ADCL; /* Read LSB result */ ad = ADCH; /* Read MSB result */ ad = ad<<8; /* Shift MSB 8 times */ ad = ad|b; /* Combine MSB and LSB */ return ad; /* Return adc reading */ } /************************************************************************************** * Function : Int_ASCII * * * * Description : Function to convert integer value to ASCII * * * * Parameters : ab - integer to be converted * ***************************************************************************************/ void Int_ASCII(int ab) { char i; char array[4]; for(i=1; i<=2; i++) /* Convert decimal to ASCII */ { array[i] = ab%10; /* Separate each integer */ ab = ab/10; } for(i=2; i>=1; i--) { Data(array[i]+'0'); /* Display on LCD */ } } /************************************************************************************** * Function : Command * * * * Description : Function to send a command to LCD * * * * Parameters : cmd - command to be sent * ***************************************************************************************/ void Command(unsigned char cmd) { PORTD |= 0X40; /* RS-0 for command register, E-1,Enable pin made high */ PORTB = cmd; /* Command loaded to data lines */ _delay_us(50); PORTD = 0X00; /* E-0, Enable pin made low */ } /************************************************************************************** * Function : Data * * * * Description : Function to display a character on LCD * * * * Parameters : dat - Character to be displayed * ***************************************************************************************/ void Data(unsigned char dat) { PORTD |= 0X60; /* RS-1 for data register, E-1,Enable pin made high */ PORTB = dat; /* Data loaded to data lines */ _delay_us(50); PORTD = 0X00; /* E-0, Enable pin made low */ } /************************************************************************************** * Function : Display * * * * Description : Function to display string on LCD * * * * Parameters : loc - location * * LCD - String to be displayed * ***************************************************************************************/ void Display(char loc, const char *LCD) { Command(loc); /* Address of location to display data */ while(*LCD!='\0') /* Check for termination character */ { Data(*LCD); /* Display the character on LCD */ LCD++; /* Increment the pointer */ } } /************************************************************************************* END OF PROGRAM **************************************************************************************/ |
Topics related to AVR ATmega32 Mini Development Board
- AVR ATmega32 Mini Development Board – Overview
- AVR ATmega32 Mini Development Board – Interfacing LED
- AVR ATmega32 Mini Development Board – Interfacing LCD
- AVR ATmega32 Mini Development Board – Serial communication(USART)
- AVR ATmega32 Mini Development Board – Interfacing Switch
- AVR ATmega32 Mini Development Board – Interfacing Buzzer
- AVR ATmega32 Mini Development Board – Interfacing POT(ADC)
- AVR ATmega32 Mini Development Board – Interfacing Temperature sensor
- AVR ATmega32 Mini Development Board – Interfacing Servo Motor
- AVR ATmega32 Mini Development Board – Interfacing μRFID
Resources
How to buy?
- Click here to buy rhydoLABZ AVR ATmega16 Development Board-Mini
- Click here to buy rhydoLABZ AVR ATmega32 Development Board-Mini
SupportPlease share your ideas with us, visit our forum for discussion
Leave a Reply
You must be logged in to post a comment.