PDA

View Full Version : I am Completely NEW to PICS and LOST PIC18f252



BCbeginner
- 26th February 2011, 18:57
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?


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

cncmachineguy
- 26th February 2011, 19:24
I don't see where you ever call the ADC routine

Bruce
- 26th February 2011, 20:05
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;

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.

BCbeginner
- 27th February 2011, 03:16
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)



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

ScaleRobotics
- 27th February 2011, 03:29
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.

BCbeginner
- 27th February 2011, 15:10
it is not there? Now what?

ScaleRobotics
- 27th February 2011, 15:17
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/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&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?

BCbeginner
- 27th February 2011, 16:27
2.60A i just purchased it from mouser this last week.