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

📄 cheshi.h

📁 GSM MCU 开发板
💻 H
字号:
#pragma OPTIMIZE(6,size)   	//优化级别与优化方式
//#pragma LARGE 				//编译模式 SMALL  COMPACT LARGE


#include <ctype.h>			//字符函数
#include <stdio.h>		//一般IO/函数
#include <string.h>			//字符串函数
//#include <stdlib.h>			//标准函数
//#include <mach.h>			//数学函数
#include <intrins.h>		//内部函数
//#include <stdarg.h>		//变量参数表


typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;


//#include <struct.h>
//#include <EventDef.h>
#define  CPU_TYPE2    2    //定义CPU的类型
#define  PLC900    	 1
#define  SM5964      2
#define  C8051F330   3

//--------标准51单片机---新茂产品-------------

#if   CPU_TYPE2==SM5964
	#include <CPU.h>

	sbit IO_IGT 	=P3^4;
	//外部中断
	sbit IO_P35		=P3^2;
	sbit IO_P24		=P2^4;
	sbit IO_P25		=P2^5;

	sbit IO_P03		=P1^3;
	sbit IO_P04		=P1^4;
	sbit IO_P05		=P1^5;
	sbit IO_P06		=P1^6;
	sbit IO_P07		=P1^7;
	#define BELL  P3_3
	sbit LED_INT0 = P0^0;
	sbit LED_INT1 = P0^1;
	sbit LED_INT2 = P0^2;
	sbit LED_INT3 = P0^3;
	sbit LED_INT4 = P0^4;
	sbit LED_INT5 = P0^5;
	sbit LED_INT6 = P0^6;
	sbit LED_INT7 = P0^7;

    sbit LED_S2 = P1^1;

    #define _Nop()    _nop_()
	//LED的背光控制
	#define ring_tone_1    	IO_RINGTONE=1
	#define ring_tone_0	   	IO_RINGTONE=0
	//系统休眠与掉电
	sfr WDTC   = 0x9F;

	//#define system_sleep   	_Nop();	//	MISO=1;  //PCON=0x01
	//#define watch_dog_clear		WDTC=0xa3    */

	//sfr WDTC   = 0x9F;
	//WDTC,9FH:  WDTE -- CLEAR -- -- PS2 PS1 PS0
	//WDTE:   看门狗定时器使能位,1有效
	//CLEAR:  看门狗定时器复位位,1有效
	//PS2 PS0:时钟源分频选择位  0-16-32-64-128-256-512-1024
	#define system_sleep   		PCON=0x01
	#define system_powerdown	PCON=0x02
	#define watch_dog_clear		WDTC=0xa3

//--------------------------------------------------------------------
//-----C8051F330----新华龙产品---------------------------------------------
#elif   CPU_TYPE2==C8051F330      //12                      023//50元
  #include <c8051f330.h>
//-----------------------------------------------------------------------------
// 16-bit SFR Definitions for 'F30x
//-----------------------------------------------------------------------------

sfr16 DP       = 0x82;                 // data pointer
sfr16 TMR2RL   = 0xca;                 // Timer2 reload value
sfr16 TMR2     = 0xcc;                 // Timer2 counter
sfr16 PCA0CP1  = 0xe9;                 // PCA0 Module 1 Capture/Compare
sfr16 PCA0CP2  = 0xeb;                 // PCA0 Module 2 Capture/Compare
sfr16 PCA0     = 0xf9;                 // PCA0 counter
sfr16 PCA0CP0  = 0xfb;                 // PCA0 Module 0 Capture/Compare

//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------
#define system_sleep  SW2=1
#define SYSCLK       24500000          // SYSCLK frequency in Hz
#define BAUDRATE     9600              // Baud rate of UART in bps
//#define SAMPLE_RATE  100000            // Sample frequency in Hz
//#define INT_DEC      4096              // integrate and decimate ratio
	sbit IO_HKS		=P0^7;
    sbit IO_HSK1	=P0^3;
    sbit IO_RING     =P0^4;
	sbit IO_IGT 	=P0^6;
	//外部中断
	sbit IO_P01		=P1^1;
	sbit IO_P02		=P1^2;
	sbit IO_P03		=P1^3;
	sbit IO_P04		=P2^4;
	sbit IO_P05		=P1^5;
	sbit IO_P06		=P1^6;
	sbit IO_P07		=P1^7;
	sbit LED_S1 = P0^0;
    sbit LED_S2 = P1^1;
    sbit LED_INT = P1^4;
	sbit SW2 = P0^3;                       // SW2='0' means switch pressed
	sbit RI     = SCON0 ^ 0;
	sbit TI     = SCON0 ^ 1;
 	sbit ES     =0xAC;
	sfr  SBUF      = 0x99; /* UART0 DATA BUFFER */
	                    // LED='1' means ON




