名稱:溫濕度計傳感器DHT11控制數(shù)碼管顯示(代碼在文末付費(fèi)下載)
軟件:QuartusII
語言:Verilog
代碼功能:
使用溫濕度傳感器DHT11采集環(huán)境的溫度和濕度,并在數(shù)碼管顯示。
本代碼已在開發(fā)板驗(yàn)證
開發(fā)板資料:
DHT11傳感器電路圖:
演示視頻:
FPGA代碼Verilog/VHDL代碼資源下載網(wǎng):www.hdlcode.com
部分代碼展示
//========================================================================== //溫濕度計dht11的數(shù)據(jù)采集,采集間隔1s //========================================================================== module?dht11( i_clk, i_rst_n, io_data, ???o_temp, o_humi ); input?i_clk;//50mhz input?i_rst_n;//低電平復(fù)位 inout?io_data;//數(shù)據(jù)端口 output?reg?[7:0]o_temp;//輸出溫度 output?reg?[7:0]o_humi;//輸出濕度 reg?o_data;//輸出數(shù)據(jù) reg?[39:0]get_data;//dht11獲取的數(shù)據(jù) reg?[5:0]data_num;//獲取數(shù)據(jù)的位數(shù) reg[3:0]crt_state;//三段狀態(tài)機(jī) reg?[3:0]next_state; parameter?idle =?4'b0001;//空閑狀態(tài) parameter?init =?4'b0010;//主機(jī)請求復(fù)位狀態(tài) parameter?ans? =?4'b0100;//從機(jī)應(yīng)答 parameter?rd_data =?4'b1000;//接受數(shù)據(jù) reg?data_sam1;//輸入采樣1 reg?data_sam2;//輸入采樣2 reg?data_pluse;//檢測輸入上升沿脈沖 always@(posedge?i_clk?) begin data_sam1<=io_data; data_sam2<=data_sam1; data_pluse<=(~data_sam2)&data_sam1; end reg[26:0]?cnt_1s;//1s計數(shù)器?? always@(posedge?i_clk?or?negedge?i_rst_n?) if(!i_rst_n) cnt_1s<=27'd0; else?if(cnt_1s==27'd49999999) cnt_1s<=27'd0; else cnt_1s<=cnt_1s+1'b1; reg?updata=0; reg[26:0]?cnt_2s=27'd0;//2s計數(shù)器?? always@(posedge?i_clk?or?negedge?i_rst_n?) if(!i_rst_n) cnt_2s<=27'd0; else?if(cnt_2s==27'd99999999) cnt_2s<=27'd0; else cnt_2s<=cnt_2s+1'b1; always@(posedge?i_clk) ????if(cnt_2s==27'd99999999) ????????updata<=1; ????else ????????updata<=0; /////////============狀態(tài)機(jī) always@(posedge?i_clk?or?negedge?i_rst_n?) if(!i_rst_n) crt_state<=idle; else?if(updata==1)//2s更新一次 crt_state<=idle; else crt_state<=next_state;
設(shè)計文檔:
1. 工程文件
2. 程序文件
3. 程序編譯
4. RTL圖
5. 仿真圖
按鍵消抖模塊仿真
數(shù)碼管顯示模塊仿真
開啟控制模塊仿真
閱讀全文