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

📄 dtmf_gen.lst

📁 pic16c6x和pic16c7xxx都可以通用
💻 LST
📖 第 1 页 / 共 5 页
字号:

MPC "C" COMPILER BC.193 22-Aug-1995                                     PAGE  1


                                  /*****************************************************************************
                                  * DTMF tone generation using PIC16C74
                                  *
                                  * Written for the "Digital Signal Processing Using the PIC16C74" Ap Note
                                  *
                                  * Generates 16 DTMF tones (1-9,0,*,#,A,B,C,D) out PWM port 1
                                  *
                                  * Uses PICTONE.C and ANALOGIO.C modules
                                  *
                                  * D. Mostowfi 4/95
                                  ******************************************************************************/
                                  #include <delay14.h>

                                  #pragma option +l;

                                  #include <16c74.h>      /* c74 header file */
                                  #pragma option +l;
0FFB                              #define MAXROM 4091
0005 0FFB                         #pragma memory ROM [MAXROM] @ 0x05;
0020 0060                         #pragma memory RAM [0x60]   @ 0x20;
00A0 0060                         #pragma memory RAM [0x60]   @ 0xA0;
                                  #pragma option +l;

                                  #include <math.h>
                                  #pragma option +l;



                                  #include "analogio.c"   /* analog I/O module */
                                  /****************************************************************************
                                  * Analog I/O Module
                                  *
                                  * Written for "Digital Signal Processing with the PIC16C74" Application Note
                                  *
                                  * This module contains functions that read the A-D inputs, initialize the PWM
                                  * ports, and write values to the PWM ports.
                                  *
                                  * D. Mostowfi 4/95
                                  ****************************************************************************/
0001                              #define active          1       /* define active as 1 */
0000                              #define LOW             0       /* define LOW as 0 */
0001                              #define HIGH            1       /* define HIGH as 1 */

0000                              #define OFFSET          0       /* define offset binary mode as 0 */
0001                              #define TWOS            1       /* define two's compliment mode as 1 */

0001                              #define AD_FORMAT       TWOS    /* define A-D format as TWOS */
0001                              #define PWM_FORMAT      TWOS    /* define PWM format as TWOS */
0001                              #define PWM_RES         HIGH    /* define PWM resolution as HIGH */

002C                              bits FLAGS;                     /* general purpose flags */
0003                              #define sample_flag     FLAGS.1 /* define sample_flag as FLAGS.1 */


                                  /*****************************************************************************

MPC "C" COMPILER BC.193 22-Aug-1995                                     PAGE  2


                                  * A-D Converter Routine - reads A-D converter inputs
                                  *
                                  * usage:
                                  *       - call get_sample(channel #)
                                  *       - returns 8 bit value
                                  *****************************************************************************/
                                  char get_sample(char channel)
002D                              {
0005 1283    BCF    STATUS,RP0
0006 00AD    MOVWF  2D
002E                              char i;

0007 019E    CLRF   ADRES             ADRES=0;                    /* clear ADRES */
0008 1003    BCF    STATUS,C          STATUS.C=0;                 /* clear carry */
0009 0DAD    RLF    2D                RLCF(channel);              /* and rotate channel 3 times */
000A 0DAD    RLF    2D                RLCF(channel);              /* to put in proper position */
000B 0DAD    RLF    2D                RLCF(channel);              /* for write to ADCON0 */
000C 082D    MOVF   2D,W              ADCON0=channel;              /* write channel to ADCON0 */
000D 009F    MOVWF  ADCON0
000E 141F    BSF    ADCON0,0          ADCON0.0=1;                 /* turn on A-D */
000F 01AE    CLRF   2E                i=0;                        /* set delay loop variable to 0 */
0010 1283    BCF    STATUS,RP0        while(i++<=5){};            /* delay (to ensure min sampling time) */
0011 082E    MOVF   2E,W
0012 0AAE    INCF   2E
0013 00A1    MOVWF  21
0014 3005    MOVLW  05h
0015 0221    SUBWF  21,W
0016 1D03    BTFSS  STATUS,Z
0017 1C03    BTFSS  STATUS,C
0018 2810    GOTO   0010h
0019 1283    BCF    STATUS,RP0        ADCON0.2=1;                 /* start conversion */
001A 151F    BSF    ADCON0,2
001B 1283    BCF    STATUS,RP0        while(ADCON0.2){}           /* wait for eoc */
001C 191F    BTFSC  ADCON0,2
001D 281B    GOTO   001Bh
001E 1283    BCF    STATUS,RP0        ADCON0.0=0;                 /* turn off a-d converter */
001F 101F    BCF    ADCON0,0
                                      if(AD_FORMAT==TWOS){        /* if format is two's compliment */
0020 3080    MOVLW  80h                 ADRES.7=!ADRES.7;         /* compliment MSB */
0021 069E    XORWF  ADRES
                                      }
0022 1283    BCF    STATUS,RP0        return ADRES;               /* return value in a-d result reg */
0023 081E    MOVF   ADRES,W
0024 0008    RETURN 
                                  }


                                  /******************************************************************************
                                  * PWM Initialization Routine - sets up PR2, sets output to mid-point, and
                                  * starts timer 2 with interrupts disabled.
                                  *
                                  * usage:
                                  *       - call init_PWM(PR2 register value)
                                  ******************************************************************************/
                                  void init_PWM(char _pr2)

