⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hello_world.c

📁 altera niosii SOPC helloword 学习
💻 C
字号:
/* 
 * "Hello World" example. 
 * 
 * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
 * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example 
 * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
 * device in your system's hardware. 
 * The memory footprint of this hosted application is ~69 kbytes by default  
 * using the standard reference deisgn. 
 *
 * You can reduce the footprint to as little as 3118 bytes by making some changes 
 * in the Nios II IDE, though this affects the functionality available to you. 
 * The options available as well as their effects are described briefly below. 
 * Check in the Nios II Software Developers Manual for a more complete 
 * description.
 * 
 * In the SW Application project (hello_world):
 *
 *  - In the C/C++ Build page
 * 
 *    - Set the Optimization Level to -O3
 * 
 * In System Library project (hello_world_syslib):
 *  - In the C/C++ Build page
 * 
 *    - Set the Optimization Level to -O3
 *
 *    - Define the preprocessor option ALT_NO_INSTRUCTION_EMULATION 
 *      This removes software exception handling, which means that you cannot 
 *      run code compiled for Nios II cpu with a hardware multiplier on a core 
 *      without a the multiply unit. Check the Nios II Software Developers 
 *      Manual for more details.
 *
 *    - Check the Faster code/not debuggable
 *
 *  - In the System Library page:
 *    - Set Periodic system timer and Timestamp timer to none
 *      This prevents the automatic inclusion of the timer driver.
 *
 *    - Set Max file descriptors to 4
 *      This reduces the size of the file handle pool.
 *
 *    - Uncheck Clean exit (flush buffers)
 *      This removes the call to exit, and when main is exitted instead of 
 *      calling exit the software will just spin in a loop.
 *
 *    - Check Small C library
 *      This uses a reduced functionality C library, which lacks  
 *      support for buffering, file IO, floating point and getch(), etc. 
 *      Check the Nios II Software Developers Manual for a complete list.
 *
 *    - Check Reduced device drivers
 *      This uses reduced functionality drivers if they're available. For the
 *      standard design this means you get polled UART and JTAG UART drivers,
 *      no support for the LCD driver and you lose the ability to program 
 *      CFI compliant flash devices.
 *
 *      
 *
 */

#include "system.h"
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
#include "lcd_1602.h"
#include <stdio.h>




int main()
{ 
  alt_u8 led;
  alt_u8 key;
  volatile char j = 0x30;
  volatile int i;
  initialcd();
  while (1) 
  {  
  // initialcd();
  for(i=0;i<200000;i++) ;
  led = 0x1;
  *(unsigned int *)PIO_LED_BASE = led; 
  for(i=0;i<200000;i++) ;
  led = 0x2;
  *(unsigned int *)PIO_LED_BASE = led;
  
  key = (alt_u8)*(unsigned int *)PIO_KEY_BASE;
  key &= 0x3;
  if(key == 1) 
  {
  displaystring(0xC0,"  THIS IS KEY1  ");
   for(i=0;i<2000000;i++) ;
   for(i=0;i<2000000;i++) ;
 printf("I love SOPC \n");
  }
  else if(key == 2) 
  {
  displaystring(0x80,"Welcome 00IC.com");
   for(i=0;i<2000000;i++) ;
   for(i=0;i<2000000;i++) ;
   printf("Welcome www.00IC.com\n");
  }
  printf("HelloWorld from FPGA/SOPC!\n");          
  displaystring(0x80,"SOC:HelloWorld");
  writelcddata(j);
  displaystring(0xC0,"We do the best!"); 
  j++;
  if(j > 0x39) j = 0x30; 
  }
  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -