Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `define SPACE 0
- `define DOT 1
- `define SCORE 2
- `define UNDERSCORE 3
- `define COLON 4
- `define A 15
- `define B 16
- `define C 17
- `define D 18
- `define E 19
- `define F 20
- `define G 21
- `define H 22
- `define I 23
- `define J 24
- `define K 25
- `define L 26
- `define M 27
- `define N 28
- `define O 29
- `define P 30
- `define Q 31
- `define R 32
- `define S 33
- `define T 34
- `define U 35
- `define V 36
- `define W 37
- `define X 38
- `define Y 39
- `define Z 40
- //=======================================================
- // This code is generated by Terasic System Builder
- //=======================================================
- module VGA_TEXT(
- //////////// CLOCK //////////
- input ADC_CLK_10,
- input MAX10_CLK1_50,
- input MAX10_CLK2_50,
- //////////// SDRAM //////////
- output [12:0] DRAM_ADDR,
- output [1:0] DRAM_BA,
- output DRAM_CAS_N,
- output DRAM_CKE,
- output DRAM_CLK,
- output DRAM_CS_N,
- inout [15:0] DRAM_DQ,
- output DRAM_LDQM,
- output DRAM_RAS_N,
- output DRAM_UDQM,
- output DRAM_WE_N,
- //////////// SEG7 //////////
- output [7:0] HEX0,
- output [7:0] HEX1,
- output [7:0] HEX2,
- output [7:0] HEX3,
- output [7:0] HEX4,
- output [7:0] HEX5,
- //////////// KEY //////////
- input [1:0] KEY,
- //////////// LED //////////
- output [9:0] LEDR,
- //////////// SW //////////
- input [9:0] SW,
- //////////// VGA //////////
- output [3:0] VGA_B,
- output [3:0] VGA_G,
- output VGA_HS,
- output [3:0] VGA_R,
- output VGA_VS,
- //////////// Accelerometer //////////
- output GSENSOR_CS_N,
- input [2:1] GSENSOR_INT,
- output GSENSOR_SCLK,
- inout GSENSOR_SDI,
- inout GSENSOR_SDO,
- //////////// Arduino //////////
- inout [15:0] ARDUINO_IO,
- inout ARDUINO_RESET_N,
- //////////// GPIO, GPIO connect to GPIO Default //////////
- inout [35:0] IOGPIO
- );
- //=======================================================
- // REG/WIRE declarations
- //=======================================================
- wire c0, c1, c2, c3;
- VGA_PLL vga_clk(MAX10_CLK1_50, c0, c1, c2, c3);//, phase: 0°, 90°, 180° 270°
- reg [20:0] count;
- reg [10:0] currentLine;
- reg [10:0] currentColumn;
- reg [10:0] x;
- reg [10:0] y;
- reg [5:0] carattere;
- reg [2:0] size; //dimensione testo
- reg [7:0]R_val;
- reg [7:0]G_val;
- reg [7:0]B_val;
- //135MHz
- parameter Htime = 144;//41; //clock
- parameter Vtime = 3;//10; //lines
- parameter VBporch = 38;//2; //lines
- parameter VFporch = 1;//2; //lines
- parameter HBporch = 248;//2; //clk
- parameter HFporch = 16;//2; //clk
- parameter columns = 1280;
- parameter lines = 1024;
- parameter lineTime = (columns+HFporch+Htime+HBporch); //th
- parameter totalFrame = lineTime*(lines+VFporch+Vtime+VBporch);
- assign VGA_HS = ((currentColumn) > (columns+HFporch) && (currentColumn < (columns+HFporch+Htime)));//HSYNC_val;
- assign VGA_VS = ((currentLine) > (lines+VFporch) && (currentLine) < (lines+VFporch+Vtime));//VSYNC_val;
- assign VGA_R[3:0] = R_val[3:0];
- assign VGA_G[3:0] = G_val[3:0];
- assign VGA_B[3:0] = B_val[3:0];
- //tabella font
- //n righe, n elementi, n colonne
- reg [7:0] font [41][6] = '{
- '{8'h00,8'h00,8'h00,8'h00,8'h00,8'h00}, // //0
- '{8'h30,8'h30,8'h00,8'h00,8'h00,8'h00}, // . //1
- '{8'h08,8'h08,8'h08,8'h08,8'h08,8'h00}, // - //2
- '{8'h40,8'h40,8'h40,8'h40,8'h40,8'h40}, // _ //3
- '{8'h24,8'h00,8'h00,8'h00,8'h00,8'h00}, // : //4
- '{8'h1e,8'h31,8'h29,8'h25,8'h23,8'h1e}, // 0 //5
- '{8'h22,8'h21,8'h3f,8'h20,8'h20,8'h20}, // 1 //6
- '{8'h32,8'h29,8'h29,8'h29,8'h29,8'h26}, // 2 //7
- '{8'h12,8'h21,8'h21,8'h25,8'h25,8'h1a}, // 3 //8
- '{8'h18,8'h14,8'h12,8'h3f,8'h10,8'h10}, // 4 //9
- '{8'h17,8'h25,8'h25,8'h25,8'h25,8'h19}, // 5 //10
- '{8'h1e,8'h25,8'h25,8'h25,8'h25,8'h18}, // 6 //11
- '{8'h01,8'h01,8'h31,8'h09,8'h05,8'h03}, // 7 //12
- '{8'h1a,8'h25,8'h25,8'h25,8'h25,8'h1a}, // 8 //13
- '{8'h06,8'h29,8'h29,8'h29,8'h29,8'h1e}, // 9 //14
- '{8'h3e,8'h09,8'h09,8'h09,8'h09,8'h3e}, // A //15
- '{8'h3f,8'h25,8'h25,8'h25,8'h25,8'h1a}, // B //16
- '{8'h1e,8'h21,8'h21,8'h21,8'h21,8'h12}, // C //17
- '{8'h3f,8'h21,8'h21,8'h21,8'h12,8'h0c}, // D //18
- '{8'h3f,8'h25,8'h25,8'h25,8'h25,8'h21}, // E //19
- '{8'h3f,8'h05,8'h05,8'h05,8'h05,8'h01}, // F //20
- '{8'h1e,8'h21,8'h21,8'h21,8'h29,8'h1a}, // G //21
- '{8'h3f,8'h04,8'h04,8'h04,8'h04,8'h3f}, // H //22
- '{8'h21,8'h21,8'h3f,8'h21,8'h21,8'h21}, // I //23
- '{8'h10,8'h20,8'h20,8'h20,8'h20,8'h1f}, // J //24
- '{8'h3f,8'h04,8'h0c,8'h0a,8'h11,8'h20}, // K //25
- '{8'h3f,8'h20,8'h20,8'h20,8'h20,8'h20}, // L //26
- '{8'h3f,8'h02,8'h04,8'h04,8'h02,8'h3f}, // M //27
- '{8'h3f,8'h02,8'h04,8'h08,8'h10,8'h3f}, // N //28
- '{8'h1e,8'h21,8'h21,8'h21,8'h21,8'h1e}, // O //29
- '{8'h3f,8'h09,8'h09,8'h09,8'h09,8'h06}, // P //30
- '{8'h1e,8'h21,8'h29,8'h31,8'h21,8'h1e}, // Q //31
- '{8'h3f,8'h09,8'h09,8'h09,8'h19,8'h26}, // R //32
- '{8'h12,8'h25,8'h25,8'h25,8'h25,8'h18}, // S //33
- '{8'h01,8'h01,8'h01,8'h3f,8'h01,8'h01}, // T //34
- '{8'h1f,8'h20,8'h20,8'h20,8'h20,8'h1f}, // U //35
- '{8'h0f,8'h10,8'h20,8'h20,8'h10,8'h0f}, // V //36
- '{8'h1f,8'h20,8'h10,8'h10,8'h20,8'h1f}, // W //37
- '{8'h21,8'h12,8'h0c,8'h0c,8'h12,8'h21}, // X //38
- '{8'h01,8'h02,8'h0c,8'h38,8'h04,8'h02}, // Y //39
- '{8'h21,8'h31,8'h29,8'h25,8'h23,8'h21} // Z //40
- };
- //array che contiene le scritte
- reg [5:0] arrayChar [columns/6][lines/8]; //6 = larghezza font - 8 = altezza font (8 solo perchè è un byte, ne usiamo solo 6 di bit)
- //=======================================================
- // Structural coding
- //=======================================================
- reg [6:0]selectedChar;
- reg [8:0]colonna;
- reg [3:0]xChar;
- reg [3:0]yChar;
- always @(posedge c0)
- begin
- if (count < totalFrame)
- count <= (count + 1'b1) % totalFrame;
- else
- count <= 0;
- end
- always @(posedge c1)
- begin
- currentColumn <= count%lineTime;
- currentLine <= count/lineTime;
- end
- always @(posedge c2)
- begin
- selectedChar <= currentColumn/(8*size);
- colonna <= currentLine/(8*size);
- xChar <= (currentColumn/size)%8-1;
- yChar <= (currentLine/size)%8-1;
- end
- always @(posedge c3)
- begin
- if ((currentLine) < lines && (currentColumn) < columns)
- begin
- if (font[arrayChar[selectedChar][colonna]][xChar][yChar])
- begin
- R_val [7:0] <= 255;
- G_val [7:0] <= 255;
- B_val [7:0] <= 255;
- end
- else
- begin //------
- R_val [7:0] <= 0;
- G_val [7:0] <= 0;
- B_val [7:0] <= 0;
- end //------
- end
- else
- begin
- R_val [7:0] <= 0;
- G_val [7:0] <= 0;
- B_val [7:0] <= 0;
- end
- end
- always @(1)
- begin
- size = 2;
- arrayChar[1][1] <= `T;
- arrayChar[2][1] <= `E;
- arrayChar[3][1] <= `S;
- arrayChar[4][1] <= `T;
- arrayChar[5][1] <= `DOT;
- arrayChar[6][1] <= `DOT;
- arrayChar[7][1] <= `DOT;
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement