symbol PORTB = 6

#1
I have returned to trying to program PICAXE using PIC Basic Programming and Projects (Dogan Ibrahim) using PICAXE Editor. In project 3 four symbols are defined:

symbol TRISB = =134
symbol PORTB = 6
symbol led = B0
symbol ms500 = 500
when I check the program in PICAXE editor it shows a syntax error in line 2 at or before character 12

Can anyone explain why I get this error. I can't find any reason why this particular register is causing the problem.
 

hippy

Technical Support
Staff member
#2
PORTB is a reserved word in commands for older PICAXE chips, for example -

Low PORTB 1

Similarly for PORTC -

If PORTC pin2 = 1 Then

I would guess they remain reserved words for consistency.

You can get round the issue by using #DEFINE rather than SYMBOL. Note there are no equal signs used -

#Define PORTB 6
#Define PORTC 7
 
#3
Thanks for yor reply hippy, I had thought there was a special case for PORTB. I changed the program to #DEFINE PORTB = 6 and the syntax check passed
but in simulation there is no output showing. Simulating an 18M2+. THe following is the program as shown in the book, any thoughts?


symbol TRISB = 134
#DEFINE PORTB 6

symbol led = B0
symbol ms500 = 500
'set port RB pins to outputs
POKE TRISB, 0
led = 0
again: POKE PORTB,led
PAUSE ms500
led=led+1
GOTO again
END
 

hippy

Technical Support
Staff member
#4
You have to use POKESFR to update the SFR registers. POKE just writes to RAM on an M2.

I also cannot remember if POKESFR TRISB will work or not. When accessing on-chip peripherals you will often be battling with the PICAXE firmware which is doing the same, resetting and altering things you are trying to control.

The definition of TRISB is probably wrong as well, the POKESFR addresses are encoded differently to how a PIC has it, for the 18M2 I believe it should be -

Symbol TRISB = $2D

It's not usually worth accessing on-chip SFR unless there is good reason to do that. The following will achieve the same using pure PICAXE Basic -
Rich (BB code):
symbol led = B0
symbol ms500 = 500
'set port RB pins to outputs
dirsB = $FF
led = 0
again: outpinsB = led
PAUSE ms500
led=led+1
GOTO again
 
Top