#include <avr/io.h>int main(void)
本文引用地址:http://www.biyoush.com/article/201611/321006.htm{
DDRD &= ~(1 << 6);//第六位設(shè)置為輸入
DDRD &= ~(1 << 3);//第六位設(shè)置為輸入
DDRD &= ~(1 << 7);//第六位設(shè)置為輸入
PORTD |= (1 << 6);//打開(kāi)上啦電阻
PORTD |= (1 << 7);//打開(kāi)上啦電阻
DDRA |= (1 << 3);//設(shè)置為輸出
DDRB |= (1 << 0);//設(shè)置為輸出
DDRB |= (1 << 1);//設(shè)置為輸出
PORTA &= ~(1 << 3);//關(guān)蜂鳴器
while(1)
{
if(PIND & (1 << 6)) //開(kāi)關(guān)打開(kāi)的時(shí)候
{
PORTA &= ~(1 << 3);//關(guān)蜂鳴器
}
else
{
if(PIND & (1 << 7))
PORTB &= ~(1 << 0);//燈滅
else
PORTB |= (1 << 0);//燈開(kāi)
PORTA |= (1 << 3); //開(kāi)蜂鳴器
}
}
}
評(píng)論