Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to separate 8 bits into two 4 bit segments

Status
Not open for further replies.
I'm looking for some advice on how to take an 8 bit number and convert it where I preserve all of the bits in the 8 digit byte, but have them separated into to different user files. (All in assembly)

I've tried to think through it a little, but I really can't think of a way to do it.

Maybe I'm thinking about it the wrong way and splitting into two 4 bit segments won't help.
I need to take a number, say, 75, and then take the tens place value (the 7) into one bit and then the ones place value (the 5) into another bit. From there, they will be clocked separately into an LCD display.

Any help is appreciated.


Also: I'm wondering how to check the remaining memory on a PIC. I've got a 16F818 that I think was getting too full (compile errors indicating out of range). When I deleted some code, it compiled without error. How can this be checked?

Thanks!
 
Last edited:
Hi,

Check Nigel's tutorial:
There's a conversion routine there.

As for the error message, can you post the full error message and the corresponding line where it failed?
 
Here you go,
Code:
	movfw	Byte
	andlw	0x0f
	movwf	LowNibble
	swapf	Byte,w
	andlw	0x0f
	movwf	HighNibble
As for checking memory, tell us what compiler/assembler you are using and what the error message is.

Mike.
 
Thanks for the help. I'll have to think through that and see how it works. Much appreciated.

As far as the error:
I was using MPLAB MPASM to program a 16F818. Unfortunately, I've overwritten the code that was giving me an error. I had something like this towards the end of my code:

DO
STUFF
GOTO CONDA

DO
MORE STUFF
GOTO CONDB

DO
EVEN MORE STUFF
GOTO CONDC

CONDA
CONDB
CONDC
END

(Obviously not the actual code). Well, I had probably hundreds of lines of code counting my subroutines for writing to the dispay. Everything was compiling fine, and then I added several lines of code to the top. It then told me in a build error that GOTO "CONDC is out of range." I changed the name a few times, and it kept telling me it was out of range. I deleted some other peice of code that I wasn't using at the time (that wasn't causing an error beforehand) and it built successfully. This lead me to believe that the built file was too big for the PIC, and that MPLAB recognized this and as such gave an out of range error on the last few lines of code.
 
Last edited:
As for the program memory used, looked to the .lst file in MPLAB project folder. The Pickit 2 standalone software shows the program memory in a watch window, with unused memory displayed as hex FFF.
 
It's possible you are running out of memory as the 818 only has 1k of program memory. However, with MPLAB, the error should not have been goto out of range. If you are out of memory then a simple way to fix it would be to switch to either a 16F819 (2k) or the modern equivalent the 16f88 with 4k. Note that the 88 has two 2k banks and so bank switching will be required to use all of it.

Mike.
 
Code:
    movfw    Byte
    andlw    0x0f     ;0Fh
    movwf    LowNibble
    swapf    Byte,w
    andlw    0xf0     ;doesn't this have to be F0h 
    movwf    HighNibble
 
Last edited:
Code:
    movfw    Byte
    andlw    0x0f     ;0Fh
    movwf    LowNibble
    swapf    Byte,w
    andlw    0xf0     ;doesn't this have to be F0h 
    movwf    HighNibble

Shouldn't the last "andlw" be 0x0f just like the first one. The "swapf" will place the nibble-reversed value into "W" so the previous high nibble will not be in the low nibble and you will want to clear what are not its top bits.

Susan
 
Colin,

No, it should be 0x0f, as I originally posted. As Susan pointed out, the swapf reverses the nibbles.

Mike.
 
Last edited:
OK. You are doing two things at the same time. Reversing the nibbles and putting the result in w.

I was thinking you were swapping the Byte with the value in w.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top