char a,volt;
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)
{
int d,e,f,g;
d=a/100;
e=a%100;
f=e/10;
g=e%10;
adc=1;
lcddisp(d+0x30);
elay(10);
lcddisp(f+0x30);
elay(10);
lcddisp(g+0x30);
p=192;
adc=0;
lcdcmd(0x80);
elay(1000);
}
void adcfun()
{
adcint(0xc1);
volt=adcread();
convert(volt);
elay(6500);
}
/*
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);
}
}
*/
#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++);
}
}
#include<htc.h>
#include<string.h>
#include"lcdsub.c"
#include "serialsub.c"
#include"adcsub.c"
void main()
{
TRISD=0x00;
TRISC=0X00;
TRISA=0xff;
TRISC=0x00;
TRISC7=1;
lcdint();
serialint();
adcint(0xc1);
lcdstr("spiro tech's");
delay(12500);
delay(100);
serialwrite('o');
serialwrite('k');
lcdcmd(0x01);
char volt;
adcfun();
while(1)
{
char chr;
chr=serialread();
serialwrite(chr);
lcddisp(chr);
}
}
#define xtalfreq 4000000
#define baudrate 9600
void serialwrite(char tx);
char serialread();
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);
}
#define xtalfreq 4000000
#define baudrate 9600
void serialwrite(char tx);
char serialread();
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);
}
No comments:
Post a Comment