MPC "C" COMPILER BC.193 22-Aug-1995                                     PAGE  3


002F                              {
0025 1283    BCF    STATUS,RP0
0026 00AF    MOVWF  2F
0027 1683    BSF    STATUS,RP0        PR2=_pr2;                   /* reload value for 40khz PWM period */
0028 0092    MOVWF  T2CON
0029 1283    BCF    STATUS,RP0        CCP1CON.5=0;                /* set CCPxCON = 0 for 50% output */
002A 1297    BCF    CCP1CON,5
002B 1217    BCF    CCP1CON,4         CCP1CON.4=0;
002C 129D    BCF    CCP2CON,5         CCP2CON.5=0;
002D 121D    BCF    CCP2CON,4         CCP2CON.4=0;
                                      if(PWM_RES==HIGH){          /* if resolution is high, set CCPRxH=0 and */
002E 0196    CLRF   CCPR1H              CCPR1H=0x00;              /* CCPRxL=0x20 for 50% PWM duty cycle */
002F 3020    MOVLW  20h                 CCPR1L=0x20;
0030 0095    MOVWF  CCPR1L
0031 019C    CLRF   CCPR2H              CCPR2H=0x00;
0032 009B    MOVWF  CCPR2L              CCPR2L=0x20;
                                      }
0033 2839    GOTO   0039h             else{
0034 0196    CLRF   CCPR1H              CCPR1H=0x00;              /* if resolution is low, set CCPRxH=0 and */
0035 3080    MOVLW  80h                 CCPR1L=0x80;              /* CCPRxL=0x80 for 50% PWM duty cycle */
0036 0095    MOVWF  CCPR1L
0037 019C    CLRF   CCPR2H              CCPR2H=0x00;
0038 009B    MOVWF  CCPR2L              CCPR2L=0x80;
                                      }
0039 1512    BSF    T2CON,2           T2CON.TMR2ON=1;             /* start timer 2 */
003A 1683    BSF    STATUS,RP0        PIE1.TMR2IE=0;              /* and disable timer 2 interrupt */
003B 108C    BCF    PIR1,1

003C 0008    RETURN               }


                                  /*******************************************************************************
                                  * PWM Output Routine - writes output values to PWM ports
                                  *
                                  * Both high resolution and low resolution modes write 8 bit values - use of
                                  * high or low resolution depends on PWM output period.
                                  *
                                  * usage:
                                  *       - call write_PWM(channel 1 value, channel 2 value)
                                  *         if channel 2 value=0, PWM port 2 not written
                                  *******************************************************************************/
                                  void write_PWM(bits pwm_out1, bits pwm_out2)
