| ??? 08/05/05 07:14 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#98844 - Try this, It works and it's cheap Responding to: ???'s previous message |
Try this, It is not very accurate, but it works.
And it is cheap. Choose R2 to get a result of 253 in the dark. To get another range change C1. Have a nice day. Robert.
+ 5V
|
+---------+
| |
/ R1 / R2
/ LDR / About 33 K
/ /
/ /
| |
+---------+-------> I/O PORT
|
= C1: 200 nF
|
|
+ GND
; ***************************************
; * Sense light
; ***************************************
LDR BIT P3.3
LICHT DATA 5Eh
GETLIGHT: CLR LDR ; Discharge capacitor
MOV A,#100 ; Wait until empty
WACHT: DJNZ ACC,WACHT ; A is zero
SETB LDR ; C starts loading
LDR10: JB LDR,LDR20 ; It is high
INC A ; Count the time it takes
JNZ LDR10 ; te get high, Overflow
DEC A ; result is 255
LDR20: MOV LICHT,A ; Save value
RET
Result:
0 Very light
4 Near lamp
12 Normal room
12-200 Getting darker
250-255 Complete dark
|



