Social Icons

Thứ Hai, 11 tháng 11, 2013

PIC Giao Tiếp USB 3G Viettel (Huawei E173Eu-1)

                                                      SOURCE DEMO
Đây chỉ là đoạn chương trình main mẫu, chỉ mang tính chất tham khảo, chương trình rất lớn các bạn có thể tham khảo trong thư viện của Microchip

*****************************************************************
Project :  PIC24FJGB106 Giao Tiếp 3G USB Modem Viettel (Huawei E173Eu-1)
Complier : MPLAB
Date    : 11-Nov-2013
Author  : quinguyen
Company : Vinasemiconductor
Chip type               : PIC24FJ family
Program type            : Application
Core Clock frequency: 20.000000 MHz
*****************************************************************
int main (void)
{
    // Initialize the processor and peripherals.
    if ( InitializeSystem() != TRUE )
    {
        UART2PrintString( "\r\n\r\nCould not initialize system.  Halting.\r\n\r\n" );
        while (1);
    }
UART2PrintString( "****WELCOM****\r\n" );
UART2PrintString( "Vinasemiconductor\r\n" );
UART2PrintString( "3G USB MODEM\r\n" );


    // Initialize USB layers
    USBInitialize( 0 );
    APPL_Demo_State = DEMO_INITIALIZE;
    CDC_AT_Command_State = CDC_NOT_READY;
    while(1)
    {
        USBTasks();
        CDCSequence();
        if(DemoTimeUp==TRUE)
        {
            DemoTimeUp = FALSE;
            if(DemoStallCount > DEMO_STALL_COUNT)
            {
                displayOnce = TRUE;
                APPL_Demo_State = APP_DEMO_TIME_UP;
            }
            else
            {
                DemoStallCount++;
                UART2PrintString( "-----------------------------------------------\r\n" );
                UART2PrintString( "This is 3G USB Demo on MicroChip PIC24FJ series\r\n" );
                UART2PrintString( "Work by Vinasemiconductor \r\n" );
                UART2PrintString( "-----------------------------------------------\r\n" );
            }
        }

        switch(APPL_Demo_State)
        {
            case DEMO_INITIALIZE:       // Khởi tạo USB Host
                #ifdef DISABLE_DEMO
                    UART2PrintString( "3G USB Application Initialize \r\n" );
                #else
                    UART2PrintString( "3G USB Application (DEMO) Initialize \r\n" );
                #endif
                FoundDevice = FALSE;
                APPL_Demo_State = DEVICE_NOT_CONNECTED;
                break;

            case DEVICE_NOT_CONNECTED:
                USBTasks();
                if(displayOnce == FALSE)
                {
                    UART2PrintString( "No USB Device Connected \r\n" );
                    FoundDevice = FALSE;
                    displayOnce = TRUE;
                }
                if(USBHostCDC_ApiDeviceDetect()) /* TRUE if device is enumerated without error */
                {
UART2PrintString( "USB Device Connected \r\n" );
                    APPL_Demo_State = DEVICE_CONNECTED;
                    displayOnce = FALSE;
                }
                #if 0
                    if(get_uart_ch(&AT_command_buffer[1]))
                    {
                        UART2PutChar(AT_command_buffer[1]);
                    }
                #endif
                break;

            case DEVICE_3G_SWITCH:                // Chuyển sang Modem
                if(USBHostCDC_ApiDeviceDetect()) /* TRUE if device is enumerated without error */
                {
                    APPL_Demo_State = DEVICE_CONNECTED;
                    displayOnce = FALSE;
                }
                break;

            case DEVICE_CONNECTED:
                UART2PrintString( "VIETTEL Huawei E173Eu-1 Connected \r\n" ); // Modem đã kết nối
                deviceAttached = TRUE;
                DeviceReady = FALSE;
                set_timer_wait(100);
                APPL_Demo_State = DEVICE_3G_QUERY;
                break;

            case DEVICE_3G_QUERY:
                if(SystemTimeUp == TRUE)
                {
                  UART2PrintString( "VIETTEL Huawei E173Eu-1 Ready \r\n" );   // Modem sẵn sàng
                    set_timer_wait(100);
                  APPL_Demo_State = DEVICE_3G_IDLE;
                }
                break;

            case DEVICE_3G_IDLE:
                if(SystemTimeUp == TRUE)
                {
                    set_timer_wait(1000);
                                      UART2PrintString("SMS Polling \r\n" );
                                      AT_Command_Send("ATZ");                     // Gửi lệnh ATcommand
                }
                break;

            case APP_DEMO_TIME_UP:
                if(displayOnce == TRUE)
                {
                    displayOnce = FALSE;
                    CDC_AT_Command_State = CDC_NOT_READY;
                }
                break;
            default :
                break;
        }
    }
}

                  HÌNH ẢNH THỰC TẾ VÀ KẾT QUẢ





Đến đây các bạn có thể gửi lệnh ATcommand và làm việc như các Modem khác, điều khiển hay thu thập dữ liệu gì thì tùy vào mục đích ứng dụng của mỗi người, chúc các bạn thành công
Sơ đồ mạch điện các bạn có thể tìm trên mạng hoặc trong datasheet con PIC24FJ256GB106, vì làm bằng boad đục lỗ nên chưa có sơ đồ mạch cụ thể!

Thanks and Best Regards 

Nguyễn Ngọc Qui
Automation Engineer
Email: quinguyentgvn@gmail.com
Phone: 0938 430 305


1 nhận xét:

  1. bn cho hỏi là bên bạn có modul này không
    http://myjowen.blogspot.com/search?updated-min=2012-01-01T00%3A00%3A00-08%3A00&updated-max=2013-01-01T00%3A00%3A00-08%3A00&max-results=7
    mình đang muốn tìm mua mà không biết mua ở đâu.
    cảm ơn bạn.

    Trả lờiXóa

 

Sample text

Sample Text

Sample Text