#include <htc.h>
unsigned char temp2;
unsigned char temp3;
unsigned char lsb;
unsigned char msb;
unsigned char mmb;
void dataconv(unsigned char);
void dataconv(unsigned char data)
{
lsb=data%10;
lsb=48|lsb;
data=data/10;
mmb=data%10;
mmb=48|mmb;
msb=data/10;
msb=48|msb;
}
void delay()
{
int i;
for(i=0;i<12275;i++);
}
void serialwrite(unsigned char data)
{
TXREG=data;
while(TXIF==0);
}
void interrupt ISR(void)
{
if(RCIF==1)
{
RC0=1;
if(RCREG=='a'){
serialwrite('b');
dataconv(temp2);
serialwrite(msb);
delay();
serialwrite(mmb);
delay();
serialwrite(lsb);
dataconv(temp3);
serialwrite(msb);
delay();
serialwrite(mmb);
delay();
serialwrite(lsb);
}
}
}
void main()
{
TXSTA=0X20;
RCSTA=0X90;
SPBRG=129;
BRGH=1;
TRISC7=1;
TRISC6=0;
TRISA=0XFF;
TRISD=0X00;
TRISB=0X00;
ADCON0=0X01;
ADCON1=0X0C;
ADCON2=0X2D;
PEIE=1;
GIE=1;
RCIE=1;
serialwrite('a');
delay();
serialwrite('b');
while(1)
{
delay();
ADCON0=0X05;
GODONE=1;
while(GODONE==1);
PORTD=ADRESH;
temp2=ADRESH;
delay();
ADCON0=0X09;
GODONE=1;
while(GODONE==1);
temp3=ADRESH;
}
}