目的:將8個(gè)led燈分成兩組,這兩組輪流點(diǎn)亮
程序1:
#include<iom128v.h>
#include<macros.h>
#define uint unsigned int
#define uchar unsigned char
void delay(uint del)
{
uint i,j;
for(i=0;i<del;i++)
for(j=0;j<1241;j++)
;
}
void main()
{
DDRA=0xff;
PORTA=0xf0;
while(1)
{
DDRE=DDRE|BIT(2);
PORTE=PORTE|BIT(2);
DDRA=0xff;
PORTA=~PORTA;
delay(1000); //延遲1s
}
}
程序2:
#include<iom128v.h>
#include<macros.h>
#define uint unsigned int
#define uchar unsigned char
void main()
{
DDRA=0xff;
PORTA=0xf0;
while(1)
{
uint i,j;
DDRE=DDRE|BIT(2);
PORTE=PORTE|BIT(2);
DDRA=0xff;
PORTA=~PORTA;
for(i=0;i<1000;i++) //延遲1s
{
for(j=0;j<1241;j++)
;
}
}
}
第二個(gè)程序可以實(shí)現(xiàn),第一個(gè)卻不能實(shí)現(xiàn),為什么呢?
LZ用studio單步調(diào)試一下不就知道問題出在哪里了。
歡迎光臨 (http://www.torrancerestoration.com/bbs/) | Powered by Discuz! X3.1 |