LDR 16F877

Status
Not open for further replies.

ser_kant

New Member
I have Pbp. I use 16F877. I want to use analog ports A and E. get output from B channels. (for example channel 0). I know how to connect the channels and other circuit elements. All I want to learn is how can I get the 0 and 1 from analog channels. As far as I understand A/D conversion gives too much bits, I only want to take 0 and 1. For example when the LDR voltage is above 3 I want to light the led when it is below turn off the led. i think the program is so simple, please send me one, i need this for my term project
 

You read the analogue value from the LDR into a register, you may as well only use the top 8 bits, rather than the full 10 bits (it will simplify things).

You then test the value, it could look something like this:

Code:
If Reading > Testvalue Then
  Do Over
Else
  Do Under

To do it in assembler you subtract the values, and test the status flags, if you check on the PICList there is a complete section about such comparisons.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…