#include <avr/io.h>int main(void)
本文引用地址:http://m.butianyuan.cn/article/201611/321007.htm{
DDRD &= ~(1 << 6);//設(shè)置為輸入
DDRD &= ~(1 << 3);//設(shè)置為輸入
DDRD &= ~(1 << 7);//設(shè)置為輸入
PORTD |= (1 << 6);//打開上啦電阻
PORTD |= (1 << 7);//打開上啦電阻
DDRA |= (1 << 3);//設(shè)置為輸出
DDRB |= (1 << 0);//設(shè)置為輸出
DDRB |= (1 << 1);//設(shè)置為輸出
PORTA &= ~(1 << 3);//關(guān)蜂鳴器
while(1)
{
switch(PIND & 0b11000000)
{
case 0b10000000:
{
PORTB |= (1 << 0);
PORTA |= (1 << 3);
break;
}
case 0b01000000:
{
PORTB |= (1 << 1);
break;
}
default:
{
PORTA &= ~(1 << 3);
PORTB = 0;
}
}
}
}
評論