Sei sulla pagina 1di 4

#include <stdint.

h>
#include "G:\cources\embedded\microprocessor based\arm\ARM\tm4c123gh6pm.h"
#include "delay.h"
#include "portf_init.h"
#include "portb_init.h"
#include "systick_init_with_interrupt.h"
#include "esb.h"
#include "uart.h"
#include "adc.h"
//==================================================
===========================
void ready_(void);
//==================================================
===========================
extern uint16_t count1; //5 times loop
extern uint16_t count2;
extern uint16_t count3;
char status=0;
//==================================================
===========================
void main(void)
{
portf_init();
portb_init();
GPIO_PORTB_DATA_R |= 0x10;
SysTick_Init_with_interrupt(160000); //interrupt every 10 milli sec
serial0_begin(9600);
delayMs(500);
esb_init();
while(1)
{
ready_();

//==================================================
==========
if(count3 >400) //init every 10 sec
{
esb_init();
count3=0;
}
if(count2 > 300) //send pilot every 3 sec
{
serial0_write_str("AT+CIPSEND=0,4\r\n"); delayMs(100);
serial0_write_str("Fp\r\n"); delayMs(50);
count2=0;
}

//==================================================
==========
if((GPIO_PORTB_DATA_R & 0x01)==0) {status=1; count1=0;}
if((GPIO_PORTB_DATA_R & 0x02)==0) {status=2; count1=0;}
if((GPIO_PORTB_DATA_R & 0x04)==0) {status=3; count1=0;}
if((GPIO_PORTB_DATA_R & 0x08)==0) {status=4; count1=0;}
int i=0;
while(status)
{
switch(status)
{
case 1 :
{
for(i=0 ; i<5 && status ;)
{
if(count1>30) //every 300 milli sec
{

serial0_write_str("AT+CIPSEND=0,4\r\n"); delayMs(100); serial0_write_str("Ft\r\n");


//touch
count1=0;i++;
}
ready_();
}
status=0; // send 5 times and stop
break;
}
case 2 :
{
for(i=0 ; i<5 && status ;)
{
if(count1>30)
{

serial0_write_str("AT+CIPSEND=0,4\r\n"); delayMs(100); serial0_write_str("Fd\r\n");


//open door
count1=0;i++;
}

ready_();
}
status=0; // send 25 times and stop
break;
}
case 3 :
{
for(i=0 ; i<5 && status ;)
{
if(count1>30)
{

serial0_write_str("AT+CIPSEND=0,4\r\n"); delayMs(100); serial0_write_str("Fw\r\n");


//wheel
count1=0;i++;
}

ready_();
}
status=0; // send 25 times and stop
ready_(); break;
}
case 4 :
{
for(i=0 ; i<5 && status ;)
{
if(count1>30)
{

serial0_write_str("AT+CIPSEND=0,4\r\n"); delayMs(100); serial0_write_str("Fa\r\n");


//air condition
count1=0;i++;
}
ready_();
}
status=0; // send 25 times and stop
ready_(); break;
}
}
}

//==================================================
==========

if(!(GPIO_PORTF_DATA_R & 0x01))


{
serial0_write_str("AT+CIPMUX=1\r\n");
//GPIO_PORTF_DATA_R=0x08;
delayMs(100);
serial0_write_str("AT+CIPSEND=0,4\r\n");
//GPIO_PORTF_DATA_R=0x04;
delayMs(100);
serial0_write_str("Fa\r\n");
GPIO_PORTF_DATA_R=0x00;
}
}
}
//==================================================
===================================================
=============================
void ready_(void)
{
if(serial0_available())
{
char c = serial0_read();
if((c=='C'))
{
while(!serial0_available());
switch (serial0_read())
{
case 'h': GPIO_PORTF_DATA_R=0x0C;
delayMs(100); GPIO_PORTF_DATA_R=0x00; //for debuging purpose
serial0_write_str("AT+CIPSEND=0,4\r\n");
delayMs(100); serial0_write_str("Co\r\n"); //ack
break;

case 'i': GPIO_PORTF_DATA_R=0x0A;


delayMs(100); GPIO_PORTF_DATA_R=0x00;
serial0_write_str("AT+CIPSEND=0,4\r\n");
delayMs(100); serial0_write_str("Co\r\n"); //ack
break;

case 'e':GPIO_PORTF_DATA_R=0x08;
delayMs(100); GPIO_PORTF_DATA_R=0x00; //switch car's electricity of
serial0_write_str("AT+CIPSEND=0,4\r\n");
delayMs(100); serial0_write_str("Co\r\n"); //ack
break;

case 'o':GPIO_PORTF_DATA_R=0x04;
delayMs(100); GPIO_PORTF_DATA_R=0x00; //for debuging purpose
// serial0_write_str("AT+CIPSEND=0,4\r\n");
delayMs(100); serial0_write_str("Co\r\n"); //ack
status=0;count2=0;count3=0;
break;

case 'L':GPIO_PORTF_DATA_R=0x04;
delayMs(100); GPIO_PORTF_DATA_R=0x00; //for debuging purpose
esb_init(); count2=0;count3=0;
break;
}
}
else if(c=='F')
{
while(!serial0_available());
if(serial0_read()=='A') esb_init();
}
count2=0; // reset because you are recieving data
}
}

Potrebbero piacerti anche