Compare value ...


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Try this:
    Code:
    INTCON = 0 ' NO INTERRUPT
    ADCON1 = %10001110 '
    ADCON0 = %000101 'Disable Converter Module
    ANSEL = %00000001 'Disable Inputs Tranne AN0
    OSCCON = %01100000 'Internal RC set to 4MHZ
    CMCON = 7 
    TRISA = %10001111 ' impostazioni INP/OUT
    TRISB = %00000000 ' delle porte
    '----------------------------------------------------
    
    temp var word
    temperature var word
    samples var word
    
    sample VAR BYTE
    quanta con 1250
    Tmax VAR byte
    Tmin VAR byte
    
    Tmin=16
    Tmax=30
    
      
      
    temp = 0 'Clear temp register
    temperature = 0 'Clear temperature register
    sample = 1 'Clear sample register
    samples = 0 'Clear samples register
    
    PORTA.6=0
       
    do
    samples=0
    FOR sample = 1 TO 20 'Take 20 samples
    ADCIN 0, temp 'Read AN0 into temp variable
    samples = samples + temp
    PAUSE 50 ' Wait 1/4 seconds per reading
    NEXT sample
    temp = samples/20 'Average over 20 samples (Every 5 seconds)
    temperature= (temp*10) */ quanta
    
    
    Pause 200 ' Timeout for LCD to settle
    LCDOUT $FE, 1 ' cancella LCD
    LCDOUT $FE, 2 ' ritorna al primo carattere
    lcdout $FE, 2, "Temp ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C"
    lcdout $FE, $C0, "Tmin ",#Tmin DIG 1,#Tmin Dig 0," Tmax ",#Tmax DIG 1,#Tmax Dig 0
    
          
    If temperature/1000 > Tmax then
    PORTA.6=1
    else
    PORTA.6=0
    Endif
    loop

  2. #2
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by louislouis View Post
    Try this:
    Code:
    INTCON = 0 ' NO INTERRUPT
    ADCON1 = 001110 '
    ADCON0 = 0101 'Disable Converter Module
    ANSEL = 000001 'Disable Inputs Tranne AN0
    OSCCON = 100000 'Internal RC set to 4MHZ
    CMCON = 7 
    TRISA = 001111 ' impostazioni INP/OUT
    TRISB = 000000 ' delle porte
    '----------------------------------------------------
    
    temp var word
    temperature var word
    samples var word
    
    sample VAR BYTE
    quanta con 1250
    Tmax VAR byte
    Tmin VAR byte
    
    Tmin=16
    Tmax=30
    
      
      
    temp = 0 'Clear temp register
    temperature = 0 'Clear temperature register
    sample = 1 'Clear sample register
    samples = 0 'Clear samples register
    
    PORTA.6=0
       
    do
    samples=0
    FOR sample = 1 TO 20 'Take 20 samples
    ADCIN 0, temp 'Read AN0 into temp variable
    samples = samples + temp
    PAUSE 50 ' Wait 1/4 seconds per reading
    NEXT sample
    temp = samples/20 'Average over 20 samples (Every 5 seconds)
    temperature= (temp*10) */ quanta
    
    
    Pause 200 ' Timeout for LCD to settle
    LCDOUT $FE, 1 ' cancella LCD
    LCDOUT $FE, 2 ' ritorna al primo carattere
    lcdout $FE, 2, "Temp ",dec2 (temperature/100),".", dec1 (temperature//100),$DF,"C"
    lcdout $FE, $C0, "Tmin ",#Tmin DIG 1,#Tmin Dig 0," Tmax ",#Tmax DIG 1,#Tmax Dig 0
    
          
    If temperature/1000 > Tmax then
    PORTA.6=1
    else
    PORTA.6=0
    Endif
    loop
    it's all very strange!
    Testing the code with temperature / 1000 in the same way PORTA.6 goes ON
    Not even dividing by 1000 is it possible to obtain the right comparison


    Then I added the Do .. loop and everything went crazy.
    The room temperature changed with each cycle and the DOOR. 6 went its own without ON and OFF criteria without considering the temperature.

Similar Threads

  1. How to compare two temperatures
    By SKOLS1 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th April 2012, 10:07
  2. how to hserin compare with known value?
    By aa222k in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 23rd November 2010, 19:48
  3. Is there a faster way to compare?
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 8th February 2010, 20:48
  4. how to compare data
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 1st November 2009, 23:30
  5. Compare Data
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 14th February 2008, 21:40

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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