View previous topic :: View next topic |
Author |
Message |
GegFord
Joined: 16 Dec 2019 Posts: 5
|
18F1320 PortB direct addressing |
Posted: Mon Dec 16, 2019 7:43 am |
|
|
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: 19545
|
|
Posted: Mon Dec 16, 2019 7:47 am |
|
|
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
|
|
Posted: Tue Dec 17, 2019 5:32 am |
|
|
Wow! That's fantastic. I'll give it a try, Thanks ever so much. |
|
|
|