多功能手持?jǐn)?shù)字示波表_第1頁(yè)
多功能手持?jǐn)?shù)字示波表_第2頁(yè)
多功能手持?jǐn)?shù)字示波表_第3頁(yè)
多功能手持?jǐn)?shù)字示波表_第4頁(yè)
多功能手持?jǐn)?shù)字示波表_第5頁(yè)
已閱讀5頁(yè),還剩22頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、-. z軟件設(shè)計(jì)1 .軟件流程圖Verilog HDL和C語(yǔ)言程序相結(jié)合的軟件流程圖見(jiàn)圖2。圖2 軟件流程圖2 . 軟件設(shè)計(jì)局部程序源碼頻率計(jì)Verilog HDL程序本程序主要用于測(cè)量出輸入信號(hào)的頻率。采用等精度測(cè)量的方法,在整個(gè)測(cè)量圍誤差一樣??梢宰詣?dòng)切換量程,指示數(shù)據(jù)小數(shù)點(diǎn)的位置和頻率單位。當(dāng)輸入信號(hào)頻率過(guò)低時(shí)還能發(fā)出相應(yīng)的指示信號(hào),通知CPU做出相應(yīng)控制。通過(guò)適度的采樣控制減小了測(cè)量誤差。module frequency(clk,ret,F*_clr,F*in,Fout,LF,spoint,flag_MK); input wire clk,ret; input wire F*in; /

2、待測(cè)頻率輸入端口input wire F*_clr; /CPU的控制信號(hào),控制頻率計(jì)清零output reg 15:0Fout; /測(cè)得的頻率值output reg LF; /低頻標(biāo)志,高電平是表示為低頻output reg 1:0spoint; /指示小數(shù)點(diǎn)的位置output reg 1:0flag_MK; /頻率單位:M 標(biāo)志 K 標(biāo)志 wire F*_cph;reg 7:0cp_ch;reg Fend; /測(cè)頻完畢標(biāo)志reg Fsst; /控制本地標(biāo)頻開(kāi)場(chǎng)計(jì)數(shù)的標(biāo)志 0:開(kāi)場(chǎng)計(jì)數(shù) reg 39:0Ns; /對(duì)本地標(biāo)頻的計(jì)數(shù)reg 23:0LFCH; /低頻檢測(cè)計(jì)數(shù)器,對(duì)底頻率和直流做出警

3、報(bào)和指示reg 15:0N*,N*1; /對(duì)待測(cè)頻率的計(jì)數(shù),N*1檢測(cè)低頻被測(cè)信號(hào)的暫存器reg s0,s1,s2,s3,s4,s5,s6,s7,s8,s*1000;always(posedge clk or negedge ret)if(!ret) begin s*1000=1b0; s0=1b0; s1=1b0; s2=1b0; s3=1b0; s4=1b0; s5=1b0; s6=1b0; s7=1b0; s8=1b0; endelse begin s*1000=1000); s0=(Ns=40d100_0); s1=(Ns=40d100_00); s2=(Ns=40d100_000);

4、 s3=(Ns=40d100_000_0); s4=(Ns=40d100_000_00); s5=(Ns=40d100_000_000); s6=(Ns=40d100_000_000_0); s7=(Ns=40d100_000_000_00); s8=40d100_000_000_000); endalways(posedge clk or negedge ret)if(!ret) begin Fend=1b0; flag_MK=2b00; spoint=2b00; Fout=16h0000; endelse begin if(Fend) Fend=1b0; if(F*_clr) Fend=1

5、b1; if(s*1000) case(s0,s1,s2,s3,s4,s5,s6,s7,s8) /-F-sp-MK 9b10_0000_000:Fout,Fend,spoint,flag_MK=N*,5b1_01_10; 9b01_0000_000:Fout,Fend,spoint,flag_MK=N*,5b1_10_10; 9b00_1000_000:Fout,Fend,spoint,flag_MK=N*,5b1_11_10; 9b00_0100_000:Fout,Fend,spoint,flag_MK=N*,5b1_01_01; 9b00_0010_000:Fout,Fend,spoint

6、,flag_MK=N*,5b1_10_01; 9b00_0001_000:Fout,Fend,spoint,flag_MK=N*,5b1_11_01; 9b00_0000_100:Fout,Fend,spoint,flag_MK=N*,5b1_01_00; 9b00_0000_010:Fout,Fend,spoint,flag_MK=N*,5b1_10_00; 9b00_0000_001:Fout,Fend,spoint,flag_MK=N*,5b1_11_00; endcase endalways(posedge clk or posedge Fend)if(Fend) begin LFCH

