Compare value ...


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Code:
    Tmax=Tmax*100  you cannot do this ,Tmax is a byte var
          
    If temperature > Tmax then
    rele=1
    else
    rele=0
    Endif
                                    
    goto main

    this will work the pbp inline intermediate results are word sized
    Code:
    If temperature > (Tmax*100) then
    rele=1
    else
    rele=0
    Endif
    Warning I'm not a teacher

  2. #2
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by richard View Post

    [CODE]

    this will work the pbp inline intermediate results are word sized
    Code:
    If temperature > (Tmax*100) then
    rele=1
    else
    rele=0
    Endif
    I tried, but nothing changes

    my code now is :

    Code:
    ​'****************************************************************'*  Name    : 16F88_LM235.BAS                                   *
    '*  Author  :                                    *
    '*  Notice  : Copyright (c) 2020                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 04/04/2020                                        *
    '*  Version : 1.0                                               *
    '*  
    '****************************************************************
    'PIC 16F88
    '    Hardware Assignments
    '    --------------------
    ' LCD circuitery
    '01     - Vss (GND)
    '02     - Vdd (+5V)
    '08 RS  - PORTB.2
    '09 E   - PORTB.3
    '10 DB4 - PORTB.4
    '11 DB5 - PORTB.5
    '12 DB6 - PORTB.6
    '13 DB7 - PORTB.7
    
    
    ' --------  bit a bit controllo 0=output  1=input
    
    
    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
    '----------------------------------------------------
    
    
    
    
    DEFINE LCD_DREG PORTB       'Porta B DATA OUT 
    DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7 
    
    
    
    
    DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
    DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2
    
    
    
    
    DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
    DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3
    
    
    
    
    DEFINE LCD_BITS 4           'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2          'Number lines on LCD 
    
    
    
    
    DEFINE LCD_COMMANDUS 2000   'Command delay time in us 
    DEFINE LCD_DATAUS 50        'Data delay time in us
    
    
    
    
    '    EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
    '===========================================================================    
    '=========================================================================== 
    
    
    
    
    '===========================================================================
    '*****  SETTAGGIO PORTE 
    
    
    
    
    '      VAR      PORTA.0     'LM235M            Pin 17  
    IncButton    VAR    PORTA.1     'SW          Pin 18
    DecButton    VAR    PORTA.2     'SW          Pin 1
    SetButton    VAR    PORTA.3     'SW          Pin 2     
    '      VAR    PORTA.4     '                  Pin 3     
    '      VAR    PORTA.5     '                  Pin 4
    Rele   VAR    PORTA.6     '                  Pin 15
    '      VAR    PORTA.7     '                  Pin 16 
    '-----------------------------------------------
    '       Var       PORTB.0   '                   Pin  6
    '       var    PORTB.1   '                   Pin  7
    l_rs    var       PORTB.2   'LCD  sig. RS       Pin  8
    l_en    Var    PORTB.3   'LCD sig. E         Pin  9
    l_d4    var       PORTB.4   'LCD 4              Pin 10
    l_d5    var    PORTB.5   'LCD 5              Pin 11
    l_d6    var    PORTB.6   'LCD 6              Pin 12
    l_d7    var    PORTB.7   'LCD 7              Pin 13
    
    
    
    
    '--------------------------------------------------------------
    
    
    
    
    '---------Define ADCin Parameters   
    DEFINE ADC_BITS 10      'set number of bits in result
    DEFINE ADC_CLOCK 3      'set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS
    
    
    
    
    
    
    
    
    '    RAM Assignments and Variables
    '===========================================================================        
    CounterA    var byte    ' General purpose Variable
    CounterB    var byte    ' General purpose Variable
    CounterC    var byte    ' General purpose Variable
    Dummy       var word  
    DatoEE      var byte
    Tcomp       VAR word
    Grade       var Byte
    TimeOut     var word    ' Variable for SetUp Menu Time-Out
    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
     
    START:
    '*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
    '*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~  
    for sample = 0 to 3
        rele=1
        pause 1000
        rele=0
        pause 1000
    next sample
    
    
    
    
    Lcdout $FE, 1           'Clear screen
      
    temp = 0 'Clear temp register
    temperature = 0 'Clear temperature register
    sample = 1 'Clear sample register
    samples = 0 'Clear samples register
    
    
    'rele=0
    
    
    main:
       
    samples=0
    FOR sample = 1 TO 20 'Take 20 samples
    ADCIN 0, temp 'Read AN0 into temp variable
    samples = samples + temp
    PAUSE 40 ' 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," TEmpe", temperature
    
    
          
    If temperature > (Tmax*100) then
    rele=1
    else
    rele=0
    Endif
                                    
    goto main

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    lcdout $FE, $C0," TEmpe", temperature

    what does this line display the temperature value as ?
    Warning I'm not a teacher

  4. #4
    Join Date
    Apr 2020
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    Quote Originally Posted by richard View Post
    lcdout $FE, $C0," TEmpe", temperature

    what does this line display the temperature value as ?
    ASCII code, one strange character, and it changes every time the temperature changes

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,392


    Did you find this post helpful? Yes | No

    Default Re: Compare value ...

    ASCII code, one strange character, and it changes every time the temperature changes
    lcdout $FE, $C0," TEmpe", dec temperature


    removing all the unused/unecessary stuff " just noise" , using a proper config and displaying a result more in keeping with lm35 accuracy

    this works just fine
    Code:
    '****************************************************************'*  '*  Name    : 16F88_LM235.BAS                                   *
    '*  Author  :                                    *
    '*  Notice  : Copyright (c) 2020                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 04/04/2020                                        *
    '*  Version : 1.0                                               *
    '*  
    '****************************************************************
    #CONFIG
      __config  _CONFIG1, _INTRC_IO & _WDT_ON & _PWRTE_OFF & _MCLR_ON & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF & _CCP1_RB0 & _CP_OFF
      __config  _CONFIG2, _FCMEN_ON & _IESO_ON
    #ENDCONFIG
    'PIC 16F88
    '    Hardware Assignments
    '    --------------------
    ' LCD circuitery
    '01     - Vss (GND)
    '02     - Vdd (+5V)
    '08 RS  - PORTB.2
    '09 E   - PORTB.3
    '10 DB4 - PORTB.4
    '11 DB5 - PORTB.5
    '12 DB6 - PORTB.6
    '13 DB7 - PORTB.7
    
    
    adcon1.7=1
    ANSEL = %000001 'Disable Inputs Tranne AN0
    OSCCON = %01100000 'Internal RC set to 4MHZ
    TRISA = %10111111 ' impostazioni INP/OUT
    TRISB = 0 ' delle porte
    '----------------------------------------------------
    DEFINE LCD_DREG PORTB       'Porta B DATA OUT 
    DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7 
    DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
    DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2
    DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
    DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4           'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2          'Number lines on LCD DEFINE LCD_COMMANDUS 2000   'Command delay time in us 
    DEFINE LCD_DATAUS 50        'Data delay time in us
    
    
    '    EEPROM Locations Codice ASCII es. a=97 b=98 c=99 ...
    
    
    '===========================================================================
    '*****  SETTAGGIO PORTE 
    
    
    Rele   VAR    PORTA.6     '                  Pin 15
    '--------------------------------------------------------------
    '---------Define ADCin Parameters   
    DEFINE ADC_BITS 10      'set number of bits in result
    DEFINE ADC_CLOCK 3      'set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS
    
    
    '    RAM Assignments and Variables
    '=========================================================================== 
    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
     
    START:
    Lcdout $FE, 1           'Clear screen
    rele=0
    
    
    main:   
    samples=0
    FOR sample = 1 TO 20 'Take 20 samples
    ADCIN 0, temp 'Read AN0 into temp variable
    samples = samples + temp
    PAUSE 40 ' Wait 1/4 seconds per reading
    NEXT sample
    temp = samples/20 'Average over 20 samples (Every 5 seconds)
    temperature= temp */ quanta
    
    
    LCDOUT $FE, 1 ' cancella LCD
    LCDOUT $FE, 2 ' ritorna al primo carattere
    lcdout $FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature//10),$DF,"C"
    lcdout $FE, $C0," TEmpe", dec temperature 
          
    If temperature > (Tmax*10) then
    rele=1
    else
    rele=0
    Endif
                                    
    goto main
    Warning I'm not a teacher

Similar Threads

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

Members who have read this thread : 0

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