• AVR Freaks

Hot!Assembly Code to Read Humidity Sensor

Page: < 12345.. > >> Showing page 2 of 7
Author
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3118
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/14 08:54:35 (permalink)
-1 (1)
The data line needs a pull-up resistor.
(Error in post #13)
post edited by Gort2015 - 2019/03/14 08:58:21

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#21
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3118
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/14 09:07:06 (permalink)
-1 (1)
I have code for these devices in C and ASM.
Supports blue, white and black varients.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#22
delfindelfin
Super Member
  • Total Posts : 196
  • Reward points : 0
  • Joined: 2017/01/19 12:32:58
  • Location: Mexico
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/14 18:33:38 (permalink)
#23
qhb
Superb Member
  • Total Posts : 9919
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Assembly Code to Read Humidity Sensor 2019/03/14 18:42:06 (permalink)
0
I suspect you're striking problems with the Proteus simulator.
Are you going to try this on real hardware?
 
 
#24
delfindelfin
Super Member
  • Total Posts : 196
  • Reward points : 0
  • Joined: 2017/01/19 12:32:58
  • Location: Mexico
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/14 19:47:16 (permalink)
0
Yes, of course. I am going to test it on real hardware. But I don't have a real digital analyzer to see the data sended by the sensor. I still don't understand how the PIC is able to drive low the 1k resistor when is acting as an output. The internal resistor of the PIC is smaller than the one of the sensor? How does the output pins work?
#25
qhb
Superb Member
  • Total Posts : 9919
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Assembly Code to Read Humidity Sensor 2019/03/14 19:58:00 (permalink)
0
An output pin is driven low by a FET transistor.
It can easily drive the pin close to ground while sinking 8.5 mA (parameter D080 in the PIC16F877A datasheet)
A 1k resistor only passes 5 mA when there is 5V across it.
#26
delfindelfin
Super Member
  • Total Posts : 196
  • Reward points : 0
  • Joined: 2017/01/19 12:32:58
  • Location: Mexico
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/16 11:15:51 (permalink)
0
Well, back to this... This the code that I need to add to send the Start Signal to the sensor 
 

 
;****************************************************************************************************************************************************************
;**** READ SENSOR ROUTINE ***************************************************************************************************************************************
;****************************************************************************************************************************************************************
 
READSENSOR
                      BANKSEL    TRISC            ; Selection of Memory Bank 1 (STATUS Register: 01)
                      CLRF          TRISC            ; Configuration of PORTC as Output (Sensor Signals: RC5-DATA )

                      BANKSEL    PORTC            ; Selection of Memory Bank 0
                      CLRF          PORTC            ;
                      CALL          DELAY_1ms     ; Sending Start Signal (RC5-DATA low for at least 800 uS)

                      MOVLW       b'11111111'
                      MOVWF       PORTC           ; Sending Start Signal (RC5-DATA high )

                      BANKSEL     TRISC            ; Selection of Memory Bank 1 (STATUS Register: 01)

                      MOVLW       b'11111111'
                      MOVWF       TRISC             ; Configuration of PORTC as Input (Sensor Signals: RC5-DATA )

                      RETURN
DELAY_1ms
                      MOVLW        .1                     ; Delay of 1 ms
                      MOVWF        TMR0
 
LOOP_DEL1
                        BTFSS       INTCON,2               ;  Waiting until Overflow Flag bit is set (1)
                        GOTO       LOOP_DEL1
                        BCF          INTCON,2                    ; Resetting Overflow Flag bit (0)
RETURN

;****************************************************************************************************************************************************************
 

After that the sensor sends the data.
How do I store in a register the data sended by the sensor?
post edited by delfindelfin - 2019/03/16 11:20:13
#27
qhb
Superb Member
  • Total Posts : 9919
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Assembly Code to Read Humidity Sensor 2019/03/16 13:42:41 (permalink)
0
delfindelfin
...
How do I store in a register the data sended by the sensor?

You have to manually receive each bit sent by the sender, and reassemble the 40 bits back into the byte data.
I described one way to determine if each bit is a zero or a one back in post#14.
 
#28
delfindelfin
Super Member
  • Total Posts : 196
  • Reward points : 0
  • Joined: 2017/01/19 12:32:58
  • Location: Mexico
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/16 21:58:55 (permalink)
0
How do I wait for the rising edge and check if the signal is now low or high in assembly code? 
#29
qhb
Superb Member
  • Total Posts : 9919
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Assembly Code to Read Humidity Sensor 2019/03/17 02:58:50 (permalink)
0
delfindelfin
How do I wait for the rising edge and check if the signal is now low or high in assembly code?

Really?
This is programming 101. Do you have ANY experience at all?
If that is your programming level, I think you better start with flashing an LED first.
 
#30
delfindelfin
Super Member
  • Total Posts : 196
  • Reward points : 0
  • Joined: 2017/01/19 12:32:58
  • Location: Mexico
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/17 03:27:17 (permalink)
0
I think I know but I forgot it. So I am going to spend the next hours trying to remember it. I don't have much experience with assembly, actually. It is the forgetting curve and the "Use it or lose it". That's what I am programming all basic examples to have them in my computer, so if I forgot I just have to review them
post edited by delfindelfin - 2019/03/17 03:52:30
#31
qhb
Superb Member
  • Total Posts : 9919
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Assembly Code to Read Humidity Sensor 2019/03/17 03:48:11 (permalink)
+1 (1)
What do you have experience with?
There's nothing stopping you implementing this in C instead.
 
#32
pcbbc
Super Member
  • Total Posts : 891
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/17 03:52:25 (permalink)
0
delfindelfin
I think I know but I forgot it. So I am going to spend the next hours trying to remember it. I don't have much experience with assembly, actually
The code you need to wait for a rising edge is very similar to...
LOOP_DEL1 
BTFSS INTCON,2 ; Waiting until Overflow Flag bit is set (1)
GOTO LOOP_DEL1
But of course you will be checking the relevent port bit, and not the INTCON register.


I have no idea if this project is possible in C (i’ll Take qhb’s advice that it is), but if it is you might want to start there? Or as others suggest start with a more simple assembler project. Even as an experienced assembler programmer, when interfacing with new hardware I am unfamiliar with, getting it working in a high level language would always be my first step (if possible). Then, if I really need assembler for some esoteric reason, I have the necessary experience with the protocol.

Generally I find with two unknowns to deal with (no experience with assembler, no experience with protocol, for example) the difficulty level of any task is not doubled, be increases according to a square rule!
post edited by pcbbc - 2019/03/17 03:56:44
#33
delfindelfin
Super Member
  • Total Posts : 196
  • Reward points : 0
  • Joined: 2017/01/19 12:32:58
  • Location: Mexico
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/17 03:54:26 (permalink)
0
I don't have much experience qhb. At the moment I am trying to program all basic examples and some sensors. I have an idea of what to do, but that's all 
#34
pcbbc
Super Member
  • Total Posts : 891
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/17 04:03:04 (permalink)
0
delfindelfin
I don't have much experience qhb. At the moment I am trying to program all basic examples and some sensors. I have an idea of what to do, but that's all 
Do you mean you have experience programming in BASIC, or not much experience programming at all?

If no experience programming, I would suggest a course in C programming first before attempting programming for an embedded device. Learning to code can be hard, and embedded world has limitations which hamper your learning. Crawl, walk, run.
#35
delfindelfin
Super Member
  • Total Posts : 196
  • Reward points : 0
  • Joined: 2017/01/19 12:32:58
  • Location: Mexico
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/17 04:03:44 (permalink)
0
pcbbc I want to do it in assembly because if I do it in C, I am never going to learn assembly and I don't think it is so hard to program. Some time ago I did something similar in assembly with a thermocouple and a chip called max6675 using SPI and it wasn't that hard, and this is actually easier 
#36
delfindelfin
Super Member
  • Total Posts : 196
  • Reward points : 0
  • Joined: 2017/01/19 12:32:58
  • Location: Mexico
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/17 04:05:16 (permalink)
0
No I didn't mean BASIC programming language. I meant the basic things you can do with a microcontroller.  Besides something that I don't like about C is that you use a lot of libraries, and in my opinion, you are never going to learn electronics if you don't know assembly. Even if you use C in the future, knowing assembly language, gives you a better understanding of everything, and allows you to code better in higher programming languages. So I have to do it in assembly
post edited by delfindelfin - 2019/03/17 04:36:07
#37
delfindelfin
Super Member
  • Total Posts : 196
  • Reward points : 0
  • Joined: 2017/01/19 12:32:58
  • Location: Mexico
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/17 04:54:21 (permalink)
0
Do you have any recommendations to learn assembly language? a book or something ...
#38
qhb
Superb Member
  • Total Posts : 9919
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: Assembly Code to Read Humidity Sensor 2019/03/17 04:58:53 (permalink)
0
Gooligum Tutorials for base and mid-range PICs.
The simple tutorials are free, which should get you started.
If you like them, you can purchase the more advanced ones.
 
#39
pcbbc
Super Member
  • Total Posts : 891
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: Assembly Code to Read Humidity Sensor 2019/03/17 05:09:00 (permalink)
0
delfindelfinBesides something that I don't like about C is that you use a lot of libraries
Not for embedded programming you don’t. This project requires absolutely zero libraries.

you are never going to learn electronics if you don't know assembly.
You mean programming? Electronics and assemble language are completely unrelated.

Even if you use C in the future, knowing assembly language, gives you a better understanding of everything, and allows you to code better in higher programming languages.
Agreed - But jumping in with assembler is the wrong place to start if you have NO experience of programming. Heck, I claim it is the wrong place to start if you have no experience of an micro controllers in general. Or no experience with a new protocol. Forgive me, but you seem to have all three of these working against you. All we are suggesting is you start with something you ARE familiar with x hence the question by qhb...
qhbWhat do you have experience with?

You can move onto assembler later.

So I have to do it in assembly
As has been pointed out, you do not HAVE to do it in assembler. You have chosen to do that, but it seems without any of the prerequisites. As I have said, I am a seasoned assembler programmer (having completed numerous projects on 6502, PIC, x86, x64, SH-4, ARM) but I didn’t start by learning assembler, and I would never start by talking to some new hardware I am unfamiliar with by using it.
#40
Page: < 12345.. > >> Showing page 2 of 7
Jump to:
© 2019 APG vNext Commercial Version 4.5