#include "iom16v.h"
#include "macros.h"
#include "SHUIPING.H"
#define BAUD 9600
#define FXTAL 12000000
#pragma interrupt_handler USART_Received_Ir:12
unsigned char a,b;
unsigned char TX_Buffer;
unsigned char RX_Buffer;
unsigned char TX_Flag;
unsigned char RX_Flag;
//串口IO初始化函数
void USART_IO_Init()
{
DDRD|=BIT(PD1); //PD1:TX为输出状态
}
//串口初始化函数
void USART_Init()
{
unsigned int Temp;
USART_IO_Init();
UCSRA=0x00;
UCSRB=0x00;
UCSRC|=BIT(URSEL)|BIT(UCSZ1)|BIT(UCSZ0);
Temp=(FXTAL/BAUD/16)-1;
UBRRH=((Temp>>8)&0x00ff);
UBRRL=(Temp&0x00ff);
UCSRB|=BIT(TXEN)|BIT(RXEN)|BIT(RXCIE);
SREG|=BIT(7);
}
USART_Send(unsigned char *data)
{
unsigned char cnt=0;
while(*(data+cnt))
{
while(!(UCSRA&(BIT(UDRE))));
UDR=*(data+cnt);
while(!(UCSRA&(BIT(TXC))));
UCSRA|=BIT(TXC);
cnt++;
}
}
USART_Received_Ir()
{
UCSRB&=~BIT(RXCIE);
RX_Buffer=UDR;
RX_Flag=1;
UCSRB|=BIT(RXCIE);
}
//主函数
void main()
{
DDRA=0XFF;
DDRC=0XFF;
PORTA=0XFF;
PORTC=0XFF;
USART_Init();
while(1)
{
loop://a=PINA;
b=PINC;
TX_Flag=(b!=0XFF);
if(TX_Flag)
{
//Delayms(600000);
//RX_Flag=1;
if(TX_Flag)
{
USART_Send("AT
");
Delayus(2000);
USART_Send("AT+CMGF=1
");
Delayus(2000);
USART_Send("AT+CSCS="UCS2"
");
Delayus(2000);
USART_Send("AT+CSMP=17,167,0,24
");
Delayus(2000);
USART_Send("AT+CMGS="手机号"
"); //编译时已经通过UNICODE转码
Delayus(2000);
USART_Send("发送的内容
"); //编译时已经通过UNICODE转码
Delayus(2000);
USART_Send("0x1A");
}
Delayms(500);
}
else
{
goto loop;
}
Delayhour(2);
if(TX_Flag)
{
//RX_Flag=1;
USART_Send("AT
");
Delayus(2000);
USART_Send("AT+CMGF=1
");
Delayus(2000);
USART_Send("AT+CSCS="UCS2"
");
Delayus(2000);
USART_Send("AT+CSMP=17,167,0,24
");
Delayus(2000);
USART_Send("AT+CMGS="手机号"
"); //编译时已经通过UNICODE转码
Delayus(2000);
USART_Send("发送内容
"); //编译时已经通过UNICODE转码
Delayus(2000);
USART_Send("0x1A");
Delayus(2000);
}
b=PINC;
TX_Flag=(b!=0XFF);
if(TX_Flag)
{
Delayhour(24);
goto loop;
}
else
{
goto loop;
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>