《多功能手持数字示波表.pdf》由会员分享,可在线阅读,更多相关《多功能手持数字示波表.pdf(26页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-软件设计 1 .软件流程图 V e r i l o g H D L和 C 语 言 程 序 相 结 合 的 软 件 流 程 图 见 图2。图 2 软 件 流 程 图 2.软件设计 局部程序源码 频率计Verilog HDL 程序 本程序主要用于测量出输入信号的频率。采用等精度测量的方法,在整个测量围误差一样。可以自动切换量程,指示数据小数点的位置和频率单位。当输入信号频率过低时还能发出相应的指示信号,通知 CPU 做出相应控制。通过适度的采样控制减小了测量误差。-module frequency(clk,ret,F*_clr,F*in,Fout,LF,spoint,flag_MK);input
2、 wire clk,ret;input wire F*in;/待测频率输入端口 input wire F*_clr;/CPU 的控制信号,控制频率计清零 output reg 15:0Fout;/测得的频率值 output reg LF;/低频标志,高电平是表示为低频 output reg 1:0spoint;/指示小数点的位置 output reg 1:0flag_MK;/频率单位:M 标志 K 标志 wire F*_cph;reg 7:0cp_ch;reg Fend;/测频完毕标志 reg Fsst;/控制本地标频开场计数的标志 0:开场计数 reg 39:0Ns;/对本地标频的计数 re
3、g 23:0LFCH;/低频检测计数器,对底频率和直流做出警报和指示 reg 15:0N*,N*1;/对待测频率的计数,N*1 检测低频被测信号的暂存器 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;end else -begin s*1000=1000);s0=(Ns=40d100_0);s1=(Ns=40d100_00)
4、;s2=(Ns=40d100_000);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);end always(posedge clk or negedge ret)if(!ret)begin Fend=1b0;flag_MK=2b00;spoint=2b00;Fout=16h0000;end else begin if(Fend)Fend=1b0;if(F*_clr
5、)Fend=1b1;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 end always(posedge clk or posedge Fend)if(Fend)begin LFCH=24h
7、000000;LF=1b0;end else begin LFCH=LFCH+1b1;if(LFCH=24d100_000_00)begin LF=(N*1=N*);LFCH=24h000000;end if(LFCH=24d0)N*1=N*;end always(posedge clk or negedge ret)if(!ret)Fsst=1b0;else if(F*_cph)Fsst=!Fend;/边沿对齐 always(posedge clk or posedge Fend)if(Fend)Ns=40h0000000000;else if(Fsst)Ns=Ns+1b1;assign F
8、*_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 程序 主要用于转换控制液晶的协议,加快 CPU 的写入和控制,可以做到两时钟并行周期。部有的 PWM 模块用于控制液晶的显示亮度,CPU 只需要向相应的存放器写入亮度控制数就
9、能控制液晶的亮度。module TFT_LCD_IP(/Clcok Input 时钟和复位 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:0coe_lcd_data,output coe_lc
10、d_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 的前置分频存放器 reg 2:0 count;/脉频计数器 reg 2:
11、0 pwm_buf;/占空比07 reg 31:0 read_data;/总线从外界读取的数据存放器 wire check;/中间检测信号 wire all_cs;assign all_cs=(avs_address7:0=8h00);/write to ip_TFT form NiosII cpu assign check=avs_write&all_cs;assign coe_lcd_wr=check 1b1:1b0;assign coe_lcd_cs=(avs_chipselect&all_cs)1b0:1b1;assign coe_lcd_rs=avs_address8;assign
12、coe_lcd_data=(avs_chipselect&all_cs)avs_writedata15:0:16hzzzz;/使用一个时钟读取时,触摸板能读出正常数据,但是出现闪屏 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_busy=1b1;coe_touch_dclk=1b1;coe_touch_cs=1b1;en
13、d 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_touch_dclk=avs_writedata0;8b0010_0000:coe_touch_cs =avs_writeda
14、ta0;8b0100_0000:read_data0=coe_touch_int;8b1000_0000:read_data0=coe_touch_dout;endcase end end always(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)begin div_buf=20h00000;div_se=1b1;end else begin div_buf=div_buf+1b1;/计数器
15、计满自动清零 div_se=1b0;end end always(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;/遇到与脉宽调制器一样时,输出管脚清零 else if(count=3b000)coe_lcd_pwm=1b1;/计满时对管脚置一 if(div_se)count=count+1b1;/计数器计满自动清零 end end endmodule 触摸
16、板控制程序Verilog HDL 程序 主要用于转换触摸板 AD 的串行协议,使 CPU 能够对其进展并行控制。它在很大程度上减小了 CPU 检测触点的难度,加快了软件的运行速度,防止了高速运行的 CPU 使用延时降低速度去控制低速的触摸板串行 AD 的情况。Moduletouch_contrl_IP(ret,clk,address,read,readdata,dint,busy,dclk,dcs,dout,din);/-Avalon-MM IO-input ret,clk;input 1:0address;input read;output reg11:0 readdata;/-Avalon
17、-MM 要读出的数据 reg 11:0t*data,tydata;/触点的*Y 轴坐标 reg CEND;/触摸板总读写完毕标志/-部逻辑 IO-input dint;/触摸板按下指示管脚 input busy;/触摸芯片忙指示脚 input dout;/触摸芯片转换的数据-output reg dclk;/送给触摸芯片的时钟 output reg dcs;/触摸芯片的片选 output reg din;/送给触摸芯片的数据脚 parameter CH*=8h90,CHY=8hd0;reg declk;/延时后的时钟信号 reg 15:0delay;/时钟延时 reg 7:0count;/运行
18、计数器 reg 7:0CHbuf;/通道选择存放器 reg 7:0wsbuf;/写入数据的存放器 reg 11:0rbuf;/读出数据的存放器 reg 1:0dstate;/通道选择状态存放器 reg 3:0state;/状态控制存放器 reg wr_cs;/写读使能标志位 reg wr_end;/数据写读完毕标志位/-三态总线接口-always(posedge clk or negedge ret)if(!ret)readdata=12h00000;else if(read)case(address)2d0:readdata0=CEND;2d1:readdata=t*data;2d2:rea
19、ddata=tydata;default:readdata=CEND;endcase always(posedge clk or negedge ret)if(!ret)begin declk=1b0;delay=16h0000;end-else begin if(delay=16d20)begin delay=16h0000;declk=declk;end else delay=delay+1b1;end/-写读*轴、Y 轴的分配-always(posedge declk or negedge ret)if(!ret)begin CHbuf=CH*;dstate=2d1;wr_cs=1b0;
20、CEND=1b0;end else 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;-end end 2d2:begin if(wr_end)begin t*data=rbuf;CHbuf=CHY;wr_cs=1b1;dstate=2d3;end else begin wr_cs=1b0;dstate=2d2;end end 2d3:begin wr_cs=1b0;if(wr_end)begin tydata
21、=rbuf;CEND=1b1;dstate=2d3;end else dstate=2d1;end default:dstate=2d1;endcase-end/=向触摸 AD 芯片写数据=always(posedge declk or negedge ret)if(!ret)begin dclk=1b1;dcs=1b1;din=1b1;count=8h00;wr_end=1b0;state=4d0;end else begin case(state)4d0:begin wr_end=1b0;if(wr_cs)state=4d1;else state=4d0;end 4d1:begin dcs
22、=1b1;dclk=1b0;din=1b0;state=4d2;end/-写入数据-4d2:begin dcs=1b0;count=8h00;wsbuf=CHbuf;/写*轴转换命令-state=4d3;end-4d3:begin din=wsbuf7;state=4d4;end 4d4:begin wsbuf=wsbuf6:0,wsbuf7;dclk=1b1;state=4d5;end 4d5:begin if(count=8h7)begin count=8h00;dclk=1b1;state=4d6;end else begin count=count+1b1;dclk=1b0;state
23、=4d3;end end/-读出数据-4d6:begin din=1b0;dclk=1b1;rbuf=12h00000;if(busy)state=4d6;else state=4d7;end-4d7:begin dclk=1b0;state=4d8;end 4d8:begin rbuf0=dout;state=4d9;end 4d9:begin dclk=1b1;if(count=8d11)begin count=8h00;dcs=1b1;wr_end=1b1;state=4d0;end else begin count=count+1b1;rbuf=rbuf10:0,rbuf11;stat
24、e=4d7;end end default:state=4d0;endcase-end endmodule 液晶显示程序C 语言程序 此程序用于控制液晶显示。根据配置信息在液晶上显示相应信息,控制人机交互等功能。*include define.h*include *include *include io.h*include system.h*include asc_zm.h e*tern volatile uint CLD;/=写入命令=void write_(uint address,uint num)send_mand(address);send_data(num);/=设置地址=void
25、 Set_ramaddr(uint*,uint y)write_(0*0021,y);/行首址 write_(0*0020,*);/列首址 /=液晶初始化=void LCD_init(void)lcd_res(0);/低电平复位 DelayNS(500000);lcd_res(1);write_(0*00,0*0000);DelayNS(3000);-write_(0*07,0*0001);DelayNS(3000);/Display Control 1 write_(0*08,0*0405);DelayNS(3000);/Display Control 2 0808 write_(0*30,
26、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);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);Dela
27、yNS(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,0*1313);DelayNS(3000);write_(0*07,0*0101);DelayNS(3000);/Display Control 1 write_(0*17,0*0001);DelayNS(3000);/Power Control 5
28、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*0B00);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(3
29、000);/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(3000);/LCD Driving Wave Control 0*0701 write_(0*03,0*1030);DelayNS(3000);/Entry Mode 0*1030竖频显示指令/0*1038横频显示 write_(0*04,0*0000);
30、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(3000);/Window Horizontal RAM Address Start write_(0*51,0*00ef);DelayNS(3000);/Window Horizontal RAM Address End write_(0*52,0*00
31、00);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 Control write_(0*61,0*0001);DelayNS(3000);/Base Image Display Control write_(0*90,0*0015);DelayNS(3000);/Panel interface control 1
32、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 Set(Horizontal Address)write_(0*21,0*013f);DelayNS(3000);/RAM Address Set(Vertical Address)write_(0*07,0*0021);DelayNS(3000);/
33、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*18b0 write_(0*20,0*0000);DelayNS(3000);write_(0*21,0*0000);DelayNS(3000);/=整屏显示一种颜色=void DispOneColor(uint Color)uint i,j;write_(0*004
34、f,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_clean(u16*,u16 y,u16*_length,u16 y_length,u8 colour)*功 能:去除一个指定区域*/void LCD_clean(alt_u16*,alt_u16 y,alt_u16*_length,alt_u16 y_length,alt_
35、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);/*名 称:DispSmallPic*功 能:在指定的位置显示一 65K 色的图片*参 数:str :图片数组名*/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
36、);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(temp);/*名 称:DrawSingleAscii*功 能:在指定的位置单个字符*参 数:*:*坐标*y :y 坐标*LineColor:字符的颜色*FillColor:字符背景颜色*返 回 值:无*/void DrawSingleAscii(uint*,uint y,uchar OffSet,uint LineColor,uint FillColor)uchar i
37、,j;uchar str;for(i=1;i11;i+)Set_ramaddr(237-(y+i),*);send_mand(0*22);str=AsciiLibOffSeti;for(j=0;j6;j+)if(str&(0*01j send_data(uint)(LineColor&0*ffff);-else send_data(uint)(FillColor&0*ffff);/*名 称:DrawSingleHz*功 能:在指定的位置显示汉字*参 数:*:*坐标*y :y 坐标*LineColor :汉字的颜色*FillColor :汉字背景颜色*返 回 值:无*/void DrawSing
38、leHz(uint*,uint y,uchar*pHz,uint LineColor,uint FillColor,uchar Mod)uint j=0,i=0,k=0;uint str,len;/-统计是否在字库中出现 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),*
39、);-send_mand(0*22);str=(uchar)HzLibj.Mski*28|(uchar)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*功 能:在指定的位置显示多个字符*参 数:*:*坐标*y :y 坐标-*
40、LineColor :字符的颜色*FillColor :字符背景颜色*返 回 值:无*/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*功 能:显示频率数字*送入的频率数据恒定为 4 位*/void Disp_F*(unsigned int*,unsigned int y,
41、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_Vpp(unsigned int Vpp*,unsigned int Vppn)uint i,vs1,vs2,ma*=0,min=255;uint
42、Au3=125,50,25,Aub6=1,10,100,1000,10000,100000;ulong Vpp=0,sVbufz=0,sVbufm=0;for(vs2=0;vs2=1020)|(Vppn=0)DrawSingleAscii(302,46,26,RED,WHITE);else Vpp=(Vpp*-Vppn)*(AubCLD/3)*500)/(AuCLD%3)*256);for(i=5;i;i-)if(Vpp/Aubi)break;if(i2)vs2=0;for(vs1=i-3;vs1i;vs1+)if(vs1=2)DrawSingleAscii(314-(+vs2)*6,46,1
43、0,RED,WHITE);/参加标点 Vpp=Vpp/Aubvs1;DrawSingleAscii(314-(+vs2)*6,46,Vpp%10,RED,WHITE);else vs2=0;-while(i-)DrawSingleAscii(302-(i)*6,46,Vpp%10,RED,WHITE);Vpp=Vpp/10;DrawSingleAscii(308,46,16,BLUE,WHITE);/m 触屏校准程序C 语言程序 由于触摸板输出的坐标信息与液晶的坐标相差很大,还需要定期的予以校准,这给人机交互带来一定的不便。本程序就用于触摸板的校准。在校准完成后保存校准信息。通过相应的算法计算
44、出触点相对于液晶的坐标。运算精度可以小于一个像素点。很好的解决了这个问题。*include *include *include define.h*include screen_adjust.h*define*L0 200*define YL0 280 *define*L1 120*define YL1 160*define*L2 40*define YL2 40 u16 TL*=155,TLy=113;u16 offset*=158,offsety=141;/*功 能:比拟触摸点是否在相应区域 *传入值为左上角坐标和右下角坐标*如在区域会返回 0*ff,否则返回 0;-*/u8 Area_ch
45、eck(u16 top_left_*,u16 top_left_y,u16 lower_right_*,u16 lower_right_y)u16*L,YL;touch_LCD(&*L,&YL);if(*Ltop_left_*&*Ltop_left_y&YL800)|(*t2800)|(Yt22100)|(*t12000)|(Yt13400)|(*t03400)|(Yt03200);/-TL*,TLy,offset*,offsety 的值 TL*=10*(*t0-*t2)/(*L0-*L2);TLy=10*(Yt0-Yt2)/(YL0-YL2);offset*=*t1-*L1*(*t0-*t2)/(*L0-*L2);offsety=Yt1-YL1*(Yt0-Yt2)/(YL0-YL2);