標(biāo)題:
AVR_點(diǎn)亮LED程序
[打印本頁(yè)]
作者:
liuqq
時(shí)間:
2015-5-22 01:11
標(biāo)題:
AVR_點(diǎn)亮LED程序
//++++++++++++++++++++++++++++++++++
很糾結(jié)的用ICC AVR寫了個(gè)程序。調(diào)試通過(guò),木有仿真下載線。貌似挺貴,
窮人家的孩子買不起。鉆研下做個(gè)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單片機(jī)更加復(fù)雜,|運(yùn)算是關(guān)鍵
DDRB=0XFF;
PORTB=0XFF;
while(1)
{
for(k=0;k<8;k++) //for語(yǔ)句
{
PORTB&=~BIT(k);//取反操作
delay(500);//延時(shí)500ms
PORTB|=BIT(k);
delay(500);
}
}
}//我靠!寫完了。滾床睡覺(jué),很晚了, 明天是該死的體育考試,oh my god
作者:
liuqq
時(shí)間:
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);
}
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1