Write a C program to implement a circuit is used to switch on a fan connected to
ID: 2266190 • Letter: W
Question
Write a C program to implement a circuit is used to switch on a fan connected to DC motor when the temperature is greater than a threshold value (30c) and display the temperature in the computer using RS232C, atmega8. (Embedded system course) Write a C program to implement a circuit is used to switch on a fan connected to DC motor when the temperature is greater than a threshold value (30c) and display the temperature in the computer using RS232C, atmega8. (Embedded system course) (Embedded system course)Explanation / Answer
#include<avr/io.h>
#include<util/delay.h>
void init_adc()
{
ADMUX = (1<<REFS0);
ADCSRA = (1<<ADPS1) | (1<<ADPS2) | (1<<ADEN);
}
uint16_t read_adc(uint8_t ch)
{
init_adc();
ch = ch & 0b00000111;
ADMUX | = ch;
ADCSRA | = (1<<ADSC);
while(!(ADCSRA & (1<<ADIF)));
ADCSRA | = (1<<ADIF);
return (ADC);
}
int main(void)
{
int x;
init_adc();
DDRB=0xFF;
while(1)
{
x = read_adc(0);
if (x>102.4)
PORTB = 0b00010000;
else if (x<21)
PORTB = 0b00000010;
else
PORTB = 0b00000000;
}
return 0;
}
another method
#include<reg52.h>
#include<stdio.h>
void delay(void);
sbit motor_pin_1 = P2^0;
sbit motor_pin_2 = P2^1;
void main()
{
do
{
motor_pin_1 = 1;
motor_pin_2 = 0; //Rotates Motor Anit Clockwise
delay();
motor_pin_1 = 1;
motor_pin_2 = 1; //Stops Motor
delay();
motor_pin_1 = 0;
motor_pin_2 = 1; //Rotates Motor Clockwise
delay();
motor_pin_1 = 0;
motor_pin_2 = 0; //Stops Motor
delay();
}while(1);
}
void delay()
{
int i,j;
for(i=0;i<1000;i++)
{
for(j=0;j<1000;j++)
{
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.