Access and manipulating SFR registers

GrahamGo

Senior Member
With the M2 series I notice the absence of setbit, clearbit and togglebit, can't find testbit, maybe that's - bitx ?

I cannot understand this because it seems a basic requirement. I am playing with some SFR's and the following code works, but it seems quite inefficient. So my question, is there a better way to set, clear and test bits in the SFR (and other locations, variables etc for that matter)

Code:
; just playing with OSCTUNE variable which has a hypothetical bit 3 called TXEN

symbol OSCTUNE = $9b 			' declare the SFR address
symbol OSCTUNE.TXEN = $08 ' declare the SFR bit name at position bit3 
 
pokesfr OSCTUNE,$08 ' preset bit 3

    peeksfr OSCTUNE,b0 : b0=bit3 ' this to test bit 3's status

pokesfr OSCTUNE,$FF ' preset to all 1's

    peeksfr OSCTUNE,b0 : b0=b0 AndNot OSCTUNE.TXEN : pokesfr OSCTUNE,b0 ' this to clear the SFR's bit 3

pokesfr OSCTUNE,$00 ' preset to all 0's

    peeksfr OSCTUNE,b0 : b0=b0 Or OSCTUNE.TXEN : pokesfr OSCTUNE,b0 ' this to set the SFR's bit 3
 
Last edited:

westaust55

Moderator
Not "knocking" the new M2 parts but through PICAXE history there have been a few "levels" with respect to program space, number of variables and available commands. A heirarchy within the PICAXE chips is the way to think of it.
Hence the M2 parts do not have the same bit control and test functions as the X2 parts.
PIC memory capacity for the firmware is also a deciding factor in what commands can be provided in a particular PICAXE part type.

Often the same functionality can be achieve in lower tier by bit-banging techniques as you have found.

At the end of the day, there are not a significant number of questions about SFR access suggesting most PICAXE users stay within the main BASIC commands.
 

srnet

Senior Member
I cannot understand this because it seems a basic requirement.
There will be different views as to what is a 'basic requirement'.

As any function will occupy some of the available memory space, it becomes a decision of what other functions do you leave out or how much do you cut the space available for user programs ?
 

GrahamGo

Senior Member
Hi, I'm starting to see the intricacies. But its taking some time! I bought into the M2 without really studying the chip differences, I actually thought the X parts where "old".

Anyway, I now have the M2 i2C portion pretty much sorted and working using the chips hardware, but getting the slave interrupt part correct is taking some effort. I am waiting for some X2 parts to arrive in order to double check my M2 hardware i2C and SPI both work the same as the X2.

But the divide between the M2 X2 is closing a little. For me the M2 multitasking is of special interest. I have just made a big edit on the original post as I "saw the light" but would still appreciate any hints etc. One day I can maybe contribute?
 
Last edited:

GrahamGo

Senior Member
There will be different views as to what is a 'basic requirement'.

As any function will occupy some of the available memory space, it becomes a decision of what other functions do you leave out or how much do you cut the space available for user programs ?
Yes I can see this, and I accept what you say. Now to compare the flash of the M2 and X2 parts - just kidding..!
 

hippy

Ex-Staff (retired)
The way I'd do it is ...

Symbol OSCTUNE = $9b
Symbol OSCTUNE.TXEN = bit3

PeekSfr OSCTUNE, b0
If OSCTUNE.TXEN = 1 Then ...

PeekSfr OSCTUNE, b0
OSCTUNE.TXEN = 0
PokeSfr OSCTUNE, b0

And so on.
 

GrahamGo

Senior Member
The way I'd do it is ...
And so on.
Thanks @Hippy. I fundamentally misunderstood the Basic variable-general description in the manual. Earlier I tried something like your example but obviously got that wrong.... Now I just need to apply this new knowledge.. brilliant!
 

westaust55

Moderator
A potted PICAXE history

