📄 main.c
字号:
//ICC-AVR application builder : 2008-7-29 下午 04:04:26
// Target : M16
// Crystal: 3.6864Mhz
#include <iom16v.h>
#include <macros.h>
#include "pic_crc_data.h"
#include "xmodem.h"
#define true 1
#define false 0
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
uchar receive_data[STRING_LENGTH];
int receive_sp=0;
void Delay(unsigned int Delay_MS);
void send_a_byte( unsigned char data ) ;
void mms_atsent(void);
void Xmodem(void);
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9600 (0.0%)
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
UBRRL = 0x01; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x98;
}
//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;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
extern uchar temp_char0=0;
#pragma interrupt_handler uart0_rx_isr:iv_USART0_RXC
void uart0_rx_isr(void)
{
//uart has received a character in UDR
//uchar temp_char0;
unsigned char temp;
temp=UDR;
temp_char0 = temp;
if(temp_char0 == 'C')
{ //检测是否收到 C
receive_C = 1;
}
if(temp_char0 == '>')
{ //检测是否收到 >
receive_DAYUHAO = 1;
}
if(temp_char0 == 'K')
{ //检测是否收到 >
receive_OK = 1;
}
if(temp_char0 == '1')
{ //检测是否收到 >
receive_MMSTRACE = 1;
}
if(temp_char0 == 'U')
{ //检测是否收到 >
receive_DOWNFINE = 1;
}
/*if (/*(temp_char0 == CHARGE_LINE)|| (temp_char0 == ENTER))
{
do_serial_data(receive_sp); //收到回车,接收指针归零 ,并处理接收数据
receive_sp = 0;
}
else
{
receive_data[receive_sp++] =temp;
}
if (receive_sp > 40) //接收超长,接收指针规零
receive_sp = 0;*/
}
/*********************************************************************
*********************************************************************/
void main(void)
{
int i;
init_devices();
for(i = 0; i< STRING_LENGTH ; i++) //清接收缓存//40
{
receive_data[i] = 0;
}
receive_sp = 0;
receive_OK = 0;
send_a_byte(ENTER); //发送回车,测试模块
Delay(500);
receive_OK = 0;
send_m_byte("at\r\n",4); //发送AT,测试模块
send_a_byte(ENTER);
while(receive_OK== 0);
Xmodem();
Delay(10);
mms_atsent();
}
void send_a_byte( unsigned char data )
{
/* 等待发送缓冲器为空 */
while ( !( UCSRA & (1<<UDRE)) )
;
/* 将数据放入缓冲器,发送数据 */
UDR = data;
}
void send_m_byte(uchar *string, uint length)
{
uint i; //发送多字节
for(i = 0; i< length; i++)
{
send_a_byte(string[i]);
}
}
/*
*************************************
*延时子程序,延时约10×i机器周期 *
*************************************/
void intDelay(uint i)
{
while(i--);
}
//1MS的延时
void Delay(unsigned int Delay_MS)
{
unsigned char i;
while(Delay_MS--)
{
for(i=0;i<111;i++);
}
}
void sendcmd(unsigned char *by_Array)
{
while(*by_Array)
{
while (!( UCSRA & (1<<UDRE)));
UDR=*by_Array;
by_Array++;
}
}
void mms_atsent(void)
{
receive_OK=0;
sendcmd("AT$MMSW=0\r\n") ;
while(receive_OK==0) ;
Delay(10);
receive_DAYUHAO=0;
sendcmd("AT$MMSW=1,1\r\n") ;
while(receive_DAYUHAO==0) ;
receive_OK=0;
sendcmd(dial_number);
send_a_byte(ctrl_z);
while(receive_OK==0) ;
Delay(10);
receive_DAYUHAO=0;
sendcmd("AT$MMSW=4,1\r\n");
while(receive_DAYUHAO==0) ;
receive_OK=0;
sendcmd(subject);
send_a_byte(ctrl_z);
while(receive_OK==0) ;
Delay(10);
receive_DAYUHAO=0;
sendcmd("AT$MMSW=5,1,1\r\n");
while(receive_DAYUHAO==0) ;
receive_OK=0;
sendcmd("mypicture");
send_a_byte(ctrl_z);
while(receive_OK==0) ;
Delay(10);
receive_OK=0;
sendcmd("AT$MMSW=6,1,\"test.jpg\"\r\n");
while(receive_OK==0) ;
Delay(10);
receive_OK=0;
sendcmd("AT$MMSSEND\r\n");
while(receive_OK==0) ;
Delay(10);
receive_MMSTRACE=0;
while(receive_MMSTRACE==0) ;
receive_OK=0;
sendcmd(deletmms);
while(receive_OK==0) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -