cmp335* - : tailieuhoctap@hutech.2 TÍCH QSYS VÀO QUARTUS II .3 CHO NIOS II. 40 II - Bài 1: HDL. sinh viên - 5 Giáo viên - 5 .1 VHDL B2: Family là Cyclone IV E Available devices là EP4CE115F29C7 Finish 2 BÀI 1: B3: File > New: B4: VHDL File - Save B5: Project Navigator File Set as Top-level Entity BÀI 1: 3 B6: Processing > Start Compilation Start Compilation B7: B8: File > New Block Diagram/Schematic File. 4 BÀI 1: - Symbol Tool - Trong khung Libraries Project D_FF.
- vào file D_FF_block.bdf Set as Top-Level Entity. - Start Compilation - Assignments > Import Assignments DE2_115_pin_assignments. BÀI 1: 5 - - Start Compilation B9: Tools > Programmer Hardware Setup USB-Blaster.sof Add File, .sof output_files). 6 BÀI 1: RUN / PROG ) sang RUN vào Start cho DE2-115.
SW[1] SW[0] KEY[0] LEDR[0] LEDR[1] RESET D CK Q Qnot 1 0 1 0 0 0 1 BÀI 1: 7 Bài 1.1 -> 8 và gán chân S0 S2: SW[0] SW[2], E: SW[10], D0 D7: LEDG[0] LEDG[7].2 -> 3 và gán chân D0 D7: SW[10] SW[17], Q0 Q2: LEDR[10] LEDR[12].1 VHDL Verilog HDL.3 -> 8 và gán chân S0 S2: SW[10] SW[12], E: SW[0], D0 D7: LEDR[0] LEDR[7].4 -> 3 và gán chân D0 D7: SW[1] SW[8], Q0 Q2: LEDG[5] LEDG[7].3 MÁY TR NG THÁI MOD 10 1.1 File > New State Machine File.2 State Machine Editor: - State Tool -> state10. - Transition Tool -> state10. - Dùng côn Add New Input Port - Add New Output Port - State Table Transition BÀI 1: 11 - Generate HDL File VHDL hay Verilog HDL. 12 BÀI 1: RESET UP Clk Y SW[0] SW[1] KEY[0] LEDG 1 1 0 1 0 0 0 0 0 0 0 0 Bài 1.
14 BÀI 2: BÀI 2: T NHÚNG 2.1 QSYS Trong bài này, Qsys dùng II/e và và : T 1. Qsys: Qsys Tools > Qsys Click File > Save sw2_led8. clk_0 Rename clock_main. BÀI 2: 15 Qsys ii_sys sau: Nios II/e - Trong tab Component Library (bên trái) Embedded Processors, và click vào Nios II Processor.
- - - Ghi chú: On-chip memory RAM 2 KB. - - Chip, và click vào On-Chip Memory (RAM or ROM). BÀI 2: 17 - Click Add - gõ vào 32K. - onchip_memory2_0 thành onchip_memory.
Ghi chú: ing. Các PIO: - Trên tab Component Library, trong Peripherals Microcontroller Peripheral, và click vào PIO (Parallel I/O). 18 BÀI 2: Click Add 2 Basic Settings Input. pio_0 thành sw.
Thêm vào PIO Width = 8, Direction là Output tên thành led. Trên tab Component Library, trong Peripherals Debug and Performance, và click vào System ID Peripheral. BÀI 2: 19 - 1337 sysid_qsys_0 thành sysid_1337. Ghi chú: o 12 errors và 6 warnings.
- 20 BÀI 2: Clock_main > clk Nios2_proc > clk Onchip_memory > clk1 Sw > clk Led > clk Sysid_1337 > clk Ghi chú: - ác chân reset: Clock_main > clk_reset Nios2_proc > reset_n Onchip_memory > reset1 Sw > reset Led > reset Sysid_1337 > reset Ghi chú: 2 errors và 6 warnings. - Avalon Memories: Nios2_proc > data_master Nios2_proc > jtag_debug_module Onchip_memory > s1 Sw > s1 Led > s1 Sysid_1337 > control_slave Ghi chú: 8 errors và 2 warnings. - Nios2_proc > instruction_master BÀI 2: 21 Nios2_proc > jtag_debug_module Onchip_memory > s1 Ghi chú: 10 errors và 2 warnings. - System > Assign Base Addresses.
Ghi chú: - Double-click vào nios_proc. Reset Vector onchip_memory. Trong Exception Vector onchip_memory. - clock_main > clk_in_reset nio2_proc > reset_n.
- Double- Export sw > external_connection (Conduit). 22 BÀI 2: sw sw sw_external_conn. - Click vào tab Generation. - Click Generate - Click Exit Quartus.2 TÍCH H P H TH NG QSYS VÀO QUARTUS II - Project > Add/Remove Files in Project., c synthesis All Files file sw2_led8.qip - Open Add OK.
- Project Navigator Files .qip và Set as Top-Level Entity 24 BÀI 2: - Processing > Start Compilation Start Compilation - File > New Block Diagram/Schematic File. BÀI 2: 25 - Symbol Tool - Trong khung Libraries Project. - Generate Pins for Symbols Ports. - Set as Top-Level Entity cho file sw2_led8_bdf.bdf Processing > Start Compilation 26 BÀI 2: - Assignments > Import Assignments DE2_115_pin_assignments.
- - Start Compilation - Tools > Programmer Hardware Setup ên USB-Blaster. BÀI 2: 27 - Programmer ile .sof Add File - RUN / PROG trên kit DE2 sang RUN Start 2.3 N P PH N M M CHO NIOS II - Tools > Nios II Software Build Tools for Eclipse. - File > New > Nios II Application and BSP from Template. - Trong SOPC Information File name, sw2_led8.
Trong CPU Name nios2_proc. Trong Project name sw2_led8. Trong Project template Hello World. BÀI 2: 29 - File > New > Nios II Application.
30 BÀI 2: - sw2_led8_board. Click vào nút BSP location. - C sw2_led8_bsp. - Project Explorer sw2_led8_board New > Source File.
BÀI 2: 31 - Trong Source file, gõ main.c; trong Template Default C source template. Save sw2_led8_board Run As > 3 Nios II Hardware. sw2_led8_board Run As > Run Configurations. Trong Tab Target Connection Refresh Connection 32 BÀI 2: System ID Properties n vào các check box Ignore mismatched system ID và Ignore mismatched system timestamp.
Downloading 00008000 ( 0%) Downloading 00008F1C (61%) Downloaded 4KB in 0.0s Verifying 00008000 ( 0%) Verifying 00008F1C (61%) Verified OK Starting processor at address 0x00008020 BÀI 2: 33 Bài 2.1 LEDR7 khi SW0 on, LEDR7 khi SW1 on. Ghi chú: Dùng hàm usleep delay 100000 s = 100 ms. Ghi chú Bài 2. - ledg), gán cho LEDG0 LEDG7.
- n là key), gán cho KEY0 - BÀI 3: 35 Bài 3.1: SW7 các LED xanh.h" void main() { int * sw_ptr = (int *)SW_BASE; int * led_ptr = (int *)LEDG_BASE; int * key_ptr = (int *)KEY_BASE; while (1) { if (*(key_ptr+3) > 0) { *(led_ptr)=*(sw_ptr); *(key_ptr+3)=0; } } } Bài 3.2 - - SW0 lên LEDG1 LEDG0. - SW0 lên LEDG7 LEDG0.2 NG T - trong Qsys).h" void main(void) { int * sw_ptr = (int *)SW_BASE; int * led_ptr = (int *)LED_BASE; int * key_ptr = (int *)KEY_BASE; *(key_ptr+2) = 0x0F; __builtin_wrctl(3,1); __builtin_wrctl(0,1); while (1); } } void interrupt_handler(void) { int ipending; ipending = __builtin_rdctl(4); // if (ipending & 0x01) // key_isr(); } void key_isr(void) BÀI 3: 37 { int * led_ptr = (int *) LED_BASE; int * key_ptr = (int *) KEY_BASE; int * sw_ptr = (int *) SW_BASE; *(led_ptr) = *(sw_ptr); *(key_ptr + 3) = 0; } Bài 3.4 - - - 38 BÀI 4: LCD BÀI 4: LCD 4.1 XÂY D NG PH N C NG - - -chip 128 K. - PIO ngõ vào 2 bit, gán cho KEY0 KEY1.2 PH N M M NHÚNG Bài 4.h" void lcd_init(void); void lcd_printf(char message[],int line); int main() { usleep(15000); /* Wait for more than 15 ms before init */ lcd_init(); lcd_printf( ); lcd_printf( ); while (1); return 0; } void lcd_init(void) { IOWR(LCD_BASE,0,0x38);usleep(4100); IOWR(LCD_BASE,0,0x0C);usleep(100); BÀI 4: LCD 39 IOWR(LCD_BASE,0,0x06);usleep(100); IOWR(LCD_BASE,0,0x01);usleep(2000); IOWR(LCD_BASE,0,0x02);usleep(2000);} void lcd_printf(char message[],int line) { int i; if (line==1) IOWR(LCD_BASE,0,0x80); else IOWR(LCD_BASE,0,0xC0); usleep(100); for(i = 0; message[i] != 0; i++) { IOWR (LCD_BASE,2,message[i]); usleep(100); } } Bài 4.2 - Dòng 1: Counter 1 = xxx - Dòng 2: Counter 2 = yyy - 456.