?? cheshi.lst
字號:
748 1 send_count=0xff;timer_S_cnt=0;
749 1 while(timer_S_cnt<15&&(AT_Command_Status==COMMAND_WAIT))
750 1 { if(strsearch("+CMGS:")) break;
751 2 else if(txd_rxd_bit) break;
752 2 watch_dog_clear;
753 2 }
754 1
755 1 // num_tmp1為短信號, 從16進制轉成 文本方式才能發送出去
756 1 para_temp[0]=(num_tmp1/10)+0x30;
757 1 para_temp[1]=(num_tmp1%10)+0x30;
758 1 para_temp[2]=0x0d;para_temp[3]=0x00;
759 1 Send_AT_Command(SMS_CMGD);//刪除處理完的短信
760 1 timer_S_cnt=0; while(timer_S_cnt<2&&(AT_Command_Status==COMMAND_WAIT)) watch_dog_clear;
761 1 Send_AT_Command(SIM_ID);
762 1 if(TC35_bit==0)
763 1 Send_AT_Command(SMSS_ID);
764 1 // IO_OUT=1;
765 1 for(i=0;i<=MAX_TM-2;i++)
766 1 { uart_buff[i]=0;
767 2 }
768 1 }
769 //======================================================================
770 //================進行SIM卡的電話本讀======================================================
771 //======================================================================
772 uchar PHONE_RD( ) //read_tmp=0x30+i; 要讀的電話號碼
773 { uchar j;
774 1
775 1 Send_AT_Command(PHONE_READ);
776 1 send_count=0;
777 1 timer_S_cnt=0; while(timer_S_cnt<1&&(AT_Command_Status==COMMAND_WAIT)) watch_dog_clear;
778 1
779 1 if(j=strsearch("+CPBR:")) //+CPBW: 1,"13818120592",129,"chia"
780 1 { j=j+9;
781 2
782 2 do
783 2 {
784 3 para_temp[TMP_BUF++]= uart_buff[j++];
785 3 if( uart_buff[j]=='"')
786 3 { //para_temp[t++]=';';para_temp[t++]=0x0d;para_temp[t++]=0x00;
787 4 return(TMP_BUF);
788 4 }
789 3
790 3
791 3 }while(j<=24);
792 2
793 2
794 2 }
795 1 else if(uart_buff[1]==0x0d&&uart_buff[0]==0x34)
796 1 { return(FALSE);
797 2 }
798 1 else return(FALSE);
799 1 }
C51 COMPILER V7.50 CHESHI 11/16/2008 00:57:23 PAGE 14
800
801 //======================================================================
802 //========================進行SIM卡中的1到20條短信號碼的讀==============================================
803 //======================================================================
804 uchar READ_TEL(uchar r) //讀短信號碼1-20個
805 { uchar i;
806 1 for(i=0;i<=10;i++) uart_buff[i]=0;
807 1 para_temp[0]=(r/10)+0x30;para_temp[1]=(r%10)+0x30; para_temp[2]=0; para_temp[3]=0;
808 1 Send_AT_Command(SMS_CMGR);
809 1 timercount=0; while(timercount<2) ;
810 1 return(0);
811 1
812 1 }
813
814
815
816
817 void Initialize_Model(void) //初始化 PIN檢測
818 {
819 1 uchar i;
820 1 Sys_Init();
821 1
822 1 P0=0;//IO_IGT=1;
823 1 PT2272_BIT=0;PT2272_TMP=0;//
824 1 io_p01_on=1; io_p00_on=1;
825 1 io_p02_on=1;io_p01_bit=0;
826 1 io_p03_on=1; io_p02_bit =0;
827 1 for(i=0;i<12;i++)
828 1 {//進行初始化,并顯示
829 2 Send_AT_Command(TC35_INIT);
830 2 if(uart_buff[1]==0x0d&&uart_buff[0]==0x30)
831 2 { break;}
832 2 else if(uart_buff[receive_count-1]==0x0d&&uart_buff[receive_count-2]=='0')
833 2 { break;}
834 2 if((i%4)==0)
835 2 {
836 3 IO_IGT=1;
837 3 }
838 2 else if((i%2)==0)
839 2 {
840 3 IO_IGT=0;
841 3 }
842 2 timer_S_cnt=0; while(timer_S_cnt<5&&(AT_Command_Status==COMMAND_WAIT)) watch_dog_clear;
843 2
844 2 }
845 1 if(i>=11) goto at_eer;
846 1
847 1
848 1 for(i=0;i<12;i++)
849 1 {
850 2 if(Send_AT_Command(CHECK_PIN))
851 2 {//如有收到回應進行分析收到的信息,
852 3 uart_buff[receive_count]=0;
853 3 if(strsearch("READY")!=0)
854 3 break;
855 3 }
856 2 timer_S_cnt=0; while(timer_S_cnt<2&&(AT_Command_Status==COMMAND_WAIT)) watch_dog_clear;
857 2 //LED_INT=~LED_INT;
858 2 }
859 1 if(i>=11)
860 1 {
861 2 at_eer: Send_AT_Command(RESET_TC35);
C51 COMPILER V7.50 CHESHI 11/16/2008 00:57:23 PAGE 15
862 2 timer_S_cnt=0;while(timer_S_cnt<2) watch_dog_clear;
863 2 Send_AT_Command(SMSS_ID);
864 2 // timer_S_cnt=0; while(timer_S_cnt<2&&(AT_Command_Status==COMMAND_WAIT)) watch_dog_clear;
865 2
866 2 //eer_int=15;
867 2 timer_S_cnt=0; while(timer_S_cnt<10) watch_dog_clear;
868 2
869 2 }
870 1 BELL=0;
871 1 IO_IGT=0;
872 1 Send_AT_Command(SIM_ID);
873 1 Send_AT_Command(AT_IPR);
874 1 BELL=1;
875 1
876 1 Send_AT_Command(REQUEST_MOD);
877 1 if(strsearch("TC35\x0d\x0a")==0)
878 1 {Send_AT_Command(SMSS_ID); TC35_bit=0;}
879 1 else TC35_bit=1;
880 1 timer_S_cnt=0; while(timer_S_cnt<7) watch_dog_clear;
881 1 Send_AT_Command(SMSS_ID);
882 1
883 1 }
884
885
886
887
888 void Sys_Init(void)//話機啟動的初始化程序,包含鍵盤與定時器,串口等
889 {
890 1 //TH0=(65536-46080)/256;//重新裝入定時25mS的初值到TH0,TL0 56320
891 1 //TL0=(65536-46080)%256;
892 1 //65536-(11.0592/12)*20MS*1000=To 18432 47104
893 1 //1ms定時
894 1 //11.0592/12 = 0.9216 M (記數頻率)
895 1 //1ms記數 921.6次
896 1 //16位 2^16 - x = 922 x=64614 FC66
897 1 //定時器里不斷放fc66,不用懷疑51定時器得到的 1ms的精確性嗎
898 1
899 1
900 1
901 1
902 1 // TH0 = 0xf6;
903 1 // TL0 = 0x50;
904 1
905 1 TH0 = 0xB8;TL0 = 0x00; //20ms的時鐘基準
906 1
907 1 //串口中斷
908 1 TI=0; RI=0;
909 1 SCON=0x50; //選用方式1
910 1 TMOD=0x20;
911 1 TMOD = (TMOD & 0xf0) | 1;//MODE 1
912 1 // TH1=0xe8; //波特率為9600
913 1 // TL1=0xe8;
914 1 TH1=0xfd; //波特率為9600
915 1 TL1=0xfd;
916 1 PCON=0x00; //倍頻0x80
917 1 IE = 0xb0; // EA XX ET2 ES ET0 EX0 ET1 EX1
918 1 TR1=1; //enable TIMER1
919 1
920 1 ES=1; //開串口開斷
921 1 TR0=1; //串口接收中斷
922 1 ET0=1; //T0 中斷
923 1 ET1=0; // T1 中斷
C51 COMPILER V7.50 CHESHI 11/16/2008 00:57:23 PAGE 16
924 1 EA=1;
925 1 P0=0xFF;
926 1 P1=0xFF;
927 1 P2=0xFF;
928 1 P3=0xFF;
929 1 // P4=0xff;
930 1 timer_1S_cnt=0;
931 1 receive_count=0;
932 1 IO_IGT=1;send_count=0xff; //表示禁止發送,可以接收
933 1
934 1 LED_INT3=1;LED_INT7=0;
935 1 io_p06_on=1;IO_IGT=0;
936 1 IO_OUT=1;
937 1
938 1 }
939 //======================================================
940 //這里為AT指令處理區,所有的AT指令都在這時對uart_buff數組進行賦值,并發送出去,
941 //-正常情況下,AT指令反回也會在這里接收完
942 //------------------------
943 //-----------------------
944 ///==========================================
945
946 uchar Send_AT_Command( uchar type) //發送AT指令
947 //撥號時號碼放在phone.number
948 //其他用para_temp
949 {
950 1 AT_Command_Type=type;
951 1 send_count=0;
952 1 switch(type)
953 1 {
954 2
955 2 case VOICE_DIAL: //語音撥號
956 2 strcpy(uart_buff,"ATD");
957 2 strcat(uart_buff,para_temp);
958 2 // strcpy(uart_buff,"ATD10086;");
959 2 //strcat(uart_buff,";");
960 2
961 2 break;
962 2 case RESET_TC35: //復位TC35
963 2 strcpy(uart_buff,"AT+CFUN=1,1");
964 2 break;
965 2 case CHECK_PIN: //檢查當前是否要輸入PIN碼
966 2 strcpy(uart_buff,"AT+CPIN?");
967 2 break;
968 2
969 2 case TC35_INIT: //TC35初始化命令 ATE0 ATV0 合體
970 2 strcpy(uart_buff,"ATE0V0");
971 2 break;
972 2 //0D 0A 54 43 33 35 0D 0A
973 2 case REQUEST_MOD: //模塊版型號
974 2 strcpy(uart_buff,"AT+CGMM");
975 2 break;
976 2
977 2 case SIM_ID: // 也是合體組合 ATE0 ATV0 AT+CMGF=1 AT+CNMI=2,1
978 2 strcpy(uart_buff,"ATE0V0+CMGF=1+CNMI=2,1");
979 2 break;
980 2 case AT_IPR: // 波特率 9600
981 2 strcpy(uart_buff,"AT+IPR=9600"); break;
982 2 case CALL_ID: //讀來電顯示
983 2 strcpy(uart_buff,"AT+CLCC");
984 2 break;
985 2
C51 COMPILER V7.50 CHESHI 11/16/2008 00:57:23 PAGE 17
986 2 case SMSS_ID: //TC35i模塊專用
987 2 strcpy(uart_buff,"ATE0V0^SSMSS=1+CNMI=2,1");
988 2 break;
989 2 case HOOKOFF: //掛機,停止通話
990 2 strcpy(uart_buff,"ATH");
991 2 break;
992 2 case SMS_CMGF: //SMS 接收方式,
993 2 strcpy(uart_buff,"ATE0V0+CMGF=0");
994 2 break;
995 2
996 2 case PHONE_WRITE: //存電話號碼
997 2 strcpy(uart_buff,"AT+CPBW=");
998 2 strcat(uart_buff,para_temp);
999 2 break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -