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

📄 tele_control.lst

📁 基于PIC单片机的智能电话控制系统
💻 LST
📖 第 1 页 / 共 5 页
字号:
     1: //***********************************

     2: //***********************************

     3: #include "tele_control.h"

     4: //**************************************************

     5: //define the sign of this program use

     6: //**************************************************

     7: void Initial(void);                             //set when power up

     8: void SFRSET(void);                              //clear WDT

     9: void Time(void);                                //timer and off the time

    10: void KEYScan(void);                             //key scan

    11: void interrupt numberint(void); //interrupt program

    12: void Display(void);

    13: void ds1302_read_time(void);

    14: void ds1302_write_time(void);

    15: void ds1302_write(uchar reg,uchar data);

    16: uchar ds1302_read(uchar reg);

    17: void change_time(void);

    18: void timechange(void);                  //time is changed

    19: void voice(unsigned char data);

    20: void calling(void);                             //test calling?

    21: void pass_word_test(void);              //test the pass word

    22: void busy_test(void);                   //test telephone off?

    23: void system_reset(void);                //reset system

    24: void key_control(void);                 //control key

    25: void jdq_indect(void);

    26: void jdq_check(void);

    27: void reset_password(void);

    28: void reset_ringtimes(void);

    29: //***********************************************

    30: //define bit variable

    31: //***********************************************

    32: static volatile bit time_change,calling_bit0,calling_bit1;

    33: static volatile bit calling_bit2,calling_bit3,calling_bit4;

    34: static volatile bit Tel_num_change,password_bit,jdq_delay;

    35: static volatile bit check_bit0,check_bit1;

    36: static volatile bit reset_bit0,reset_bit1,reset_bit2;

    37: //***********************************************

    38: //define variable

    39: //***********************************************

    40: static volatile uchar kcap[4];

    41: static volatile uchar dsbuf[4];

    42: static volatile uchar password_buf[8];

    43: static volatile uchar password1_buf[7];

    44: static volatile uchar password_times;

    45: static volatile uchar Bit_Select;

    46: static volatile uchar year,month,day,week,hour,minute,second,inc4ms;

    47: static volatile uchar Tel_num,timedelay,timedelay0,timedelay1,timedelay2,timedelay3;

    48: static volatile uchar STA,STA1,STA2;//for 2:1

    49: static volatile uchar dot,flash;

    50: static volatile uchar calling_t0,calling_t1,calling_t2,calling_t3;

    51: static volatile uint calling_times,calling_times1;

    52: static volatile uchar voice_times,voice_tone;

    53: static volatile uint voice_delay;

    54: //************************************************

    55: //blow define led7code value

    56: //duan ma:<7:0>=afbgcehd

    57: const char LED7[16]={   0XED,0X28,0XB5,0XB9,    //0,1,2,3

    58:                                                 0X78,0XD9,0XDD,0XA8,    //4,5,6,7

    59:                                                 0XFD,0XF9,0X00,0Xd4,    //8,9,a,b a=black,b=F

    60:                                                 0X6d,0Xec,0X10,0x1d};   //c,d,e,f c=U,d=n,e=-,f=o

    61: //************************************************

    62: //blow define ledbit value

    63: const char bitcode[8]={ 0X01,0X02,0X04,0X08,    

    64:                                                 0X10,0X20,0X40,0X80};

    65: //***********************************************

    66: //blow define led4code vale

    67: const char LED4[16]={   0X00,0X20,0X10,0X30,    //0,1,2,3

    68:                                                 0X40,0X60,0X50,0X70,    //4,5,6,7

    69:                                                 0X80,0Xa0,0X90,0Xb0,    //8,9,a,b

    70:                                                 0Xc0,0Xe0,0Xd0,0xf0};   //c,d,e,f

    71: 

    72: //************************************************

    73: //blow define telephone number Key value 

    74: const char Telnum[16]={ 0X0d,0X08,0X04,0X0f,    //d,8,4,#       

    75:                                                 0X02,0X00,0X06,0X0b,    //2,0,6,b

    76:                                                 0X01,0X09,0X05,0X0a,    //1,9,5,a

    77:                                                 0X03,0X0e,0X07,0x0c};   //3,*,7,c

    78: //*************************************************

    79: union{

    80:         struct

    81:                 {

    82:                 volatile unsigned k0:1;         volatile unsigned k1:1;

    83:                 volatile unsigned k2:1;         volatile unsigned k3:1;

    84:                 volatile unsigned lk0:1;        volatile unsigned lk1:1;

    85:                 volatile unsigned lk2:1;        volatile unsigned lk3:1;

    86:                 volatile unsigned kk0:1;        volatile unsigned kk1:1;

    87:                 volatile unsigned kk2:1;        volatile unsigned kk3:1;

    88:                 }b;

    89: volatile uint allkey;

    90: volatile uchar halfkey[2];

    91:         }key;

    92: //**********************************************************

    93: void main(void)

    94: {       

    95:         Initial();

    96:         SFRSET();

    97:   ////////////////////////////

    98:  //the all cycle of program//

    99: ////////////////////////////

   100:         while(1)

   101:         {

   102:                 asm("clrwdt");                  //clear WDT

   103:                 Time();                                 //timer and off the time

   104:                 if(Bit_Select&0x01)

   105:                 {       Display();                      //display and keyscan

   106:                         KEYScan();

   107:                         if(STA==0x00)

   108:                         {

   109:                                 ds1302_read_time();

   110:                         }

   111:                         else if(STA==0x03)

   112:                         {

   113:                                 if(key.allkey==0x0000)

   114:                                 {

   115:                                         calling_times++;

   116:                                         if(calling_times==0x1d4c)       //30S

   117:                                         {

   118:                                                 calling_times=0x0000;

   119:                                                 STA=0x00;

   120:                                                 STA1=0x00;

   121:                                                 STA2=0x00;

   122:                                         }

   123:                                 }

   124:                                 else

   125:                                 {

   126:                                         calling_times=0x0000;

   127:                                 }

   128:                         }

   129:                         else if(STA==0x02)

   130:                         {

   131:                                 if(key.allkey==0x0000)

   132:                                 {

   133:                                         calling_times++;

   134:                                         if(calling_times==0x09c4)       //10S

   135:                                         {

   136:                                                 calling_times=0x0000;

   137:                                                 STA=0x00;

   138:                                                 STA1=0x00;

   139:                                                 STA2=0x00;

   140:                                         }

   141:                                 }

   142:                                 else

   143:                                 {

   144:                                         calling_times=0x0000;

   145:                                 }

   146:                         }

   147:                         else

   148:                         {

   149:                                 if(Tel_num_change)

   150:                                 {

   151:                                         calling_times=0x0000;

   152:                                 }

   153:                                 else

   154:                                 {

   155:                                         calling_times++;

   156:                                         if(calling_times==0x1d4c)       //30S

   157:                                         {

   158:                                                 calling_times=0x0000;

   159:                                                 Tel_num=0x00;

   160:                                                 VOICE=0;

   161:                                                 INTE=1;

   162:                                                 ANALOGUP=0;

   163:                                                 STA=0x00;

   164:                                                 STA1=0x00;

   165:                                                 STA2=0x00;

   166:                                         }

   167:                                 }

   168:                                 if(key.b.kk0|key.b.kk3)

   169:                                 {

   170:                                         calling_times=0x0000;

   171:                                         Tel_num=0x00;

   172:                                         VOICE=0;

   173:                                         INTE=1;

   174:                                         ANALOGUP=0;

   175:                                         STA=0x00;

   176:                                         STA1=0x00;

   177:                                         STA2=0x00;

   178:                                         key.b.kk0=0;

   179:                                         key.b.kk3=0;

   180:                                 }

   181:                         }

   182:                 }

   183:                 else

   184:                 {

   185:                         Display();                      //put display

   186:                         inc4ms++;

   187:                         if(STA==STA2){STA1=STA;}        //important data 2:1

   188:                         else if(STA1==STA2){STA=STA1;}

   189:                         else if(STA==STA1){STA2=STA;}

   190:                         else{STA=0x00;STA1=0X00;STA2=0X00;}

   191:                         switch(STA)

   192:                         {

   193:                         case 0:

   194: //                              ds1302_read_time();

   195:                                 if((second&0x0f)>0x07)

   196:                                 {

   197:                                         dsbuf[0]=year;

   198:                                         dsbuf[1]=month;

   199:                                         dsbuf[2]=day;

   200:                                         dsbuf[3]=((week<<4)&0xf0)|(dsbuf[3]&0x0f);

   201:                                         dot=0x54;

   202:                                 }

   203:                                 else

   204:                                 {

   205:                                         dsbuf[0]=hour;

   206:                                         dsbuf[1]=minute;

   207:                                         dsbuf[2]=second;

   208:                                         dsbuf[3]=0xa0|(dsbuf[3]&0x0f);

   209:                                         dot=0x50;

   210:                                 }

   211:                                 flash=0x00;

   212:                                 key_control();

   213:                                 calling();

   214:                         break;

   215:                         case 1:         //all join

   216:                                 dsbuf[0]=0xbc;          //FU

   217:                                 dsbuf[1]=0xdf;          //N 

   218:                                 dsbuf[2]=0xff;

   219:                                 dsbuf[3]=0xa0;

   220:                                 if(Tel_num_change)

   221:                                 {

   222:                                         unsigned char i;

   223:                                         Tel_num_change=0;

   224:                                         if(Tel_num==1)  //JDQ indect change

   225:                                         {

   226:                                                 voice(0x64);

   227:                                                 i=0x08;

   228:                                                 STA=0x05;

   229:                                         }

   230:                                         if(Tel_num==2)  //reset password

   231:                                         {

   232:                                                 voice(0x68);

   233:                                                 i=0x04;

   234:                                                 STA=0x06;

   235:                                         }

   236:                                         if(Tel_num==3)  //reset ring times

   237:                                         {

   238:                                                 voice(0x6c);

   239:                                                 i=0x0c;

   240:                                                 STA=0x07;

   241:                                         }

   242:                                         if(Tel_num==4)  //check JDQ sta and heard

   243:                                         {

   244:                                                 voice(0x70);

   245:                                                 i=0x02;

   246:                                                 STA=0x08;

   247:                                         }

   248:                                         if(STA==0x01){voice(0x7c);}

   249:                                         else{

   250:                                         dsbuf[0]=0xbc;          //FU

   251:                                         dsbuf[1]=0xde;          //N

   252:                                         dsbuf[2]=Tel_num;       //

   253:                                         dsbuf[3]=i|0xe0;        //

   254:                                         }

   255:                                         Tel_num==0;

   256:                                 }

   257:                         break;

   258:                         case 2:         //reset all data

   259:                                 if(key.b.k3){reset_bit0=1;dsbuf[3]=0xe8;}

   260:                                 if(reset_bit0){if(key.b.k2){reset_bit1=1;reset_bit0=0;dsbuf[3]=0xec;dsbuf[2]=0xee;}}

   261:                                 if(reset_bit1){if(key.b.k1){reset_bit2=1;reset_bit1=0;dsbuf[3]=0xee;dsbuf[1]=0xee;}}

⌨️ 快捷键说明

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