Need help finish temperature sensor using asm code
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Need help finish temperature sensor using asm code

  1. #1
    Join Date
    Feb 2013
    Posts
    2

    Post Need help finish temperature sensor using asm code

    hi wondering if anyone can help me out with this, ive got the lcd displaying information, but i want it to display the temperature using the lm35 and adc0804 as well, using asm code. Basically i need to get the current reading from the lm35 and convert them in the adc0804 and then display that reading in degrees on the lcd display. I have found some similar projects like this but they were written in C. any help needed, thanks in advance

    current embedded image
    http://www.flickr.com/photos/6024224...in/photostream

    current code:
    Code:
    $mod51
    rw equ P3.1
    rs equ P3.0
    en equ P3.2
    
    org 0000h
    
    clr rw
    acall lcd_init
    main:
    mov a, #'W'
    acall lcd_data
    mov a,#'e'
    acall lcd_data
    mov a, #'l'
    acall lcd_data
    mov a,#'c'
    acall lcd_data
    mov a, #'o'
    acall lcd_data
    mov a,#'m'
    acall lcd_data
    mov a, #'e'
    acall lcd_data
    mov a,#' '
    acall lcd_data
    mov a,#'K'
    acall lcd_data
    mov a,#'e'
    acall lcd_data
    mov a,#'i'
    acall lcd_data
    mov a,#'t'
    acall lcd_data
    mov a,#'h'
    acall lcd_data
    sjmp $
    
    
    lcd_init:
    mov a,#01h
    acall lcd_cmd
    mov a,#38h
    acall lcd_cmd
    mov a,#0ch
    acall lcd_cmd
    mov a,#06h
    acall lcd_cmd
    ret
    
    
    lcd_cmd:
    clr rs
    mov p2,a
    setb en
    acall delay
    clr en
    ret
    
    lcd_data:
    setb rs
    mov p2,a
    setb en
    acall delay
    clr en
    ret
    
    delay:
    mov r0,#5h
    l2: mov r1,#0ffh
    l1: djnz r1,l1
        djnz r0,l2
    ret
    
    
    
    end
    [HTML]

  2. #2
    Join Date
    Feb 2013
    Location
    United States
    Posts
    56

    Re: Need help finish temperature sensor using asm code

    What processor / microcontroller are you using?
    Do you know the code for reading from the ADC?
    What range of numbers does the ADC give and how do they correspond to the temperature?
    Is the temperature to be displayed in Celsius or Fahrenheit?

  3. #3
    Join Date
    Feb 2013
    Posts
    2

    Re: Need help finish temperature sensor using asm code

    its an 8051 micro controller. at89c51
    i think it will be something along the lines of this, correct me if im wrong
    rd equ P1.0 ;Read signal P1.0
    wr equ P1.1 ;Write signal P1.1
    cs equ P1.2 ;Chip Select P1.2
    intr equ P1.3 ;INTR signal P1.3

    adc_port equ P2 ;ADC data pins P2
    adc_val equ 30H ;ADC read value stored here

    org 0H
    start: ;Start of Program
    acall conv ;Start ADC conversion
    acall read ;Read converted value
    mov P3,adc_val ;Move the value to Port 3
    sjmp start ;Do it again

    conv: ;Start of Conversion
    clr cs ;Make CS low
    clr wr ;Make WR Low
    nop
    setb wr ;Make WR High
    setb cs ;Make CS high
    wait:
    jb intr,wait ;Wait for INTR signal
    ret ;Conversion done

    read: ;Read ADC value
    clr cs ;Make CS Low
    clr rd ;Make RD Low
    mov a,adc_port ;Read the converted value
    mov adc_val,a ;Store it in local variable
    setb rd ;Make RD High
    setb cs ;Make CS High
    ret ;Reading done
    the temperature will range from using the voltage formula
    so 1v=100 degrees Celsius
    .50v= 50 degrees Celcius

    it is to be displayed in Celcius

  4. #4
    Join Date
    Feb 2013
    Location
    United States
    Posts
    56

    Re: Need help finish temperature sensor using asm code

    One you have a numeric representation of the temperature stored in adc_val, you just need to convert that number (I am guessing it is between 0 and 255) to degrees Celsius and then display that Celsius number as characters on the LCD.

    I am not familiar with the 8051 microcontroller so I do not know what instructions are available, specifically if it can multiply or divide. Being able to divide by ten would be helpful. It might be easier to first determine how many characters are needed to display the temperature by comparing it with 10 or 100. One piece of code could handle temperatures between 0 and 9, another piece of code could handle temperature between 10 and 99, and another could handle temperatures 100 and more. You could even do a series of comparisons or subtractions to further break the temperature into groups of 10 to 19, 20 to 29, 30 to 39, ... The goal would be to get each digit of the temperature to be a value between 0 an 9. That number would then be converted to the character code for '0' to '9' by adding the value for character '0'.

    Another approach, if ample memory is available, is to create a table of character strings, with one character string for each value of adc_val. For example, if each temperature would displayed as four characters, such that temperatures below 100 would have a decimal point and a tenth of degree, then you would need 4 x 256 = 1024 bytes to store the table. Your code would then simply convert the adc_val value to a table index by multiplying by the character string length. To multiply by four, you could shift the value to the left by two bits or add the value to itself a couple times.

    I hope this gives you some ideas.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center