//-----------51兼容产品------飞利浦系列-----------------------------------------------
#elif   CPU_TYPE2==PLC900

  #include "P89LPC930.h"
  #define system_sleep     _nop_();
  #define IO_HSK1			INT0
  #define IO_HKS			INT1
  #define IO_SYNC			P0_3
  #define IO_IGT			OCC
  #define IO_OUT			P0_4
  #define  LED_INT         XTAL2
  //#define IO_IGT			P1_3
	//#define INIT_A          P3_2
	//#define INIT_B          P3_3

#endif
//-----------------------------------------------------------------------------------------




//=============================================================================
//                  基本的常用常量
//=============================================================================
#define ON		1
#define OFF		0
#define TRUE	1
#define true    1
#define FALSE	0

//=============================================================================
//                    所有的ICON共用一个16位的标志
//=============================================================================

//=============================================================================
//code  unsigned char SimCard_PinCode[]={"1234"};//SIM卡PIN码
//code  unsigned char SimCard_PinMode =1;
	#define  PIN_MODE_INPUT			0	//0可以使用未启用PIN码的卡,如要求输入PIN码则提示用户输入
    #define  PIN_MODE_AUTO        	1	//1可以使用未启用PIN码的卡,如要求输入PIN码,则自动输入
	#define  PIN_MODE_ENABLE		2	//2-使用强制启用,并将1234修改为指定PIN码,如不对则提示出错代码.
	#define  PIN_MODE_ONETIMES		3	//3-只使用指定的PIN码来验证,如不对或PIN码没有启用提示出错代码.
	#define  PIN_MODE_ROLL			4	//4-每次使用话机开机时改动一次PIN码.
//============================================================================

//int_case  低   1    1    1       1        1    1     1   1    1     高位
//             键盘 拨号 出错   通话中断  摘机 挂机  振铃
//#define INT_KEY_PRESS       0x01  	//键盘中断
#define INT_DIAL_SUCCESS    	0x02  	//拨号成功
#define INT_DIAL_FAILURE	0x04	//拨号出错
#define	INT_TALK_STOP		0x08  	//通话中断及拨号失败标志
#define INT_PICKUP         	0x10  	//摘机
#define INT_HANGOFF		0x20  	//挂机
#define	INT_RING		0x40  	//振铃
#define	INT_RINGOFF		0x80	//振铃信号停止

//话机的运行状态 ic.system_server
#define	SYS_ALARM					0x03	//处于报警时间设置状态
#define	SYS_RING					0x01	//来电,未摘机
#define SYS_PARA					0x05	//来电,用户已摘机
#define SYS_SBC						0x02	//来电,用户已摘机
#define	SYS_SMSR					0xff	//主叫摘机
#define SYS_START					0x30	//话单查寻
#define SYS_SMSS					0x31	//未接来电
#define SYS_TEL						0x32    //已接来电
#define SYS_DIAL                    0x33




