⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 可程控开关电容滤波器设计源代码.txt

📁 可程控开关电容滤波器设计的三部分代码。用到的芯片有AT89C2051、MAX261等。
💻 TXT
字号:
1.滤波器部分
/*--------------------------------------------------------------------------AT892051.H
Header file for the Atmel AT89C2051.
Copyright (c) 1988-2002 Keil Elektronik GmbH and Keil Software, Inc.
All rights reserved.
--------------------------------------------------------------------------*/
#ifndef __AT892051_H__
#define __AT892051_H__
/*------------------------------------------------
Byte Registers
------------------------------------------------*/
sfr SP      = 0x81;
sfr DPL     = 0x82;
sfr DPH     = 0x83;
sfr PCON    = 0x87;
sfr TCON    = 0x88;
sfr TMOD    = 0x89;
sfr TL0     = 0x8A;
sfr TL1     = 0x8B;
sfr TH0     = 0x8C;
sfr TH1     = 0x8D;
sfr P1      = 0x90;
sfr SCON    = 0x98;
sfr SBUF    = 0x99;
sfr IE      = 0xA8;
sfr P3      = 0xB0;
sfr IP      = 0xB8;
sfr PSW     = 0xD0;
sfr ACC     = 0xE0;
sfr B       = 0xF0;
/*------------------------------------------------
PCON Bit Values
------------------------------------------------*/
#define IDL_    0x01
#define STOP_   0x02
#define EWT_    0x04
#define EPFW_   0x08
#define WTR_    0x10
#define PFW_    0x20
#define POR_    0x40
#define SMOD_   0x80
/*------------------------------------------------
TCON Bit Registers
------------------------------------------------*/
sbit IT0  = 0x88;
sbit IE0  = 0x89;
sbit IT1  = 0x8A;
sbit IE1  = 0x8B;
sbit TR0  = 0x8C;
sbit TF0  = 0x8D;
sbit TR1  = 0x8E;
sbit TF1  = 0x8F;
/*------------------------------------------------
TMOD Bit Values
------------------------------------------------*/
#define T0_M0_   0x01
#define T0_M1_   0x02
#define T0_CT_   0x04
#define T0_GATE_ 0x08
#define T1_M0_   0x10
#define T1_M1_   0x20
#define T1_CT_   0x40
#define T1_GATE_ 0x80
#define T1_MASK_ 0xF0
#define T0_MASK_ 0x0F
/*------------------------------------------------
P1 Bit Registers
------------------------------------------------*/
sbit P1_0 = 0x90;
sbit P1_1 = 0x91;
sbit P1_2 = 0x92;
sbit P1_3 = 0x93;
sbit P1_4 = 0x94;
sbit P1_5 = 0x95;
sbit P1_6 = 0x96;
sbit P1_7 = 0x97;
sbit AIN0 = 0x90;       /* + Analog comparator input */
sbit AIN1 = 0x91;       /* - Analog comparator input */
/*------------------------------------------------
SCON Bit Registers
------------------------------------------------*/
sbit RI   = 0x98;
sbit TI   = 0x99;
sbit RB8  = 0x9A;
sbit TB8  = 0x9B;
sbit REN  = 0x9C;
sbit SM2  = 0x9D;
sbit SM1  = 0x9E;
sbit SM0  = 0x9F;
/*------------------------------------------------
IE Bit Registers
------------------------------------------------*/
sbit EX0  = 0xA8;       /* 1=Enable External interrupt 0 */
sbit ET0  = 0xA9;       /* 1=Enable Timer 0 interrupt */
sbit EX1  = 0xAA;       /* 1=Enable External interrupt 1 */
sbit ET1  = 0xAB;       /* 1=Enable Timer 1 interrupt */
sbit ES   = 0xAC;       /* 1=Enable Serial port interrupt */
sbit ET2  = 0xAD;       /* 1=Enable Timer 2 interrupt */
sbit EA   = 0xAF;       /* 0=Disable all interrupts */

/*------------------------------------------------
P3 Bit Registers (Mnemonics & Ports)
------------------------------------------------*/
sbit P3_0 = 0xB0;
sbit P3_1 = 0xB1;
sbit P3_2 = 0xB2;
sbit P3_3 = 0xB3;
sbit P3_4 = 0xB4;
sbit P3_5 = 0xB5;
/* P3_6 Hardwired as AOUT */
sbit P3_7 = 0xB7;

