I am Completely NEW to PICS and LOST PIC18f252


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2011
    Posts
    4

    Default I am Completely NEW to PICS and LOST PIC18f252

    I am familiar with BS2's and propellers but i am lost with this. When i try and compile this code, i get a series of errors... redefinition of VAR and redefinition of Label. What am i missing. Can anybody help? am i missing some more defines or includes?

    Code:
    Define OSC 4
    
    include "bs2defs.bas"
    
    Progress Var Byte
    Relay1 var PORTC.2
    Relay2 var PORTC.1
    Relay3 var PORTC.0
    StatLED var PORTA.0
    OptoPin var PORTB.0
    ADres	var	byte	' A-to-D result: one byte.
    CS	var PORTB.2		' Chip select is pin 0. 
    AData VAR PORTB.7	' ADC data output is pin 1. 
    CLK	VAR PORTB.6  	' Clock is pin 2. 
    baud  	con   	16468 	' N9600
    i var byte
     
    
    
    Start:
      high CS			' Deselect ADC to start.
      progress = 0
      gosub One
      Gosub Two
      Gosub Three
      If Progress = 3 then 
              completegood
      Else
              high Statled
      endif
    
    
    One:  'This will test the output of relay 1 and check its value through the ADC
      High Relay1
      Pause 10
    'Run ADC code
      Low Relay1
    'Test ADC value to be within range 80-100
      If (ADRes>80) and (ADres<100) then 
       i = 0
        REPEAT
         High StatLED
         Pause 500
         Low StatLED
         Pause 500
         i = i + 1
        UNTIL i > 7
      else 
       i = 0
        REPEAT   
         High Relay1
         Pause 500
         Low Relay1
         Pause 200 
         i = i + 1
        UNTIL i > 7  
      ENDIF   
     return
    
    Two:'This will test the output of relay 2 and check its value through the ADC
      High Relay2
      Pause 10
    'Run ADC code
      Low Relay2
    'Test ADC value to be within range 105-140
      If (ADRes>105) and (ADres<140) then 
      goto  BLEDG
      else 
        i = 0
       REPEAT   
         High Relay1
         Pause 500
         Low Relay1
         Pause 200 
         i = i + 1
       UNTIL i > 7  
      ENDIF   
     return
    Three:'This will test the output of relay 3 and check its value through the ADC
      High Relay3
      Pause 10
    'Run ADC code
      If Optopin = 1 then 
        Optogood
      endif 
      Low Relay3
    'Test ADC value to be within range 200-260
      If (ADRes>200) and (ADres<260) then 
      goto BLEDG
      else 
       i = 0
       REPEAT   
         High Relay3
         Pause 500
         Low Relay3
         Pause 200 
         i = i + 1
       UNTIL i > 7
       Progress = progress + 1   
      ENDIF   
     return
    
    BLEDG: 'Tested out good so we will let everyone know. 
     i = 0
     REPEAT
       High StatLED
       Pause 500
       Low StatLED
       Pause 500
       i = i + 1
     UNTIL i > 7
      return
    
    OptoGood: 'Tested out good so we will let everyone know.
      i = 0
     REPEAT
       High StatLED
       Pause 100
       Low StatLED
       Pause 100
       i = i + 1
     UNTIL i > 4
      return
    
    CompleteGood: 'Tested out good so we will let everyone know.
     REPEAT
       High StatLED
       Pause 100
       Low StatLED
       Pause 300
     end
    
    
     
    
    ADC:
      low CS		' Activate the ADC0831. 
      shiftin AData,CLK,msbpost,[ADres\9]	' Shift in the data. 
      high CS		' Deactivate '0831.
      pause 500
      serout 3,baud,[ADres]
      pause 1000

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: I am Completely NEW to PICS and LOST PIC18f252

    I don't see where you ever call the ADC routine
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default Re: I am Completely NEW to PICS and LOST PIC18f252

    ADRES is already defined in the P18F252.inc file. Change this to something else.

    Your IF/THEN/ELSE has Completegood without a GOTO or GOSUB before it.

    Completegood has a REPEAT with no UNTIL, no RETURN (or goto somewhere else), and END after it.

    Start falls right through to One, which has a RETURN. If you want it to loop back to Start, place a goto Start at the end of Start.

    This should have a GOSUB before Optogood;
    Code:
     If Optopin = 1 then 
        GOSUB Optogood
      endif
    You have a few goto BLEDG that need to be gosub BLEDG, etc.

    REPEAT must have an UNTIL to end it. Always GOSUB any routine that RETURNs, and for multiple IF/THEN/ELSE place your goto or gosub on the line after the THEN. IF Optopin = 1 THEN Optogood would work, but when you place Optogood on a line by itself, the compiler sees this as a lable. Not an instruction telling it to jump to Optogood.

    Just go slowly through your code line-by-line. You'll see the errors.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Feb 2011
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: I am Completely NEW to PICS and LOST PIC18f252

    Thanks so far for the help.
    I have cleaned up the code, see below, and now i have a whole new list of errors.

    What does all of this mean? (errors are in the attachment)


    Code:
    Define OSC 4
    
    include "bs2defs.bas"
    
    Progress Var Byte
    Relay1 var PORTC.2
    Relay2 var PORTC.1
    Relay3 var PORTC.0
    StatLED var PORTA.0
    OptoPin var PORTB.0
    ADVar	var	byte	' A-to-D result: one byte.
    CS	var PORTB.2		' Chip select is pin 0. 
    AData VAR PORTB.7	' ADC data output is pin 1. 
    CLK	VAR PORTB.6  	' Clock is pin 2. 
    baud  	con   	16468 	' N9600
    i var byte
    A Var PORTA.6
    
    ' BASIC Stamp II Interface for the ADC0831 
    ' 8-bit analog-to-digital converter
    
     
    
    high CS			' Deselect ADC to start.
    Start:
      high CS			' Deselect ADC to start.
      progress = 0
      gosub One
      Gosub Two
      Gosub Three
      If Progress = 3 then 
      gosub  completegood
      Else
              high Statled
      endif
    
    
    One:  'This will test the output of relay 1 and check its value through the ADC
      High Relay1
      Pause 10
      gosub ADC'Run ADC code
      Low Relay1
    'Test ADC value to be within range 80-100
      If (ADVar>80) and (ADVar<100) then 
       i = 0
        REPEAT
         High StatLED
         Pause 500
         Low StatLED
         Pause 500
         i = i + 1
        UNTIL i > 7
      else 
       i = 0
        REPEAT   
         High Relay1
         Pause 500
         Low Relay1
         Pause 200 
         i = i + 1
        UNTIL i > 7  
      ENDIF   
     return
    
    Two:'This will test the output of relay 2 and check its value through the ADC
      High Relay2
      Pause 10
      Gosub ADC'Run ADC code
      Low Relay2
    'Test ADC value to be within range 105-140
      If (ADVar>105) and (ADVar<140) then 
      gosub BLEDG
      else 
        i = 0
       REPEAT   
         High Relay1
         Pause 500
         Low Relay1
         Pause 200 
         i = i + 1
       UNTIL i > 7  
      ENDIF   
     return
    Three:'This will test the output of relay 3 and check its value through the ADC
      High Relay3
      Pause 10
      gosub ADC'Run ADC code
      If Optopin = 1 then 
      gosub Optogood
      endif 
      Low Relay3
    'Test ADC value to be within range 200-260
      If (ADVar>200) and (ADVar<260) then 
      goto BLEDG
      else 
       i = 0
       REPEAT   
         High Relay3
         Pause 500
         Low Relay3
         Pause 200 
         i = i + 1
       UNTIL i > 7
       Progress = progress + 1   
      ENDIF   
     return
    
    BLEDG: 'Tested out good so we will let everyone know. 
     i = 0
      REPEAT
       High StatLED
       Pause 500
       Low StatLED
       Pause 500
       i = i + 1
      UNTIL i > 7
     return
    
    OptoGood: 'Tested out good so we will let everyone know.
      i = 0
      REPEAT
       High StatLED
       Pause 100
       Low StatLED
       Pause 100
       i = i + 1
     UNTIL i > 4
     return 
    
    CompleteGood: 'Tested out good so we will let everyone know.
     
       High StatLED
       Pause 100
       Low StatLED
       Pause 300
     end
    
    
     
    
    ADC:
      low CS		' Activate the ADC0831. 
      shiftin AData,CLK,msbpost,[ADVar\9]	' Shift in the data. 
      high CS		' Deactivate '0831.
      pause 500
      serout 3,baud,[ADVar]
      pause 1000
    Attached Images Attached Images  

  5. #5
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: I am Completely NEW to PICS and LOST PIC18f252

    It looks like Mpasm doesn't know where to find its include files. Look in your directory: C:\Program Files\Microchip\MPASM Suite and see if you can find a P18F252.INC file in there.

  6. #6
    Join Date
    Feb 2011
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: I am Completely NEW to PICS and LOST PIC18f252

    it is not there? Now what?

  7. #7
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: I am Completely NEW to PICS and LOST PIC18f252

    Sounds like a 100 meg download is in order. What version of PBP do you have? If it is 2.60, then you can download the newest version of mplab ide. http://www.microchip.com/stellent/id...&part=SW007002

    Otherwise, you will need 8.15, which can be found here: http://melabs.com/resources/win_ide.htm

    Which version of Mplab ide do you have?

  8. #8
    Join Date
    Feb 2011
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: I am Completely NEW to PICS and LOST PIC18f252

    2.60A i just purchased it from mouser this last week.

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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