Arduino Photo resistor ( lights the LED when dark & dims the LED when there is light)
up vote
0
down vote
favorite
sbi DDRB, 5 //led output
cbi DDRC, 0 //LDR input
sbi PORTC, 0 //pull up resistor
//---- Conversion starts here ----//
LDI R16 , 0x87
STS ADCSRA, R16
LDI R16 , 0x11
STS ADMUX, R16
//configurations done
READ_ADC:
//CBI PORTB,5
LDS R18, ADCSRA
SBR R18,0b01000000
STS ADCSRA,R18
KEEP_POLING :
LDS R19, ADCSRA
SBRS R19, 4
//
RJMP KEEP_POLING // loop bc conversion not complegted ADIGF =0+
LDS R16, ADCSRA
SBR R16,0b00010000
STS ADCSRA,R16
// above is setting bit 4 to 1 indicating that conversion over
//below is reading the high and low byte of the ADC
LDS R16,ADCL //8 bits
LDS R17,ADCH // read 2 bits
LDI R20, 0Xf4
CP R16,R20 //IF R16>=R20
BRGE greateq // The low bits are greater than 244 so if ADCH has a value of one which is 2^8=256+244=500
CP R20,R16 //IF R20> R16 (It's dim)
BRGE check
greateq:
LDI R21,0X01 //Here we are checking if it is greater than or equal to one (2^8 on or more)
CP R17,R21
brge light
CP R21, R17
brge dim
check: // The ADCL has a decimal value lower than 244 so we need either 2^9 or both 2^8 and 2^9 but ( 2^8 alone is not enough )
LDI R23,0x02 // Greater than or equal to 2 aka either (2^9 is on) or (2^8 and 2^9 together are on)
CP R17,R23
brge light
CP R23, R17
brge dim
light:
CBI PORTB, 5 // Turns off the LED
dim:
SBI PORTB, 5 // Turns on the LED
RJMP READ_ADC
The problem is that the LED always stays on.
The code is supposed to keep on checking whether the light intensity has exceeded 500 or not and if it did it should clear the bit which the LED is connected to , but if there is a light intensity more than 500 it should set the bit to 1 to light up the LED.
What is messing up the values in my code?
assembly arduino embedded adc
add a comment |
up vote
0
down vote
favorite
sbi DDRB, 5 //led output
cbi DDRC, 0 //LDR input
sbi PORTC, 0 //pull up resistor
//---- Conversion starts here ----//
LDI R16 , 0x87
STS ADCSRA, R16
LDI R16 , 0x11
STS ADMUX, R16
//configurations done
READ_ADC:
//CBI PORTB,5
LDS R18, ADCSRA
SBR R18,0b01000000
STS ADCSRA,R18
KEEP_POLING :
LDS R19, ADCSRA
SBRS R19, 4
//
RJMP KEEP_POLING // loop bc conversion not complegted ADIGF =0+
LDS R16, ADCSRA
SBR R16,0b00010000
STS ADCSRA,R16
// above is setting bit 4 to 1 indicating that conversion over
//below is reading the high and low byte of the ADC
LDS R16,ADCL //8 bits
LDS R17,ADCH // read 2 bits
LDI R20, 0Xf4
CP R16,R20 //IF R16>=R20
BRGE greateq // The low bits are greater than 244 so if ADCH has a value of one which is 2^8=256+244=500
CP R20,R16 //IF R20> R16 (It's dim)
BRGE check
greateq:
LDI R21,0X01 //Here we are checking if it is greater than or equal to one (2^8 on or more)
CP R17,R21
brge light
CP R21, R17
brge dim
check: // The ADCL has a decimal value lower than 244 so we need either 2^9 or both 2^8 and 2^9 but ( 2^8 alone is not enough )
LDI R23,0x02 // Greater than or equal to 2 aka either (2^9 is on) or (2^8 and 2^9 together are on)
CP R17,R23
brge light
CP R23, R17
brge dim
light:
CBI PORTB, 5 // Turns off the LED
dim:
SBI PORTB, 5 // Turns on the LED
RJMP READ_ADC
The problem is that the LED always stays on.
The code is supposed to keep on checking whether the light intensity has exceeded 500 or not and if it did it should clear the bit which the LED is connected to , but if there is a light intensity more than 500 it should set the bit to 1 to light up the LED.
What is messing up the values in my code?
assembly arduino embedded adc
1
These kind of problems are easier understood when a schematic is also attached. Should we assume the circuit is correct? You are driving the LED directly from the ATMega256p output pin and sensing the photo-resistor by ADC'verting the drop on it when put in a voltage divider, right? Thecbi portb, 5
falls through tosbi portb, 5
that will undo the clear. Are you missing arjmp portb, 5
before the labeldim
?
– Margaret Bloom
Nov 11 at 10:58
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
sbi DDRB, 5 //led output
cbi DDRC, 0 //LDR input
sbi PORTC, 0 //pull up resistor
//---- Conversion starts here ----//
LDI R16 , 0x87
STS ADCSRA, R16
LDI R16 , 0x11
STS ADMUX, R16
//configurations done
READ_ADC:
//CBI PORTB,5
LDS R18, ADCSRA
SBR R18,0b01000000
STS ADCSRA,R18
KEEP_POLING :
LDS R19, ADCSRA
SBRS R19, 4
//
RJMP KEEP_POLING // loop bc conversion not complegted ADIGF =0+
LDS R16, ADCSRA
SBR R16,0b00010000
STS ADCSRA,R16
// above is setting bit 4 to 1 indicating that conversion over
//below is reading the high and low byte of the ADC
LDS R16,ADCL //8 bits
LDS R17,ADCH // read 2 bits
LDI R20, 0Xf4
CP R16,R20 //IF R16>=R20
BRGE greateq // The low bits are greater than 244 so if ADCH has a value of one which is 2^8=256+244=500
CP R20,R16 //IF R20> R16 (It's dim)
BRGE check
greateq:
LDI R21,0X01 //Here we are checking if it is greater than or equal to one (2^8 on or more)
CP R17,R21
brge light
CP R21, R17
brge dim
check: // The ADCL has a decimal value lower than 244 so we need either 2^9 or both 2^8 and 2^9 but ( 2^8 alone is not enough )
LDI R23,0x02 // Greater than or equal to 2 aka either (2^9 is on) or (2^8 and 2^9 together are on)
CP R17,R23
brge light
CP R23, R17
brge dim
light:
CBI PORTB, 5 // Turns off the LED
dim:
SBI PORTB, 5 // Turns on the LED
RJMP READ_ADC
The problem is that the LED always stays on.
The code is supposed to keep on checking whether the light intensity has exceeded 500 or not and if it did it should clear the bit which the LED is connected to , but if there is a light intensity more than 500 it should set the bit to 1 to light up the LED.
What is messing up the values in my code?
assembly arduino embedded adc
sbi DDRB, 5 //led output
cbi DDRC, 0 //LDR input
sbi PORTC, 0 //pull up resistor
//---- Conversion starts here ----//
LDI R16 , 0x87
STS ADCSRA, R16
LDI R16 , 0x11
STS ADMUX, R16
//configurations done
READ_ADC:
//CBI PORTB,5
LDS R18, ADCSRA
SBR R18,0b01000000
STS ADCSRA,R18
KEEP_POLING :
LDS R19, ADCSRA
SBRS R19, 4
//
RJMP KEEP_POLING // loop bc conversion not complegted ADIGF =0+
LDS R16, ADCSRA
SBR R16,0b00010000
STS ADCSRA,R16
// above is setting bit 4 to 1 indicating that conversion over
//below is reading the high and low byte of the ADC
LDS R16,ADCL //8 bits
LDS R17,ADCH // read 2 bits
LDI R20, 0Xf4
CP R16,R20 //IF R16>=R20
BRGE greateq // The low bits are greater than 244 so if ADCH has a value of one which is 2^8=256+244=500
CP R20,R16 //IF R20> R16 (It's dim)
BRGE check
greateq:
LDI R21,0X01 //Here we are checking if it is greater than or equal to one (2^8 on or more)
CP R17,R21
brge light
CP R21, R17
brge dim
check: // The ADCL has a decimal value lower than 244 so we need either 2^9 or both 2^8 and 2^9 but ( 2^8 alone is not enough )
LDI R23,0x02 // Greater than or equal to 2 aka either (2^9 is on) or (2^8 and 2^9 together are on)
CP R17,R23
brge light
CP R23, R17
brge dim
light:
CBI PORTB, 5 // Turns off the LED
dim:
SBI PORTB, 5 // Turns on the LED
RJMP READ_ADC
The problem is that the LED always stays on.
The code is supposed to keep on checking whether the light intensity has exceeded 500 or not and if it did it should clear the bit which the LED is connected to , but if there is a light intensity more than 500 it should set the bit to 1 to light up the LED.
What is messing up the values in my code?
assembly arduino embedded adc
assembly arduino embedded adc
edited Nov 11 at 1:23
asked Nov 11 at 1:17
Rana
62
62
1
These kind of problems are easier understood when a schematic is also attached. Should we assume the circuit is correct? You are driving the LED directly from the ATMega256p output pin and sensing the photo-resistor by ADC'verting the drop on it when put in a voltage divider, right? Thecbi portb, 5
falls through tosbi portb, 5
that will undo the clear. Are you missing arjmp portb, 5
before the labeldim
?
– Margaret Bloom
Nov 11 at 10:58
add a comment |
1
These kind of problems are easier understood when a schematic is also attached. Should we assume the circuit is correct? You are driving the LED directly from the ATMega256p output pin and sensing the photo-resistor by ADC'verting the drop on it when put in a voltage divider, right? Thecbi portb, 5
falls through tosbi portb, 5
that will undo the clear. Are you missing arjmp portb, 5
before the labeldim
?
– Margaret Bloom
Nov 11 at 10:58
1
1
These kind of problems are easier understood when a schematic is also attached. Should we assume the circuit is correct? You are driving the LED directly from the ATMega256p output pin and sensing the photo-resistor by ADC'verting the drop on it when put in a voltage divider, right? The
cbi portb, 5
falls through to sbi portb, 5
that will undo the clear. Are you missing a rjmp portb, 5
before the label dim
?– Margaret Bloom
Nov 11 at 10:58
These kind of problems are easier understood when a schematic is also attached. Should we assume the circuit is correct? You are driving the LED directly from the ATMega256p output pin and sensing the photo-resistor by ADC'verting the drop on it when put in a voltage divider, right? The
cbi portb, 5
falls through to sbi portb, 5
that will undo the clear. Are you missing a rjmp portb, 5
before the label dim
?– Margaret Bloom
Nov 11 at 10:58
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53245010%2farduino-photo-resistor-lights-the-led-when-dark-dims-the-led-when-there-is-l%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
These kind of problems are easier understood when a schematic is also attached. Should we assume the circuit is correct? You are driving the LED directly from the ATMega256p output pin and sensing the photo-resistor by ADC'verting the drop on it when put in a voltage divider, right? The
cbi portb, 5
falls through tosbi portb, 5
that will undo the clear. Are you missing arjmp portb, 5
before the labeldim
?– Margaret Bloom
Nov 11 at 10:58