Monday, 19 October 2015

PIC16F877A ADC(POT HG VALUE, VOLTAGE, TEMPERATURE)


//*****************************ADC CODE***********************//

#include<pic.h>
#include<htc.h>
#include"piclcd.h"
#include<stdio.h>
#define _PIC16F877A_H
//__CONFIG(PWRTE_ON & FOSC_HS & LVP_OFF & WDTE_OFF);

int adc()
{
unsigned int x;
GO=1;
while((ADCON0&0x04)==0x04);
x=(ADRESL+(ADRESH*255));
return x;
}
int main()

{
unsigned int v,a,t;
unsigned char z[40];
int i=0;
TRISD=0x00;
ADCON0=0xc1;
ADCON1=0Xc0;
lcd_init();
cmd(0x80);
string("EMBEDDED_LAB SUMMITBHARDWAJ.BLOGSPOT.IN");
while(1)
{
a=adc();
v=((a*5)/1023);
t=((a*5)/10.24);
sprintf(z,"adc=%3d volt=%2dV temp=%3d'c",a,v,t);
cmd(0xc0);
i=0;
while(z[i]!='\0')
{
dat(z[i]);
i++;
}
}
}
//****************************************************************//

//**************************LCD CODE****************************//
#include<pic.h>
#include<htc.h>
#include<stdio.h>
#define _PIC16F877A_H
__CONFIG(PWRTE_ON & FOSC_HS & LVP_OFF & WDTE_OFF);

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

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


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

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

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

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

PORTD=l|0X50;
delay(20);
PORTD=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);
}


void num(unsigned int p)
{
unsigned int k,w,b=1;
k=p;
while(k>=10)
{
b=b*10;
k=k/10;
}
while(b>=1)
{
w=p/b;
p=p%b;
b=b/10;
dat(w+48);
}
}

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



No comments:

Post a Comment