View previous topic :: View next topic |
Author |
Message |
husq
Joined: 08 Dec 2005 Posts: 5
|
About the ports |
Posted: Fri Dec 16, 2005 10:47 am |
|
|
I have been looking around the forum for info and I have found alot. But not where I can read about the ports. In many examples people point to PortA, PortB with a number like
#byte PortB=6, where can I find the adress to the corresponding port?
Another thing, this #byte command why use it, it is declared as an int so why not use the int instead?
Greatful for any answare. |
|
|
Ttelmah Guest
|
|
Posted: Fri Dec 16, 2005 11:14 am |
|
|
First part. The chip's data sheet.
Second part. These a fixed 'registers' in the processor. If you create a variable, it talks to the user RAM. The byte definition, creates a 'dummy' register, which talks to a specified address. You can use the int definition, like this:
Code: |
int8 PORTA;
#locate PORTA=0x6
|
This declares an integer variable called 'PORTB', and then tells the compiler to put this at address 6. The #byte declaration, does both parts in one line.
Best Wishes |
|
|
Ttelmah Guest
|
|
Posted: Fri Dec 16, 2005 11:26 am |
|
|
Other than not being able to tell my 'PORTA', from my 'PORTB', hopefully the rest makes sense.....
Best Wishes |
|
|
husq
Joined: 08 Dec 2005 Posts: 5
|
Thanks!! |
Posted: Fri Dec 16, 2005 11:28 am |
|
|
You say data sheet, I was looking at it and is it in the I/O part, discribed as bit6, bit5 etc? |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri Dec 16, 2005 11:54 am |
|
|
I don't know what chip you using. but lets say the 16F877A
This is the spec.
http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf
Goto page 19
You will see port A at 0x5
trisA at 0x85 and a whole lot more.
I think of the #byte as an overlay.
#byte Tims_great_8bit_variable = 0xF83
//note: no semicolon 83=D0 on a 18F452
This overlays the variable on the pins,.. so to speak
You still have to set the tris correctly.
then on outputs if you set the variable, the pins are set.
on input.. the variable is the value of the digital voltage at the pins.
Does that make sense? |
|
|
husq
Joined: 08 Dec 2005 Posts: 5
|
Absolutly |
Posted: Fri Dec 16, 2005 12:07 pm |
|
|
Thank you very much, it all makes sense now! |
|
|
|