Welcome
Username or Email:

Password:


Missing Code




[ ]
[ ]
Online
  • Guests: 6
  • Members: 0
  • Newest Member: omjtest
  • Most ever online: 396
    Guests: 396, Members: 0 on 12 Jan : 12:51
Members Birthdays:
No birthdays today

Next birthdays
11/27 Dax (42)
11/27 Mino (49)
11/29 Sonic (58)
Contact
If you need assistance, please send an email to forum at 4hv dot org. To ensure your email is not marked as spam, please include the phrase "4hv help" in the subject line. You can also find assistance via IRC, at irc.shadowworld.net, room #hvcomm.
Support 4hv.org!
Donate:
4hv.org is hosted on a dedicated server. Unfortunately, this server costs and we rely on the help of site members to keep 4hv.org running. Please consider donating. We will place your name on the thanks list and you'll be helping to keep 4hv.org alive and free for everyone. Members whose names appear in red bold have donated recently. Green bold denotes those who have recently donated to keep the server carbon neutral.


Special Thanks To:
  • Aaron Holmes
  • Aaron Wheeler
  • Adam Horden
  • Alan Scrimgeour
  • Andre
  • Andrew Haynes
  • Anonymous000
  • asabase
  • Austin Weil
  • barney
  • Barry
  • Bert Hickman
  • Bill Kukowski
  • Blitzorn
  • Brandon Paradelas
  • Bruce Bowling
  • BubeeMike
  • Byong Park
  • Cesiumsponge
  • Chris F.
  • Chris Hooper
  • Corey Worthington
  • Derek Woodroffe
  • Dalus
  • Dan Strother
  • Daniel Davis
  • Daniel Uhrenholt
  • datasheetarchive
  • Dave Billington
  • Dave Marshall
  • David F.
  • Dennis Rogers
  • drelectrix
  • Dr. John Gudenas
  • Dr. Spark
  • E.TexasTesla
  • eastvoltresearch
  • Eirik Taylor
  • Erik Dyakov
  • Erlend^SE
  • Finn Hammer
  • Firebug24k
  • GalliumMan
  • Gary Peterson
  • George Slade
  • GhostNull
  • Gordon Mcknight
  • Graham Armitage
  • Grant
  • GreySoul
  • Henry H
  • IamSmooth
  • In memory of Leo Powning
  • Jacob Cash
  • James Howells
  • James Pawson
  • Jeff Greenfield
  • Jeff Thomas
  • Jesse Frost
  • Jim Mitchell
  • jlr134
  • Joe Mastroianni
  • John Forcina
  • John Oberg
  • John Willcutt
  • Jon Newcomb
  • klugesmith
  • Leslie Wright
  • Lutz Hoffman
  • Mads Barnkob
  • Martin King
  • Mats Karlsson
  • Matt Gibson
  • Matthew Guidry
  • mbd
  • Michael D'Angelo
  • Mikkel
  • mileswaldron
  • mister_rf
  • Neil Foster
  • Nick de Smith
  • Nick Soroka
  • nicklenorp
  • Nik
  • Norman Stanley
  • Patrick Coleman
  • Paul Brodie
  • Paul Jordan
  • Paul Montgomery
  • Ped
  • Peter Krogen
  • Peter Terren
  • PhilGood
  • Richard Feldman
  • Robert Bush
  • Royce Bailey
  • Scott Fusare
  • Scott Newman
  • smiffy
  • Stella
  • Steven Busic
  • Steve Conner
  • Steve Jones
  • Steve Ward
  • Sulaiman
  • Thomas Coyle
  • Thomas A. Wallace
  • Thomas W
  • Timo
  • Torch
  • Ulf Jonsson
  • vasil
  • Vaxian
  • vladi mazzilli
  • wastehl
  • Weston
  • William Kim
  • William N.
  • William Stehl
  • Wesley Venis
The aforementioned have contributed financially to the continuing triumph of 4hv.org. They are deserving of my most heartfelt thanks.
Forums
4hv.org :: Forums :: Computer Science
« Previous topic | Next topic »   

PIC asm question

Move Thread LAN_403
AndrewM
Mon Apr 10 2006, 01:33AM Print
AndrewM Registered Member #49 Joined: Thu Feb 09 2006, 04:05AM
Location: Bigass Pile of Penguins
Posts: 362
Easy question, just dont have a PIC on hand to lash up and resolve this for myself:

When I move binary bytes to the PIC ports, which port bit corresponds to which bit in my binary string. For example, does 00000001 have the "1" in the pin 0 or pin 7 position??

Is this true for bank 0 and bank 1?

I ask because I *think* i remember setting the port directions in bank 1 operating differently that setting the output states normally in bank 0

