I have finished the programming part.
#include <avr/io.h>
#include <util/delay.h>
//Simple Wait Function
void Wait()
{
uint8_t i;
for(i=0;i<250;i++)
{
_delay_loop_2(0);
}
}
void main(){
DDRC = 0x00; // Configure Port C as input port
PORTC = 0xFF; //enable internal pull-up
DDRD = 0xF0; // Configure Port D as input port
PORTD = 0xFF; //enable internal pull-up
while(1){
if(PINC==0xfe){ //pull key 1
PORTD|=_BV(7); //relay on
}
else if(PINC==0xfd){ //pull key 2
PORTD&=~_BV(7); //relay off
}
else{
if((PIND & 0b00000001) == 0b00000001) //get input
PORTD&=~_BV(7); //relay off
else{
PORTD|=_BV(7); //relay on
Wait(); //5 second delay
}
}
}
}
I have set:
when distance sensor get the signal, the mist machine would work after 5 seconds.
To add the programming to the microcontroller , an AVR-ISP programmer is needed.
Here is a programmer for me to transfer the program from the computer to the microcontroller .
Microcontroller
AVR-ISP Programmer