Page 571 - 3-2
P. 571

rx_clk_cnt <= 0;
                                            if(rx_bit_cnt >= 8) rx_bit_cnt <= 0; //  수신데이터 bit count
                                                    else rx_bit_cnt <= rx_bit_cnt +1'b1;
                                            end
                                            else rx_clk_cnt <= rx_clk_cnt + 1'b1; //always  하나 빼서 할 수 있음


                                            if ( rx_bit_cnt < 8 && rx_clk_cnt == baud_rate) // receive data
                                            begin
                                                    rx_data_buffer[rx_bit_cnt] <= rxd;
                                                    state_rx <= 1;
                                            end


                                            else if (rx_bit_cnt == 8&& rx_clk_cnt == baud_rate && rxd ==
            1)// stop receiving
                                            begin
                                                    state_rx <= 0;
                                                    rx_data <= rx_data_buffer; // data  출력
                                            end


                                            // if stop bit is not received, clear the received data
                                            else if (rx_bit_cnt == 8 && rx_clk_cnt == baud_rate && rxd != 1)
                                            begin
                                                    state_rx <= 0;
                                                    rx_data_buffer <= 8'b00000000; // invalidate
                                            end
                              end
                    end
            end


            always @(posedge clk, negedge reset)
            begin
                    if(!reset)
                    begin
                            Light<=2'b0;
                            fan<=2'b00;
                            B_D<=1'b0;
                    end


                    else
                    begin
                            if(rx_data=="A")
                            begin
                                    //fan<=fan;
                                    Light<=2'b11;
                                    B_D<=1'b0;


                                                         - 571 -
   566   567   568   569   570   571   572   573   574   575   576