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

📄 gsm_control.c

📁 Visuabaic interface with com connect to computer
💻 C
字号:

#include <90usb1287>

#include <stdio.h>

#define BAUD 9600 /*9600 bps at 8.00 MHZ*/


//Used for SPLINT
#ifdef S_SPLINT_S
#include"splint.h"
#endif


//Includes
#include<iom128.h>
#include<inavr.h>
#include"AVRSMS_com.h"
#include"AVRSMS_api.h"
#include"AVRSMS_tools.h"


//! Flag imported from AVRSMS_com.c
extern int rx_ack;

//! Storage for new message index, see main loop
volatile int read_index;


/*! \brief Sytem initialization
 *
 *  This function will set:
 *  -Correct baud rate
 *  -Modem init
 *  -Wait message
 *  -Receiver on
 *
 *  \param void
 *  \retval void
 */
void MAIN_init( void )
{
    COM_UART_init( 12 );                        //Find corret baud rate in data sheet, must run @ 9600bps
    __enable_interrupt( );                      //Enable interrupt
    API_phoneinit( );                           //Initialize phone for textual messaging
    COM_rx_reset( );                            //Reset receive buffer after API_phoneinit()
    COM_setSearchString( CMTI_ );               //Wait for "+CMTI: ,Storage,index\r\n"
    COM_rx_on( );                               //Ready to receive
}
 
 
 /*This routine for controlling the relay
 */ 
void control_relay( void )
{
    int i,j;
    
    for(i=0,j=4; i<4,j<8; i++,j++)
    {    
    PORTB.j = msgbuff[i];                        //Set PORTB.0 ... PORT.8     
    }
}    


/*! \brief Main loop
 *
 *  This function is a simple main loop.
 *  Whenever a new message arrives, rx_ack  = 1, it is read and decoded.
 *  Toggle Breakpoint after API_readmsg, and view the result in msgbuff
 *  found in AVRSMS_api.c
 *
 *  \param void
 *  \retval void
 */
 void main( void )
{

    MAIN_init( );                               //Setup USART and modem

    read_index = 0;                             //Init variable

    for(;;)                                     //Forever
    {
        if( rx_ack == 1 )                       //New Message has arrived
        {
            read_index = TOOLS_decodeCMTI( );   //Find index
            API_readmsg( read_index );          //Read new message, and decode
            
            control_relay();
            
            COM_setSearchString( 1 );           //PLACE BREAKPOINT AT THIS LINE. Set searchstring to "+CMTI: " again, wait for new message.
            COM_rx_reset( );                    //Reset buffer and interrupt routine
            COM_rx_on( );                       //Ready to receive
        }
    }
}

⌨️ 快捷键说明

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