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 CCS Technical Support

18F1320 PortB direct addressing

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



Joined: 16 Dec 2019
Posts: 5

View user's profile Send private message

18F1320 PortB direct addressing
PostPosted: Mon Dec 16, 2019 7:43 am     Reply with quote

In the past I successfully completed numerous projects using the 16F876. I declared Port B like this:

#Byte PortB = 0x06

That was fine, never had any problems.

I'm now working with an 18F1320. The address given for Port B is 0xF81, and indeed the Watch window give the PortB address as 0XF81 but how do I address is directly as before?

I tried:
#Long PortB = 0x0F81

But that didn't work. I found a way around what I wanted to do without addressing the port directly but I would love to know, just out of interest how to do it. It may be that is can't be done at all - that too would be a valid reply to the question.

Any insights gladly received.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Dec 16, 2019 7:47 am     Reply with quote

Are you reading or writing?.

On the PIC18, things change. You need to write to the LAT (not to the port),
but read from the port.

Best way is to use the compiler defines:
Code:

#byte LATB=getenv("SFR:LATB")
#byte PORTB=getenv("SFR:PORTB")


Then to read things from the port, read 'PORTB', but to write values to
the port, write to LATB.
GegFord



Joined: 16 Dec 2019
Posts: 5

View user's profile Send private message

PostPosted: Tue Dec 17, 2019 5:32 am     Reply with quote

Wow! That's fantastic. I'll give it a try, Thanks ever so much.
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