Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module knight_rider(
- input clk, rst,
- output [7:0] r
- );
- // másodperces engedélyező jel
- reg [25:0] cntr = 0;
- wire en = (cntr == 9/*49999999*/); // 1 Hz
- always @(posedge clk)
- if (rst | en)
- cntr <= 0;
- else
- cntr <= cntr + 1;
- reg [7:0] shr = 8'b00000001;
- reg dir = 0;
- wire first = (shr[1] == 1);
- wire last = (shr[6] == 1);
- // shiftelés iránya
- always @(posedge clk)
- if ( rst )
- dir <= 0;
- else if ( en )
- if ( (first & dir) | (last & !dir) )
- dir <= ~dir;
- // shiftelés
- always @(posedge clk)
- if ( rst )
- shr <= 8'b00000001;
- else if ( en )
- if ( dir ) // jobbra
- shr <= { shr[0], shr[7:1] };
- else // balra
- shr <= { shr[6:0], shr[7] };
- assign r = shr;
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement