mayasunny
Member level 3
hie all, controller : PIC16F877A , module :sim800 , Xc8 compiler, Crystal frequency: 20MHz.
the problem is, when i am giving "AT\r" to microcontroller GSM modem not responding.
i checked
1. tested GSM, Connected to serial port using com port in my pc, the result is good gsm modem responded with "OK"
2. Connected my board to Serial port using com i got "AT" in my hyper terminal and i gave "OK" then the code working perfectly
3. When i combined the two with a connector wire of three pin then the system is not working properly
will you please suggest any remedies or solutions with your experience? and if you can please describe what is the problem actually?
below is my code:
the problem is, when i am giving "AT\r" to microcontroller GSM modem not responding.
i checked
1. tested GSM, Connected to serial port using com port in my pc, the result is good gsm modem responded with "OK"
2. Connected my board to Serial port using com i got "AT" in my hyper terminal and i gave "OK" then the code working perfectly
3. When i combined the two with a connector wire of three pin then the system is not working properly
will you please suggest any remedies or solutions with your experience? and if you can please describe what is the problem actually?
below is my code:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 #pragma config FOSC = HS // Oscillator Selection bits (XT oscillator) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled) #pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled) #pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled) #pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming) #pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off) #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control) #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off) #include <xc.h> #include<string.h> #define _XTAL_FREQ 20000000 char a[]={"AT \n"}; char buf,*Rec; static char data[10]; unsigned int res,res1,i,j; void UART_Init(int baudRate) { BRGH=0; SYNC=0; TXSTA = 0X20; // Asynchronous mode, 8-bit data & enable transmitter RCSTA = 0X90; // Enable Serial Port and 8-bit continuous receive SPBRG = 31; // baud rate @20Mhz Clock } void UART_TxChar(char ch) { while(TXIF == 0); // Wait till the transmitter register becomes empty TXIF = 0; // Clear transmitter flag TXREG = ch; // load the char to be transmitted into transmit reg } char UART_RxChar(void) { while(RCIF == 0); // Wait till the data is received if (OERR) { CREN=0; // toggle CREN off and on to clear overrun CREN=1; } RCIF = 0; // Clear receiver flag return(RCREG); // Return the received data to calling function } char *UART_Read_Text(unsigned int length) // to read data continously { for(j=0; j<length; j++) { buf = UART_RxChar(); // Receive a char from serial port data[j] = buf; UART_TxChar(data[j]); } return(data); } void str(char ch) // to write data continously { for(i=0;a[i]!=0;i++) { UART_TxChar(a[i]); } } void main(void) { char ch; TRISD = 0X00; PORTD = 0X00; TRISC = 0x80; // Configure Rx pin(rc7) as input and Tx(rc6) as output UART_Init(9600); //Initialize the UART module with 9600 baud rate while(1) { str(ch); Rec = UART_Read_Text(2); // res = Rec[0]; // res1 = Rec[1]; res = strncmp(data,2,"OK"); if(res == 0) // if(res == 'O' && res1 == 'K') { RD0 = 1; // turn on led __delay_ms(3000); RD0 = 0; } else{ RD1 = 1; __delay_ms(3000); RD1 = 0; } /*res1 = strcmp(data,"ERROR"); if(res == 0) { RD1 = 1; __delay_ms(3000); RD1 = 0; } */ } return; }
Last edited by a moderator: