Report

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Report.

v
module REPORT
(
input CLOCK_50,
input [0:0] KEY,
input [9:0] SW,
output [7:0] HEX0,
output [7:0] HEX1,
output [7:0] HEX2,
output [7:0] HEX3,
output [9:0] LEDR,
output [7:0] HEX4,
output [7:0] HEX5
);

system nios_system(
.clk_clk
(CLOCK_50),
.reset_reset_n (KEY[0]),
.hex0_external_connection_export ({8'b0,HEX0}),
.hex1_external_connection_export ({8'b0,HEX1}),
.hex2_external_connection_export ({8'b0,HEX2}),
.hex3_external_connection_export ({8'b0,HEX3}),
.hex4_external_connection_export ({8'b0,HEX4}),
.switch_external_connection_export ({16'd0, SW}),
.led_external_connection_export ({16'd0, LEDR}),
.hex5_external_connection_export ({8'b0,HEX5})

);

endmodule #include <stdio.h>


#include "io.h"
#include "system.h"
#include "altera_avalon_timer_regs.h"
#include "sys/alt_irq.h"
unsigned int counter = 0;
int data = 0x300;
int *led_pt = LED_BASE;
int *sw_pt = SWITCH_BASE;
int led_value = 0x300;
int value,value2;
int status;
int segment_decode [] = {0x40,
0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0x08,0x03,0x46,0x21,0x06,0x0E};
void timer_Init(){
unsigned int period = 0;
// Stop Timer
IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE,
ALTERA_AVALON_TIMER_CONTROL_STOP_MSK);
//Configure period
period = 50000000 - 1;
IOWR_ALTERA_AVALON_TIMER_PERIODL(TIMER_0_BASE, period);
IOWR_ALTERA_AVALON_TIMER_PERIODH(TIMER_0_BASE, (period >> 16));
IOWR_ALTERA_AVALON_TIMER_CONTROL(TIMER_0_BASE,
ALTERA_AVALON_TIMER_CONTROL_CONT_MSK | // Continue counting mode
ALTERA_AVALON_TIMER_CONTROL_ITO_MSK | // Interrupt enable
ALTERA_AVALON_TIMER_CONTROL_START_MSK);// Start Timer
}
void Timer_IRQ_Handler(void* isr_context){

status = IORD(SWITCH_BASE, 0) & 0x1;


if (status != 1){
counter ++;
}

int hours = counter / 3600;


int minutes = (counter % 3600) / 60;
int seconds = counter % 60;
int reset1 = (IORD(SWITCH_BASE, 0) >> 1)& 0x1;

if (reset1 == 1){
hours = 0;
minutes = 0;
seconds = 0;
counter = 0;
}

if (hours >= 23 & minutes >= 59 & seconds >= 59){


hours = 0;
minutes = 0;
seconds = 0;
counter = 0;
}
if (hours == 24 ){
hours = 0;
minutes = 0;
seconds = 0;
counter = 0;
}
// SHift led.
int sw_led = (*sw_pt >> 9)&0x1;
printf("*sw_led_value=%d\n", sw_led);
if(sw_led == 1)
led_value = (led_value >> 1) | ((led_value & 0x1) << 9);
else
led_value = (led_value << 1) | ((led_value & 0x200) >> 9);

*led_pt = led_value;
int sec_0 = seconds % 10;
int sec_1 = seconds / 10;
int min_0 = minutes % 10;
int min_1 = minutes / 10;
int hour_0 = hours % 10;
int hour_1 = hours / 10;
int sec0 = (IORD(SWITCH_BASE,0) >> 2)& 0x1;
int sec1 = (IORD(SWITCH_BASE,0) >> 3)& 0x1;
int min0 = (IORD(SWITCH_BASE,0) >> 4)& 0x1;
int min1= (IORD(SWITCH_BASE,0) >> 5)& 0x1;
int hour0= (IORD(SWITCH_BASE,0) >> 6)& 0x1;

if (sec0 ==1){
counter++;
}

if (sec1 == 1){
counter +=10;
}

if (min0 ==1){
counter +=60;
}

if (min1 ==1){
counter +=600;
}

if (hour0 ==1){
counter +=3600;
}

IOWR(HEX0_BASE, 0, segment_decode[sec_0]);
IOWR(HEX1_BASE, 0, segment_decode[sec_1]);
IOWR(HEX2_BASE, 0, segment_decode[min_0]);
IOWR(HEX3_BASE, 0, segment_decode[min_1]);
IOWR(HEX4_BASE, 0, segment_decode[hour_0]);
IOWR(HEX5_BASE, 0, segment_decode[hour_1]);

// Clear Timer interrupt bit


IOWR_ALTERA_AVALON_TIMER_STATUS(TIMER_0_BASE,
ALTERA_AVALON_TIMER_STATUS_TO_MSK);
}
void main(){
timer_Init();
alt_ic_isr_register(0, TIMER_0_IRQ, Timer_IRQ_Handler, (void*)0,
(void*)0);
while(1);
}

You might also like