Tuesday, February 16, 2010

C Program - AT command

#include regx52.h
#include stdio.h
#include string.h
sbit but = P1^1;
sbit but2 = P1^2;
sbit but3 = P1^3;
sbit but4 = P1^4;
void InitUART(void)
{
 TMOD=0x20;//Timer 1,Mode 2
 TH1 = -3;// 9600 baud rate at 11.059 MHz
 TR1=1; // Start Timer1
 TL1=-3;
 SCON=0x52;// 8-bit UART mode 1
}

void getline (char *line)  {
  while ((*line++ = getchar()) != '\n');
}

void main()
{
 unsigned char AT[] = "AT+CKPD=";
 unsigned char responce[2];
 InitUART();

 but = 1;
 but2 = 1;
 but3 = 1;
 but4 = 1;
 led = 0;
 while(1)
 {
  if(but == 0 || but2 == 0 || but3 == 0 || but4 == 0)
  {
   printf("AT+CKPD=");
                        putchar('"');
                        putchar('1');
                        putchar('"');
   putchar(0x0d);
   putchar(0x0a);
   getline(responce);
      //gets(responce,10);    // waiting for "OK" 
   // if(responce[0]=='O'&&responce[1]=='K')
//   printf(responce);
//   if((responce[0]=='O')&&(responce[1]=='K'))
//    led = 1;
//   else 
//    led = 0;

  }

No comments:

Post a Comment