akulet
Newbie level 2
in this project am using the folowing components.
a. hardware
-micro controller AT89C51
-temperature sensor Ds18B20
-LCD display LM016L
-AN-DC motor
COMPIM serial connector
b.software components
-Proteus simulator
-Keil compiler
C-language
CONNECTION
compim serial connector to the micro controller in port p3.0 and p3.1
temperature to the micro controller through port p17
FAN-DC motor to the micro controller through port p16
LCD display to the micro controller through port p0
THE OPERATION
the user enters temperature value from the computer having an interface developed in V.B. then signal from the computer is sent into the micro controller by compim serial connector as the constant value.
then this constant value should be displayed on LCD and maintained constant.
now when a motor is rotating, temperature sensor should sense the effect caused by the rotation of the motor on the refrigerator. then the sensed temperature value by the sensor should be measured and these two values that is constant and measured one should be compared and if they are equal, the motor should be switched off and the buzzer is sounded.
this is tried code please friends help me edit code to fit my project
for the circuit design please click the like
a. hardware
-micro controller AT89C51
-temperature sensor Ds18B20
-LCD display LM016L
-AN-DC motor
COMPIM serial connector
b.software components
-Proteus simulator
-Keil compiler
C-language
CONNECTION
compim serial connector to the micro controller in port p3.0 and p3.1
temperature to the micro controller through port p17
FAN-DC motor to the micro controller through port p16
LCD display to the micro controller through port p0
THE OPERATION
the user enters temperature value from the computer having an interface developed in V.B. then signal from the computer is sent into the micro controller by compim serial connector as the constant value.
then this constant value should be displayed on LCD and maintained constant.
now when a motor is rotating, temperature sensor should sense the effect caused by the rotation of the motor on the refrigerator. then the sensed temperature value by the sensor should be measured and these two values that is constant and measured one should be compared and if they are equal, the motor should be switched off and the buzzer is sounded.
this is tried code please friends help me edit code to fit my project
Code C - [expand] 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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 // #include <avr/io.h> #define F_CPU 1000000 #include <util/delay.h> #include <avr/interrupt.h> #include <avr/sleep.h> // #define data 15 #define MAX_DIGITS 4 #define DISPLAYBUFFERSIZE 4 #define TEMP_BUFFERSIZE 128 //unsigned int data_buffer[data] = {0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F,0X80,0X39,0X71,0x00}; //active low data unsigned int data_buffer[data] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff}; unsigned int displaybuffer[DISPLAYBUFFERSIZE]; unsigned int tempbuffer[TEMP_BUFFERSIZE]; unsigned int ones = 0; unsigned int tens = 0; unsigned int hundreds = 0; unsigned int thousands = 0; unsigned int digit_count = 0; unsigned int displaybuffer_cnt = 0; unsigned int blank_digit = 10; unsigned int temperature; unsigned int temp_buffer_counter = 0; void chip_init(void); void configure_timer2_ctc(void); void display_temperature(unsigned int temp); void temp_compare(unsigned int temp); int main(void) { cli(); // disable interrupts first chip_init(); // initialize ATmega168 sei(); // Enable interrupts now while(1) { temp_compare(temperature); // relax sleep_enable(); } return 0; } void conf_adc(void) { ADMUX = 0; // use ADC0 ADMUX |= (1 << REFS0); // use AVcc as the reference ADMUX |= (1 << ADLAR); // Right adjust for 8 bit resolution ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // 128 prescale ADCSRA |= (1 << ADATE); // Set ADC Auto Trigger Enable ADCSRB = 0; // 0 for free running mode ADCSRA |= (1 << ADEN); // Enable the ADC ADCSRA |= (1 << ADIE); // Enable Interrupts ADCSRA |= (1 << ADSC); // Start the ADC conversion } // Timer2 configuration in CTC mode void configure_timer2_ctc(void) { // reset all TCNT2 = 0; TCCR2B = 0; TIMSK2 = 0; // when the processor is running at 1MHz, prescaled by 32 //OCR2A = 0xf9; OCR2A = 0x80; // prescale by 32, resulting input freq. to the timer is 31250Hz //TCCR2B |= (1<<CS21)|(1<<CS20); // prescale by 8, resulting input freq. to the timer is 1250Hz TCCR2B |= (1<<CS21); // enable CTC mode of timer0 TCCR2A |= (1<<WGM21); // enable compare match interrupt TIMSK2 |= (1<<OCIE2A); } void chip_init(void) { DDRD = 0xff; //DDRC = 0X78; DDRB = 0xff; PORTD = 0x00; PORTB = 0x00; conf_adc(); configure_timer2_ctc(); } void display_temperature(unsigned int temp) { // _delay_us(500); if((temp >= 0) && (temp < 10)) { thousands = blank_digit; hundreds = blank_digit; tens = blank_digit; ones = temp; // fill the display buffer displaybuffer[0] = data_buffer[ones]; displaybuffer[1] = data_buffer[tens]; displaybuffer[2] = data_buffer[hundreds]; displaybuffer[3] = data_buffer[thousands]; } else if((temp > 9) && (temp < 100)) { thousands = blank_digit; hundreds = blank_digit; tens = temp / 10; ones = temp % 10; displaybuffer[0] = data_buffer[ones]; displaybuffer[1] = data_buffer[tens]; displaybuffer[2] = data_buffer[hundreds]; displaybuffer[3] = data_buffer[thousands]; } else if((temp > 99) && (temp < 1000)) { thousands = blank_digit; hundreds = temp / 100; tens = (temp % 100) / 10; ones = (temp % 100) % 10; displaybuffer[0] = data_buffer[ones]; displaybuffer[1] = data_buffer[tens]; displaybuffer[2] = data_buffer[hundreds]; displaybuffer[3] = data_buffer[thousands]; } else if((temp > 999) && (temp < 10000)) { thousands = temp / 1000; hundreds = (temp % 1000) / 100; tens = ((temp % 1000) % 100) / 10; ones = ((temp % 1000) % 100) % 10; displaybuffer[0] = data_buffer[ones]; displaybuffer[1] = data_buffer[tens]; displaybuffer[2] = data_buffer[hundreds]; displaybuffer[3] = data_buffer[thousands]; } // // _delay_us(500); if((temp >= 0) && (temp < 10)) { thousands = blank_digit; hundreds = blank_digit; tens = blank_digit; ones = temp; // fill the display buffer displaybuffer[0] = data_buffer[thousands]; displaybuffer[1] = data_buffer[hundreds]; displaybuffer[2] = data_buffer[tens]; displaybuffer[3] = data_buffer[ones]; } else if((temp > 9) && (temp < 100)) { thousands = blank_digit; hundreds = blank_digit; tens = temp / 10; ones = temp % 10; displaybuffer[0] = data_buffer[thousands]; displaybuffer[1] = data_buffer[hundreds]; displaybuffer[2] = data_buffer[tens]; displaybuffer[3] = data_buffer[ones]; } else if((temp > 99) && (temp < 1000)) { thousands = blank_digit; hundreds = temp / 100; tens = (temp % 100) / 10; ones = (temp % 100) % 10; displaybuffer[0] = data_buffer[thousands]; displaybuffer[1] = data_buffer[hundreds]; displaybuffer[2] = data_buffer[tens]; displaybuffer[3] = data_buffer[ones]; } else if((temp > 999) && (temp < 10000)) { thousands = temp / 1000; hundreds = (temp % 1000) / 100; tens = ((temp % 1000) % 100) / 10; ones = ((temp % 1000) % 100) % 10; displaybuffer[0] = data_buffer[thousands]; displaybuffer[1] = data_buffer[hundreds]; displaybuffer[2] = data_buffer[tens]; displaybuffer[3] = data_buffer[ones]; } } ISR(TIMER2_COMPA_vect) { display_temperature(temperature); //display_temperature(17); // select digit position PORTB = 1<<digit_count; digit_count++; digit_count &= (MAX_DIGITS - 1); // send data to the display PORTD = displaybuffer[displaybuffer_cnt]; // displaybuffer_cnt++; displaybuffer_cnt &= (DISPLAYBUFFERSIZE - 1); } ISR(ADC_vect) { unsigned char status_reg; // Save global interrupt flags status_reg = SREG; // disable interrupts first asm("cli"); // Calculate temperature value and store it in tempbuffer tempbuffer[temp_buffer_counter++] = ((ADCH * 5/255.0) - 0.5)/ 0.01; //_delay_us(3500); if(temp_buffer_counter == TEMP_BUFFERSIZE) { // reset temp_buffer_counter temp_buffer_counter = 0; for(unsigned cnt = 0; cnt < TEMP_BUFFERSIZE; cnt++) { temperature += tempbuffer[cnt]; } // Compute average temperature temperature = temperature / TEMP_BUFFERSIZE; } // Restore interrupts globally SREG = status_reg; } void temp_compare(unsigned int temp) { if ((temperature >= 0) && (temperature <= 29)) { //switch green led on PORTB = 0x80; } else if ((temperature >= 30) && (temperature <= 35)) { //switch motor and yellow led on PORTB = 0X20; } else if(temperature >= 36) { //switch buzzer and red led on keeping the motor on PORTB = 0X30; } }
for the circuit design please click the like
Last edited by a moderator: