原创 NIOS II学习四~~JTAG UART

2010-4-23 16:14 3541 7 7 分类: FPGA/CPLD

通过向console接收字符 并接行相应程序


include <stdio.h>
#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
#define static void TestLED( void );
static void TestLED( void )
{
alt_u8 led = 0x2;
alt_u8 dir = 0;
int j;
volatile int i;
for (j=0;j<100;j++)
{ if (led & 0x81)
{ dir = (dir ^ 0x1); }
if (dir)
{ led = led >> 1; }
else
{ led = led << 1; }
IOWR_ALTERA_AVALON_PIO_DATA(LED_BASE, led);
i = 0;
while (i<200000)
i++;
}
return ;
}


int main()
{
static int ch = 97;
printf("-------------------------------------------\n");
printf("Please input characters in console: \n");
printf("'g':run leds \n");
printf("Other characters except 'g':nothing to do \n");
printf("'q':exit \n");
printf("-------------------------------------------\n");
while((ch = getchar())!='q')
{
if(ch=='g')
{
printf("LEDs begin run...\n");
TestLED();
printf("LEDs run over.\n");
}
}
return 0;
}

文章评论0条评论)

登录后参与讨论
我要评论
0
7
关闭 站长推荐上一条 /2 下一条