标题:
AVR_点亮LED程序
[打印本页]
作者:
liuqq
时间:
2015-5-22 01:11
标题:
AVR_点亮LED程序
//++++++++++++++++++++++++++++++++++
很纠结的用ICC AVR写了个程序。调试通过,木有仿真下载线。貌似挺贵,
穷人家的孩子买不起。钻研下做个AVR ISP还是比较靠谱,加油!
+++++++++++++++++++++++++++++++++++//
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<1141;j++);
}
}
void main()
{
uchar k;
DDRA|=BIT(2);
PORTA|=BIT(2);//我表示AVR的位操作比51单片机更加复杂,|运算是关键
DDRB=0XFF;
PORTB=0XFF;
while(1)
{
for(k=0;k<8;k++) //for语句
{
PORTB&=~BIT(k);//取反操作
delay(500);//延时500ms
PORTB|=BIT(k);
delay(500);
}
}
}//我靠!写完了。滚床睡觉,很晚了, 明天是该死的体育考试,oh my god
作者:
liuqq
时间:
2015-5-22 01:17
#include <iom16.h>
#include <macros.h>
/* This seems to produce the right amount of delay for the LED to be
* seen
*/
void Delay()
{
unsigned char a, b;
for (a = 1; a; a++)
for (b = 1; b; b++)
;
}
void LED_On(int i)
{
PORTB = ~BIT(i); /* low output to turn LED on */
Delay();
}
void main()
{
int i;
DDRB = 0xFF; /* output */
PORTB = 0xFF; /* all off */
while (1)
{
/* forward march */
for (i = 0; i < 8; i++)
LED_On(i);
/* backward march */
for (i = 8; i > 0; i--)
LED_On(i);
/* skip */
for (i = 0; i < 8; i += 2)
LED_On(i);
for (i = 7; i > 0; i -= 2)
LED_On(i);
}
}
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1