|
写法一:
#include "system.h"
#include <stdio.h>
#include <stdlib.h>
#include "altera_avalon_pio_regs.h"
#include "altera_avalon_jtag_uart.h"
#include "alt_types.h"
//int main (void) __attribute__ ((weak, alias ("alt_main")));
int main (void)
{
alt_u8 led = 0x2;
int i =0;
FILE* fp;
fp = fopen ("/dev/jtag_uart", "r+");
while (1)
{
if( fp )
{
printf("\r\nOK!");
}
IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, 7) ;
usleep(500000);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, 0) ;
usleep(500000);
}
fclose(fp);
return 0;
}
写法二:
#include "system.h"
#include <stdio.h>
#include <stdlib.h>
#include "altera_avalon_pio_regs.h"
#include "altera_avalon_jtag_uart.h"
#include "alt_types.h"
//int main (void) __attribute__ ((weak, alias ("alt_main")));
int main (void)
{
alt_u8 led = 0x2;
int i =0;
FILE* fp;
while (1)
{
fp = fopen ("/dev/jtag_uart", "r+");
if( fp )
{
printf("\r\nOK!");
fclose(fp);
}
IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, 7) ;
usleep(500000);
IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, 0) ;
usleep(500000);
}
return 0;
}
测试平台:
1、芯片为EP2C8Q208;
2、使用外部8M SDRAM;
实验结果:
1、写法一 无论下载到板上还是debug模式,始终运行正常,1S灯闪烁一次;
2、写法二 下载到板上以后,闪烁2下就不闪了,然后一直亮,但是,使用debug时,无论多长时间,会一直闪烁。
以上测试结果经过反复论证,实在令人费解,哪位知道是何故也? |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|