7、=24h000000; LF=1b0; endelse begin LFCH=LFCH+1b1; if(LFCH=24d100_000_00) begin LF=(N*1=N*); LFCH=24h000000; end if(LFCH=24d0) N*1=N*; endalways(posedge clk or negedge ret)if(!ret) Fsst=1b0;else if(F*_cph) Fsst=!Fend; /邊沿對(duì)齊always(posedge clk or posedge Fend)if(Fend) Ns=40h0000000000;else if(Fsst) Ns=N

8、s+1b1;assign F*_cph=(cp_ch=8b11110000); always(posedge clk or posedge Fend)if(Fend) cp_ch=2b00;else cp_ch=cp_ch7:0,F*in;always(posedge clk or posedge Fend) if(Fend) N*=16h0000; else if(F*_cph) N*=N*+1b1; endmodule LCD控制器Verilog HDL程序主要用于轉(zhuǎn)換控制液晶的協(xié)議,加快CPU的寫入和控制,可以做到兩時(shí)鐘并行周期。部有的PWM模塊用于控制液晶的顯示亮度,CPU只需要向相應(yīng)

9、的存放器寫入亮度控制數(shù)就能控制液晶的亮度。module TFT_LCD_IP( / Clcok Input時(shí)鐘和復(fù)位 input csi_clk, input csi_reset_n, / Avalon-MM Slave 總線的連接 input avs_chipselect, input 8:0 avs_address, /RS,A2,A1,A0 / 3-2-1-0 位 input avs_write, input 31:0 avs_writedata, input avs_read, output 31:0 avs_readdata, / ip_TFT 液晶的接口 output 15:0co

10、e_lcd_data, output coe_lcd_cs, output coe_lcd_rs, output coe_lcd_wr, output reg coe_lcd_pwm, output reg coe_lcd_res, input coe_touch_int, input coe_touch_dout, output reg coe_touch_din, output reg coe_touch_busy, output reg coe_touch_dclk, output reg coe_touch_cs);reg div_se;reg 19:0 div_buf; /PWM的前

11、置分頻存放器reg 2:0 count; /脈頻計(jì)數(shù)器reg 2:0 pwm_buf; /占空比07reg 31:0 read_data;/總線從外界讀取的數(shù)據(jù)存放器wire check; /中間檢測(cè)信號(hào) wire all_cs;assign all_cs=(avs_address7:0=8h00);/ write to ip_TFT form NiosII cpuassign check=avs_write & all_cs;assign coe_lcd_wr=check 1b1:1b0;assign coe_lcd_cs=(avs_chipselect & all_cs) 1b0:1b1;

12、assign coe_lcd_rs=avs_address8;assign coe_lcd_data=(avs_chipselect & all_cs) avs_writedata15:0:16hzzzz; /使用一個(gè)時(shí)鐘讀取時(shí),觸摸板能讀出正常數(shù)據(jù),但是出現(xiàn)閃屏assign avs_readdata=read_data;always(negedge csi_clk or negedge csi_reset_n) begin if (!csi_reset_n) begin pwm_buf=3b111; coe_lcd_res=1b1; coe_touch_din=1b1; coe_touch_

13、busy=1b1; coe_touch_dclk=1b1; coe_touch_cs=1b1; end else if(avs_chipselect & (!all_cs) begin case (avs_address7:0) 8b0000_0001:pwm_buf=avs_writedata2:0; 8b0000_0010:coe_lcd_res=avs_writedata0; 8b0000_0100:coe_touch_din = avs_writedata0; 8b0000_1000:coe_touch_busy = avs_writedata0; 8b0001_0000:coe_to

14、uch_dclk = avs_writedata0; 8b0010_0000:coe_touch_cs = avs_writedata0; 8b0100_0000: read_data0= coe_touch_int; 8b1000_0000: read_data0= coe_touch_dout; endcase endendalways(posedge csi_clk or negedge csi_reset_n)begin if (!csi_reset_n) begin div_buf=20h00000; div_se=1b0; end else if(div_buf=20d100000

15、) begin div_buf=20h00000; div_se=1b1; end else begin div_buf=div_buf+1b1; /計(jì)數(shù)器計(jì)滿自動(dòng)清零 div_se=1b0; endendalways(posedge csi_clk or negedge csi_reset_n)begin if (!csi_reset_n) begin coe_lcd_pwm=1b1; count=3b000; end else begin if(count=pwm_buf) coe_lcd_pwm=1b0; /遇到與脈寬調(diào)制器一樣時(shí),輸出管腳清零 else if(count=3b000)

16、coe_lcd_pwm=1b1; /計(jì)滿時(shí)對(duì)管腳置一 if(div_se) count=count+1b1; /計(jì)數(shù)器計(jì)滿自動(dòng)清零 endend endmodule觸摸板控制程序Verilog HDL程序主要用于轉(zhuǎn)換觸摸板AD的串行協(xié)議,使CPU能夠?qū)ζ溥M(jìn)展并行控制。它在很大程度上減小了CPU檢測(cè)觸點(diǎn)的難度,加快了軟件的運(yùn)行速度,防止了高速運(yùn)行的CPU使用延時(shí)降低速度去控制低速的觸摸板串行AD的情況。Moduletouch_contrl_IP(ret,clk,address,read,readdata,dint,busy,dclk,dcs,dout,din);/-Avalon-MM IO-in

