📄 main.c
字号:
if(StringCompare(RxBuf,SMSin,SMSinLen)) // 如果收到OK完成 +CMTI: "SM", 1
{
return (OK);
}
else
{
return (ERROR);
}
}
/*-----------------------------------------------------------------------*/
/////////////// 将设置号码存入内存 /////////////////
/*-----------------------------------------------------------------------*/
void CheckSMS(void)
{
unsigned char i=0,j=0,index,numlen=0;
for(;i<12;i++)
{
PhoneNum[i] = 0;
}
/* do
{
i++;
j=i+1;
}
//while((Pdu[i] == 'G') && (Pdu[j] == 'H'));
index = j+1;
i = index;
while(Pdu[i++] == '+')numlen++;
j = 79; */
index = 79;
for(i=0;i<11;i++)
{
PhoneNum[i] = Pdu[index++];
PhoneNum_to_EEPROM();
}
}
unsigned char CheckPhoneNum(void)
{
unsigned char i;
for(i=0;i<12;i++)
{
if( PhoneNum != 0) return (FALSE);
}
return (TRUE);
}
/*-----------------------------------------------------------------------*/
////////////////////////// 接收处理短信息 ///////////////////////////
/*-----------------------------------------------------------------------*/
void RecSMS(void)
{
unsigned char count,i=0,j=0,x,y;
Put_AT_String("AT+CMGR=1",9);
while(RxBuf[i] != 0x0D)
{
i++;
}
i = 76;
j = i;
if((RxBuf[i] == 'G') && (RxBuf[j+1] == 'H'))
{
count = 0;
while(1)
{
Pdu[count] = RxBuf[count];
x = count;
y = count;
if((RxBuf[x-2] == 0x30) && (RxBuf[y-1] == 0x0D))
{
break;
}
count++;
}
CheckSMS();
Delete_SMS(1);
}
else
{
Delete_SMS(1);
}
}
unsigned char DetQEITING(void)
{
volatile unsigned char tmp;
if(!(DetQT()))
{
release = 0;
DelayMs(10);
if(!(DetQT())) {DettqFlag = 1;}
}
else
{
release = 1;
}
if(release && DettqFlag)
{
DettqFlag = 0;
CplLED();
return (TRUE);
}
return (FALSE);
}
void IGT(unsigned char n)
{
if(n)
{
PORTD &= ~(1<<PD6);
DDRD |= (1<<PD6);
}
else
{
DDRD &= ~(1<<PD6);
}
}
void work(void)
{
while(1)
{
if(CheckSMS_in())
{
RecSMS();
}
if(CallInFlag)
{
Put_AT_command(Ata,AtaLen);
CallInFlag = 0;
}
if((BusyFlag) || (NoCarrierFlag))
{
Put_AT_command(Ath,AthLen);
CallOut = 0;
BusyFlag = 0;
NoCarrierFlag = 0;
}
if(DetQEITING() && (!CallOut))
{
CallOut = 1;
DialNum();
}
}
}
/*-----------------------------------------------------------------------*/
///////////////////////////// 初始化MC55 //////////////////////////////
/*-----------------------------------------------------------------------*/
void InitMC55(void)
{
unsigned char tmp;
IGT(OFF);
DelayMs(500); // 置低MC55 IGT口 200mS ,启动MC55模块
IGT(ON);
DelayMs(500);
IGT(OFF);
// DelayMs(1000); // 等待模块启动
ClrRTS();
DelayMs(50); // 激活MC55串口
SetRTS();
DelayMs(50);
ClrRTS();
DelayMs(50); // 激活MC55串口
SetRTS();
// DelayMs(1000); // 激活MC55串口
TxIndex = 0;
RxIndex = 0;
while(!DetQEITING());
PutString("AT",2,0);
DelayMs(500);
PutString("AT",2,1);
PutString("ATV0",4,1);
PutString("ATE0",4,1);
PutString("AT+CNMI=2,1",11,1);
PutString("AT+CMGF=1",9,1);
Delete_SMS(ALL);
PhoneNum_to_EEPROM();
EEPROM_to_PhoneNum();
}
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/*
#pragma interrupt_handler int0_isr:2
void int0_isr(void)
{
//external interupt on INT0
DialNum();
}
#pragma interrupt_handler int1_isr:3
void int1_isr(void)
{
//external interupt on INT1
}
*/
////////////////////////////////////////////////////////////////////////////////
void port_init(void)
{
PORTB = 0x01;
DDRB = 0x01;
PORTC = 0x00; //m103 output only
DDRC = 0x02;
PORTD = 0x0C;
DDRD = 0x50;
}
//UART0 initialize
// desired baud rate: 19200
// actual: baud rate:19200 (0.0%)
// char size: 8 bit
// parity: Disabled
//#ifdef XTAL == 3.6864
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
UBRRL = 0x0B; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0xD8;
}
//#endif
//#ifdef XTAL == 7.3728
/*void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
UBRRL = 0x17; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0xD8;
}*/
//#endif
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
uart0_init();
MCUCR = 0x00;
GICR = 0x00; //0xC0;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
InitMC55();
}
//
void main(void)
{
DelayMs(1000);
init_devices();
work();
/*
while(1)
{
DetQEITING();
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -