📄 main.c
字号:
#include <reg2051.h>
#include "Dialer_program.h"
unsigned char data p[16];
unsigned char keybuf[20];
unsigned char data nkey;
unsigned char data timetype0;
unsigned char data count;
unsigned char data systime1;
unsigned char data timetype1;
unsigned char data audiocount;
bit section;
bit play_bit;
bit timeup;
bit dialbit;
void sysinit (void){
unsigned char i;
// IE = 0X97;
PT0 = 1; //设定定时0优先
// ET1 = 1; //开定时中断1
ET0 = 1;
PCON |= 0x00; //10000000开smod
SCON = 0x50;
TMOD= 0x21; //0001,0001 定时器1模式0,定时器0模式0
TH1 = 0XFC; //3.57_2330
TL1 = 0XFC;
// TH1 = 0XFC; //11.0592_9600
// TL1 = 0XFE;
TR1 = 1;
// REN = 1; //Serial接受允许
// ES = 1;
EX0 = 1; //开中断0
EA = 1;
nkey = 0;
dialbit=0;
for (i=0;i<17;i++)p[i] = 0x00;
for (i=0;i<21;i++)keybuf[i] = 0x00;
EEReadPage(&p[0],0x00,0x00,16); //读出IP号码
EEReadPage(&p[0],0x00,0x00,16); //读出IP号码
EEReadPage(&p[0],0x00,0x00,16); //读出IP号码
}
void play (unsigned char ch){
timetype0 = ch;
TR0 = 1;
}
void clrbuf(void){
setbit = 0; //key标志
count = 0; //dialkey count
play_bit = 1;
}
void main(void){
Polarity = 1;
still = 0; //0 Still SOUND;1 Enable SOUND
audiopin = 0;
led = 1;
delay(0x50);
sysinit();
while (!dialbit);
dial ("17968\0");
delay(0x90);
dial (0x3c);
delay(0x90);
dial (0x3c);
delay(0x90);
dial (&keybuf[0]);
// still = 1;
// putbuf(0x70);
// polarity_detect();
Polaridy_audio_HZ();
while (1);
}
//**************************************************************************拨号函数
void dial(unsigned char *str){
while (*str){
senddtmf(*str - 0x30);
delay(0x15);
senddtmf(0xff);
delay(0x5);
str ++;
}
}
//**************************************************************************
void time0 (void) interrupt 1 {
static unsigned char i=0,j=0,k=0,m=0; //i 450HZ count ;j 0Hz count; k audio count;
timeup = 0;
// led = ~led;
if ((audiocount > 40)&&(audiocount < 50)){ //450hz
i ++ ;
j = 0;
k = 0;
if (i == 4){
m++;
audiopin = 0;
}
}
else if (audiocount < 5){ //0hz
i = 0;
j ++ ;
k = 0;
}
else { //audio hz
// led = ~led;
i = 0;
j = 0;
k ++ ;
}
TR0 = 0;
if (m > 0){
led = 0;
if(k>1){
led = 1;
still = 1; //0 Still SOUND;1 Enable SOUND
Polarity = 0;
while (1);
}
}
}
/*
void time1 (void) interrupt 3 {
TF1 = 0;
switch(timetype1){
case polaritytime:
// if (systime1 == 0x00){
timeup = 1;
TR1 = 0;
// }
// else systime1 --;
break;
}
} */
//**************************************************************************
void polarity_detect(void){
/* unsigned char i=0,j=0,k=0,L=0; //i计音频个数,J计450的计数,k计非450的计数
bit STATUS_AUDIO=0;
while(1){
timetype0 = polaritytime;
// systime1 = 0x01;
TH0 = 0x8c;
TL0 = 0x00;
TR0 = 1; //启动定时器2-100毫秒检测
timeup = 0;
while (!timeup){
if(!audio_detect){
while (!audio_detect);
i++;
}
}
if ((i < 0x3f) && (i > 0x26)){
j++;
k=0;
i=0;
L=0;
led = 1;
if ( j==5 )STATUS_AUDIO = 1;
}
else if (i>40){
// putbuf(i);
k=0;
i=0;
L++;
led = 0;
}
}*/
}
void Polaridy_audio_HZ (void ){
unsigned char i;
timetype0 = polaritytime;
i = 100;
while (1){
TH0 = 0x8c;
TL0 = 0x00;
timeup = 1;
audiocount=0;
TR0 = 1;
while (timeup){
if (!audio_detecy){
while (!audio_detecy & timeup );
audiocount++;
}
}
}
}
void putbuf(unsigned char ch){
TI = 0;
SBUF = ch;
while (!TI);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -