<font color=#000066>DESIGN OF LDR</font>
#include <reg51.h>
#include <math.h>
#include "header.h"
#include "pcf8591.c"
#include "i2c.c"
#include "lcd.C"
unsigned char adc1,adc2,adc3,adc4,predata; /* adc local variable declaration*/
/********************** Main function ****************************/
void init()
{
IE = 0x81;
TCON =0x41;
SCON = 0x50;
/* uart in mode 1 (8 bit), REN=1 */
TMOD = TMOD | 0x20 ; /* Timer 1 in mode 2 */
TH1 = 0xF5; /* 9600 Bds at 11.059MHz */
TL1 = 0xF5; /* 9600 Bds at 11.059MHz */
EA = 1; /* Enable global interrupt */
TR1 = 1;
}
void split_numbers(unsigned int number)
{
hundreds = (number / 100);
number %= 100;
tens = (number / 10);
number %= 10;
ones = number ;
}
void main(void)
{
//char *str1=",*str2;
delay(10000); /* startup delay.*/
lcdinit(); /* initialize on board LCD.*/
clrscr(10); /* it cleares both the screen */
printstr(" LDR ",0,0); /* Print string into LCD Screen.*/
printstr(" Data Logger ",0,1); /* Print string into LCD Screen.*/
delay(10000);
delay(10000);
delay(10000);
delay(10000);
clrscr(10); /* it cleares both the screen */
printstr("INTENSITY: ",0,0); /* Print string into LCD Screen.*/
init();
while(1)
{
/* Get ADC Value */
adc1 = PCF8591_get(CH1);
adc2 = PCF8591_get(CH2);
adc3 = PCF8591_get(CH3);
adc4 = PCF8591_get(CH4);
/* Show CH2 on LCD */ predata = ((adc2*100)/255);
gotoxy(11,0);
split_numbers(predata);
lcddat(hundreds+0x30);
lcddat(tens+0x30);
lcddat(ones+0x30);
lcddat(' ');
lcddat('%');
lcddat(' ');