Documentos de Académico
Documentos de Profesional
Documentos de Cultura
sbit LCD_RS_Direction at TRISB2_bit; sbit LCD_EN_Direction at TRISB3_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit;
unsigned char Convert(unsigned char); void disp(void); void msgsend(void); unsigned long Vin, mV,Vdec,Vfrac; unsigned char op[12]; unsigned char i,j,lcd[5],ch1,ch2,temp;
unsigned char ch; unsigned int adc_rd; char *text; long tlong; // end lcd module connections
//const char atc10[] = "AT+CMGD=1"; const char atc10[] = "AT+CMGF=1"; const char atc12[] = "AT+CMGS=";
const char atc14[] = "High Temperature is read from Patient of 333"; const char atc13[] = "+919848160532" ; const char atc15[] = "Doctor Attended The Patient of 333"; const char atc16[] = "Sensor 3 reading is out of range";
// lcd interface messages const LCD_MESSAGE_LENGTH = 16; const char lcd1[] = "Initializing...."; const char lcd2[] = "Power-Up GSM!!!"; const char lcd3[] = "RD3-Continue"; const char lcd4[] = "System Ready! ";
char gsm_state = 0; char response_rcvd = 0; short responseID = -1, response = -1; char msg[LCD_MESSAGE_LENGTH+1];
// copy const to ram string char * CopyConst2Ram(char * dest, const char * src){ char * d ; d = dest; for(;*dest++ = *src++;) ; return d; }
char tmp; if (PIR1.RCIF == 1) { tmp = UART1_Read(); // do we have uart rx interrupt request? // get received byte
// process reception through state machine // we are parsing only "OK" and "RING" responses switch (gsm_state) { case 0: { response = -1; if (tmp == 'O') gsm_state = 1; break; } case 1: { if (tmp == 'K') { response = GSM_OK; gsm_state = 50; } else gsm_state = 0; break; } // reset state machine // we have 'K' -> // we have "OK" response // expecting CR+LF // clear response // we have 'O', it could be "OK" // expecting 'K'
gsm_state = 51; else gsm_state = 0; break; } case 51: { if (tmp == 10) { response_rcvd = 1; responseID = response; } gsm_state = 0; break; }
// expecting LF
void send_atc1(const char *st) { // send command string while(*st) { UART1_Write(*st++); } } // get GSM response, if there is any short get_response() { if (response_rcvd) { response_rcvd = 0; return responseID; } else return -1;
// wait for GSM response void wait_response(char rspns) { while (get_response() != rspns) ; }
TRISB=0x00; TRISC=0x00; TRISD0_bit = 1; TRISD1_bit = 1; TRISD2_bit = 1; TRISD3_bit = 1; // place a call input // hang up input // answer a call input // continue with PIC program
LCD_Out(2,1,CopyConst2Ram(msg,lcd3));
UART1_init(9600);
Delay_ms(5000);
LCD_Out(1,1,"--- Sensor --- "); text = "VALUE: 0.00"; LCD_Out(2,1,text); // assign text to string
while(1) { LCD_Out(1,12,"1"); Vin = ADC_read(1); // get ADC value from 2nd channel
; t= Convert(adc_rd);
//comparision
if(t>0x28) {
msgsend()
; // Mesg to be sent
/*
Delay_ms(4000);
//comparision
LCD_Out(1,12,"2"); Vin = ADC_read(2); t = Convert(adc_rd); // get ADC value from 2nd channel
if(t<0x09) { if(m==1)
Delay_ms(4000);
LCD_Out(1,12,"3");
Vin = ADC_read(3);
t = Convert(adc_rd);*/
/*
//comparision
send_atc1(atc16); UART1_Write(0x1A);
*/
//Delay_ms(2000);
// while (1)
// Lcd_Cmd(LCD_CLEAR);
Vin = 488*Vin; // Scale up the result Vin = Vin /10; // Convert to temperature in C Vdec = Vin / 100; // Decimal part Vfrac = Vin % 100; // Fractional part LongToStr(Vdec,op); // Convert Vdec to string in "op" temp = Vdec;
Lcd_Out(2,7,lcd); // Output to LCD Lcd_Chr_Cp('.'); // Display "." ch1 = Vfrac / 10; // Calculate fractional part ch2 = Vfrac % 10; // Calculate fractional part Lcd_Chr_Cp(48+ch1); // Display fractional part Lcd_Chr_Cp(48+ch2); // Display fractional part
return temp;
void disp(void) {
Lcd_Init();
// Lcd_Init_EP4, see Autocomplete // send command to LCD (cursor off) // send command to LCD (clear LCD)
LCD_Cmd(_LCD_CURSOR_OFF); LCD_Cmd(_LCD_CLEAR);
// assign text to string // print string a on LCD, 2nd row, 1st column
Delay_ms(4000); }
void msgsend(void) {
send_atc1(atc12); UART1_Write(0x22);
//sending mesg
//Phone number
// wait_response(GSM_OK);
Delay_ms(500); }