原创 SOPC入门的第一个程序

2009-4-5 21:23 1662 10 10 分类: FPGA/CPLD

最近学习FPGA的SOPC相关东西,搞了个简单系统,在NIOS-II环境下写了个入门流水灯程序,呵呵,发表发表。


#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"


  /*
   * This is a freestanding application, so we want to use alt_main
   * as the entry point.  However, if the debugger is run on this
   * application, it will try to set a breakpoint at main, which
   * the application does not contain.  The below line creates an
   * alias so the debugger is able to set a breakpoint at main,
   * yet the application retains alt_main as it's entry point.
   */



int main (void)
{
  alt_u8 led = 0x2;
  alt_u8 dir = 0;
  volatile int i;
    
  /*
   * Infinitely shift a variable with one bit set back and forth, and write
   * it to the LED PIO.  Software loop provides delay element.
   */
  while (1)
  {
    if (led & 0x9)
    {
      dir = (dir ^ 0x9);
    }


    if (dir)
    {
      led = led >> 1;
    }
    else
    {
      led = led << 1;
    }
    IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, led);


    /*
    * The delay element in this design has been written as a while loop
    * to avoid confusing the software debugger.  A tight, one line software
    * delay loop such as:
    *   for(i=0; i<200000; i++);
    * can cause problems when it is stepped through using a software debugger.
    * The while loop below produces the same behavior as the for loop shown
    * above, but without causing potential debugger problems. 
    */
 
    i = 0;
    while (i<200000)
      i++;
  }


  return 0;
}

文章评论0条评论)

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