#include
void Delay(unsigned int T)
{
unsigned int i,j;
for (i=0;i
asmvolatile("nop"); //匯編指令,讓單片機運行空指令
}
void main()
{
DDRA=0XFF;
//DDRA=0B11111111;//定義PA端口全為輸出
DDRE = 0x04;
PORTE= 0X04;//開發(fā)板控制LED時需要PE2使能端置1
while (1)
{
PORTA=0X00;
Delay(1000);
PORTA=0XFF;
Delay(1000);
}
}
流水燈(IO 作輸入口使用)
#include
void delay(unsigned int t)
{
unsigned int i,j;
for (i=1;i
asmvolatile("nop");
}
int main()
{
DDRE=0X04;
PORTE=0X04;
DDRA=0XFF;
delay(100);
PORTA=0XFF;
delay(100);
DDRD=0X00;
while(1)
{
unsigned char a;
a=PIND;
delay(1000);
if (0xff-a==0b10010001)
{
delay(100);
PORTA=0X00;
delay(100);
}
if (0xff-a==0b10010010)
{
delay(100);
PORTA=0XFF;
delay(100);
}
}
return 0;
}