注:本人博文整理至CSDN以方便查阅,源博文位于EDN
在ICCAVR中的三中方法
#include
#define _BV(bit) (1<<bit)<bit) <="" span="" style="margin: 0px; ">方法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
delay(5000);
asm("cbi 0x12,5");//将PD5设为低电平
delay(5000);
/*PORTA 0x1B; B 0x18; C 0x14; D 0x12
DDRA 0x1A; 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;