Page 142 - 3-2
P. 142

//parameter Green=2'b10, Red=2'b01;


            s_test U2 (arduino_purchase,clk,reset,sen1_in,sen1_out,warning_sig,speaker1,speaker2,speaker3);


            assign green=(warning_sig)?1'b0:1'b1;
            assign red=(warning_sig)?1'b1:1'b0;
            assign lamp=(warning_sig)?1'b1:1'b0;


            endmodule
            ---------------------------------------------------------------------
            //< 스위치 모듈>


            // d_sw output timing -> 50[Mhz]  기준 BOUNCING DELAY       뒤에 출력
            // BOUNCING_DELAY     값 조절가능


            module sw_debouncing (clk, rst, b_sw, d_sw);


                    input clk, rst, b_sw;


                    output reg d_sw;


                    reg [25:0] cnt;
                    reg     key_state;


                    parameter BOUNCING_DELAY = 12500000;            // boungcing count num
                    parameter ACTIVE_HIGH        = 1'b1;    // active_high switch
                    parameter ACTIVE_LOW         = 1'b0;    // active_low  switch
                    parameter KEY_ON                         = 0;
                    parameter KEY_OFF                        = 1;


                    always @(posedge clk, negedge rst) begin
                            if(!rst) begin
                                    cnt <= 0;
                                    key_state <= KEY_ON;
                                    d_sw <= 0;
                            end
                            else begin
                                    if(key_state == KEY_ON) begin           //KEY_ON
                                            cnt <= 0;
                                            if(b_sw == ACTIVE_HIGH) begin
                                                    d_sw <= 1;
                                                    key_state <= KEY_OFF;
                                            end
                                            else begin
                                                    d_sw <= 0;


                                                         - 142 -
   137   138   139   140   141   142   143   144   145   146   147