You are on page 1of 9

BÁO CÁO THỰC HÀNH “THIẾT KẾ SoC”

Tên bài thực hành: Bài 8 – MODEL SIM


Tên thành viên nhóm:

 Phan Thế Hoàng 21093641


 Đinh Đức Hùng 21107541
 Đào Phan Gia Huy 21085241

Ngày thực hiện: 14/ 03/ 2024

Bài 1:

Bài 1: Sử dụng Modelsim mô phỏng 8 Led sáng đuổi từ Trái sang Phải, thời gian
delay là 10us. Báo cáo biểu đồ dạng sóng thể hiện đầy đủ 8 trạng thái sáng đuổi
của 8 Led, và mô tả giải thích dạng sóng trên ModelSim
Phần cứng Qs:

Code C:

-1-
#include <stdio.h>

#include "system.h"

#include "altera_avalon_timer_regs.h"

#include "sys/alt_irq.h"

#define LEDS_BASE 0x11050

unsigned int i =0;

volatile unsigned int counter = 0;

void Timer_IRQ_Handler(void* irs_context) {

counter++;

IOWR(LEDS_BASE, 0, (1 << (counter % 8)));

IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE,
ALTERA_AVALON_TIMER_STATUS_TO_MSK);

-2-
}

void Timer_Init(void) {

unsigned int period = 0;

IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE,
ALTERA_AVALON_TIMER_CONTROL_STOP_MSK);

period = (50000 - 1);

IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE, period &


0xFFFF);

IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE, (period
>> 16) & 0xFFFF);

IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE,
ALTERA_AVALON_TIMER_CONTROL_CONT_MSK |
ALTERA_AVALON_TIMER_CONTROL_ITO_MSK |
ALTERA_AVALON_TIMER_CONTROL_START_MSK);

int main() {

Timer_Init();

alt_ic_isr_register(0, TIMER_0_IRQ, Timer_IRQ_Handler, NULL, NULL);

unsigned int leds = 0;

while (1) {

for ( i = 0; i < 8; i++) {

leds = (1 << i);

IOWR(LEDS_BASE, 0, leds);
-3-
usleep(100000);

for ( i = 7; i >= 0; i--) {

leds = (1 << i);

IOWR(LEDS_BASE, 0, leds);

usleep(100000);

return 0;

Link video minh chứng

-4-
Bài 2 Phần cứng Qsys: NIOS, Clock, On-chip Memory, Timer, LCD Thực hiện
hiển thị các số từ 0 - 9 lên LCD với thời gian 10uS Sử dụng Modelsim để mô
phỏng, báo cáo thể hiện đầy đủ các tín hiệu: + Dạng sóng thực hiện Command lên
LCD + Dạng sóng thực hiện ghi Data lên LCD + Dạng sóng thể hiện thời gian
10uS cho mỗi lần ghi data.
Bài làm

Phần cứng Qs:

Code C:

* Function Description

* =============== =====================================

* alt_printf Only supports %s, %x, and %c ( < 1 Kbyte)

* alt_putstr Smaller overhead than puts with direct drivers

* Note this function doesn't add a newline.

* alt_putchar Smaller overhead than putchar with direct drivers

* alt_getchar Smaller overhead than getchar with direct drivers


-5-
*

*/

#include "sys/alt_stdio.h"

#include "system.h"

#include <stdio.h>

#include <unistd.h>

#include "string.h"

#include "altera_avalon_lcd_16207_regs.h"

#include "io.h"

#define LCD_WR_COMMAND_REG 0

#define LCD_RD_STATUS_REG 1

#define LCD_WR_DATA_REG 2

#define LCD_RD_DATA_REG 3

void lcd_init()

usleep(15000);

IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_16207_0_BASE,0x38);

usleep(4150);

IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_16207_0_BASE,0x06);

usleep(4150);

-6-
IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_16207_0_BASE,0x0E);

usleep(4150);

IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_16207_0_BASE,0x01);

usleep(2050);

void lcd_init_2()

usleep(15000); /* Wait for more than 15 ms before init */

/* Set function code four times -- 8-bit, 2 line, 5x7 mode */

IOWR(LCD_16207_0_BASE, LCD_WR_COMMAND_REG, 0x38);

usleep(4100); /* Wait for more than 4.1 ms */

IOWR(LCD_16207_0_BASE, LCD_WR_COMMAND_REG, 0x38);

usleep(100); /* Wait for more than 100 us */

IOWR(LCD_16207_0_BASE, LCD_WR_COMMAND_REG, 0x38);

usleep(5000); /* Wait for more than 100 us */

IOWR(LCD_16207_0_BASE, LCD_WR_COMMAND_REG, 0x38);

usleep(100); /* Wait for more than 100 us */

/* Set Display to OFF*/

IOWR(LCD_16207_0_BASE, LCD_WR_COMMAND_REG, 0x08);

usleep(100);

-7-
/* Set Display to ON */

IOWR(LCD_16207_0_BASE, LCD_WR_COMMAND_REG, 0x0C);

usleep(100);

/* Set Entry Mode -- Cursor increment, display doesn't shift */

IOWR(LCD_16207_0_BASE, LCD_WR_COMMAND_REG, 0x06);

usleep(100);

/* Set the Cursor to the home position */

IOWR(LCD_16207_0_BASE, LCD_WR_COMMAND_REG, 0x02);

usleep(2000);

/* Display clear */

IOWR(LCD_16207_0_BASE, LCD_WR_COMMAND_REG, 0x01);

usleep(2000);

int main()

IOWR(LCD_16207_0_BASE, LCD_WR_COMMAND_REG, 0x06);

usleep(100);

IOWR(LCD_16207_0_BASE, LCD_WR_DATA_REG,0x38);

while (1);

-8-
return 0;

-9-

You might also like