0030 0031                         {
003D 1283    BCF    STATUS,RP0
003E 00B1    MOVWF  31
003F 0804    MOVF   FSR,W
0040 00B0    MOVWF  30

                                      if(PWM_FORMAT==TWOS){       /* if format is two's compliment */
0041 3080    MOVLW  80h                 pwm_out1.7=!pwm_out1.7;   /* compliment msb's */
0042 06B0    XORWF  30
0043 1FB0    BTFSS  30,7                pwm_out2.7=!pwm_out1.7;
0044 2847    GOTO   0047h
0045 13B1    BCF    31,7
0046 2849    GOTO   0049h

MPC "C" COMPILER BC.193 22-Aug-1995                                     PAGE  4


0047 1283    BCF    STATUS,RP0
0048 17B1    BSF    31,7
                                      }
                                      if(PWM_RES==HIGH){          /* if resolution is high */
0049 1003    BCF    STATUS,C            STATUS.C=0;               /* clear carry */
004A 1283    BCF    STATUS,RP0          pwm_out1=RRCF(pwm_out1);  /* rotate right and write two lsb's */
004B 0CB0    RRF    30
004C 1803    BTFSC  STATUS,C            CCP1CON.4=STATUS.C;       /* to CCP1CON4 and CCP1CON5 */
004D 2850    GOTO   0050h
004E 1217    BCF    CCP1CON,4
004F 2852    GOTO   0052h
0050 1283    BCF    STATUS,RP0
0051 1617    BSF    CCP1CON,4
0052 1003    BCF    STATUS,C            STATUS.C=0;
0053 1283    BCF    STATUS,RP0          pwm_out1=RRCF(pwm_out1);
0054 0CB0    RRF    30
0055 1803    BTFSC  STATUS,C            CCP1CON.5=STATUS.C;
0056 2859    GOTO   0059h
0057 1297    BCF    CCP1CON,5
0058 285B    GOTO   005Bh
0059 1283    BCF    STATUS,RP0
005A 1697    BSF    CCP1CON,5
005B 1283    BCF    STATUS,RP0          if(pwm_out2!=0){          /* if pwm_out2 not 0, do the same */
005C 08B1    MOVF   31
005D 1903    BTFSC  STATUS,Z
005E 2871    GOTO   0071h
005F 1003    BCF    STATUS,C              STATUS.C=0;             /* for channel 2 */
0060 1283    BCF    STATUS,RP0            pwm_out2=RRCF(pwm_out2);
0061 0CB1    RRF    31
0062 1803    BTFSC  STATUS,C              CCP2CON.4=STATUS.C;
0063 2866    GOTO   0066h
0064 121D    BCF    CCP2CON,4
0065 2868    GOTO   0068h
0066 1283    BCF    STATUS,RP0
0067 161D    BSF    CCP2CON,4
0068 1003    BCF    STATUS,C              STATUS.C=0;
0069 1283    BCF    STATUS,RP0            pwm_out2=RRCF(pwm_out2);
006A 0CB1    RRF    31
006B 1803    BTFSC  STATUS,C              CCP2CON.5=STATUS.C;
006C 286F    GOTO   006Fh
006D 129D    BCF    CCP2CON,5
006E 2871    GOTO   0071h
006F 1283    BCF    STATUS,RP0
0070 169D    BSF    CCP2CON,5
                                        }
                                      }
0071 1283    BCF    STATUS,RP0        CCPR1L=pwm_out1;            /* write value to CCPR1L */
0072 0830    MOVF   30,W
0073 0095    MOVWF  CCPR1L
0074 08B1    MOVF   31                if(pwm_out2!=0){            /* if pwm_out2 not 0, do the same */
0075 1903    BTFSC  STATUS,Z
0076 287A    GOTO   007Ah
0077 1283    BCF    STATUS,RP0          CCPR2L=pwm_out2;          /* for CCPR2L */
0078 0831    MOVF   31,W
0079 009B    MOVWF  CCPR2L

MPC "C" COMPILER BC.193 22-Aug-1995                                     PAGE  5


                                      }
007A 0008    RETURN               }                               /* done */
                                  #include "pictone.c"    /* tone generation module */
                                  /*****************************************************************************
                                  * Tone Generation Module
                                  *
                                  * Written for "Digital Signal Processing with the PIC16C74" Application Note.
                                  *
                                  * This module contains a C callable module that generates single or dual
                                  * tones using a difference equation method:
                                  *
                                  * y1(n)=a1*x(n-1)+b1*y1(n-1)-y1(n-2)
                                  * y2(n)=a2*x(n-1)+b2*y2(n-1)-y2(n-2)
                                  *
                                  * The routine is written in assembly language and uses the optimized signed
                                  * 8x8 multiply routine and scaling routine in the file 8BITMATH.C.
                                  *
                                  * D. Mostowfi 2/95
                                  *****************************************************************************/
                                  #include "8bitmath.c"  /* 8 bit signed math routines */
                                  /******************************************************************************
                                  * 8 bit Multiply and Scaling Routines
                                  *
                                  * Written for "Digital Signal Processing with the PIC16C74" Application Note.
                                  *
                                  *
                                  * This module provides a 8 bit signed multiply and scaling routine for the
                                  * PICTONE.C tone generation program. The routines are adapted from "Math
                                  * Routines for the 16C5x" in  Microchip's Embedded Controller Handbook.
                                  *
                                  * All numbers are assumed to be signed 2's compliment format.
                                  *
                                  * D. Mostowfi 11/94
                                  *******************************************************************************/
0032                              char multcnd;                /* 8 bit multiplicand */
0033                              char multplr;                /* 8 bit multiplier */
0034                              char result_h;               /* result - high byte */
0035                              char result_l;               /* result - low byte */
0036                              char sign;                   /* result sign */

                                  #asm

⌨️ 快捷键说明

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