1、程控滤波源代码 1:/*功能:(1)TLV1544 采样程序(2)AD9851 产生 100200KHz 的正弦信号按键控制正弦信号 10KHz 步进,LCD 显示(3)AD9851 产生 40kHz800kHz 方波按键控制方波信号 40kHz 步进控制 max262 的时钟(4)DAC0832 转换输出控制(控制 AD603 的增益控制电压)(5)MAX262 滤波器中心频率及品质因数的控制*/ / CodeVisionAVR C Compiler/ (C) 1998-2004 Pavel Haiduc, HP InfoTech S.R.L./ I/O registers definiti
2、ons for the ATmega128#pragma used+sfrb PINF=0;sfrb PINE=1;sfrb DDRE=2;sfrb PORTE=3;sfrb ADCL=4;sfrb ADCH=5;sfrw ADCW=4; / 16 bit accesssfrb ADCSRA=6;sfrb ADMUX=7;sfrb ACSR=8;sfrb UBRR0L=9;sfrb UCSR0B=0xa;sfrb UCSR0A=0xb;sfrb UDR0=0xc;sfrb SPCR=0xd;sfrb SPSR=0xe;sfrb SPDR=0xf;sfrb PIND=0x10;sfrb DDRD
3、=0x11;sfrb PORTD=0x12;sfrb PINC=0x13;sfrb DDRC=0x14;sfrb PORTC=0x15;sfrb PINB=0x16;sfrb DDRB=0x17;sfrb PORTB=0x18;sfrb PINA=0x19;sfrb DDRA=0x1a;sfrb PORTA=0x1b;sfrb EECR=0x1c;sfrb EEDR=0x1d;sfrb EEARL=0x1e;sfrb EEARH=0x1f;sfrw EEAR=0x1e; / 16 bit accesssfrb SFIOR=0x20;sfrb WDTCR=0x21;sfrb OCDR=0x22;
4、sfrb OCR2=0x23;sfrb TCNT2=0x24;sfrb TCCR2=0x25;sfrb ICR1L=0x26;sfrb ICR1H=0x27;sfrw ICR1=0x26; / 16 bit accesssfrb OCR1BL=0x28;sfrb OCR1BH=0x29;sfrw OCR1B=0x28; / 16 bit accesssfrb OCR1AL=0x2a;sfrb OCR1AH=0x2b;sfrw OCR1A=0x2a; / 16 bit accesssfrb TCNT1L=0x2c;sfrb TCNT1H=0x2d;sfrw TCNT1=0x2c; / 16 bi
5、t accesssfrb TCCR1B=0x2e;sfrb TCCR1A=0x2f;sfrb ASSR=0x30;sfrb OCR0=0x31;sfrb TCNT0=0x32;sfrb TCCR0=0x33;sfrb MCUCSR=0x34;sfrb MCUCR=0x35;sfrb TIFR=0x36;sfrb TIMSK=0x37;sfrb EIFR=0x38;sfrb EIMSK=0x39;sfrb EICRB=0x3a;sfrb RAMPZ=0x3b;sfrb XDIV=0x3c;sfrb SPL=0x3d;sfrb SPH=0x3e;sfrb SREG=0x3f;#pragma use
6、d-/ Interrupt vectors definitions/ CodeVisionAVR C Compiler/ (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.#pragma used+void delay_us(unsigned int n);void delay_ms(unsigned int n);#pragma used-/* CodeVisionAVR C CompilerPrototypes for standard library functions(C) 1998-2003 Pavel Haiduc, HP InfoTech
7、 S.R.L.*/#pragma used+int atoi(char *str);long int atol(char *str);float atof(char *str);void itoa(int n,char *str);void ltoa(long int n,char *str);void ftoa(float n,unsigned char decimals,char *str);void ftoe(float n,unsigned char decimals,char *str);void srand(int seed);int rand(void);void *malloc
8、(unsigned int size);void *calloc(unsigned int num, unsigned int size);void *realloc(void *ptr, unsigned int size); void free(void *ptr);#pragma used-#pragma library stdlib.lib/ CodeVisionAVR C Compiler/ (C) 1998-2005 Pavel Haiduc, HP InfoTech S.R.L./ Prototypes for string functions#pragma used+char
9、*strcat(char *str1,char *str2);char *strcatf(char *str1,char flash *str2);char *strchr(char *str,char c);signed char strcmp(char *str1,char *str2);signed char strcmpf(char *str1,char flash *str2);char *strcpy(char *dest,char *src);char *strcpyf(char *dest,char flash *src);unsigned char strcspn(char
10、*str,char *set);unsigned char strcspnf(char *str,char flash *set);unsigned int strlenf(char flash *str);char *strncat(char *str1,char *str2,unsigned char n);char *strncatf(char *str1,char flash *str2,unsigned char n);signed char strncmp(char *str1,char *str2,unsigned char n);signed char strncmpf(cha
11、r *str1,char flash *str2,unsigned char n);char *strncpy(char *dest,char *src,unsigned char n);char *strncpyf(char *dest,char flash *src,unsigned char n);char *strpbrk(char *str,char *set);char *strpbrkf(char *str,char flash *set);signed char strpos(char *str,char c);char *strrchr(char *str,char c);c
12、har *strrpbrk(char *str,char *set);char *strrpbrkf(char *str,char flash *set);signed char strrpos(char *str,char c);char *strstr(char *str1,char *str2);char *strstrf(char *str1,char flash *str2);unsigned char strspn(char *str,char *set);unsigned char strspnf(char *str,char flash *set);char *strtok(c
13、har *str1,char flash *str2);unsigned int strlen(char *str);void *memccpy(void *dest,void *src,char c,unsigned n);void *memchr(void *buf,unsigned char c,unsigned n);signed char memcmp(void *buf1,void *buf2,unsigned n);signed char memcmpf(void *buf1,void flash *buf2,unsigned n);void *memcpy(void *dest
14、,void *src,unsigned n);void *memcpyf(void *dest,void flash *src,unsigned n);void *memmove(void *dest,void *src,unsigned n);void *memset(void *buf,unsigned char c,unsigned n);#pragma used-#pragma library string.lib/*TLV1544 驱动程序CS PG0 DO PG1 DI PG2CLK PG3 EOC PG4*/ CodeVisionAVR C Compiler/ (C) 1998-
15、2000 Pavel Haiduc, HP InfoTech S.R.L./#include “stdlib.h“/#define bits2(x) (1=1;delay_us(20);while(*(unsigned char *) 0x63)i-)ddsi=fre / freqency 为四个字节,将其一一存入到 ddsi fre=fre8; for(i=0;i=1;i-)ddsi=fre / freqency 为四个字节,将其一一存入到 ddsi fre=fre8; for(i=0;i0)Post_Msg(*p);delay_us(50);p+;PORTC.5 =1; /* 此函数用于显
16、示单个字母,daxiao 为 0 时表示初始大小 16*16 为 1 放大一倍,为 2 放大两倍,最大为 3 显示为 64*64H 表示横向偏移 029,L 表示纵向偏移 014 */void Word(unsigned char H,unsigned char L,unsigned char daxiao,unsigned char p)daxiao=daxiao*5;daxiao=daxiao0)Post_Msg(*Text);Text+;delay_us(5);/*显示字符串,包括中文字符,可混合中英文即符号 /注:自己加的X0:列设置(0-29) Y0:行设置 (0-15)*/void
17、 Show_text1(unsigned char H,unsigned char L,unsigned char *Text) Send_Com(0x12,0xB1); /自己加的Send_Com(0x60,H);Send_Com(0x70,L*16);Send_Com(0xf0,0xa0); /进入 ASII 表 0 while(*Text)0)Post_Msg(*Text);Text+;delay_us(5);/*显示单个数字*/void Show_num(unsigned char H,unsigned char L,unsigned char Num) Send_Com(0xF0,0
18、xA0); /进入 ASCII 区块 0Send_Com(0x60,H);Send_Com(0x70,L*8);Post_Msg(Num+48);/*Num 代表符号在 ASCII 区块 0 的编号*/void New_Show(unsigned char H,unsigned char L,unsigned char Num) Send_Com(0xF0,0xA0); /进入 ASCII 区块 0Send_Com(0x60,H);Send_Com(0x70,L*8); /8 改为了 16Post_Msg(Num);/*Num 代表符号在 ASCII 区块 0 的编号 注:自己加的*/void
19、 New_Show1(unsigned char H,unsigned char L,unsigned char Num) Send_Com(0x12,0xB1);Send_Com(0xF0,0xA0); /进入 ASCII 区块 0Send_Com(0x60,H);Send_Com(0x70,L*8); /8 改为了 16Post_Msg(Num);/*显示浮点数 */void Show_number(unsigned char X0,unsigned char Y0,float Num,unsigned char DpLen)unsigned char i=0,j=0,mynum6;uns
20、igned int temp; bit flag=0; /flag:是否为负 Send_Com(0x60,Y0); /消隐Send_Com(0x70,X0*8); for(i=0;i0);j=0;/-处理小数部分- if(flagdoPost_Msg(mynumi+48);i+; while(i(H%8);Post_Msg(Temp);PORTC.5 =1; /*没有 Read 操作的画点函数,速度提高,但每行只每字节只画一点 */void New_point(unsigned char H,unsigned char L)unsigned char Temp=0x00;PORTC.5 =0;
21、 Send_Com(0x60,H/8);Send_Com(0x70,L);Temp|=0x80(H%8);Post_Msg(Temp);PORTC.5 =1; /*画实点 注: 自己加的*/void onereal_point(unsigned char x1,unsigned char y1)Send_Com(0x12,0xB1); /进入图形图层Send_Com(0x00,0xC5); /图形模式point(x1,y1); Send_Com(0x00,0xCD);Send_Com(0x12,0xB2);/*画虚点(一字节中画一点) 注:自己加的*/void oneitem_point(un
22、signed char x1,unsigned char y1)Send_Com(0x12,0xB1); /进入图形图层Send_Com(0x00,0xC5); /图形模式New_point(x1,y1); /*画虚线 注:自己加的x1,y1 分别表示所画直线的起点坐标 ,x2,y2 表示的是所画的直线的终点坐标*/void item_Line(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2)float xielv;float temp; unsigned char i; Send_Com(0x12,0xB
23、1); /进入图形图层Send_Com(0x00,0xC5); /图形模式xielv=(float)(x2)-(float)(x1)/(float)y2-(float)(y1);if(y1=y2)if(x1y2)xielv=-xielv;for(i=0;ix1,y2y1;必须得保证这两个条件 */ void Line(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2)float xielv;float temp; unsigned char i; Send_Com(0x12,0xB1); /进入图形图层Sen
24、d_Com(0x00,0xC5); /图形模式xielv=(float)(x2)-(float)(x1)/(float)y2-(float)(y1);if(y1=y2)if(x1y2)xielv=-xielv;for(i=0;iy2)xielv=-xielv;for(i=0;i1)max262_ctrzi6=(q_data3)max262_ctrzi7=(q_data5)for(i=0;i1)max262_ctrzi3=(fre_data3)max262_ctrzi4=(q_data1)max262_ctrzi6=(q_data3)max262_ctrzi7=(q_data5)for(i=0;
25、i0)fre_counter-; flag1=1; elsefre_counter=fre_counter;itoa(fre_counter,str3);for(i=0;i0)q_counter-;if(type=0) Show_text(0,2,text32); /显示低通滤波器类型result=44000*clk_lpq_counter;ad9851(0x01,result); MAX262(type,Q_lpq_counter); /送控制字到 max262q=64.0/(128-Q_lpq_counter); /转换为品质因数 Q elseShow_text(0,2,text33); /显示高通滤波器类型 result=44000*clk_hpq_counter;ad9851(0x01,result); MAX262(type,Q_hpq_counter); /送控制字到 max262q=64.0/(128-Q_hpq_counter); /转换为品质因数 Q itoa(q_counter+1,str1);for(i=0;i0)DAC0832_counter-;