Sie sind auf Seite 1von 5

void GSM_Msg_Read(int position)

{
int i,k;
char flag,read_cmd[10];
i=0;
sprintf(read_cmd,"AT+CMGR=%d\r",position);
USART_SendString(read_cmd);
MSdelay(1000);
GSM_Msg_Display();
}
void GSM_Msg_Display()
{

void GSM_Msg_Read(int position)


{
int i,k;
char flag,read_cmd[10];
i=0;
UART1_Write_Text("AT+CMGR=%d\r");
USART1_Text(read_cmd);
MSdelay(1000);
GSM_Msg_Display();
}
void GSM_Msg_Display()
{

/* Testing connection with SIM300*/

sbit LED at RB4_bit;


//char receive;
char RX[]=;
//char SR[];
//unsigned short i;

void main()
{
CMCON=0x07;
TRISA=0;
TRISB=0b00000010;
LED=0;
/*output[1]=' ';
output[2]=' ';
output[3]=' ';
output[4]=' ';*/

delay_ms(60000);//delay to let SIM300 ready


UART1_Init(9600);
UART1_Write_Text("AT\r");
Delay_ms(2000);
while(1)
{
if(UART1_Data_Ready() == 1)
{

UART1_Read_Text(&RX,"\r\n",6);
}
Delay_ms(2000);
for(i=0;i<5;i++) //string length is 5
{
if(SR[i]==RX[i]) //here a[] is the string which is received through uart and
x[] is predefined string
{
b++; //increment b value by one
}
}
if(b==5)
{
b=0;
UART1_Write_Text("ATH\r");
LED=~LED;//write your output
}

void main() {

/* we first have to do the init of the serial comm port, the adcon, etc. */

Init_System();

while (1==1) {

/*****************************************************************************/
/* */
/* */
/* */
/*****************************************************************************/
void Init_System() {

ADCON1 = 0x06;
INTCON = 0xC0;
OPTION_REG = 0x80;

UART1_Init(RS232_BAUD_RATE); /* Pic to correct baud */


Delay_ms(100);
DataValid = FALSE;
memset(Button_Number,0,sizeof(Button_Number));
portd = NULL;
portc = NULL;

/*****************************************************************************/
/* */
/* */
/* */
/****************************************************************************

void LCD_Send(char text[]) {

char trash[20] = "";

UART1_Write_Text(text); /* sends text to ezLCD-304 */

if (UART1_Data_Ready()) {
portb = 0x040;
UART1_Read_Text(trash,"\r\n",4);
Delay_ms(100);
} else {
portb = 0x020;
Delay_ms(100);
}
}

dim i as word
dim receive as string[25]
dim delimiter as string[2]
dim tempb as byte
dim tempst as string[3]

...
delimiter[0]=chr(13)
delimiter[1]=chr(10)
delimiter[2]=0
UART1_Write_Text("AT*REG1?"+delimiter)
i = 0
receive=""
while i<2000
delay_us(500)
if UART1_Data_Ready = 1 then
tempb=UART1_Read
if tempb >= 32 then
receive=receive+chr(tempb)
else
receive=receive+"#"
ByteToStr(tempb,tempst)
ltrim(tempst)
strcat(receive,tempst)
end if
end if
inc(i)
wend
Lcd_Out(1, 1,receive)

char read char(void)


{
while (PIR1bits.RC1IF == 0) { // wait for char
if (RCSTA1bits.OERR == 1) {
RCSTA1bits.OERR = 0; // clear overrun if it occurs
RCSTA1bits.CREN = 0;
RCSTA1bits.CREN = 1;
}
}
return RCREG1;
}

void main()
{

ANSELA = 0; //Digital I/O for PORTA


TRISA = 0b00100001;
PORTA = 0;
APFCON0.RXDTSEL = 1; //0:RX is on RC5 1:RX is on RA1
TRISC = 0;
PORTC = 0;

RCSTA.RX9D = 0;
RCSTA.ADDEN = 0;
RCSTA.CREN = 1; // eneble reception.
RCSTA.SPEN = 1; //Serial port enable
RCSTA.RX9 = 0;

T1CON = 1; // Turn on timer TMR1


PIR1.TMR1IF = 0; // Reset the TMR1IF bit
TMR1H = 0xFC; // TMR1H and TMR1L timer registers are returned
TMR1L = 0x18; // their initial values
PIE1.TMR1IE = 1; // Enable an interrupt on overflow
INTCON = 0xC0; // Enable interrupt (bits GIE and PEIE)

PWM1_Init(4000); //initialize PWM at 5Khz

UART1_Init(9600);

while(1)
{
if (UART1_Data_Ready())
{
//Blink the LED, indication data is coming in.
PORTA = 4;
delay_ms(50);
PORTA = 0;

sVal = UART1_Read();

//My debug code to see what character coming in


EEPROM_Write(0x00+ii, sVal);
ii++;

if (sVal == '3')
motor_run_fast();
else
motor_stop();

} //UART ready
}
}

Das könnte Ihnen auch gefallen