Friday 16 September 2016

Digital_Thermometer

Digital_Thermometer:


Code:


#include<avr/io.h>
#define F_CPU 80000000
#include<util/delay.h>

unsigned char arr1[10]={0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F};
#include <inttypes.h>
unsigned int i,j;
void initadc()
{
ADMUX=(1<<REFS0);
ADCSRA=(1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);
}

uint16_t ReadADC(uint8_t ch)
{
//Select ADC Channel ch must be 0-7
//ch=ch&0b00000111;
ADMUX=0xc0;
//Start Single conversion
ADCSRA|=(1<<ADSC);
//Wait for conversion to complete
while(!(ADCSRA & (1<<ADIF)));
//Clear ADIF by writing one to it
ADCSRA|=(1<<ADIF);
return(ADC);
}

void show(int k)
{
switch(k)
{
case 0:
PORTB=0x01;
PORTD=~arr1[i];
_delay_us(20);
break;

case 1:
PORTB=0x02;
PORTD=~arr1[j];
_delay_us(10);
break;

}
}

void convert(int k)
{
   i=k/10;
   j=k%10;
   for(int l=0;l<50;l++)
   {
    for(int k=0;k<2;k++)
    {
     show(k);
_delay_us(100);
    }
   }  
}

int main(void)
{
int temp=0;
int result=0;
DDRB=0xff;
DDRD=0xff;
   // DDRC=0xff;
uint16_t adc_result[10];
initadc();
while(1)
{
for(int n=0;n<10;n++)
adc_result[n]=ReadADC(0);
for(int n=0;n<10;n++)
temp=temp+adc_result[n];
result=temp/40;
convert(result);
result=0;
temp=0;
//_delay_ms(1);
}
}


Simulation:




0 comments:

Post a Comment

if you have any doubt please let me know