Code mikroC cho hệ thống chống trộm.

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • trnghia1004
    Đệ tử 1 túi
    • Feb 2013
    • 15

    #1

    Code mikroC cho hệ thống chống trộm.

    Các anh cho em hỏi đoạn code em bị làm sao mà module sim của em nó không hiểu được, em nghĩ là do phần <CR><LF> có vấn đề.
    Attached Files
  • trnghia1004
    Đệ tử 1 túi
    • Feb 2013
    • 15

    #2
    // LCD module connections
    sbit LCD_RS at RB4_bit;
    sbit LCD_EN at RB5_bit;
    sbit LCD_D4 at RB0_bit;
    sbit LCD_D5 at RB1_bit;
    sbit LCD_D6 at RB2_bit;
    sbit LCD_D7 at RB3_bit;

    sbit LCD_RS_Direction at TRISB4_bit;
    sbit LCD_EN_Direction at TRISB5_bit;
    sbit LCD_D4_Direction at TRISB0_bit;
    sbit LCD_D5_Direction at TRISB1_bit;
    sbit LCD_D6_Direction at TRISB2_bit;
    sbit LCD_D7_Direction at TRISB3_bit;
    // End LCD module connections
    char str3[22],str2[20],str[20];
    char ch;
    int isti, idex, index = 0, ngat = 0,is = 0;
    void interrupt_rda()
    {
    if (Uart1_Data_Ready() == 1)
    {
    ch = Uart1_Read();
    // vi dieu khien se nhan chuoi phan hoi tu module_Sim
    if (isti == 1) // cho phep nhan chuoi khi da khoi tao thanh cong
    {
    if (ch == 10 && index == 0) // ch == <LF>
    is = 1; // bat dau nhan chuoi
    if (ch == 10 && index > 0) // ch == <CR>
    {
    idex = index;
    ngat = 1; // ket thuc 1 chuoi
    isti = 2;
    }
    if ((ch != 10) && (ch != 13) && (is = 1))
    {
    str[index] = ch;
    index++;
    }
    }
    }
    }
    int kiemtra()
    {
    int k,j;
    for (j = 0;j < idex; j++)
    {
    if (str2[0] == str[j])
    {
    for (k = 0; k < strlen(str2); k++)
    {
    if (str2[k] != str[j+k])
    break;
    }
    if (k == strlen(str2))
    {
    idex = 0;
    index = 0;
    return 1;
    }
    }
    }
    idex = 0;
    index = 0;
    return 0;
    }
    void send_sms_user()
    {
    Uart1_Write_Text("AT+CMGS\"01222066002\"");
    Uart1_Write(13);
    delay_ms(500);
    Uart1_Write_Text(str3);
    }
    void goidien()
    {
    Uart1_Write_Text("ATD01222066002;");
    Uart1_Write(13);
    delay_ms(8000);
    Uart1_Write("ATH");
    }
    void main()
    {
    ADCON1 = 0x0F;
    INTCON.GIE = 1;
    TRISD = 0X00;
    TRISC = 0XFF;
    PORTD = 0X00;
    PORTC = 0XFF;
    LCD_Init();
    Uart1_Init(9600);
    Lcd_Cmd(_LCD_CURSOR_OFF);
    Lcd_Cmd(_LCD_CLEAR);
    Uart1_Write_Text("AT");
    Uart1_Write(13);
    strcpy(str2,"OK");
    if (kiemtra() == 1)
    {
    Uart1_Write_Text("AT+IPR=9600");
    Uart1_Write(13);
    delay_ms(200);
    UART1_Write_Text("ATE1");
    Uart1_Write(13);
    delay_ms(200);
    UART1_Write_Text("AT+CMGF=1");
    Uart1_Write(13);
    delay_ms(200);
    UART1_Write_Text("AT+CMGD=1");
    Uart1_Write(13);
    delay_ms(200);
    }
    Lcd_Out(1,1,"HT Chong Trom");
    delay_ms(1000);
    while (1)
    {
    if (PORTC.F0 == 0)
    {
    PORTD.F0 = 1;
    Lcd_Out(2,1,"Co trom");
    strcpy(str3,"Co trom");
    send_sms_user();
    delay_ms(2000);
    goidien();
    }
    if (PORTC.F0 == 1)
    {
    PORTD.F0 = 0;
    LCD_OUT(2,1,"An Toan");
    }
    }
    }

    Comment

    • trnghia1004
      Đệ tử 1 túi
      • Feb 2013
      • 15

      #3
      có ai rành thì giúp mình với.
      I'm always appreciate with your help. Please!!!

      Comment

      Working...