This article is reproduced in: workshop!
I. Hardware (using Quartus II 9.0)
1. Create a project, enable the system-wide image search system builder, and add a CPU
Select standard Nias.
2. Add PLL
Click launch Altera's altpll megawizard
The speed level of the device is based on your FPGA. My FPGA is ep2c8, so select 8
The input clock is determined by the crystal oscillator. It is 50 MHz on the board.
Two clocks are output:
C0 50 MHz phase 0
C1 50 MHz phase-72 degrees
Rename PLL. CO in clock settings to sys_clk, and PLL. C1 to sd_clk.
Select sys_clk for CPU clock
3. Add SDRAM (k4s641632h on the Board)
Presets select Custom
Data width: 16
4. Add jtag_uart
5. Add Pio
Select 4 for width. There are only four LEDs on my board.
Select output port only for direction.
Rename Pio to led_pio
6. Add the System ID
7. Click system-> auto assign base address and auto assign irqs. the system configuration is complete.
Click Generate to generate the system.
8. Create a schematic BDF file in Quartus II, and add the just-created system-based platform-based system.
After configuring I/O, run Quartus and go to the target board ......
Ii. Software (nioii 9.0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
* Led. h
*
* Created on: 2010-7-17
* Author: Administrator
*/
# Ifndef led_h _
# Define led_h _
Void led (unsigned char DIR)
{
Unsigned char K, led;
Unsigned int I, J;
For (k = 10; k --)
{
For (I = 0; I <4; I ++)
{
If (! DIR) led = 1 <I;
Else led = 8> I;
Iowr_altera_avalon_pio_data (led_pio_base ,~ LED );
J = 0;
While (j <100000) J ++;
}
}
}
# Endif/* led_h _*/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include <stdio. h>
# Include <string. h>
# Include "system. H"
# Include "altera_avalon_pio_regs.h"
# Include "alt_types.h"
# Include "led. H"
Int main ()
{
File * FP;
Char STR [6];
Char str1 [5];
Char str2;
Fp = fopen ("/dev/jtag_uart", "R + ");
If (FP)
{
While (strcmp (str1, "stop ")! = 0)
{
Printf ("LEDs are ready, please input start or stop \ n ");
Fgets (STR, 6, FP );
Strcpy (str1, STR );
Str1 [4] = '\ 0 ';
If (strcmp (STR, "Start") = 0) printf ("LEDs have run over, please input P or N or stop \ n ");
While (strcmp (str1, "stop ")! = 0)
{
Str2 = GETC (FP );
If (str2 = 'n ')
{
LED (0 );
Printf ("LEDs have run over, please input P or N or S \ n ");
}
Else if (str2 = 'P ')
{
LED (1 );
Printf ("LEDs have run over, please input P or N or s' \ n ");
}
Else if (str2 ='s ') strcpy (str1, "stop ");
}
}
}
Printf ("LEDs have run over \ n ");
Fclose (FP );
Return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run