2012年10月28日 星期日

P6-55 8bit Binary change into Gray code適用於DE2-70

P6-55 8bit Binary change into Gray code適用於DE2-70







//--------------------------------------
//Convert 8-bit binary code to Gray code
//using for loop
//filename : bin2gra.v
//--------------------------------------
module bin2gray(SW, LEDR, LEDG , CLOCK_27 ,KEY ,HEX0 ,HEX1 ,HEX2,HEX3 );

input  [17:0] SW; // toggle switches
input  [7:0] KEY;     // Push bottom
input  CLOCK_27; //Clock 27MHz , 50Mhz

output [17:0] LEDR; // red  LEDS   
  output [7:0] LEDG; // green LEDs
    
    output [6:0] HEX0,HEX1,HEX2,HEX3; //7-segment display
    parameter length = 8;       //8-bit length
  
//set original program input , output 

//bin2gra(Gry, Bin);

//output [length-1:0] Gry;    //Gray code putput
//input [length-1:0] Bin;     //Binary input
wire [length-1:0] Bin;
reg [length-1:0] Gry;
    
        
    //mapping to hardware 
    assign LEDR = SW;
    assign Bin=SW[7:0];
    

integer i;

always @ (Bin)
begin 
for (i=0; i<length-1; i = i+1)
Gry[i]=Bin[i] ^ Bin[i+1];

Gry[i] = Bin[i];
end
    assign LEDG[7:0]=Gry;

endmodule

沒有留言:

張貼留言

WOKWI DHT22 & LED , Node-Red + SQLite database

 WOKWI DHT22 & LED , Node-Red + SQLite database Node-Red程式 [{"id":"6f0240353e534bbd","type":"comment&...