#include<htc.h>
#define motor RB1
#define buzz RC3
#include"lcdsub.c"
#include"adcsub.c"
#include"serialsub.c"
/*void serialwrite(char tx);
char serialread();
void serialstr(char *serstr);
void dream(int);*/
//void serialstr(int);
void dream(int u)
{
while(u--);
}
void main()
{
TRISB=0X00;
TRISD=0X00;
TRISC=0X00;
TRISC6=0X00;
lcdint();
serialint();
adcint(0xc1); //ch 1 AN0
//adcint(0xc9); //ch2 AN1
lcdstr("..INITIALIZING..");
dream(6500);
dream(65000);
serialstr("serial communication OK...\r");
serialstr("reading sensor values");
lcdcmd(0x01);
lcdstr("READING SNR VAL");
//buzz=0;
//motor=1;
while(1)
{
adcfun1();
//lcdcmd(0xc0);
serialstr("\r");
dream(100);
serialstr("CH1:");
lcdch1();
adcfun2();
serialstr(" ");
serialstr("CH2:");
lcdch2();
serialstr("\r");
buzz=0;
motor=1;
//break;
while(a2>=0 && b2>=5 && c2>=0)
{
buzz=1;
motor=0;
lcdcmd(0x01);
lcdstr("ACCIDENT OCCURED");
lcdcmd(0xc0);
lcdstr("call HELP!!!");
serialstr("Calling help.....dialing\r");
a2,b2,c2=0;
lcdcmd(0x01);
break;
/*if(a2<=0 && b2<=5 && c2<=0)
{
break;
}*/
}
}
}
#define rs RC0
#define rw RC1
#define en RC2
int count=0;
int adc=0;
int p=192;
void lcdint();
void lcddisp(char chr);
void lcdcmd(int cmd);
void delay(int s);
void lcdstr(unsigned char *str);
void lcddisp1(char);
void delay(int s)
{
while(s--);
}
void lcdint()
{
lcdcmd(0x38);
lcdcmd(0x01);
lcdcmd(0x0E);
lcdcmd(0x06);
lcdcmd(0x80);
}
void lcdread()
{
char chrrd;
rw=1;
rs=1;
chrrd=PORTD;
en=1;
delay(100);
en=0;
}
void lcddisp(char chr)
{
/*if(count==16)
{
lcdcmd(0x80);
lcdstr(" ");
lcdcmd(0x80);
count=0;
}
if(adc==1)
{
lcdcmd(p);
rw=0;
rs=1;
PORTD=chr;
en=1;
delay(100);
en=0;
p++;
}*/
rw=0;
rs=1;
PORTD=chr;
en=1;
delay(100);
en=0;
//count++;
}
void lcdcmd(int cmd)
{
rw=0;
rs=0;
PORTD=cmd;
en=1;
delay(100);
en=0;
if(cmd==0x01)
count=0;
}
void lcddisp1(char disp1)
{
rw=0;
rs=1;
PORTD=disp1;
en=1;
delay(100);
en=0;
}
void lcdstr(unsigned char *str)
{
while(*str)
{
delay(2500);
lcddisp1(*str++);
}
}
char a,volt;
int a1,b1,c1,a2,b2,c2;
int ch=0;
void serialwrite(char);
void elay(int s)
{
while(s--);
}
void adcint(int ch)
{
ADCON0=ch;
ADCON1=0x82;
ADIF=0;
}
unsigned int adcread()
{
ADGO=1;
while(ADGO==1);
elay(100);
ADGO=0;
ADIF=0;
a=(ADRESH<<8 | ADRESL)*0.49;
return(a);
}
void convert(char volt)
{
//serialwrite(volt);
int d,e,f,g=0;
d=a/100;
e=a%100;
f=e/10;
g=e%10;
if(ch==0)
{
a2=d;
b2=f;
c2=g;
}
if(ch==1)
{
a1=d;
b1=f;
c1=g;
}
//adc=1;
/*lcddisp(d+0x30);
elay(10);
lcddisp(f+0x30);
elay(10);
lcddisp(g+0x30);
//p=192;
//adc=0;
lcdcmd(0x80);
elay(1000);
*/
}
void adcfun1()
{
adcint(0xc1);
volt=adcread();
convert(volt);
elay(6500);
ch=0;
}
void adcfun2()
{
adcint(0xc9);
volt=adcread();
convert(volt);
elay(6500);
ch=1;
}
/*
void main()
{
char volt;
TRISA=0xff;
TRISE=0x00;
TRISD=0x00;
TRISC=0x00;
while(1)
{
intlcd();
adcint(0xc1);
volt=adcread();
convert(volt);
elay(6500);
lcdcmd(0x01);
}
}
*/
lcdch1()
{
serialwrite(a1+0x30);
elay(10);
serialwrite(b1+0x30);
elay(10);
serialwrite(c1+0x30);
//lcdcmd(0x80);
elay(10000);
//lcdcmd(0x01);
}
lcdch2()
{
serialwrite(a2+0x30);
elay(10);
serialwrite(b2+0x30);
elay(10);
serialwrite(c2+0x30);
//lcdcmd(0x80);
elay(10000);
//lcdcmd(0x01);
}
#define xtalfreq 4000000
#define baudrate 9600
void serialwrite(char);
void serialint()
{
TRISC6=0;
TRISC7=1;
SPBRG=25;//((xtalfreq/16)*1/baudrate)-1;
BRGH=1;
SYNC=0;
SPEN=1;
CREN=1;
SREN=0;
TXIE=0;
RCIE=1;
TX9=0;
RX9=0;
TXEN=0;
TXEN=1;
}
void serialwrite(char tx)
{
TXREG=tx;
while(TRMT==0);
TRMT=0;
}
char serialread()
{
char rx;
while(RCIF==0);
rx=RCREG;
RCIF=0;
return (rx);
}
void serialstr(char *serstr)
{
while(*serstr)
{
serialwrite(*serstr++);
}
}
#define motor RB1
#define buzz RC3
#include"lcdsub.c"
#include"adcsub.c"
#include"serialsub.c"
/*void serialwrite(char tx);
char serialread();
void serialstr(char *serstr);
void dream(int);*/
//void serialstr(int);
void dream(int u)
{
while(u--);
}
void main()
{
TRISB=0X00;
TRISD=0X00;
TRISC=0X00;
TRISC6=0X00;
lcdint();
serialint();
adcint(0xc1); //ch 1 AN0
//adcint(0xc9); //ch2 AN1
lcdstr("..INITIALIZING..");
dream(6500);
dream(65000);
serialstr("serial communication OK...\r");
serialstr("reading sensor values");
lcdcmd(0x01);
lcdstr("READING SNR VAL");
//buzz=0;
//motor=1;
while(1)
{
adcfun1();
//lcdcmd(0xc0);
serialstr("\r");
dream(100);
serialstr("CH1:");
lcdch1();
adcfun2();
serialstr(" ");
serialstr("CH2:");
lcdch2();
serialstr("\r");
buzz=0;
motor=1;
//break;
while(a2>=0 && b2>=5 && c2>=0)
{
buzz=1;
motor=0;
lcdcmd(0x01);
lcdstr("ACCIDENT OCCURED");
lcdcmd(0xc0);
lcdstr("call HELP!!!");
serialstr("Calling help.....dialing\r");
a2,b2,c2=0;
lcdcmd(0x01);
break;
/*if(a2<=0 && b2<=5 && c2<=0)
{
break;
}*/
}
}
}
#define rs RC0
#define rw RC1
#define en RC2
int count=0;
int adc=0;
int p=192;
void lcdint();
void lcddisp(char chr);
void lcdcmd(int cmd);
void delay(int s);
void lcdstr(unsigned char *str);
void lcddisp1(char);
void delay(int s)
{
while(s--);
}
void lcdint()
{
lcdcmd(0x38);
lcdcmd(0x01);
lcdcmd(0x0E);
lcdcmd(0x06);
lcdcmd(0x80);
}
void lcdread()
{
char chrrd;
rw=1;
rs=1;
chrrd=PORTD;
en=1;
delay(100);
en=0;
}
void lcddisp(char chr)
{
/*if(count==16)
{
lcdcmd(0x80);
lcdstr(" ");
lcdcmd(0x80);
count=0;
}
if(adc==1)
{
lcdcmd(p);
rw=0;
rs=1;
PORTD=chr;
en=1;
delay(100);
en=0;
p++;
}*/
rw=0;
rs=1;
PORTD=chr;
en=1;
delay(100);
en=0;
//count++;
}
void lcdcmd(int cmd)
{
rw=0;
rs=0;
PORTD=cmd;
en=1;
delay(100);
en=0;
if(cmd==0x01)
count=0;
}
void lcddisp1(char disp1)
{
rw=0;
rs=1;
PORTD=disp1;
en=1;
delay(100);
en=0;
}
void lcdstr(unsigned char *str)
{
while(*str)
{
delay(2500);
lcddisp1(*str++);
}
}
char a,volt;
int a1,b1,c1,a2,b2,c2;
int ch=0;
void serialwrite(char);
void elay(int s)
{
while(s--);
}
void adcint(int ch)
{
ADCON0=ch;
ADCON1=0x82;
ADIF=0;
}
unsigned int adcread()
{
ADGO=1;
while(ADGO==1);
elay(100);
ADGO=0;
ADIF=0;
a=(ADRESH<<8 | ADRESL)*0.49;
return(a);
}
void convert(char volt)
{
//serialwrite(volt);
int d,e,f,g=0;
d=a/100;
e=a%100;
f=e/10;
g=e%10;
if(ch==0)
{
a2=d;
b2=f;
c2=g;
}
if(ch==1)
{
a1=d;
b1=f;
c1=g;
}
//adc=1;
/*lcddisp(d+0x30);
elay(10);
lcddisp(f+0x30);
elay(10);
lcddisp(g+0x30);
//p=192;
//adc=0;
lcdcmd(0x80);
elay(1000);
*/
}
void adcfun1()
{
adcint(0xc1);
volt=adcread();
convert(volt);
elay(6500);
ch=0;
}
void adcfun2()
{
adcint(0xc9);
volt=adcread();
convert(volt);
elay(6500);
ch=1;
}
/*
void main()
{
char volt;
TRISA=0xff;
TRISE=0x00;
TRISD=0x00;
TRISC=0x00;
while(1)
{
intlcd();
adcint(0xc1);
volt=adcread();
convert(volt);
elay(6500);
lcdcmd(0x01);
}
}
*/
lcdch1()
{
serialwrite(a1+0x30);
elay(10);
serialwrite(b1+0x30);
elay(10);
serialwrite(c1+0x30);
//lcdcmd(0x80);
elay(10000);
//lcdcmd(0x01);
}
lcdch2()
{
serialwrite(a2+0x30);
elay(10);
serialwrite(b2+0x30);
elay(10);
serialwrite(c2+0x30);
//lcdcmd(0x80);
elay(10000);
//lcdcmd(0x01);
}
#define xtalfreq 4000000
#define baudrate 9600
void serialwrite(char);
void serialint()
{
TRISC6=0;
TRISC7=1;
SPBRG=25;//((xtalfreq/16)*1/baudrate)-1;
BRGH=1;
SYNC=0;
SPEN=1;
CREN=1;
SREN=0;
TXIE=0;
RCIE=1;
TX9=0;
RX9=0;
TXEN=0;
TXEN=1;
}
void serialwrite(char tx)
{
TXREG=tx;
while(TRMT==0);
TRMT=0;
}
char serialread()
{
char rx;
while(RCIF==0);
rx=RCREG;
RCIF=0;
return (rx);
}
void serialstr(char *serstr)
{
while(*serstr)
{
serialwrite(*serstr++);
}
}
No comments:
Post a Comment