can you disable hserin without disabling hserout

hax

New Member
I am running out of I/Os and I am using Hserout to send serial commands to an Oled screen, using a 40x1. Thats all working well.


But I have an LED wired to portc 7 which I was hoping to use as an output at the same time.


Trouble is that when you use the hsersetup command, the chip attempts to receive serial in via portc 7, making it an input rather than an output.

Is there a way to write to the appropriate memory location to set portc 7 to either an input or output while the hserout command still works on the adjacent pin?


I know I can turn off (hsersetup off) but I'd prefer not to every time I write to the screen because then the LED will flash every time I write to the screen. (all be it briefly)

I am almost constantly writing to the screen, and the led will be flashing like mad.

I'm hoping someone has mapped the memory location required to do this. ? Maybe Tech can help?
 

hax

New Member
Or failing that, is there a way to use the programming serial out pin as an output?

I know the 18x1 uses POKE $05,%00001000 but that doesnt work on the 40X1.


Anyone know what is the address for the 40x1 serial out programming pin?
 

womai

Senior Member
According to the Microchip datasheets for the 16F88 (on which the Picaxe 18X is based) and the 16F887 (Picaxe 40X1), both Picaxes have the PORTA register at the same SFR address ($05). I assume you actually tried POKE $05,%00001000 on the 40X1? (or do you just assume it won't work?). In that case there must be a difference in the firmware. Just before poking $05, you may also try to poke SFR address $85 (i.e. TRISC register, which decides if the pin is an input or an ouput - beware, the bit coding is the opposite of the Picaxe, i.e. 0 is output and 1 is input).

Wolfgang
 

hax

New Member
Thanks Wolfgang,

Originally I did try POKE $05,%00001000 but it does not work on the 40x1. After your info, I also tried poke $05,%00000000 but that didnt work either.


Thanks also for the SFR $85 address but that does not work too...

I tried the following:


poke $85,%00000000

and

poke $85%11111111

both without success.

I noticed that when I used poke $85,%00000000 that the download serial out line would go high for half a second every second. Not sure if this gives anyone a clue as to what could be happening? Also, portc outputs were not working with this command.

I assume that if it was poke $85,%1111111 then it would turn on outputs and poke $85,%00000000 would make them inputs...

If anyone has used the download serial out port successfully, do let us know!
 

Dippy

Moderator
Never tried it. All the following is based on Data Sheets:

Firslty, I don't understand why C.7 is causing the LED to flash? C.7 (pin 26) is Hserin as you say and in input mode.
Is there some ack from the OLED coming back to PICAXE? If it ain't needed disconnect it maybe?

Guesswork:
Can't you just set TRISC (87h?) bit 6 to 0? Flash your LED and then back to 1 when finished?
I wouldn't touch it, but if it's really needed you may like to look disabling/enabling SPEN (RCSTA<7>) Serial Port Enable bit Address 18h. Bit that could mess up any Hser setup.
Then fiddle with TRISC. Then restore it before your next Hserout.
I just don't know if it'll upset other things. I don't know the firmware routine.
I think I'd move my LED to another pin. If you've run out of legs could you tristate or multiplex?

I haven't checked on that particular chip, but isn't 85h ($85) TRISA?
And TRISx only sets direction, you need to look at PORTx. PORTC is 07h.
 

Technical

Technical Support
Staff member
Due to the way the PIC internal hardware serial port works, when you enable the serial operation you get both pins setup for serial, you cant use TXD without RXD or vice versa.
 

hax

New Member
OK thanks Tech and all.

After reading all that it sounds like I have no choice but to try to use the download pin serial out as a regular output.

But the 18x trick of using POKE $05,%00001000 does not work on my 40x1.

Could Technical spill the beans as to which register to poke to on the 40x1?
 

Dippy

Moderator
Wrong HEX. Check out the Microchip Data Sheet.

On a 16F88/18X the serial out pin is on ICpin2 = PortA.3.

POKE $05,%00001000. That should set PortA<3> high
Fine on 16F88 / 18X.

I'm probably looking at wrong PIC Data Sheet but 40X1 Serial Out is on IC Pin7 which corresponds to PIC PortA<5>.

Therefore, if I am looking at correct Data Sheet, you should try POKE $05,%00100000
That will set PortA<5:0> to %100000.

I would always read the PortA before Poking as writing to a Port will set the output latch to the values you've specified.
Reading Microchip Data Sheets is really a good move.
 

hax

New Member
Thanks Dippy,

Yes that was it. Confirming that POKE $05,%00100000 does work correctly with a 40X1 serial out download pin.


Now this sets other pins low which is not what I would like.

I remember a long time ago there was some discussion on how to mask bits with the & symbol and the "OR" instruction. But this was over my head. Maybe Hippy can comment on this as he is the resident expert on number crunching?


I can see that the and function in the manual refers to masking all other "nibbles" but then I dont get how the OR function is used to control the nibble I am after...
 

womai

Senior Member
Here's the most elegant solution I could come up with:

' set serial output high without affecting other pins
peek $05,b0 ' read current state of all 8 pins
bit5 = 1 ' modify only single bit corresponding to serial out pin
poke $05,b0 ' write back modified value

' set serial output low without affecting other pins
peek $05,b0
bit5 = 0
poke $05,b0


If you want to do it the hard way through bit masking, here you go (but doesn't do anything better than the previous code and is more complicated):

' set serial output high without affecting other pins
peek $05,b0 ' read current state of all 8 pins
b0 = b0 | %00100000 ' modify only single bit corresponding to serial out pin
poke $05,b0 ' write back modified value

' set serial output low without affecting other pins
peek $05,b0
b0 = b0 & %11011111 ' modify only single bit corresponding to serial out pin
poke $05,b0


Wolfgang
 

SD2100

New Member
Think I'll stick with the bit masking, seems more readable to me even though I could have dropped the b0 and used the constant %00100000 as the mask:)
 
Top