[mod edit] Moved from Gen. Sci
Back to top
Bjørn
Mon Apr 10 2006, 02:32AM
Bjørn Registered Member #27 Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
RA0 and RB0 both corresponds to bit 0 in the file registers, so they are identical in that sense and there are no differences in how they are set up.

Port B has programmable pull up resistors for input.
Port A may have only 5 I/O lines, depending on the model.
Port A may have a pin with open collector and may require an external pull-up resistor or a diode to protect it from overvoltage.

Back to top
AndrewM
Mon Apr 10 2006, 02:33AM
AndrewM Registered Member #49 Joined: Thu Feb 09 2006, 04:05AM
Location: Bigass Pile of Penguins
Posts: 362
I guess I meant which bit is bit 0?

00000000
       ^- this one?

00000000
^- or this one?

[Edit: You forgot the [code] tag.]
Back to top
Bjørn
Mon Apr 10 2006, 02:57AM
Bjørn Registered Member #27 Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
That is a matter of definition. Bit 0 is always bit 0, no matter what the actual position is.

The only way to make it completely clear, bit 0 in the file registers is labeled RA0 and RB0 on the pinout diagram in the datasheet.

movlw .1
movwf PORTB
Will cause RB0 to go high.

movlw .128
movwf PORTB
Will cause RB7 to go high.
Back to top
...
Mon Apr 10 2006, 04:19AM
... Registered Member #56 Joined: Thu Feb 09 2006, 05:02AM
Location: Southern Califorina, USA
Posts: 2445
I think what andrew is asking is which bit is the 0th bit in a binary number...

In that case, I am pretty sure it is the one furthest to the right (first example)
Back to top
Carbon_Rod
Mon Apr 10 2006, 07:42AM
Carbon_Rod Registered Member #65 Joined: Thu Feb 09 2006, 06:43AM
Location:
Posts: 1155
1.) Multibyte variables are generally “Little Endian” these days (unless one runs a SPARC machine etc. which is “Big Endian” .) ( Link2 ) It refers to how multi-byte variables like “unsigned int” are ordered when stored in memory. If ones defined a union or struct this can be a source of confusion and porting bugs. Also, if one declares signed integer math then “overflow reset” monitoring may make the code far more complex than needed.

2.) Simply put, the Microchip standard states RA0 as being the Least Significant Bit ( Link2 ) of a memory address often referring to a single byte’s bit on the right side. As Little-Endian reorders byte sequences it is a common source of bugs when doing direct bit wise operations with i/o and relying on the compiler to correctly downcast the variable. To keep it simple Microchip avoids these problems by forcing the programmer to downcast the output to 1 byte (unsigned char).
RA0 := ‘00000001’b
RA1 := ‘00000010’b
Etc.

3.) Most C compilers implement a C standard procedure stack order. When translated into procedure calls it is standard to pass arguments from right to left on the stack. When using precompiled libraries and extern calls to binary objects this can be an issue. This is why Pascal object code integration is rather rare as arguments would pass left to right on the stack in the compiler making it incompatible (only mentioned as there are numerous compilers for PICs out there that implement non-standard linker systems.)

4.) Microchips “Read Modify Write” bug is a problem that has documented procedures to avoid. See the app notes.

5.) Also the rotate ASM calls will sometimes carry in garbage from the flags if one forgets to backup, clean, and restore the core state to perform operations with interrupts active.

6.) 'xxxxxx1x'h != 'xxxxxx1x'b is a common typo

7.) Not all memory addresses are mirrored between ram banks (see TRISA and PORTA defines in the compilers pic16xxx.inc etc.)


This should cover most of the common bit related bugs,
Good luck,
Back to top
Steve Conner
Mon Apr 10 2006, 10:06AM
Steve Conner Registered Member #30 Joined: Fri Feb 03 2006, 10:52AM
Location: Glasgow, Scotland
Posts: 6706
It's the one furthest to the right.
Back to top
Bjørn
Mon Apr 10 2006, 10:59AM
Bjørn Registered Member #27 Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
If the question is about the I/O ports after all, then it is the opposite. When looking at the row of pins that is closes to you then bit 0 is to the left on chips like the 16F84 and 16F870. If you don't rotate the chip when you work on the other side then the ports on the other side will be mirrored since it is upside down.

The rule is that the significance of the bits follow the numbering of the pins so the least significant bits always have the lowest pin numbers.
Back to top

Moderator(s): Chris Russell, Noelle, Alex, Tesladownunder, Dave Marshall, Dave Billington, Bjørn, Steve Conner, Wolfram, Kizmo, Mads Barnkob

Go to:

Powered by e107 Forum System
 
Legal Information
This site is powered by e107, which is released under the GNU GPL License. All work on this site, except where otherwise noted, is licensed under a Creative Commons Attribution-ShareAlike 2.5 License. By submitting any information to this site, you agree that anything submitted will be so licensed. Please read our Disclaimer and Policies page for information on your rights and responsibilities regarding this site.