Tuesday, 20 October 2015

PIC16F1518 4ADC VALUE ON LCD PROJECT





#include<pic.h>
#include<htc.h>
#include<stdio.h>
#define __PIC16F1518_H
#define _XTAL_FREQ   16000000

__CONFIG( FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & CP_OFF & BOREN_ON & LVP_OFF );
unsigned char z[40],z1[40],z2[40],z3[40];
unsigned int v,t,w,w1,w2,w3;



void delay(unsigned int i)
{
while(i--);
}



void cmd(unsigned char c)
{
unsigned int l,h;
l=c &0X0F;
h=c>>4;


PORTB=h|0X40;
delay(20);
PORTB=h|0X00;

PORTB=l|0X40;
delay(20);
PORTB=l|0X00;
}



void dat (unsigned char c)
{
unsigned int l,h;
l=c &0X0F;
h=c>>4;

PORTB=h|0X50;
delay(20);
PORTB=h|0X10;

PORTB=l|0X50;
delay(20);
PORTB=l|0X10;
}



void lcd_init()
{
cmd(0x02);
delay(100);
cmd(0x28);
delay(100);
cmd(0x01);
delay(100);
cmd(0x80);
delay(100);
cmd(0x0e);
delay(100);
    cmd(0x0c);
delay(100);
}



void string(unsigned char *p)
{
while(*p!='\0')
{
dat(*p);
p++;
     
}
}



int adc(unsigned char ch)
{
unsigned int x;
TRISA=0XFF;
TRISB=0X00;
TRISC=0XFC;
ANSELA=0x0F;
ADCON0=(0x01)|ch;
ADCON1=0XF0;
delay(100);
GO_nDONE=1;
while(GO_nDONE);
x=(ADRESL+(ADRESH*255));
return x;
}




int main()
{
//LATB = 0x00;
int i=0;
TRISB=0x00;
lcd_init();
while(1)

{
            w=adc(0x00);
            delay(100);
            w1=adc(0x04);
            delay(100);
            w2=adc(0x08);
            delay(100);
            w3=adc(0x0C);

            v=((w*5)/1023);
t=((w*5)/10.24);
sprintf(z,"a1=%3d v=%2dV t=%3d'c|",w,v,t);
cmd(0x80);
i=0;
while(z[i]!='\0')
{
dat(z[i]);
i++;
}
 
            v=((w1*5)/1023);
t=((w1*5)/10.24);
sprintf(z1,"a2=%3d v=%2dV t=%3d'c|",w1,v,t);
cmd(0xc0);
i=0;
while(z1[i]!='\0')
{
dat(z1[i]);
i++;
}
            v=((w2*5)/1023);
t=((w2*5)/10.24);
sprintf(z2,"a3=%3d v=%2dV t=%3d'c",w2,v,t);
cmd(0x95);
i=0;
while(z2[i]!='\0')
{
dat(z2[i]);
i++;
}
            v=((w3*5)/1023);
t=((w3*5)/10.24);
sprintf(z3,"a4=%3d v=%2dV t=%3d'c",w3,v,t);
cmd(0xd5);
i=0;
while(z3[i]!='\0')
{
dat(z3[i]);
i++;
}
        }
}

No comments:

Post a Comment