17、put ret,clk;input 1:0address;input read;output reg11:0 readdata;/-Avalon-MM 要讀出的數(shù)據(jù)reg 11:0t*data,tydata; /觸點(diǎn)的*Y軸坐標(biāo) reg CEND; /觸摸板總讀寫完畢標(biāo)志/-部邏輯IO-input dint; /觸摸板按下指示管腳input busy; /觸摸芯片忙指示腳input dout; /觸摸芯片轉(zhuǎn)換的數(shù)據(jù)output reg dclk; /送給觸摸芯片的時(shí)鐘output reg dcs; /觸摸芯片的片選output reg din; /送給觸摸芯片的數(shù)據(jù)腳parameter CH*

18、=8h90, CHY=8hd0;reg declk; /延時(shí)后的時(shí)鐘信號(hào)reg 15:0delay; /時(shí)鐘延時(shí)reg 7:0count; /運(yùn)行計(jì)數(shù)器reg 7:0CHbuf; /通道選擇存放器reg 7:0wsbuf; /寫入數(shù)據(jù)的存放器reg 11:0rbuf; /讀出數(shù)據(jù)的存放器reg 1:0dstate; /通道選擇狀態(tài)存放器reg 3:0state; /狀態(tài)控制存放器reg wr_cs; /寫讀使能標(biāo)志位reg wr_end; /數(shù)據(jù)寫讀完畢標(biāo)志位/-三態(tài)總線接口-always(posedge clk or negedge ret)if(!ret) readdata=12h0000

19、0;else if(read) case(address) 2d0:readdata0=CEND; 2d1:readdata=t*data; 2d2:readdata=tydata; default:readdata=CEND; endcasealways(posedge clk or negedge ret)if(!ret) begin declk=1b0; delay=16h0000; endelse begin if(delay=16d20)begin delay=16h0000; declk=declk;endelse delay=delay+1b1; end/-寫讀*軸、Y軸的分配-

20、always(posedge declk or negedge ret)if(!ret) begin CHbuf=CH*; dstate=2d1;wr_cs=1b0;CEND=1b0; endelse begin case(dstate)2d1:begin CEND=1b0; CHbuf=CH*;if(dint) begin wr_cs=1b0; dstate=2d1;end else begin wr_cs=1b1; dstate=2d2;endend2d2:begin if(wr_end) begin t*data=rbuf; CHbuf=CHY; wr_cs=1b1; dstate=2d

21、3;endelse begin wr_cs=1b0; dstate=2d2;endend2d3:begin wr_cs=1b0; if(wr_end) begin tydata=rbuf; CEND=1b1; dstate=2d3;endelse dstate=2d1;enddefault:dstate=2d1;endcase end/=向觸摸AD芯片寫數(shù)據(jù)=always(posedge declk or negedge ret)if(!ret) begin dclk=1b1; dcs=1b1;din=1b1;count=8h00;wr_end=1b0;state=4d0; endelse b

22、egin case(state)4d0:begin wr_end=1b0; if(wr_cs) state=4d1; else state=4d0;end4d1:begin dcs=1b1; dclk=1b0; din=1b0; state=4d2;end/-寫入數(shù)據(jù)-4d2:begin dcs=1b0; count=8h00; wsbuf=CHbuf; /寫*軸轉(zhuǎn)換命令- state=4d3;end4d3:begin din=wsbuf7; state=4d4; end4d4:begin wsbuf=wsbuf6:0,wsbuf7; dclk=1b1; state=4d5;end4d5:be

