Page 689 - 3-2
P. 689

right: begin dcmotor1=2'b01; dcmotor2=2'b00;end
                            right_stop: begin dcmotor1=2'b00; dcmotor2=2'b00;end
                            up: begin       dcmotor1=2'b00; dcmotor2=2'b01; end
                            front: begin dcmotor1=2'b00; dcmotor2=2'b00; end
                            back: begin dcmotor1=2'b00; dcmotor2=2'b00; end
                            down: begin     dcmotor1=2'b00; dcmotor2=2'b10; end
                            left: begin     dcmotor1=2'b10; dcmotor2=2'b00; end
                            finish: begin dcmotor1=2'b00; dcmotor2=2'b00; end
                            default: begin  dcmotor1=2'b00; dcmotor2=2'b00;    end
                            endcase
                    end
            end


            endmodule


            ----------------------------------------------------------------
            B. uart tx- 풍선으로 눌려진 limit sw       수를 세서 raspberry pi    로 보내는 소스
            module uart_tx(clk,reset,tx_out,var2);


            input [7:0]var2;
            input reset,clk;
            output tx_out;//tx:  송신단자
            reg clk_uart; //9600bps ->  시스템 클럭이 5625      번 들어올 때 1
            reg [15:0] clk_count; //5625 까지 세기 위한 변수
            reg [7:0]tx_reg; // 송신하고자 하는 데이터를 보관하는 변수
            reg tx_empty; // 송신 완료
            reg [3:0]tx_cnt; // 전송하는 데이터 비트수를 세는 변수
            reg tx_out;


            parameter BAUD_CLK = 16'd5208; //9600bps


            always @ (posedge clk,negedge reset) //  통신 속도 맞추기
            begin
                    if(!reset)
                    begin
                            clk_count<=0;
                            clk_uart<=0;
                    end
                    else
                    begin
                            if(clk_count == BAUD_CLK)
                            begin
                                    clk_count<=0;
                                    clk_uart<=1;
                            end


                                                         - 689 -
   684   685   686   687   688   689   690   691   692   693   694