在ICCAVR中的三中方法
#include
#define _BV(bit) (1<<bit)方法1
void delay(unsigned int delaytime);
void main()
{
DDRB=0xff;
while(1)
{
PORTB|=(1<<0);//方法2
delay(5000);
PORTB&=(1<<0);
delay(5000);
PORTB&=~_BV(PB1);
delay(5000);
PORTB=_BV(PB1);
delay(5000);
asm("sbi 0x12,5");//将PD5设为高电平 //方法3<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
delay(5000);
asm("cbi 0x12,5");//将PD5设为低电平
delay(5000);
/*PORTA 0x1B; B 0x18; C 0x14; D 0x12
DDRA 0x<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />1A; B 0x17; C 0x14 D 0x11
PINA 0x19; B 0x16; C 0x13 D 0x10*/
}
}
void delay(unsigned int delaytime)
{
unsigned int i;
for(i=0;i<10000;i++)
for(;delaytime>0;delaytime--);
}
在CVAVR(codevision avr)中则有点类似51中的赋值法如
#define sclk PORTB.5
^^^^^^^^^^^^
在各函数中可这样编写
sclk=0;
文章评论(0条评论)
登录后参与讨论