ATmega128 IO 学习
扫描二维码
随时随地手机看文章
#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;//开发板控制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;
}