基于FPGA的温度显示系统剖析_第1页
基于FPGA的温度显示系统剖析_第2页
基于FPGA的温度显示系统剖析_第3页
基于FPGA的温度显示系统剖析_第4页
基于FPGA的温度显示系统剖析_第5页
已阅读5页,还剩27页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、生产实习报告基于FPGA的温度显示系统现代电子系统质量提高工程报告专业:电子科学与技术班级:电子12-1姓名:学号:1206040124一、生广实习任务极其完成情况1 .设计任务设计了一种基于FPGAf口LM75刖勺温度测量系统。硬件设计上,系统以EP4CE6E22C8N为主控芯片,采用数字温度传感器LM75A检测环境温度,并利用LM75A自带的IIC总线接口传输数据,通过数码管将温度实时显示出来;软件设计上,采用自顶向下模块化设计思想,先设计出IIC通信模块、温度显示模块,然后再编写顶层模块,将2个模块整合。2 .电路图aCt3 .程序流程图开始(结束4 .编与的程序(一)功能模块:libr

2、aryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;useieee.std_logic_arith.all;-实体-entityat24c08isport(clkinstd_logic;rst:instd_logic;scloutstd_logic;sdainoutstd_logic;urv_1instd_logic;urv_2instd_logic;sel:outstd_logic_vector(3downto0);seg:outstd_logic_vector(7downto0);beepoutstd_logi

3、c-时钟信号-复位信号-i2c时钟线-i2c数据线-上限值1-上限值2蜂鸣器输出信号线);endat24c08;一结构体-architecturearch_at24c08ofat24c08issignaclk_sslowstd_logic;signacounterstd_logic_vector(23downto0);signareaddata_reg_bufstd_logic_vector(15downto0);signareaddata_tenintegerrange0to24564;signareaddata_stdstd_logic_vector(15downto0);signaqia

4、nstd_logic_vector(3downto0);signabaistd_logic_vector(3downto0);signashistd_logic_vector(3downto0);signagestd_logic_vector(3downto0);signaqian_0integerrange0to10;signabai_0integerrange0to10;signashi_0integerrange0to10;signage_0integerrange0to10;-数码管部分信号signal sel_0signal seg_0signal countsignal clk_s

5、lowsignal scan_numsignal seg_data_buf-i2c部分信号signal sda_bufsignal linksignal readdata_reg存器signal sda_0signal scl_0std_logic_vector(3downto0);std_logic_vector(7downto0);std_logic_vector(13downto0);std_logic;std_logic_vector(1downto0);std_logic_vector(3downto0);std_logic;-i2c输入/输出数据寄存器std_logic;-sda输

6、入输出方向寄存器std_logic_vector(15downto0);-i2c读回的数据寄std_logic;-与sda端口连接信号std_logic;-与scl端口连接信号-按键消抖部分信号signaldelay_cntsignalstart_delaystd_logic_vector(19downto0);std_logic;-消抖延时计数器-按键延时开始-分频部分信号signalclk_div:std_logic_vector(12downto0);-分频计数器,5000分频,10khz-蜂鸣器部分信号signalbeep_en:std_logic;signalbeep_buf:std

7、_logic;-蜂鸣器使能信号-与beep端口连接的信号-时钟部分信号signallevel_highstd_logic;-高电平中间值,1249std_logic_vector(12 downto 0):="1001110001000"signallevel_lowsignallevel_hig_edgesignallevel_low_edge-状态机部分信号signalmain_statesignali2c_statesignali2c_per_state-分频部分常量constantdiv_parameter-分频系数,500-状态机部分常量-操作状态常量consta

8、ntread_init初始化constantread_high数据状态constantread_low数据状态-i2c每一步状态常量constantstart- -开始位constantfirst- -数据第一位constantsecond- -数据第二位constantthirdstd_logic;std_logic;std_logic;std_logic_vector(1downto0);std_logic_vector(2downto0);std_logic_vector(3downto0);std_logic_vector(2downto0)std_logic_vector(2down

9、to0)std_logic_vector(2downto0)std_logic_vector(3downto0)std_logic_vector(3downto0)std_logic_vector(3downto0)std_logic_vector(3downto0)- 低电平中间值,3749- -上升沿,4999- 下降沿,2499-状态机主状态-i2c状态-i2c每一步状态尸"000”;-EEPORM尸"001”;-读高位尸"010”;-读低位尸"0000"尸"0001”;尸"0010"尸"0011&

10、quot;-数据第三位constant fourth-数据第四位constant fifth-数据第五位constant sixth-数据第六位constant seventh-数据第七位constant eighth-数据第八位constant ack-应答位constant stop一停止位std_logic_vector(3downto0)k"0100"std_logic_vector(3downto0)k"0101"std_logic_vector(3downto0)k"0110"std_logic_vector(3downt

11、o0)k"0111"std_logic_vector(3downto0)k"1000"std_logic_vector(3downto0)k"1001"std_logic_vector(3downto0):="1010"-结构体开始beginscl<=scl_0;seg<=seg_0;sda_0<=sda_bufwhen(link)='1'else'Z'sda<=sda_0;sel<=sel_0;beep<=beep_buf;-按键消抖key:pr

12、ocess(clk,rst)beginif(notrst='1')thendelay_cnt<=(others=>'0');elsif(clk'eventandclk='1')thenifstart_delay='1'thenif(delay_cnt/="11110100001001000000")then-20ms延时delay_cnt<=delay_cnt+'1'elsedelay_cnt<=(others=>'0');endif;end

13、if;endif;endprocesskey;-分频部分div:process(rst,clk)beginif(notrst='1')thenclk_div<="0000000000000"level_high<='0'level_low<='0'level_hig_edge<='0'level_low_edge<='0'elsif(clk'eventandclk='1')thenif(clk_div/=div_parameter-'

14、1')thenclk_div<=clk_div+'1'elseclk_div<="0000000000000"endif;if(level_high='1')thenlevel_high<='0'elseif(clk_div="10011100001") thenlevel_high<='1'endif;endif;if(level_low_edge='1')thenlevel_low_edge<='0'elseif(cl

15、k_div="100111000011")thenlevel_low_edge<='1'endif;endif;if(level_low='1')thenlevel_low<='0'elseif(clk_div="111010100101")thenlevel_low<='1'endif;endif;if(level_hig_edge='1')thenlevel_hig_edge<='0'elseif(clk_div="100

16、1110000111")thenlevel_hig_edge<='1'endif;endif;endif;endprocessdiv;-EEPROMft作部分state:process(clk,rst)beginif(notrst='1')thenstart_delay<='0'scl_0<='1'sda_buf<='1'link<='0'readdata_reg<="0000000000000000"main_state<=&

17、quot;00"i2c_state<=read_init;i2c_per_state<=start;elsif(clk'eventandclk='1')thencasemain_stateis-初始化EEPROMwhen"00"=>-等待读写要求scl_0<='1'sda_buf<='1'link<='0'i2c_state<=read_init;i2c_per_state<=start;main_state<="10"

18、-读取EEPR做据when"10"=>if(level_hig_edge='1')thenscl_0<='1'elseif(level_low_edge='1')thenscl_0<='0'endif;endif;casei2cstateiswhenread_init=>-读命令地址casei2c_per_stateiswhenstart=>if(level_high='1')thensda_buf<='0'link<='1

19、9;endif;if(level_lowandlink)='1')thenlink<='1'sda_buf<='1'i2c_per_state<=first;endif;whenfirst=>if(level_low='1')thensda_buf<='0'link<='1'i2c_per_state<=second;endif;whensecond=>if(level_low='1')thensda_buf<='0

20、9;link<='1'i2c_per_state<=third;endif;whenthird=>if(level_low='1')thensda_buf<='1'i2c_per_state<=fourth;endif;whenfourth=>if(level_low='1')thensda_buf<='0'link<='1'i2c_per_state<=fifth;endif;whenfifth=>if(level_low='1&

21、#39;)thensda_buf<='0'link<='1'i2c_per_state<=sixth;endif;whensixth=>if(level_low='1')thensda_buf<='0'link<='1'i2c_per_state<=seventh;endif;whenseventh=>if(level_low='1')thensda_buf<='1'link<='1'i2c_per_stat

22、e<=eighth;endif;wheneighth=>if(level_low='1')thenlink<='0'i2c_per_state <= ack;end if;whenack=>if(level_hig_edge='1')thensda_buf<=sda;endif;if(level_high='1')thenif(sda_buf='1')thenmain_state<="00"endif;endif;if(level_low='1&

23、#39;)thenlink<='0'i2c_state<=read_high;i2c_per_state<=first;endif;whenothers=>null;endcase;whenread_high=>-读回数据casei2c_per_stateiswhenfirst=>if(level_hig_edge='1')thensda_buf<=sda;endif;if(level_high='1')thenreaddata_reg(15downto9)<=readdata_reg(14down

24、to8);readdata_reg(8)<=sda;endif;if(level_low='1')thenwhensecond=>if(level_hig_edge='1')thensda_buf<=sda;endif;if(level_high='1')thenreaddata_reg(14 downto 8);readdata_reg(14 downto 8);readdata_reg(15downto9)二readdata_reg(8) <= sda;end if;if(level_low='1')

25、theni2c_per_state <= third;end if;when third =>if(level_hig_edge='1') thensda_buf <= sda;end if;if(level_high='1') thenreaddata_reg(15 downto 9)<=readdata_reg(8)<=sda;endif;if(level_low='1')theni2c_per_state<=fourth;endif;whenfourth=>if(level_hig_edge=

26、9;1')thensda_buf<=sda;endif;if(level_high='1') thenreaddata_reg(15downto9)<=readdata_reg(14downto8);readdata_reg(8)<=sda;endif;if(level_low='1')theni2c_per_state<=fifth;endif;whenfifth=>if(level_hig_edge='1')thensda_buf<=sda;endif;if(level_high='1

27、9;)thenreaddata_reg(15downto9)<=readdata_reg(14downto8);readdata_reg(8)<=sda;endif;if(level_low='1')theni2c_per_state<=sixth;endif;whensixth=>if(level_hig_edge='1')thensda_buf<=sda;endif;if(level_high='1')thenreaddata_reg(15downto9)<=readdata_reg(14downto8);

28、readdata_reg(8)<=sda;endif;if(level_low='1')theni2c_per_state<=seventh;end if;二二whenseventh=>if(level_hig_edge='1')thensda_buf<=sda;endif;if(level_high='1')thenreaddata_reg(15downto9)readdata_reg(14downto8);readdata_reg(8)<=sda;endif;if(level_low='1')th

29、eni2c_per_state<=eighth;endif;wheneighth=>if(level_hig_edge='1')thensda_buf<=sda;endif;if(level_high='1')thenreaddata_reg(15downto9)readdata_reg(14downto8);readdata_reg(8)<=sda;endif;if(level_low='1')theni2c_per_state<=ack;endif;whenack=>if(level_high='1

30、')thenlink<='1'sda_buf<='0'i2c_per_state<=first;i2c_state <= read_low;endif;whenothers=>null;endcase;whenreadlow=>casei2c_per_stateiswhenfirst=>if(level_hig_edge='1')thenlink<='0'sda_buf<=sda;endif;if(level_high='1')thenreaddata_

31、reg(7downto1)<=readdata_reg(6downto0);readdata_reg(0)<=sda;endif;if(level_low='1')theni2c_per_state<=second;endif;whensecond=>if(level_hig_edge='1')thenlink<='0'sda_buf<=sda;endif;if(level_high='1')thenreaddata_reg(7downto1)<=readdata_reg(6downto0

32、);readdata_reg(0)<=sda;endif;if(level_low='1') theni2c_per_state<=third;endif;whenthird=>if(level_hig_edge='1')thenlink<='0'sda_buf<=sda;endif;if(level_high='1')thenreaddata_reg(7downto1)<=readdata_reg(6downto0);readdata_reg(0)<=sda;endif;if(level

33、_low='1')theni2c_per_state<=fourth;endif;whenfourth=>if(level_hig_edge='1')thenlink<='0'sda_buf<=sda;endif;if(level_high='1')thenreaddata_reg(7downto1)<=readdata_reg(6downto0);readdata_reg(0)<=sda;endif;if(level_low='1')theni2c_per_state<=

34、fifth;endif;whenfifth=>link<='0'sda_buf<=sda;endif;if(level_high='1')thenreaddata_reg(7downto1)<=readdata_reg(6downto0);readdata_reg(0)<=sda;endif;if(level_low='1')theni2c_per_state<=sixth;endif;whensixth=>if(level_hig_edge='1')thenlink<='0

35、'sda_buf<=sda;endif;if(level_high='1')thenreaddata_reg(7downto1)<=readdata_reg(6downto0);readdata_reg(0)<=sda;endif;if(level_low='1')theni2c_per_state<=seventh;endif;whenseventh=>if(level_hig_edge='1')thenlink<='0'sda_buf<=sda;endif;if(level_h

36、igh='1') thenreaddata_reg(7downto1)<=readdata_reg(6downto0);readdata_reg(0)<=sda;endif;if(level_low='1')theni2c_per_state<=eighth;endif;wheneighth=>if(level_hig_edge='1')thenlink<='0'sda_buf<=sda;endif;if(level_high='1')thenreaddata_reg(7down

37、to1)<=readdata_reg(6downto0);readdata_reg(0)<=sda;endif;if(level_low='1')theni2c_per_state<=ack;endif;whenack=>if(level_high='1')thenlink<='1'sda_buf<='1'-非应答位-i2c_per_state<=stop;endif;if(level_low='1')thenlink<='1'sda_buf<=

38、'0'i2c_per_state<=stop;endif;whenstop=>if(level_high='1')thenlink<='1'sda_buf<='1'-停止位endif;if(level_low='1')thenmain_state<="00"endif;whenothers=>null;endcase;whenothers=>null;endcase;whenothers=>null;endcase;endif;endprocess

39、state;-数据处理部分anly1:process(readdata_reg_buf)beginreaddata_ten<=conv_integer(readdata_reg_buf)*12;qian_0<=readdata_ten/1000;bai_0<=(readdata_ten/100)rem10;shi_0<=(readdata_ten/10)rem10;ge_0<=readdata_tenrem10;endprocessanly1;anly2:process(qian_0,bai_0,shi_0,ge_0)beginqian<=conv_std_

40、logic_vector(qian_0,4);bai<=conv_std_logic_vector(bai_0,4);shi<=conv_std_logic_vector(shi_0,4);ge<=conv_std_logic_vector(ge_0,4);endprocessanly2;-数码管显示部分scan:process(rst,clk)beginif(notrst='1')thencount<=(others=>'0');clk_slow<='0'elsif(clk'eventandclk=&

41、#39;1')thenif(count="11111011011111")thencount<=(others=>'0');clk_slow<=notclk_slow;elsecount<=count+'1'endif;endif;endprocessscan;seg1:process(clk_slow,rst)beginif(notrst='1')thenscan_num<="00"elsif(clk_slow'eventandclk_slow='1&

42、#39;)thenscan_num<="00"elsescan_num<=scan_num+'1'endif;endif;endprocesssegl;seg2:process(seg_data_buf)begincaseseg_data_bufiswhen"1111"=>seg_0<="10001110"when"1110"=>seg_0<="10000110"when"1101"=>seg_0<="

43、10100001"when"1100"=>seg_0<="11000110"when"1011"=>seg_0<="10000011"when"1010"=>seg_0<="10011000"when"1001"=>seg_0<="10010000"when"1000"=>seg_0<="10000000"when"0

44、111"=>seg_0<="11111000"when"0110"=>seg_0<="10000010"when"0101"=>seg_0<="10010010"when"0100"=>seg_0<="10011001"when"0011"=>seg_0<="10110000"when"0010"=>seg_0<=&

45、quot;10100100"when"0001"=>seg_0<="11111001"when"0000"=>seg_0<="11000000"whenothers=>seg_0<="11111111"endcase;endprocessseg2;seg0:process(scan_num)begincasescan_numiswhen"00"=>sel_0<="1110"seg_data_buf&

46、lt;=ge;when"01"=>sel_0<="1101"seg_data_buf<=shi;when"10"=>sel_0<="1011"seg_data_buf<=bai;when"11"=>sel_0<="0111"seg_data_buf<=qian;whenothers=>null;endcase;endprocessseg0;-数据缓存部分ss:process(clk,rst)beginif(notrs

47、t='1')thenclk_sslow<='0'counter<=(others=>'0');if(counter/="111111111111111111111110")thencounter<=counter+'1'elsecounter<=(others=>'0');clk_sslow<=notclk_sslow;endif;endif;endprocessss;buf:process(clk_sslow)beginif(clk_sslow'

48、;eventandclk_sslow='1')thenreaddata_reg_buf<=readdata_reg;elsereaddata_reg_buf<=readdata_reg_buf;endif;endprocessbuf;-蜂鸣器报警部分bep:process(clk,rst)variablecount:integerrange0to50000;-1KHz方波beginif(notrst='1')thencount:=0;beep_en<='0'elsif(clk'eventandclk='1'

49、;)thenif(beep_en='1')thencount:=count+1;if(count>50000) thencount:=0;beep_buf<=notbeep_buf;endif;elseif(noturv_1='1')thenif(readdata_reg>”0000000000000011")thenbeep_en<='1'endif;elsif(noturv_2='1')thenif(readdata_reg>”1111111111100000")thenbee

50、p_en<='1'endif;endif;endif;endif;endprocessbep;endarch_at24c08;(二)测试模块:libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;useieee.std_logic_arith.all;entitytbis-null;endtb;architecturebehv_tboftbiscomponentat24c08clkinstd_logic;rst:instd_logic;scl:outstd_logic;sda :inou

51、tstd_logic;urv_1 :instd_logic;urv_2 :instd_logic;port(-时钟信号-复位信号-i2c时钟线-i2c数据线-上限值1-上限值2sel:outstd_logic_vector(3downto0);seg:outstd_logic_vector(7downto0);beep:outstd_logic-蜂鸣器输出信号线);endcomponent;constantclockperiod:time:=20ns;signalclk_tb:std_logic:='0'signalrst_tb:std_logic;signalscl_tb:std_logic;signalsda_tb:std_logic;signalurv_1_tb:std_logic;signalurv_2_tb:std_logic;signalsel_tb:std_logic_vector(3downto0);signalseg_tb:std_logic_vector(7downto0);sign

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论