anoop kr
Member level 4
Hai i am doing a project of security system now.For that i have to take multiple inputs from different sensors.The sensors i am using are LDR , GAS sensor , PIR motion sensor and Temperature sensor(LM35). the LM35 is connecting to the PORTA [PA.0 pin].And all the other sensors are connecting to the PORTB [PB.0 ,PB.1 ,PB.2 respectively].
Initially i just dont connect the sensors and instead of that i just check the status of the port PORTA which use as the input and the PORTB which is now use as output.these are only just done for checking that whether the programe is working correctly.After i burn the hexcode into the MCU and wired it according to the code it shows malfunctions.i mean some false triggering is happening.so that without any input to the port pins the LEDs are glowing , sometimes one LED is glowing continuously.I am using Atmega32 controller.I am giving the code i had written..Please help mee..:-(
#include<avr/io.h>
#include<util/delay.h>
void main()
{
int read;
DDRA=0x00;
PORTA=0x00;
DDRB=0xFF;
PORTB=0x00;
while(1)
{
read=PINA;
switch(read)
{
case 0x01:
dis1();
break;
case 0x02:
dis2();
break;
case 0x04:
dis4();
break;
default :
disp();
break;
}
}
}
void disp()
{
PORTB=0x00;
}
void dis1()
{
PORTB=0x01;
_delay_ms(50);
}
void dis2()
{
PORTB=0x02;
_delay_ms(50);
}
void dis4()
{
PORTB=0x04;
_delay_ms(50);
}
Initially i just dont connect the sensors and instead of that i just check the status of the port PORTA which use as the input and the PORTB which is now use as output.these are only just done for checking that whether the programe is working correctly.After i burn the hexcode into the MCU and wired it according to the code it shows malfunctions.i mean some false triggering is happening.so that without any input to the port pins the LEDs are glowing , sometimes one LED is glowing continuously.I am using Atmega32 controller.I am giving the code i had written..Please help mee..:-(
#include<avr/io.h>
#include<util/delay.h>
void main()
{
int read;
DDRA=0x00;
PORTA=0x00;
DDRB=0xFF;
PORTB=0x00;
while(1)
{
read=PINA;
switch(read)
{
case 0x01:
dis1();
break;
case 0x02:
dis2();
break;
case 0x04:
dis4();
break;
default :
disp();
break;
}
}
}
void disp()
{
PORTB=0x00;
}
void dis1()
{
PORTB=0x01;
_delay_ms(50);
}
void dis2()
{
PORTB=0x02;
_delay_ms(50);
}
void dis4()
{
PORTB=0x04;
_delay_ms(50);
}