sbit RXD  = 0xB0;       /* Serial data input */
sbit TXD  = 0xB1;       /* Serial data output */
sbit INT0 = 0xB2;       /* External interrupt 0 */
sbit INT1 = 0xB3;       /* External interrupt 1 */
sbit T0   = 0xB4;       /* Timer 0 external input */
sbit T1   = 0xB5;       /* Timer 1 external input */
sbit AOUT = 0xB6;       /* Analog comparator output */
/*------------------------------------------------
IP Bit Registers
------------------------------------------------*/
sbit PX0  = 0xB8;
sbit PT0  = 0xB9;
sbit PX1  = 0xBA;
sbit PT1  = 0xBB;
sbit PS   = 0xBC;
/*------------------------------------------------
PSW Bit Registers
------------------------------------------------*/
sbit P    = 0xD0;
sbit FL   = 0xD1;
sbit OV   = 0xD2;
sbit RS0  = 0xD3;
sbit RS1  = 0xD4;
sbit F0   = 0xD5;
sbit AC   = 0xD6;
sbit CY   = 0xD7;
/*------------------------------------------------
Interrupt Vectors:
Interrupt Address = (Number * 8) + 3
------------------------------------------------*/
#define IE0_VECTOR	0  /* 0x03 External interrupt 0 */
#define TF0_VECTOR	1  /* 0x0B Timer 0 */
#define IE1_VECTOR	2  /* 0x13 External interrupt 1 */
#define TF1_VECTOR	3  /* 0x1B Timer 1 */
#define SIO_VECTOR	4  /* 0x23 Serial port */
#endif

2. MAX261参数f0,Q写入程序:
#include <REG51.H>       /* special function register declarations   */
                    /* for the intended AT89C2051 derivative         */

#include <stdio.h>       /* prototype declarations for I/O functions */

sbit P1_0=P1^0;                       /* /RESET connect to P1^0 */
sbit P1_2=P1^2;                             /* D1 connect to P1^2 */
sbit P1_3=P1^3;                             /* D0 connect to P1^3 */
sbit P1_4=P1^4;                             /* A3 connect to P1^4 */
sbit P1_5=P1^5;                             /* A2 connect to P1^5 */
sbit P1_6=P1^6;                             /* A1 connect to P1^6 */
sbit P1_7=P1^7;                             /* A0 connect to P1^7 */
sbit P3_7=P3^7;                             /*  /WR connect to P3^7 */
/*------------------------------------------------
The main C function.  Program execution starts
here after stack initialization.
------------------------------------------------*/
void main (void) {
int i;
int a[8];
for(i=0;i<8;i++)
a[i]=i;
printf("please enter number 0 to 8 by order to set MAX261: ");
for(i=0;i<8;i++)
scanf("%d",&a[i]);
P1_0=1;                                                       //  /RESET=1 to make 7555 oscillator work normally
P3_7=1;
/*------------------------------------------------
The following program section realize the function of setting f0A=1125.4HZ,
QA=90.5 of MAX261.
------------------------------------------------*/
  switch (a[i]) {

/*------------------------------------------------
The following program section realize the function of selecting  mode2 to the filter A of MAX261 
and setting F5aF4aF3aF2aF1aF0a=001000B,Q6aQ5aQ4aQ3aQ2aQ1aQ0a=1111111B
------------------------------------------------*/
case '0':  
P3_7=0;                                  //  the falling edge of /WR 
P1_2=0;                                //select mode 2,set M1a=0
P1_3=1;                                           //set M0a=1             
P1_4=0; 
P1_5=0; 
P1_6=0; 
P1_7=0;                               //address A3 A2 A1 A0=0x0
P3_7=1;                                                          
case '1':  
P3_7=0;                            //the falling edge of /WR 
P1_2=0;                                       //set F1a=0                                                    
P1_3=0;                                 //set F0a=0 
P1_4=0; 
P1_5=0; 
P1_6=0; 
P1_7=1;                  //address A3 A2 A1 A0=0x1
P3_7=1;

case '2':  
P3_7=0;                             //the falling edge of /WR 
P1_2=1;                    //set F3a=1   
P1_3=0;                                   //set F2a=0   
P1_4=0; 
P1_5=0; 
P1_6=1; 
P1_7=0;                           //address A3 A2 A1 A0=0x2
P3_7=1;

case '3':  
P3_7=0;                           //the falling edge of /WR 
P1_2=0;                           //set F5a=0   
P1_3=0;                                   //set F4a=0  
P1_4=0; 
P1_5=0; 
P1_6=1; 
P1_7=1;                           //address A3 A2 A1 A0=0x3
P3_7=1;

case '4': 
P3_7=0;                           //the falling edge of /WR 
P1_2=1;                           //set Q1a=1 
P1_3=1;                                    //set Q0a=1 
P1_4=0; 
P1_5=1; 
P1_6=0; 
P1_7=0;                    //address A3 A2 A1 A0=0x4
P3_7=1;

case '5': 
P3_7=0;                          //the falling edge of /WR 
P1_2=1;                            //set Q3a=1  
P1_3=1;                               //set Q2a=1 
P1_4=0; 
P1_5=1; 
P1_6=0; 
P1_7=1;           //address A3 A2 A1 A0=0x5
P3_7=1;


case '6': 
P3_7=0;            //the falling edge of /WR 
P1_2=1;                      //set Q5a=1  
P1_3=1;                     //set Q4a=1 
P1_4=0; 
P1_5=1; 
P1_6=1; 
P1_7=0;                  //address A3 A2 A1 A0=0x6
P3_7=1;


case '7': 
P3_7=0;                    //the falling edge of /WR 
P1_2=0;  
P1_3=1;                       //set Q6a=1
P1_4=1; 
P1_5=0; 
P1_6=0; 
P1_7=0;               //address A3 A2 A1 A0=0x7
P3_7=1;
}
}
3. AT89C2051和X25045的初始化程序:
#include <REG51.H>    /* special function register declarations   */
 /* for the intended AT89C2051 derivative         */
