problem with output RA2 and RA3


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302

    Default problem with output RA2 and RA3

    I have the below code.
    My problem is that the output RA2 and RA3 not change if (value - P2) >= 1 and (value1 - P3) >= 1.
    What wrong i have made;

    Code:
    '************************************************************************
    
        @ DEVICE PIC16F88, MCLR_OFF     ' Master Clear Options (Internal)
        
    '******************************** LCD ***********************************
        
        DEFINE LCD_DREG PORTB		    ' Selection of the port B
        DEFINE LCD_DBIT 4
        DEFINE LCD_RSREG PORTB		    ' RS on port RB2
        DEFINE LCD_RSBIT 2
        DEFINE LCD_EREG PORTB		    ' E on port RB3
        DEFINE LCD_EBIT 3
        DEFINE LCD_BITS 4		        ' Mode 4 bits
        DEFINE LCD_LINES 2		        ' LCD 2 lines of 16 caracter
    
    '****************************Define ADCIN parameters **********************
        
        DEFINE  ADC_BITS        8     	' Set number of bits in result
        DEFINE  ADC_CLOCK       3     	' Set clock source (3=rc)
        DEFINE  ADC_SAMPLEUS    50    	' Set sampling time in uS
            
    '*********************************** VARIABLES *********************
       
        TRISA = %00000011
        CMCON = 7              ' PortA = digital I/O    
        ANSEL = %00000011      ' Will set RA0-RA1 as analog and all others as digital   
        ADCON0 = %11100001	   ' Configure and turn on A/D Module
        ADCON1 = %00000010 	   ' Set PORTA analog and RIGHT justify result
                    
        adval   var Byte	   ' Create adval to store result
        value   var Word
        
        adval1  var Byte	   ' Create adval1 to store result
        value1  var Word
        
        P		VAR Byte
        P1		VAR Byte	
        P2      var Word
        P3      var Word
        
        PAUSE 500
    
        LCDOUT $FE,1,"  VOLTMETER  "
        PAUSE 1000
         
        P2 = P*50/255
        P3 = P1*50/255
      
        P2=28
        P3=10
        
    NORMAL:
    
        ADCIN 0, adval	                       ' Read channel 0 to adval
        value = adval*50/255                  
        
        ADCIN 1, adval1	                       ' Read channel 1 to adval1
        value1 = adval1*50/255               
               
        LCDOUT $FE,1,"VOLT : ",DEC2 value
        LCDOUT $FE,$C0,"AMPER: ",DEC2 value1
        
        if (value - P2) >= 1 then
        PORTA.2=1
        else
        PORTA.2=0
        endif
        
        if (value1 - P3) >= 1 then
        PORTA.3=1
        else
        PORTA.3=0
        endif
                
        PAUSE 500
            
        GOTO NORMAL

  2. #2
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    When I read the datasheet of the 16F88 then I see other configurations than you filled in at adcon0 and adcon1.
    You say:
    ADCON0 = %11100001 ' Configure and turn on A/D Module
    I read for this:
    do nothing with adcon0
    You say:
    ADCON1 = %00000010 ' Set PORTA analog and RIGHT justify result
    I read for this:
    adcon1 = %10000000 'only right justify and nothing about set port a.

  3. #3
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mat janssen
    When I read the datasheet of the 16F88 then I see other configurations than you filled in at adcon0 and adcon1.
    You say:
    ADCON0 = %11100001 ' Configure and turn on A/D Module
    I read for this:
    do nothing with adcon0
    You say:
    ADCON1 = %00000010 ' Set PORTA analog and RIGHT justify result
    I read for this:
    adcon1 = %10000000 'only right justify and nothing about set port a.
    I read this
    ADCON0.0=1 ' A/D converter module is operating

  4. #4
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    The adcon0,0 is an internal bit to tell us what the condition is of the adc.
    You need it if your programm is made in assembler.
    All of this is solved for you in the picbasicpro compiler.

  5. #5
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    i change with this:

    Code:
        CMCON = 7                       ' PortA = digital I/O    
    	ANSEL = %00000011               ' Will set RA0-RA1 as analog and all others as digital 
        TRISA = %00000011  
        ADCON0 = %11000001	            ' Configure and turn on A/D Module
        ADCON1 = %00000000 	            ' Left justified. Six Least Significant bits of ADRESL are read as ‘0’
    and work but i want only the positive result and not the negative of command: if (value - P2) >= 1
    23 - 25 = -2 (P2=25)
    27 - 25 = 2 (P2=25)
    the pin PORTA.2 turn on , and for -2 and for 2 , but i want only for 2.
    How to make this;

  6. #6
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    Test if the first number is greater then the second number and then do the subtraction. If otherwise then do nothing.

  7. #7
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mat janssen
    Test if the first number is greater then the second number and then do the subtraction. If otherwise then do nothing.
    Thank you.
    I use this code:

    Code:
        If value >= P2 then
            If (value - P2) >= 1 then
                PORTB.1=1
                else
                PORTB.1=0
                endif
            endif

Similar Threads

  1. Pin won't stay high during Repeat...Until loop??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th August 2009, 23:57
  2. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  3. COUNT is not counting again
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 33
    Last Post: - 19th June 2009, 04:52
  4. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  5. This should be simple?
    By jderson in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th September 2008, 21:20

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