PIC16F1459与DTMF芯片电话拨号器循环问题(用C编写)

时间:2015-05-08 22:47:51

标签: c pic microprocessors dtmf

我正在进行一项任务,在按下主板上的按钮时会拨打电话号码。目前我有电话拨打我选择的号码,但是他们一个接一个地拨号而不是按下按钮。我的循环中是否有一些真正基本的东西?

/* 
 * File:   assignment5.c
 *
 */
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover Mode (Internal/External Switchover Mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
// CONFIG2
#pragma config WRT = ALL // Flash Memory Self-Write Protection (000h to 1FFFh write protected, no addresses may be modified by PMCON control)
#pragma config CPUDIV = CLKDIV6 // CPU System Clock Selection Bit (CPU system clock divided by 6)
#pragma config USBLSCLK = 48MHz // USB Low SPeed Clock Selection bit (System clock expects 48 MHz, FS/LS USB CLKENs divide-by is set to 8.)
#pragma config PLLMULT = 3x // PLL Multipler Selection Bit (3x Output Frequency Selected)
#pragma config PLLEN = DISABLED // PLL Enable Bit (3x or 4x PLL Disabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>

#define _XTAL_FREQ 4000000
#include <stdio.h>
#include <stdlib.h>

/*
 * 
 */


void pulse(void){
                  RC6 = 0;  //drop clock
                  __delay_us(5);
                  RC6 = 1;
                  __delay_us(5);
}

void tone_0(){
      char i;

      RC7 =0;  //data low
      pulse();
      RC7 =1;
      pulse();
      RC7 =0;
      pulse();
      RC7 =1;
      pulse();
      RC7 = 0;
      pulse();
      __delay_ms(195);
     // RC7 = 1;
      //for (i = 0;i<5;i++)
         // pulse();
      //__delay_ms(195);
}
void tone_1(){
      char i;

      RC7 =1;  //data low
      pulse();
      RC7 =0;
      pulse();
      RC7 =0;
      pulse();
      RC7 =0;
      pulse();
      RC7 = 0;
      pulse();
      __delay_ms(195);
     // RC7 = 1;
      //for (i = 0;i<5;i++)
          //pulse();
      //__delay_ms(195);
}
void tone_2(){
      char i;

      RC7 = 0;  //data low
      pulse();
      RC7 = 1;
      pulse();
      RC7 =0;
      pulse();
      RC7 = 0;
      pulse();
      RC7 = 0;
      pulse();
      __delay_ms(195);
      //RC7 = 1;
      //for (i = 0;i<5;i++)
          //pulse();
      //__delay_ms(195);
}
void tone_3(){
      char i;

      RC7 =1;  //data low
      pulse();
      RC7 =1;
      pulse();
      RC7 =0;
      pulse();
      RC7 =0;
      pulse();
      RC7 = 0;
      pulse();
      __delay_ms(195);
      //RC7 = 1;
      //for (i = 0;i<5;i++)
         // pulse();
      //__delay_ms(195);
}
void tone_4(){
      char i;

      RC7 = 0;  //data low
      pulse();
      RC7 =0;
      pulse();
      RC7 = 1;
      pulse();
      RC7 = 0;
      pulse();
      RC7 = 0;
      pulse();
      __delay_ms(195);
     // RC7 = 1;
      //for (i = 0;i<5;i++)
          //pulse();
      //__delay_ms(195);
}
void tone_5(){
      char i;

      RC7 =1;  //data low
      pulse();
      RC7 = 0;
      pulse();
      RC7 = 1;
      pulse();
      RC7 = 0;
      pulse();
      RC7 = 0;
      pulse();
      __delay_ms(195);
      //RC7 = 1;
      //for (i = 0;i<5;i++)
         // pulse();
      //__delay_ms(195);
}
void tone_6(){
      char i;

      RC7 = 0;  //data low
      pulse();
      RC7 = 1;
      pulse();
      RC7 = 1;
      pulse();
      RC7 = 0;
      pulse();
      RC7 = 0;
      pulse();
      __delay_ms(195);
      //RC7 = 1;
      //for (i = 0;i<5;i++)
          //pulse();
      //__delay_ms(195);
}
void tone_7(){
      char i;

      RC7 = 1;  //data low
      pulse();
      RC7 = 1;
      pulse();
      RC7 = 1;
      pulse();
      RC7 = 0;
      pulse();
      RC7 = 0;
      pulse();
      __delay_ms(195);
      //RC7 = 1;
      //for (i = 0;i<5;i++)
          //pulse();
      //__delay_ms(195);
}
void tone_8(){
      char i;

      RC7 = 0;  //data low
      pulse();
      RC7 = 0;
      pulse();
      RC7 = 0;
      pulse();
      RC7 = 1;
      pulse();
      RC7 = 0;
      pulse();
      __delay_ms(195);
      //RC7 = 1;
      //for (i = 0;i<5;i++)
          //pulse();
      //__delay_ms(195);
}
void tone_9(){
      char i;

      RC7 = 1;  //data low
      pulse();
      RC7 = 0;
      pulse();
      RC7 = 0;
      pulse();
      RC7 = 1;
      pulse();
      RC7 = 0;
      pulse();
      __delay_ms(195);
      //RC7 = 1;
      //for (i = 0;i<5;i++)
          //pulse();
      //__delay_ms(195);
}
char dial(char i)
{
    if(i == 0)
        {
            tone_6();
    }
    if(i == 1)
        {
            tone_7();
    }
    if(i == 2)
        {
            tone_3();
    }
    if(i == 3)
        {
            tone_3();
    }
    if(i == 4)
        {
            tone_8();
    }
    if(i == 5)
        {
            tone_6();
    }
    if(i == 6)
        {
            tone_9();
    }
    i++;
    if(i > 6)
        i = 0;
    return i;


}
 void main(){
                  char i = 0;
                  char buttontoggle = 0;
                  char count = 0;
                                    __delay_ms(190);

                                    OSCCON =0b00110100;
                                    TRISC = 0;
                                    ANSELC = 0;
                                    TRISA = 0b11111111;
                                    WPUB6 = 1;

                                    PORTC = 0b10000100;  //clock high, data high, CE high
                                    __delay_ms(10);
                                     RC2 = 0;  //turn it on.
                                    __delay_ms(10);
             while(1)
             {

        if(RB6 == 0 )
                {
                    buttontoggle = 0;
        }
        if(RB6 == 1)
                {
                    buttontoggle = 1;
        }
                if( buttontoggle == 1)
                {
                    count = dial(count);
                }

         }

/*while (1){

                                    RC2 = 0;  //turn it on.
                                    __delay_ms(50);
                                    RC7 =1;  //data low
                                    pulse();
                                    RC7 =0;
                                    pulse();
                                    RC7 =0;
                                    pulse();
                                    RC7 =1;
                                    pulse();
                                    RC7 = 0;
                                    pulse();
                                    __delay_ms(195);
                                    RC7 = 1;
                                    for (i = 0;i<5;i++)       pulse();
                                    __delay_ms(195);
                                    RC2 =1;
        }*/
}

1 个答案:

答案 0 :(得分:0)

也许您需要查看硬件。您尚未设置端口B,但我们假设它是输入。 RB6的值是否会变低?

如果RB6设置正确,只要按下该按钮,该代码就会连续拨打您的号码(即没有逃脱)。

您的拨号例程(正在请求一个案例陈述!)也会自动修改参数i,并返回它,然后将返回值分配给调用参数(count)。这有点令人费解,可能会引起奇怪的行为。