PULLUP command for PICAXE14M2

Andrei IRL

Senior Member
Hi Everyone.

I am currently struggling to understand how to make pin assignments using bits.

I have red the manuals and found examples but it is still not clear to me.

Would any one be so kind to explain how to enable internal Pull Up resistors for PIN C.3 and PIN C.2.

I will only be using these pins as push button inputs.

Thanks very much in advance.
 

rq3

Senior Member
Hi Everyone.

I am currently struggling to understand how to make pin assignments using bits.

I have red the manuals and found examples but it is still not clear to me.

Would any one be so kind to explain how to enable internal Pull Up resistors for PIN C.3 and PIN C.2.

I will only be using these pins as push button inputs.

Thanks very much in advance.
Hi Andrei. I've never used a 14M2, but according to the manual, it has 16 available pull-up bits (B.0-B.7, and C.0-C.7).
So, to pull up C.3 and C.2 you would:
Code:
pullup %0000110000000000
Reading from RIGHT to LEFT, the bits represent B.0 through B.7 and then C.0 through C.7
 

hippy

Technical Support
Staff member
As the manual describes it and rq3 says ...

Code:
; C.0 ---------..--------- B.7
; C.1 --------.||.-------- B.6
; C.2 -------.||||.------- B.5
; C.3 ------.||||||.------ B.4
; C.4 -----.||||||||.----- B.3
; C.5 ----.||||||||||.---- B.2
; C.6 ---.||||||||||||.--- B.1
; C.7 --.||||||||||||||.-- B.0
;       ||||||||||||||||
PULLUP %abcdefghijklmnop
;
;   Bit 1111119876543210
;       543210
I find it handy to include a diagram like that where I have a PULLUP command, or a reduced version of it ...

Code:
; C.2 -------.
; C.3 ------.|
;           ||
; C.7 --.   ||         .-- B.0
;       |   ||         |
PULLUP %0000110000000000
 

Andrei IRL

Senior Member
Hi Andrei. I've never used a 14M2, but according to the manual, it has 16 available pull-up bits (B.0-B.7, and C.0-C.7).
So, to pull up C.3 and C.2 you would:
Code:
pullup %0000110000000000
Reading from RIGHT to LEFT, the bits represent B.0 through B.7 and then C.0 through C.7
Thanks very much hippy.

I was changing bit values from left to right and was getting errors about pin B.7 not existing and couldn't understand what i was doing wrong.

Thanks very much for the very good explanation and schematics.

Much appreciated.
 

rq3

Senior Member
As the manual describes it and rq3 says ...

Code:
; C.0 ---------..--------- B.7
; C.1 --------.||.-------- B.6
; C.2 -------.||||.------- B.5
; C.3 ------.||||||.------ B.4
; C.4 -----.||||||||.----- B.3
; C.5 ----.||||||||||.---- B.2
; C.6 ---.||||||||||||.--- B.1
; C.7 --.||||||||||||||.-- B.0
;       ||||||||||||||||
PULLUP %abcdefghijklmnop
;
;   Bit 1111119876543210
;       543210
I find it handy to include a diagram like that where I have a PULLUP command, or a reduced version of it ...

Code:
; C.2 -------.
; C.3 ------.|
;           ||
; C.7 --.   ||         .-- B.0
;       |   ||         |
PULLUP %0000110000000000
Hippy, this begs the obvious question. What does the 14M2 do with the extra bits? It obviously doesn't need all 16 of them (B.6,B.7,C.6,C.7 don't exist)! Are they just tossed during the compile? I'm assuming that the compiler is smart enough to know what to do (and it certainly seems to be). Is the mask consistent between versions of Picaxe to make it easier for the user, or the compiler? Or both? Just curious.
 

AllyCat

Senior Member
Hi,

Is the mask consistent between versions of Picaxe to make it easier for the user, or the compiler? Or both?
Both. The 14M2 and 20M2 base PIC chips actually have three ports internally, A, B and C, but the internal interpreter maps those to (parts of) the standard PICaxe B and C ports.

Historically, the PICaxe port.pin numbers are mapped (converted) to numbers from 0 to 15 which can be considered as counting the bits from right to left (across the two ports), or as a "power of two". Thus you can select pullup c.2 (= bit 10 = 2^10, where ^ means exponent not xor) as PULLUP 1024 , etc..

Cheers, Alan.
 

rq3

Senior Member
Hi,



Both. The 14M2 and 20M2 base PIC chips actually have three ports internally, A, B and C, but the internal interpreter maps those to (parts of) the standard PICaxe B and C ports.

Historically, the PICaxe port.pin numbers are mapped (converted) to numbers from 0 to 15 which can be considered as counting the bits from right to left (across the two ports), or as a "power of two". Thus you can select pullup c.2 (= bit 10 = 2^10, where ^ means exponent not xor) as PULLUP 1024 , etc..

Cheers, Alan.
Well put, Alan. I can see how that makes the folks writing the Picaxe bootloader and compiler have an easier life. The "extraneous" bits get deleted, which explains the compiled code size. Many thanks!
 

hippy

Technical Support
Staff member
Hippy, this begs the obvious question. What does the 14M2 do with the extra bits? It obviously doesn't need all 16 of them (B.6,B.7,C.6,C.7 don't exist)! Are they just tossed during the compile? I'm assuming that the compiler is smart enough to know what to do (and it certainly seems to be).
PE6 reports when attempts are made to set pull-ups on pins which do not exist. And, if it doesn't, those will simply be ignored.

Is the mask consistent between versions of Picaxe to make it easier for the user, or the compiler?
The bit mask is generally consistent, but not entirely. The online version of the PULLUP documentation states exactly which bits are used -

http://www.picaxe.com/BASIC-Commands/Digital-InputOutput/pullup

Code:
08M2         bit1-bit4 = C.1 to C.4 	 
14M2         bit1-bit5 = B.1 to B.5  bit8-bit12 = C.0 to C.4
18M2         bit0-bit7 = B.0 to B.7 	 
20M2         bit0-bit7 = B.0 to B.7  bit8-bit15 = C.0 to C.7
20X2         bit0-bit7 = C.0, C.6, C.7, B.0, B.1 B.5, B.6, B.7 	 
28X2/40X2    bit0-bit7 = B.0 to B.7
 
Top