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.

Rearranging data - 16F877 in assembler

Status
Not open for further replies.

atferrari

Well-Known Member
Most Helpful Member
I need to manipulate inputs pins and associated flags. For initial process I need this data arranged as follows:



INA A8 A7 A6 A5 A4 A3 A2 A1
INB B8 B7 B6 B5 B4 B3 B2 B1
INC C8 C7 C6 C5 C4 C3 C2 C1
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - --
ING G8 G7 G6 G5 G4 G3 G2 G1
INH H8 H7 H6 H5 H4 H3 H2 H1

Later, for further process I need the data rearranged like this:

reg1 A1 B1 C1 D1 E1 F1 G1 H1
reg2 A2 B2 C2 D2 E2 F2 G2 H2
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
reg7 A7 B7 C7 D7 E7 F7 G7 H7
reg8 A8 B8 C8 D8 E8 F8 G8 H8

I've been looking for matrix handling, in assembler for a 16F877 but found nothing simple to understand.

Could anyone point me in the right direction or just tell me what is the way to go? I am not asking for code (of course it would be good to have it ready) but for the idea to implement the conversion, back and forth, if necessary.

What I actually need is 8 "channels" with 16 ( 8 + 8 ) flags, each.

All what I found in PICLIST related bits handling seem to lead to a unnecessary complex solution.
 
This should do what you want. It uses indirect addressing to swap the bits around as you describe. This is 8*8 bits which is as you described it diagramatically.

Code:
StartVars       equ     20h; to 27
EndVars         equ     28h; to 2f
OuterCount      equ     30h
InnerCount      equ     31h
Temp            equ     32h


                movlw   8
                movwf   OuterCount
OuterLoop       movlw   8
                movwf   InnerCount
                movlw   StartVars
                movwf   FSR
                bcf     STATUS,IRP
InnerLoop       rrf     INDF,F
                rlf     Temp,F
                incf    FSR,F
                decfsz  InnerCount,F
                GoTo    InnerLoop
                movlw   EndVars-1
                addwf   OuterCount,W
                movwf   FSR
                movfw   Temp
                movwf   INDF
                decfsz  OuterCount,F
                GoTo    OuterLoop

If you want the start data to remain unchanged then change the inner loop to:-

Code:
InnerLoop       rrf     INDF,F
                rlf     Temp,F
                bsf     INDF,7
                btfss   Temp,0
                bcf     INDF,7
                incf    FSR,F
                decfsz  InnerCount,F

Hope that helps.

Mike.
 
Thanks a lot

Hola MIke,

I will give a try shortly. Much shorter than using rotates. :D

A lot of Gracias :!: .
 
There is a mistake in that code

It puts the bytes backwards in the answer. So the first byte will contain

A8 B8 ....... H8

This should fix it

Code:
StartVars       equ     20h; to 27
EndVars         equ     28h; to 2f
OuterCount      equ     30h
InnerCount      equ     31h
Temp            equ     32h


                movlw   8
                movwf   OuterCount
OuterLoop       movlw   8
                movwf   InnerCount
                movlw   StartVars
                movwf   FSR
                bcf     STATUS,IRP
InnerLoop       rlf     INDF,F ;  < ----------- this changed
                rlf     Temp,F
                incf    FSR,F
                decfsz  InnerCount,F
                goto    InnerLoop
                movlw   EndVars-1
                addwf   OuterCount,W
                movwf   FSR
                movfw   Temp
                movwf   INDF
                decfsz  OuterCount,F
                goto    OuterLoop

If you want the start data to remain unchanged then change the inner loop to:-

Code:
InnerLoop       rlf     INDF,F ; <---------
                rlf     Temp,F
                bsf     INDF,0 ; <----------
                btfss   Temp,0
                bcf     INDF,0 ; <----------
                incf    FSR,F
                decfsz  InnerCount,F

Hope that helps.

Mike.
 
Status
Not open for further replies.

Latest threads

Back
Top