CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

get(portb)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

get(portb)
PostPosted: Sun Jun 02, 2013 1:16 pm     Reply with quote

Hello everyone,
Is there a method where i can get the current weight value of some port
for example

Code:
get_portB()
{
//code
return weight;
}


note: PORTB is OUTPUT

Thanks in advance,
z3ngew


Last edited by z3ngew on Sun Jun 02, 2013 1:55 pm; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 1:24 pm     Reply with quote

weight?...

The port just has an 8bit value.

input_a()
input_b() etc.,

return this value for the corresponding port.
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 1:46 pm     Reply with quote

I'm sorry but is it possible that you provide me a code snippet ? I cannot get it to work. Is there some directive that need to be declared ? I used it like this:
Code:

int16 data;
data = input_B();


Thanks,
z3ngew
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 1:56 pm     Reply with quote

Depends on your chip.

In some cases the ports wake up configured for other things (generally not). So for instance on a PIC18F4550, if the PBADEN fuse is set, the whole port wakes configured for analog I/O, and you have to turn this off. There are similar things with things like some ECCP ports, etc..
This is always down to reading the chip data sheet, looking at the peripherals listed on the pins, and what their 'priority' is, then turning off any that override the normal I/O.
temtronic



Joined: 01 Jul 2010
Posts: 9173
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 1:57 pm     Reply with quote

Since Ports on a PIC are 8 bit wide,you need to declare the receiving variable as either int8 or unsigned int8 NOT int16!

int8 incoming_data;

incoming_data=port_b();

I usually say...

char incoming_data;

as 'char' is the same as 'unsigned int8' so data is from 000 to 255

This should work, if not, please post your entire program as there must be something else wrong...


hth
jay
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 2:03 pm     Reply with quote

the data is NOT INPUT,
the TRIS register is 0 => output
I just want to know the current state value of the port??

thanks,
z3ngew
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 2:30 pm     Reply with quote

Talk about moving the goalposts.....

Code:

#BYTE LATB=getenv("SFR:LATB")

//Then just read LATB as a variable


This will just read the output latch.
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 2:35 pm     Reply with quote

This works great, Many thanks my friend.
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

PostPosted: Sun Jun 02, 2013 4:59 pm     Reply with quote

I'm sorry but this method seem to work in very strange way,
if i make the following:

Code:
#BYTE LATB=getenv("SFR:LATB")
int 8 data;
data = latb;
output_b(0);
printf(lcd_putc, "%d", data);

Now the result is supposed to be there, but the result is a number 53
how com?

Thanks in advance,
z3ngew
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Mon Jun 03, 2013 1:45 am     Reply with quote

So?.

The number will be what was in the latch at the moment you read it. Dependant on what was previously written, how the chip happened to boot, etc. etc..

It'll be zero, if you read it after you write (unless pins that are controlled by other peripherals are involved).
z3ngew



Joined: 20 Apr 2013
Posts: 50

View user's profile Send private message

PostPosted: Mon Jun 03, 2013 3:46 am     Reply with quote

this code works perfectly

Code:
#byte MCU_PORTA = getenv("SFR:PORTA")


Thanks for your support,
z3ngew
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Mon Jun 03, 2013 4:02 am     Reply with quote

Er.

You seem to be misunderstanding things wildly.

The register 'PORTB', is the physical port.
The register 'LATB', is the output latch

If as you said the TRIS is set to 0, then they will only differ if the pins are overloaded.

If you write to the output latch, and the TRIS is zero, then the value you write will be sent to the port drivers. If you read the latch, this will show what is being sent to the drivers. If the value from the port differs from the latch, then something is preventing the pins going to the levels specified in the latch, and the chip is being overdriven.

PORTB, is what input_b() returns.

I have a sneaking suspicion you are trying to control TRIS yourself, and have not selected FAST_IO.

#use fast_io(b)

Then you can control TRIS and the compiler will not override your settings, and use input_b to read the port.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group