replacing 18x wit 18M2 with 4bit LCD

MrSandman

New Member
Good afternoon Gentlemen
I have been asked to create another project which I originally built 4 years ago using an 18x device. I have many PCBs in the cupboard that I wish to use.
My problem
In the LCD routine, I used a peek $30 to read the current state of the output port of the 18x
When I tried an 18M2 in its place it failed to work properly. I am presuming the peek of $30 has changed in the 18M2
Can anybody help me. I have spent thee last two days pulling my hair out. I couldn't find any thing relevant in my forum search's

Code:
symbol  	RS        	       = 2			'0 = Command 1 = Data Register
symbol  	E         	       = 3         	              '0 = Idle    1 = Enable
symbol  	RSCMDmask   = %00000000 	'Select Command register
symbol  	RSDATmask    = %00000100 	'Select Data register

'*************************************************************************
'		Write Data to LCD Command or Data registers
'*************************************************************************
SendInitCmdByte:
	pause 15                        	               'Delay 15mS at 4MHz

SendCmdByte:
	peek $30,rsbit                  	               'Recover Out0 and Out1
	RSbit = RSbit & %11                          'Send to Command register
	goto SendCmdOrDataByte

SendDataByte:
	peek $30,RSbit			'Recover Out0 and Out1
	RSbit = RSbit & %11 | RSDATmask	'Send to Data register

SendCmdOrDataByte:
	pins = DByte & %11110000 | RSbit 	'Put MSB out first
	pulsout E,1                     	              'Give a 10uS pulse on E
	pins = DByte * %00010000 | RSbit 	'Put LSB out second
	pulsout E,1                     	              'Give a 10uS pulse on E
	return
 

Goeytex

Senior Member
Hi Sandman,

To answer your question, with the 18M2 you can read the state of the output pins with " RSbit = OutpinsB " , assuming you are using PortB pins.
 

MrSandman

New Member
Cheers for that Guys, I will try that tonight.
I have looked further and may have found an answer,
Peek $4C (76) = Port C on the 18m2
Peek $4D (77) = Port B on the 18m2
 

AllyCat

Senior Member
Hi,

Yes, the M2s map the SFRs differently to the earlier and "X" chips. Basically, the first 32 bytes of the first 8 banks are mapped into a single page of 256 bytes (except for access to the first 12 bytes of each bank which is barred).

However, beware that some of the M2s re-map their port pins, so that reading/writing the SFR port registers may give incorrect or confusing results. For example the 20M2 has its B and C ports arranged neatly along the two sides (with the serial output pin as A.0) whilst the base PIC chip has pins of ports A, B and C in almost equal numbers. So, to write "portable" code, it's better to use direct PICaxe commands, when possible.

Cheers, Alan.
 

hippy

Ex-Staff (retired)
Also PEEK and POKE use for earlier PICAXE has been superseded by PEEKSFR and POKESFR commands on later PICAXE, including M2 and X2 devices. PEEK and POKE will access RAM and not the actual SFR control registers and ports.
 
Top