目的:将8个led灯分成两组,这两组轮流点亮
程序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++)
;
}
}
}
第二个程序可以实现,第一个却不能实现,为什么呢?
LZ用studio单步调试一下不就知道问题出在哪里了。
欢迎光临 (http://www.51hei.com/bbs/) | Powered by Discuz! X3.1 |