23、gin if(count=8h7) begin count=8h00; dclk=1b1; state=4d6;endelse begin count=count+1b1; dclk=1b0; state=4d3;endend/-讀出數(shù)據(jù)-4d6:begin din=1b0; dclk=1b1; rbuf=12h00000; if(busy) state=4d6; else state=4d7;end4d7:begin dclk=1b0; state=4d8;end4d8:begin rbuf0=dout; state=4d9;end 4d9:begin dclk=1b1; if(count=

24、8d11) begin count=8h00; dcs=1b1; wr_end=1b1; state=4d0; endelse begin count=count+1b1; rbuf=rbuf10:0,rbuf11; state=4d7;endenddefault:state=4d0;endcase end endmodule 液晶顯示程序C語(yǔ)言程序此程序用于控制液晶顯示。根據(jù)配置信息在液晶上顯示相應(yīng)信息,控制人機(jī)交互等功能。*include define.h*include *include *include io.h*include system.h*include asc_zm.he*t

25、ern volatile uint CLD;/=寫入命令=void write_(uint address,uint num) send_mand(address); send_data(num);/=設(shè)置地址=void Set_ramaddr(uint *,uint y) write_(0*0021,y); /行首址 write_(0*0020,*); /列首址/=液晶初始化=void LCD_init(void) lcd_res(0); /低電平復(fù)位 DelayNS(500000); lcd_res(1); write_(0*00,0*0000);DelayNS(3000); write_

26、(0*07,0*0001);DelayNS(3000);/Display Control 1 write_(0*08,0*0405);DelayNS(3000);/Display Control 2 0808 write_(0*30,0*0707);DelayNS(3000); write_(0*31,0*0407);DelayNS(3000); write_(0*32,0*0203);DelayNS(3000); write_(0*33,0*0303);DelayNS(3000); write_(0*34,0*0303);DelayNS(3000); write_(0*35,0*0202);

27、DelayNS(3000); write_(0*36,0*1007);DelayNS(3000);/0*1111 write_(0*37,0*0707);DelayNS(3000);/0*0606 write_(0*38,0*0407);DelayNS(3000);/0*0606 write_(0*39,0*0203);DelayNS(3000);/0*0606 write_(0*3a,0*0202);DelayNS(3000); write_(0*3b,0*0303);DelayNS(3000); write_(0*3c,0*0606);DelayNS(3000); write_(0*3d,

28、0*1313);DelayNS(3000); write_(0*07,0*0101);DelayNS(3000);/Display Control 1 write_(0*17,0*0001);DelayNS(3000);/Power Control 5 write_(0*10,0*16b0);DelayNS(3000);/Power Control 1 write_(0*11,0*0001);DelayNS(3000);/Power Control 2 0007 write_(0*12,0*0118);DelayNS(3000);/Power Control 3 write_(0*13,0*0

29、B00);DelayNS(3000);/Power Control 4 0*1400 write_(0*29,0*0004);DelayNS(3000);/V High Voltage 0*0c write_(0*2a,0*0000);DelayNS(3000);/V High Voltage 0*0080 write_(0*12,0*01B8);DelayNS(3000);/Power Control 3 0*013e write_(0*01,0*0100);DelayNS(3000);/Driver Output Control write_(0*02,0*0300);DelayNS(30

30、00);/LCD Driving Wave Control 0*0701 write_(0*03,0*1030);DelayNS(3000);/Entry Mode 0*1030豎頻顯示指令/0*1038橫頻顯示 write_(0*04,0*0000);DelayNS(3000);/Resizing Control write_(0*09,0*0028);DelayNS(3000);/Display Control 3 0*0028 write_(0*0c,0*0000);DelayNS(3000);/interface select write_(0*50,0*0000);DelayNS(3

31、000);/Window Horizontal RAM Address Start write_(0*51,0*00ef);DelayNS(3000);/Window Horizontal RAM Address End write_(0*52,0*0000);DelayNS(3000);/Window Vertical RAM Address Start write_(0*53,0*013f);DelayNS(3000);/Window Vertical RAM Address End write_(0*60,0*2700);DelayNS(3000);/Driver Output Cont

32、rol write_(0*61,0*0001);DelayNS(3000);/Base Image Display Control write_(0*90,0*0015);DelayNS(3000);/Panel interface control 1 0010 write_(0*92,0*0000);DelayNS(3000);/Panel interface control 2 write_(0*93,0*0000);DelayNS(3000);/Panel interface control 3 write_(0*20,0*00ef);DelayNS(3000);/RAM Address

33、 Set (Horizontal Address) write_(0*21,0*013f);DelayNS(3000);/RAM Address Set (Vertical Address) write_(0*07,0*0021);DelayNS(3000);/Display Control 1 write_(0*07,0*0061);DelayNS(3000);/Display Control 1 write_(0*07,0*0173);DelayNS(3000);/Display Control 1 write_(0*10,0*16b0);DelayNS(3000);/10bo 0*18b

