SIM300使用PIC16f在Mikroc发送短信

时间:2016-03-08 17:52:24

标签: sms gsm pic mikroc

我一直在尝试使用SIM300模块发送短信。虽然尝试使用超级终端时模块工作正常,但我无法使用PIC发送短信。

下面是我试过的代码(LCD也包括在内(Lcd工作正常)):

  

编程:MikroC
  控制器:PIC16f877A
  模块:SIM300

sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;

void main(){
//CMCON = 7;                        //Disable Comparators
Lcd_Init();                        // Initialize LCD
UART1_init(9600);                   //Initiate baud rate to 9600
Delay_ms(500);                      //Delay
UART1_Write_Text("AT+CMGF=1");      //Write "AT+CMGF=1"
UART1_Write(0x0D);                  // mean (ENTER)
Delay_ms(500);                      //Delay
UART1_Write_Text("AT+CMGS=");       //Write "AT+CMGS="
UART1_Write(0x22);                  //Write (")
UART1_Write_Text("9449869619");     //Number SMS send to
UART1_Write(0x22);                  //Write (")
UART1_Write(0x0D);                  // mean (ENTER)
Delay_ms(500);                      //Delay
UART1_Write_Text("WELCOME");
UART1_Write(0x0D);      //Words to be sent
UART1_Write(0x1A);
                //Write "ctrl+z"
Delay_ms(500);                      //Delay
Lcd_Out(1,1,"MSG SENT SUCESSFULLY"); // Write text in first row

}

1 个答案:

答案 0 :(得分:0)

你应该试试

Uart1_Write_Text(" AT + CMGF = 1 \ R&#34);

因为" \ r"代表"输入"或"返回"有时" 0x0D"不在微控制器中工作。

我一直在使用它,它对我来说很好。