Hi, I'm starting to see the intricacies. But its taking some time! I bought into the M2 without really studying the chip differences, I actually thought the X parts where "old".
Chronologically yes, the M2 parts were released later than the X2 parts but one must, as you now gather, consider the "power"/capabilities of each chip.

A potted PICAXE history (expanded upon what I had posted once before around 2008) is:

From what I have gleaned from Rev Ed’s own site:

release Date - PICAXE
?? Oct 2002 - 08
22 Jan 2003 - 18A and 28A
26 Apr 2003 - 28X
02 May 2003 - 40X
18 Sep 2003 - 18X
20 July 2004 - 08M
01 May 2007 - 14M, 28X1 and 40X1
20 Feb 2008 - 20M
31 Mar 2009 - 28X2 and 40X2 (in specific 3 V and 5 V versions)
03 Sep 2009 – 20X2
13 Aug 2010 – 18M2
03 Dec 2010 – 28X2 and 40X2 Updated (2.1 V to 5.5 V operating range)
01 July 2011 – 08M2, 14M2, 20M2
23 Jan 2012 – 18M2+
 

GrahamGo

Senior Member
That quite a history, will they be giving stuff away for their 10th anniversary in October? I need to find out where the party is being held..

My first contact with micros was the intel 8080 and a little later the z80, using a telex machine paper tape and all that. I vaguely remember writing a unix C compiler For the 8031 - times roll by......

More... Whats doing my head in ATM is trying to remember the data flow direction of peeksfr and pokesfr. One moves stuff to the left and the other to the right. I have a sticker on the monitor with arrows! Brains going... I wonder why they didn't reverse the arguments on one of them to keep the data flow direction consistent. I am sure there is an excellent reason.
 
Last edited:

Dippy

Moderator
Do you mean something like b1=Peek 80 ?

Dunno. Maybe it's done so it doesn't confuse target ex-Stamp users?
You'll just have to feed that old brain with some fish and remember it. :)
 

westaust55

Moderator
That quite a history, will they be giving stuff away for their 10th anniversary in October? I need to find out where the party is being held..
While it may be the 10th anniversary of the PICAXE later this year, Rev Ed was in business prior to that with items such as the CHIP FACTORY
http://www.picaxe.com/docs/chi001_manual.pdf


Whats doing my head in ATM is trying to remember the data flow direction of peeksfr and pokesfr. One moves stuff to the left and the other to the right.
Sorry but your left and right analogy does not help ???
Syntax of both commands the the same

PEEKSFR location,variable,variable,...
POKESFR location,data,data,...

PEEK as in look (peek) what is there = read the value out of the register
POKE as in shove (poke/store) into there = save/store the value into the register
 

Dippy

Moderator
I think he means like the example I gave on the previous page.
Other compilers use that general type of format I indicated. (I don't mean the specific command name).
On the other hand, Basic Stamp BASIC is very similar to PICAXE BASIC so that was probably the preferred syntax/format in the olden days.
 

hippy

Ex-Staff (retired)
Whats doing my head in ATM is trying to remember the data flow direction of peeksfr and pokesfr. One moves stuff to the left and the other to the right. I have a sticker on the monitor with arrows! Brains going... I wonder why they didn't reverse the arguments on one of them to keep the data flow direction consistent. I am sure there is an excellent reason.
Either option could have been chosen, it could have been either direction in both cases, and even Dippy's unary operator approach could be used for reading.

It's really just how the PICAXE Basic Language has been originally defined and evolved and there's a consistency within the data movement commands; READ / WRITE, GET / PUT, PEEK / POKE, PEEKSFR / POKESFR. It's just one of those things you have to get used to and remember.
 

GrahamGo

Senior Member
Thanks guy's. I wasn't complaining, its just that for the moment it just doesn't "stick", but my little yellow "post it" sticker with arrows is working fine.
Maybe I am depressed, we haven't seen the Sun for two days, and I live in what is regarded to be an area with the one of the best climates on the planet...... need a beer.
 
Top