34、0 write_(0*20,0*0000);DelayNS(3000); write_(0*21,0*0000);DelayNS(3000);/=整屏顯示一種顏色=void DispOneColor(uint Color) uint i,j; write_(0*004f,0); /行首址0 write_(0*004e,0); /列首址0 send_mand(0*22); for(j=0;j320;j+)for(i=0;i240;i+)send_data(Color);/=清屏=void DispClear(void) DispOneColor(BLACK);/* 名 稱: void LCD_c

35、lean(u16 *, u16 y, u16 *_length, u16 y_length, u8 colour ) * 功 能: 去除一個(gè)指定區(qū)域*/void LCD_clean(alt_u16 *, alt_u16 y, alt_u16 *_length, alt_u16 y_length, alt_u16 colour) alt_u16 i,j; for(j=0; jy_length; j+) Set_ramaddr(*,y+); send_mand(0*22); for(i=0; i*_length; i+) send_data(colour); /* 名 稱: DispSmallPi

36、c* 功 能: 在指定的位置顯示一65K色的圖片* 參 數(shù): str : 圖片數(shù)組名*/void DispSmallPic(uint *, uint y, uint w, uint h, const uchar *str) alt_u16 i,j,temp; for(j=0;jh;j+) Set_ramaddr(*,y+j); send_mand(0*22); for(i=0;iw;i+) /send_data(*(u16 *)(&str(j*w+i)*2); /高位在前 temp=str(j*w+i)*2+18; /低位在前 temp|=str(j*w+i)*2; send_data(tem

37、p); /* 名 稱: DrawSingleAscii* 功 能: 在指定的位置單個(gè)字符* 參 數(shù): * : *坐標(biāo)* y : y坐標(biāo)* LineColor : 字符的顏色* FillColor : 字符背景顏色* 返 回 值: 無(wú)*/void DrawSingleAscii(uint *, uint y, uchar OffSet, uint LineColor,uint FillColor) uchar i, j; uchar str; for (i=1;i11;i+) Set_ramaddr(237-(y+i),*); send_mand(0*22); str=AsciiLibOffSe

38、ti; for (j=0;j6;j+) if ( str & (0*01j send_data(uint)(LineColor&0*ffff); else send_data(uint)(FillColor&0*ffff); /* 名 稱: DrawSingleHz* 功 能: 在指定的位置顯示漢字* 參 數(shù): * : *坐標(biāo)* y : y坐標(biāo)* LineColor : 漢字的顏色* FillColor : 漢字背景顏色* 返 回 值: 無(wú)*/void DrawSingleHz(uint *, uint y, uchar *pHz, uint LineColor,uint FillColor,

39、 uchar Mod)uint j=0,i=0,k=0;uint str,len;/-統(tǒng)計(jì)是否在字庫(kù)中出現(xiàn)len=sizeof(HzLib)/sizeof(HzLib0);for(j=0;jsizeof(HzLib)/sizeof(HzLib0);j+) if(uchar)HzLibj.Inde*0=pHz0&(uchar)HzLibj.Inde*1=pHz1)break;/- if(jlen) for (i=0;iHZ_column;i+) Set_ramaddr(237-(y+i),*); send_mand(0*22); str = (uchar)HzLibj.Mski*28|(ucha

40、r)HzLibj.Mski*2+1; for (k=0;kk) ) /0*8000k send_data(uint)(LineColor&0*ffff); DelayNS(5); else if (NORMAL = Mod) send_data(uint)(FillColor&0*ffff); DelayNS(5); else Set_ramaddr(237-(y+i),*+k+1); send_mand(0*22); /* 名 稱: DrawString* 功 能: 在指定的位置顯示多個(gè)字符* 參 數(shù): * : *坐標(biāo)* y : y坐標(biāo)* LineColor : 字符的顏色* FillCol

41、or : 字符背景顏色* 返 回 值: 無(wú)*/void DrawString(uint *, uint y, uchar *pStr, uint LineColor,uint FillColor, uchar Mod) while(1) if (*pStr = 0) return; DrawSingleHz(*, y, pStr, LineColor, FillColor, Mod); * += HZ_column; pStr += 2; /* 名 稱: Disp_F* 功 能: 顯示頻率數(shù)字* 送入的頻率數(shù)據(jù)恒定為4位*/void Disp_F*(unsigned int *, unsigned int y, unsigned int num) unsigned char str6,i=5,spbuf; while(i-) stri=num%10; num=num/10; spbuf=4-F*_SP; for(i=0;ispbuf;i+) stri=stri+1; strspbuf=10; for(i=0;i5;i+) DrawSingleAscii(*+(i*6), y, stri, RED, WHITE);/* 名 稱: Disp_Vpp* 功 能: 顯示幅度*/void Disp_

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論