Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Reading data into a single variable

Status
Not open for further replies.

cts_casemod

Member level 4
Member level 4
Joined
Dec 9, 2010
Messages
72
Helped
14
Reputation
28
Reaction score
14
Trophy points
1,288
Location
London
Visit site
Activity points
1,950
I am trying to read 11 bits of data spread over a few different ports on my pic microcontroller, into a single 16bit variable. The code language is ASM.

The uC is 16 bits so no issues with being more than 8 bits wide.

Will this be the right way to archieve what i need?

Code:
#define INPIN1 PORTA,0
#define INPIN2 PORTA,1
#define INPIN3 PORTA,2
#define INPIN4 PORTA,3
#define INPIN5 PORTA,4
#define INPIN6 PORTA,5
#define INPIN7 PORTA,6
#define INPIN8 PORTA,7
#define INPIN9 PORTA,8
#define INPIN10 PORTB,9
#define INPIN0 PORTB,10

 
   CLRF result
 
   btfsc ANYPIN0
   bsf result,0
   btfsc ANYPIN1
   bsf result,1
   btfsc ANYPIN2
   bsf result,2
   btfsc ANYPIN3
   bsf result,3
   btfsc ANYPIN4
   bsf result,4
   btfsc ANYPIN5
   bsf result,5
   btfsc ANYPIN6
   bsf result,6
   btfsc ANYPIN7
   bsf result,7
   btfsc ANYPIN8
   bsf result,8
   btfsc ANYPIN9
   bsf result,9
   btfsc ANYPIN10
   bsf result,10
if not any sugestions?
 

The method is correct and required for arbitrarily ordered pins. I presume you know that in the present example, multiple bits can be read in one instruction.
 
The method is correct and required for arbitrarily ordered pins. I presume you know that in the present example, multiple bits can be read in one instruction.

No, as a matter of fact I didnt, and that comes out to be very usefull!!

I have available RB0 to RB9. How would I change the code to make a sequential reading of those 10 pins?

Also, since I read the pins in a row I am assuming the result would be sampled at the same time without any timing skew? This was an issue when fetching data from several different pins as the input could have changed during the read.

I would quite happily discard the 11th bit and live with 10bit resolution if that were to be the case.

Regards
 

I presume this a 16-bit processor (PIC24 or dsPIC). So PORTA and PORTB can be read in a single instruction to a memory variable and processed later. There will be still a delay between reading different ports which can't eliminated.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top