//=============================================================================
//             定义 TC35 的命令列表
//=============================================================================
#define VOICE_DIAL		0  	//语音拨号
#define AT_CSCA			1   //读短信中心号码
#define DTMF_DIAL       2	//通话中拨号
#define RESET_TC35		3	//复位TC35
#define TC35_INIT 		4	//TC35初始化命令
#define CALL_ID 		5	//读来电显示
#define SWITCHOFF_TC35 	7	//关机
#define LOCK_QUERY 		8	//检查是否启用SIM卡的PIN码保护
#define CHECK_PIN 		9	//检查当前是否要输入PIN码
#define PIN_IN_USE    		10	//启用SIM卡的PIN码,要先输入
#define PIN_PASSWORD 		11	//输入SIM卡的PIN码
#define CHANGE_PIN 			12	//修改SIM卡的PIN码 AT^SPWD="SC",1234,5678
#define SIM_ID          	13	//读出SIM卡的卡号,与SIM卡标明的卡号一样
#define REGISTER_CHECK 		14	//检查是否登陆成功
#define SIGNAL_CHECK 		15	//读取信号质量
#define HOOKOFF 			16	//挂机,停止通话
#define PICK_UP         	17 	//摘机
#define COPS_UP				18
#define  AT_CIPCLOSE         19
#define VOICE_HANDSET       20  //设为手柄方式
#define SELECT_VOLUME		21	//选择音量,0-4 5级
#define DATATIME_SET  		22	//设置TC35的内部时钟
#define DATATIME_READ 		23	//读出TC35的内部时钟
#define TC35_VERSION    	24	//读出TC35的软件版本
#define AT_CIPSHUT          25
#define AT_CLPORT           26
#define AT_CSTT             27
#define AT_CIICR            28
#define AT_CIFSR            29
#define SMS_CNMI 			30	//SMS 接收方式
#define SMS_CMGS			31  //SMS 短信发送
#define SIM_CARD_CHECK      32  //查寻是否插入SIM卡
#define AT_COMMAND          33
#define SMS_CMGR			34   //读一个短信
#define PHONE_DL_CHECK      35  //查寻已拨电话
#define PHONE_READ          36  //读电话本
#define PHONE_WRITE         37  //写电话本
#define SMS_CMGD			38
#define MONITOR_ID			39    //读小区
#define PHONE_MC_CHECK      40  //已接来电
#define PHONE_RC_CHECK      41  //未接来电
#define REQUEST_MOD			42
#define AT_CDNSGIP          43
#define AT_CDNSORIP         44
#define AT_CIPDPDP          45
#define AT_CIPHEAD          46
#define AT_CIPATS           47
#define AT_CIPSERVER        48
#define AT_CIPCSGP          49
#define TC35_IMEI           50
#define CMGS_MUB			51
#define	CMGS_SM				52
#define	SMSS_ID				53
#define PHONE_SET       	54
#define TC35_SBC	       	55  //检查电池电量
#define AT_CREG             56
#define AT_CDNSCFG          57
#define AT_CIPCCON          58
#define AT_CPBS             59
#define AT_CPBF             60
#define AT_CPMS             61
#define AT_CIPSEND          62
#define AT_CIPSTART         63
#define AT_CIPSTATUS        64
#define AT_CFUN             65
#define AT_CLTS             66
#define TC35_IPR            67
#define AT_CALARM           68
#define AT_IPR              69
#define SMS_CMGF            70
//===================================================
// 发送短消息内容方式
//====================================================
#define   	smss_tel    	0
#define 	smss_alarm		1
#define		smss_end		2
#define		smss_start		3
#define		smss_para		4
#define	    smss_sbc      	5
#define		smss_atart       6

//=============================================================================
//                  外部中断事件
//=============================================================================
//int_case
#define	INT_P01_ON     	0x01
#define	INT_P02_ON    	0x02
#define	INT_P03_ON     	0x04
#define	INT_P04_ON    	0x08
#define	INT_P05_ON     	0x10
#define	INT_P06_ON    	0x20
#define	INT_P07_ON    	0x40

//=============================================================================
//       AT命令的返回类型 AT_Command_Status
//=============================================================================
#define COMMAND_WAIT		0xff	//等待命令回应
#define COMMAND_OK			0		//命令发送正确.
#define COMMAND_CONNECT		1		//语音拨号接通电话
#define COMMAND_RING		2		//振铃输入
#define COMMAND_NO_CARRIER	3		//语音拨号没有接通
#define COMMAND_ERROR		4		//命令发送错误.
#define COMMAND_NO_DIAL		6		//没有拨号音
#define COMMAND_BUSY		7		//线路忙
#define COMMAND_UNKNOW		8		//不可识别的返回类型


uchar Read_Roll_Pin(void);
uchar Read_MONI_ID(void);
void   send_sms();
uchar Send_AT_Command( uchar type);
void  Sys_Init(void);
void  Initialize_Model(void);
uchar strsearch(uchar *ptr2);
uchar  PHONE_RD();
uchar   READ_TEL(uchar r );
void tel_diat();
uchar  Read_SMONC_ID(void);
uchar TEL_FENGXI(uchar j,r);

//viod  TEL_FIND();

⌨️ 快捷键说明

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