Professional Documents
Culture Documents
*/
#include <REGX51.H>
#define VREF 5 //VREF=5V
//Khai bao chan giao tiep ADC0808
#define ADC0808_DATA P2 //PORT
#define ADC0808_A P3_3 //PIN
#define ADC0808_B P3_2
#define ADC0808_C P3_1
#define ADC0808_ALE P3_0
#define ADC0808_START P3_5
#define ADC0808_EOC P3_6
#define ADC0808_OE P3_7
#define ADC0808_CLK P2_7
//Khai bao chan giao tiep LCD16x2 4bit
#define LCD_RS P0_1
#define LCD_RW P0_2
#define LCD_EN P0_3
#define LCD_D4 P0_4
#define LCD_D5 P0_5
#define LCD_D6 P0_6
#define LCD_D7 P0_7
unsigned char d=0x00;
tmp2 = tmp2>>4;
t = tmp1+tmp2*16;
new_value = t;
if(new_value != prev_value)
if(t>=100)
t1=t%10;
asci[2]=t1+0x30;
t=t/10;
t1=t%10;
asci[1]=t1+0x30;
t = t/10;
asci[0] = t+0x30;
else
t1=t%10;
asci[1]=t1+0x30;
t=t/10;
asci[0]=t+0x30;
asci[2] = 0x20;
LCD_SendCommand(0xC0);
for(j=0;j<=2;j++)
LCD_PutChar(asci[j]);
LCD_SendCommand(0x94);
prev_value = new_value;
void khoitao()
P1=0xFF;
P2=0x00;
P0 = 0x00;
P3=0x08;
WR = 1;
RD = 1;
IE=0x84;
void main()
khoitao();
LCD_Init();
LCD_SendCommand(0x01);
LCD_Puts("light intensity=");
while(1)
WR=0;
WR=1;
while(d==0x00);
hienthicuongdosang();
delay_ms(10);
d = 0x00;