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.

Help required on 8bit to 10bit conversion

Status
Not open for further replies.

comsians

Member level 1
Joined
May 22, 2005
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,755
I am using PIC 16F877 now i want to transfer my data which is present in SSPBUF to the prot in Parallel way of 10bit in such a way that 8bit is full consumed from port 2 and take 2bit (two pins) from port three how is it possible

Am i using MAsking or other technique ? plz help me if masking How ?
 

VVV

Advanced Member level 5
Joined
Nov 26, 2004
Messages
1,582
Helped
384
Reputation
768
Reaction score
88
Trophy points
1,328
Activity points
19,971
If the other pins of the port are inputs, you do not need to do anything else, just write to the port. Only the two pins which are outputs will be affected.

If the other port pins are also outputs and they are dedicated to other functions, then you do not want to disturb them as you update the other two bits. You need to mask them. What I suggest is keep a copy of what you write to that port, say PORT_MIRROR. Now when you write to that port, update the mirror, too.
Make sure you have a mask (MASK, has zeroes) that clears the two bits that will be coming from somewhere else, say they are coming from SOURCE.
You may need a second mask that clears all bits, except the ones you need to update, MASK_1. This is the complement of MASK.
Before applying MASK_1, you can do a few rotate operations, in case the bits are not in the position you want, say the bits you read are in positions 5:4 and you need t write to the port pins 2:1. You first shift the bits, then mask out the rest, then you do the OR, etc.

Remember, you must also write to the mirror whenever you change any of the other port pins, too.

Another techique is to simply test the bits of the SOURCE and then set/ clear the port pins. This results in the pins not being updated at the same time, but if that is acceptable, then you can use this technique, too.


Code:
movlw MASK                 ;clear the two bits in the mirror, that need updating
andwf PORT_MIRROR,F ; 
movf SOURCE,W          ;read the two bits from the source
andlw MASK_1             ;clear all other bits, if they can be non-zero, except the two you need
iorwf PORT_MIRROR,W  ;form byte now
movwf PORT_MIRROR   ;update mirror
movwf PORT                ;update port pins
 

comsians

Member level 1
Joined
May 22, 2005
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,755
Here is my detail requirement of my project

PIC will require I²C to read a CMPS03 compass module

My Preference is for 10 pins providing 10 bit parallel output representing integer data received from the compass module.

The 10 pin connections will directly connect to a VIOM module.

I have provided the code given below

unsigned int get_cmps03(void)
{
unsigned int bearing;

SEN = 1; // send start bit
while(SEN); // and wait for it to clear
ACKDT = 0; // acknowledge bit
SSPIF = 0;
SSPBUF = CMPS03_ADDR; // cmps03 I2C address
while(!SSPIF); // wait for interrupt
SSPIF = 0; // then clear it.
SSPBUF = 2; // address of register to read from - high byte of result
while(!SSPIF); //
SSPIF = 0; //
RSEN = 1; // send repeated start bit
while(RSEN); // and wait for it to clear
SSPIF = 0; //
SSPBUF = CMPS03_ADDR+1; // cmps03 I2C address - with read bit set
while(!SSPIF); // wait for interrupt
SSPIF = 0; // then clear it.
RCEN = 1; // start receiving
while(!STAT_BF); // wait for high byte of bearing
bearing = SSPBUF<<8; // and get it
ACKEN = 1; // start acknowledge sequence
while(ACKEN); // wait for ack. sequence to end
RCEN = 1; // start receiving
while(!STAT_BF); // wait for low byte of bearing
bearing += SSPBUF; // and get it
ACKDT = 1; // not acknowledge for last byte
ACKEN = 1; // start acknowledge sequence
while(ACKEN); // wait for ack. sequence to end
PEN = 1; // send stop bit
while(PEN); //
return bearing;
}
Is i send SSPBUF buffer to the output port so that to send it in parallel by using your logic

Am I right ?

PLz help me I will be wating for your response
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top