Note : Pin connection should be in according to code below. if any confusion then ask in comments below...
//PB 0=BUZZER
//PB1=LDR SENSOR
//PC2=SMOKE SENSOR
//PC0=ANALOG INPUT(TEMPERATURE SENSOR)
//PC3,PC4,PC5=E,RW,RS( 16X2 LCD)
//PD=DATA(16X2 LCD)
#define F_CPU 12000000UL //Setting F_CPU to the frequency of the microcontroller
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*ADC Conversion Complete Interrupt Service Routine ()*/
ISR(ADC_vect);
////////////////////// ////////////////////////// ////////////////////////// ////
void InitADC()
{
DDRC = 0b00111000; // Configure PortA as input
ADMUX=(1<<REFS 0); // For Aref=AVcc;
ADCSRA=(1<<ADE N)|(7<<ADPS0);
}int ReadADC(int ch)
{
ch=ch&0b00000111 ; //Select ADC Channel ch must be 0-7
ADMUX|=ch;
ADCSRA|=(1<<AD SC); //Start Single conversion
while(!(ADCSRA & (1<<ADIF))); &n bsp; //Wait for conversion to complete
ADCSRA|=(1<<AD IF); //Clear ADIF by writing one to it
return(ADC);
}
////////////////////// ////////////////////////// //////////////////////////
#define SELECT_7SEG_DDR DDRC
#define SELECT_7SEG_PORT PORTC
#define DISP1 PC5
#define DISP2 PC4
#define DATA_DDR DDRD
#define DATA_PORT PORTDchar DECODE_7SEG[11] = {0x77,0x14,0xb3,0xb6,0xd4, 0xe6,0xe7,0x34,0xf7,0xf6,0 x08};
void DISPLAY_7SEG(int a)
{
SELECT_7SEG_DDR |= (1 << DISP1) | (1 << DISP2);
DATA_DDR = 0xff; // port assigned as output
char char1;char1 = a%10;
a = a/10;
char1 = DECODE_7SEG[char1];
SELECT_7SEG_PORT &= ~((1 << DISP1) | (1 << DISP2));
DATA_PORT = char1;
SELECT_7SEG_PORT |= (1 << DISP1);char1 = a%10;
a = a/10;
char1 = DECODE_7SEG[char1];
SELECT_7SEG_PORT &= ~((1 << DISP1) | (1 << DISP2));
DATA_PORT = char1;
SELECT_7SEG_PORT |= (1 << DISP2);
}int main()
{
DDRC &=~(1<<PC0);&nbs p; //PC2=LOW INPUT FOR TEMPERATURE
DDRB|=0xFF; ; //Output for relays
PORTB = 0x00; //INITIAL VALUE
InitADC();unsigned int count;while(1 )
{
int temp_int=ReadADC(0);
DISPLAY_7SEG(temp_in t/10); & nbsp; for(count = 0; count<1000; count++)
{
DISPLAY_7SEG(temp_in t/10);
} }
return 0;
}For any query, feel free to comment below.....
Posted By :
Mahesh Nigam
(Scientist)
2019-09-27 17:13
See Author's other Published Topics
Peoples