//PIC16F877, 4MHZ, LCD

// LCD module connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

int fogadott1;
int fogadott2;
int fogadott3;
int fogadott4;
int fogadott5;
int fogadott6;
int fogadott7;
int fogadott8;
int fogadott9;
int fogadott10;
int fogadott11;
int fogadott12;
int fogadott13;

char *keszenlet = "GSM VEZERLO";
int ciklus;
signed char szam0[9] = {'3','0','1','2','3','4','5','6','7'};
void main()
{
//Adcon1 = 0x07 ;
TRISA = 0;
PORTB = 0;
TRISB = 0; // PORTB is output
PORTB = 0;
TRISE = 0; // PORTB is output
PORTE.B0=0x01;
Lcd_Init(); // Initialize LCD connected to PORTB
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
UART1_Init(19200) ;
Delay_ms(2000);
UART1_Write_Text("START");
//UART1_Write(10);
//UART1_Write(13);

akarmi:
Lcd_Out(1, 1, keszenlet);
if(UART1_Data_Ready())
{
fogadott1=fogadott2;
fogadott2=fogadott3;
fogadott3=fogadott4;
fogadott4=UART1_Read();
}
// vizsgálat, hogy a kapott adat a "RING"-e
if(fogadott1==82 & fogadott2==73 & fogadott3==78 & fogadott4==71)
{
// telefonszám lekérése
Delay_ms(3000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 3, "LEKERDEZES");
UART1_Write(65); //A
UART1_Write(84); //T
UART1_Write(43); //+
UART1_Write(67); //C
UART1_Write(76); //L
UART1_Write(67); //C
UART1_Write(67); //C
UART1_Write(13); //enter

while(fogadott1!=34){
if(UART1_Data_Ready())
{
fogadott1=fogadott2;
fogadott2=fogadott3;
fogadott3=fogadott4;
fogadott4=fogadott5;
fogadott5=fogadott6;
fogadott6=fogadott7;
fogadott7=fogadott8;
fogadott8=fogadott9;
fogadott9=fogadott10;
fogadott10=fogadott11;
fogadott11=fogadott12;
fogadott12=fogadott13;
fogadott13=UART1_Read();
}
}
// telefonszám vizsgálata:
if(fogadott1==34 &     //"
fogadott2==43 &        //+
fogadott3==51 &        //3
fogadott4==54 &        //6
fogadott5==51 &        //3
fogadott6==48 &        //0
fogadott7==00 &        //
fogadott8==00 &        //
fogadott9==00 &        //
fogadott10==00 &       //
fogadott11==00 &       //
fogadott12==00 &       //
fogadott13==00)        //
{
//PORTB.B0=0x01;  //SZAM RENDBEN
//PORTB.B3=0x00;
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 2, "SZAM RENDBEN");
UART1_Write(65); //A
UART1_Write(84); //T
UART1_Write(43); //+
UART1_Write(67); //C
UART1_Write(72); //H
UART1_Write(85); //U
UART1_Write(80); //P
UART1_Write(13); //enter
UART1_Write(10); //új sor
//Lcd_Out(1, 1, riado );
delay_ms(3000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 3, "VISSZAHIVAS");
UART1_Write('A'); //A
UART1_Write('T'); //T
UART1_Write('D'); //D
UART1_Write('+'); //+
UART1_Write('3'); //0
UART1_Write('6'); //6
for (ciklus=0 ; ciklus<9 ; ciklus++)
{
UART1_Write(szam0[ciklus]);
}
UART1_Write(';'); //;
UART1_Write(13); //enter
UART1_Write(10); //új sor
Delay_ms(8000);

}
// hívás visszautasítása:
Delay_ms(5000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 2, "BEKAPCSOLAS");
PORTB.B0=0x01;
Delay_ms(2000);
UART1_Write(65); //A
UART1_Write(84); //T
UART1_Write(43); //+
UART1_Write(67); //C
UART1_Write(72); //H
UART1_Write(85); //U
UART1_Write(80); //P
UART1_Write(13); //enter
}
goto akarmi;
}