Code: #include "/home/mun/altera/13.0sp1/nios2eds/components/altera_hal/HAL/inc/sys/alt_stdio.h" #include "/home/mun/altera/13.0sp1/nios2eds/bin/gnu/H-i686-pc-linux-gnu/nios2-elf/include/stdio.h" #include "/home/mun/altera/13.0sp1/nios2eds/bin/gnu/H-i686-pc-linux-gnu/nios2-elf/include/unistd.h" #include "/home/mun/altera/13.0sp1/ip/University_Program/Audio_Video/Video/altera_up_avalon_video_character_buffer_with_dma/HAL/inc/altera_up_avalon_video_character_buffer_with_dma.h" #include "/home/mun/altera/13.0sp1/nios2eds/bin/gnu/H-i686-pc-linux-gnu/nios2-elf/include/string.h" #include "/home/mun/Hello/system.h" #include "/home/mun/altera/13.0sp1/ip/altera/sopc_builder_ip/altera_avalon_lcd_16207/inc/altera_avalon_lcd_16207_regs.h" #include "/home/mun/altera/13.0sp1/ip/altera/sopc_builder_ip/altera_avalon_lcd_16207/HAL/inc/altera_avalon_lcd_16207.h" #include "/home/mun/altera/13.0sp1/ip/altera/sopc_builder_ip/altera_avalon_pio/inc/altera_avalon_pio_regs.h" //Seven Segmen Decoder int seg7_decoder(int a) { if (a==0) return 0x40; else if (a==1) return 0x79; else if (a==2) return 0x24; else if (a==3) return 0x30; else if (a==4) return 0x19; else if (a==5) return 0x12; else if (a==6) return 0x02; else if (a==7) return 0x78; else if (a==8) return 0x00; else if (a==9) return 0x10; else if (a==10) return 0x08; else if (a==11) return 0x03; else if (a==12) return 0x46; else if (a==13) return 0x21; else if (a==14) return 0x06; else if (a==15) return 0x0e; else return 0xff; } int main() { printf("hello_world\n"); //SD-CARD char filename[100]; char * txt = (float *)calloc(1000,sizeof(char)); printf("Initializing SD_Card devices...\n"); int volumes_mounted; sd_set_clock_to_max( 80000000 ); usleep (1000); volumes_mounted = sd_fat_mount_all();////mount fat file system. if( volumes_mounted <= 0 ) { printf( "SD Card Mount FAILED\n" ); txt = "No SD-Card detected!"; } else { printf("SD Card Mount OK\n"); sprintf(filename, "/dev/sd_controller_0/%s", "test.txt"); FILE *infile; infile = fopen(filename, "r"); int i = 0; for(i=0; i<1000; i++) { fscanf (infile, "%c", &txt[i]); } fclose(infile); for (i = 0; i<30; i=i+1) { printf("%c",txt[i]); } } //LCD FILE* fp; fp= fopen("/dev/lcd", "w"); if (fp == NULL) { fprintf(stderr, "open failed\n"); return 0; } fprintf(fp, " Biochipsoc Lab \n FBME \n"); fclose(fp); //VGA alt_up_char_buffer_dev *CHAR_BUFFER; CHAR_BUFFER= alt_up_char_buffer_open_dev("/dev/video_character_buffer_with_dma_0"); alt_up_char_buffer_init(CHAR_BUFFER); alt_up_char_buffer_clear(CHAR_BUFFER); sprintf(filename, "SD Card read test.txt :%s", txt); char text_top_row[40] = "Hello DE2-115"; char values[40] = "Switches decimal value :"; alt_up_char_buffer_string (CHAR_BUFFER, text_top_row, 15, 20); alt_up_char_buffer_string (CHAR_BUFFER, filename, 15, 22); alt_up_char_buffer_string (CHAR_BUFFER, values, 15, 24); int a=0,b=0x0000000f,j=0; int a0 = 0, a1 = 0, a2 = 0, a3 = 0, a4 = 0; int kk=0; int p=0; char c[20]; char mask[6] = " "; while(1) { //Switches a = IORD(SWITCHES_BASE,0); //Green Led and button if (IORD(GPIO_IN_BASE,0) == 65535) b=((b<<1)&0x000000fe)|((b>>7)&0x00000001); else b=((b>>1)&0x0000007f)|((b<<7)&0x00000080); //Green Led and button if (IORD(BUTTON_BASE,0) == 13) // 13 in binary is 1101 so second button is presses (active low) IOWR(GPIO_OUT_BASE,0,1); else IOWR(GPIO_OUT_BASE,0,0); //b = 0x000001ff; IOWR(LED_GREEN_BASE,0,b); //Red Led IOWR(LED_RED_BASE,0,a); //7SEG a0 = a&0x0000000f; IOWR(HEX0_BASE,0,seg7_decoder(a0)); a1 = a&0x000000f0; a1 = a1>>4; IOWR(HEX1_BASE,0,seg7_decoder(a1)); a2 = a&0x00000f00; a2 = a2>>8; IOWR(HEX2_BASE,0,seg7_decoder(a2)); a3 = a&0x0000f000; a3 = a3>>12; IOWR(HEX3_BASE,0,seg7_decoder(a3)); a4 = a&0x000f0000; a4 = a4>>16; IOWR(HEX4_BASE,0,seg7_decoder(a4)); IOWR(HEX5_BASE,0,seg7_decoder(0)); //button if (IORD(BUTTON_BASE,0) == 11) // 11 in binary is 1011 so third button is presses (active low) j= j-1; else j = j+1; if(j>15)j=0; else if(j<0)j=15; IOWR(HEX6_BASE,0,seg7_decoder(j)); IOWR(HEX7_BASE,0,seg7_decoder(j)); for (p=40; p<45; p=p+1){ alt_up_char_buffer_draw(CHAR_BUFFER , ' ', p, 24); } sprintf(c, "%d", a); alt_up_char_buffer_string (CHAR_BUFFER, c, 39, 24); usleep(200000); } return 0; }