0

I am creating a project in which an Arduino reads (gets) a value from a DHT sensor. The DHT sensor returns two values:

  1. Temperature
  2. Humidity

enter image description here

My assembly code:

sbi ddrd,5
cbi ddrd,2
sbi portd,5

start:

in r16,Pind2
cpi r16,80
brne On

jmp start

On:
cbi portd ,5
jmp start

After the code, the light remains turned on, but if the sensor sends '80' and I get it correctly it should be turned off.

Question: Am I Using the write way to read a pin?

  • The first thing I saw was a cartoon where apparently a schematic is supposed to be, so I quit before reading any of the text. –  Dec 02 '17 at 13:27
  • 1
    I'm not sure any of your code makes sense. Firstly you've got the roles of pind and portd backwards (port is for writing, pin is for reading). Secondly you haven't defined in your code what half of the stuff is (what is ddrd, what is portd, what is Portd2). Thirdly you are reading in the portd register (not an input), and then comparing it directly to a number (decimal 80, hex 0x50) - even if we assume you mean to read the inputs (pind), you haven't connected most of the pins on that port so who knows what value will return. – Tom Carpenter Dec 02 '17 at 15:49
  • @TomCarpenter I am new to it can you plz write a simple code for me which will receive data from DHT and Move it to a register? An Example Code? –  Dec 02 '17 at 17:20
  • This Tutorial shows how to read and write from complete Port but I just need One Pin and Recieve Serial Data http://www.avr-tutorials.com/digital/digital-input-output-assembly-programming-atmel-8-bits-avr-microcontrollers –  Dec 02 '17 at 17:41
  • in r16, PIND, assuming you are using avr-gcc. If you want just the bit 2, andi r16, 1<<2. – Tom Carpenter Dec 02 '17 at 20:24
  • 2
    I'm voting to close this question as off-topic because it is about AVR assembly NOT ARDUINO and was properly asked on EESE, but IMPROPERLY MIGRATED. The language is not Aduino, the pin specs are AVR NOT ARDUINO - the only thing "Arduino" about this is some soldermask masquerading as silkscreen on the board. – Chris Stratton Dec 03 '17 at 05:02
  • Yet another crap migration from @Nick Alexeev. Is there anything we can do about this? – per1234 Dec 03 '17 at 07:24
  • Gentlemen, Nick Alexeev asked me if he could migrate this. Whilst the assembler question might be marginally off-topic, this is hardly an electronics question. The question specifically mentions an Arduino Uno. Personally I would be encouraging him to ditch assembler for such a simple task. It seems completely inappropriate. – Nick Gammon Dec 03 '17 at 22:42

2 Answers2

2

You are simply reading the state of the input pin - this won't work.

Study the datasheet for the DHT22, available from Sparkfun or eslewhere.

To get data from the DTH22, you must first send a start signal, wait a specified time, then watch the level of the data line, measuring the time of each bit to determine whether it is a 1 or 0, and store the bits in five 8-bit variables. You can then examine those variables to determine the temperature and humidity.

Peter Bennett
  • 221
  • 1
  • 3
2

Instructions for writing to an individual output bit:-

 sbi portd,5 ; make Port D output bit 5 high (set)

 cbi portd,5 ; make Port D output bit 5 low (clear)

 sbi pind,5  ; toggle Port D output bit 5 (low -> high, high -> low)

Instructions for reading an individual I/O pin:-

 sbis pind,2 ; skip next instruction if Port D pin 2 is high  

 sbic pind,2 ; skip next instruction if Port D pin 2 is low
Bruce Abbott
  • 171
  • 1
  • 5