#include <stdio.h>   /* prototype declarations for I/O functions */
#ifdef MONITOR51      // Debugging with Monitor-51 needs
char code reserve [3] _at_ 0x23;  // space for serial interrupt if
#endif                          // Stop Exection with Serial Intr.
sbit P1_1=P1^1;            /* SI connect to P1^1 */
sbit P3_4=P3^4;             /* SCK connect to P3^4 */
                 //when running this program, /WP is high
void timer0 (void) interrupt 1 using 2          //define timer0 interrupt
{    P3_4=!P3_4;}
void timer1 (void) interrupt3  using 2      //define timer1 interrupt
{do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=1;
do{}while(P3_4!=0||!TF0);
P1_1=1;
do{}while(P3_4!=0||!TF0);
P1_1=0;                         //WREN instruciton:00000110B
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=1;
do{}while(P3_4!=0||!TF0);
P1_1=0;                      //Write instruction:00000010B

do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=1;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=1;
do{}while(P3_4!=0||!TF0);
P1_1=1; 
//WD1=1,WD0=0,RESET time is 200ms, BL1=0,BL0=0,no block
protect,STATUS_REG:00100000B
}
void main (void) {
P3^5=0;                                 // enable /CS
/* setup the timer 0 interrupt */
  TH0 = 0xFF;              // set timer period; t is 10 us; set the frequency of sclk is 50khz
  TL0 = 0xF6;
  TMOD = TMOD | 0x11;                    // select mode 1
  TR0 = 1;                               // start timer 0
  ET0 = 1;                               // enable timer 0 interrupt
  EA  = 1;                               // global interrupt enable
/* setup the timer 1 interrupt */
  TH1 = 0x28;          // set timer period ; feed dog time is 60 ms
  TL1 = 0x00;
  TMOD = TMOD | 0x11;                    // select mode 1
  TR1 = 1;                               // start timer 1
  ET1 = 1;                               // enable timer 1 interrupt
  EA  = 1;                               // global interrupt enable
do{}while(!TF0&&!TF1);  //wait for timer0 interrupt or timer 1 interrupt
}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -