#include<pic.h>
#include<htc.h>
#include<stdio.h>
#include"piclcd.h"
#define _PIC16F877A_H
//__CONFIG(PWRTE_ON & FOSC_HS & LVP_OFF & WDTE_OFF);
unsigned int volt,adcSmpl,time;
void fan();
int adc()
{
unsigned int x;
GO=1;
while((ADCON0&0x04)==0x04);
x=(ADRESL+(ADRESH*255));
return x;
}
int main()
{
unsigned char z[40];
int i=0;
TRISD=0x00;
TRISC=0x00;
ADCON0=0xc1;
ADCON1=0Xc0;
lcd_init();
cmd(0x80);
string("EMBEDDED_LAB, SUMMITBHARDWAJ.BLOGSPOT.IN");
while(1)
{
adcSmpl=adc();
volt=((adcSmpl*5)/1023);
time=((adcSmpl*5)/10.24);
sprintf(z,"adc=%3d volt=%2dV temp=%3d'c",adcSmpl,volt,time);
cmd(0xc0);
//PORTC=0x02;
fan();
i=0;
while(z[i]!='\0')
{
dat(z[i]);
i++;
}
}
}
void fan()
{
if(adcSmpl <= 62)
{
PORTC=0x01;
}
else if(adcSmpl <= 123)
{
PORTC=0x02;
}
else if(adcSmpl <= 185)
{
PORTC=0x04;
}
else
{
PORTC=0x07;
}
}
//************************************LCD.H******************************//
#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