PIC EQU section.

"ian field" <dai.ode@ntlworld.com> schreef in bericht
news:pwivj.2311$g81.1768@newsfe3-gui.ntli.net...
In a sample fragment of code (EQU section) of a program example from the
book PIC in Practice:


TMR0 EQU 1 ;TMR0 is FILE 1.
PORTA EQU 5 ;PORTA is FILE 5.
PORTB EQU 6 ;PORTB is FILE 6.
STATUS EQU 3 ;STATUS is FILE3.
ZEROBIT EQU 2 ;ZEROBIT is Bit 2.
COUNT EQU 0CH ;USER RAM LOCATION.
EEADR EQU 9 ;EEPROM address register
EEDATA EQU 8 ;EEPROM data register
EECON1 EQU 8 ;EEPROM control register1
EECON2 EQU 9 ;EEPROM control register2
RD EQU 0 ;read bit in EECON1
WR EQU 1 ;Write bit in EECON1
WREN EQU 2 ;Write enable bit in EECON1

How does the assembler tell the difference between a file and a bit?

The lines starting with ZEROBIT and WREN do not seem to have anything to
distinguish them from file EQUs.

TIA.
Read my answer in ABSE.

You'd better crosspost next time.

petrus bitbyter
 
Eeyore wrote:

I 'm not familiar with PIC assembler but I'd have thought an equate
assigns a *constant* value, not a temporary value to a variable.
EQU assigns an assembler expression to a label; it must remain constant.
SET works much like EQU but can be reassigned as desired.
#define is also availabe for pure text substitutions.
Don't get these confused with the CONSTANT and VARIABLE directives.
 
Eeyore wrote:
Greg Neill wrote:

It doesn't know anything about bits or files.

What IS all this 'file' talk about anyway ?
"file registers", haven't you heard of them before? No doubt it's a silly
name, but an 805x expert should know these things.
 
Eeyore wrote:
ian field wrote:
snip
EECON1 EQU 8 ;EEPROM control register1
EECON2 EQU 9 ;EEPROM control register2
RD EQU 0 ;read bit in EECON1
WR EQU 1 ;Write bit in EECON1
WREN EQU 2 ;Write enable bit in EECON1

How does the assembler tell the difference between a file and a bit?

Since when has a BIT had a value of 2 ?

Looks like sloppy documentation to me.
In PIC assembler, if you want to let's say set the LSBit of a byte in RAM,
you'd code something like this:
BSF locsym, 0
the MSBit would be set by:
BSF locsym, 7

BSF stands for "Bit Set f". "f" is Microchip's stand-in for "register
file". The first operand is the RAM location you want to modify, the second
operand is the physical bit position (7 to 0).
 
Anthony Fremont wrote:

Eeyore wrote:

I 'm not familiar with PIC assembler but I'd have thought an equate
assigns a *constant* value, not a temporary value to a variable.

EQU assigns an assembler expression to a label; it must remain constant.
As I imagined. In PL/M it would be a literal.


SET works much like EQU but can be reassigned as desired.
#define is also availabe for pure text substitutions.
Don't get these confused with the CONSTANT and VARIABLE directives.
Cheers,

Graham
 
Anthony Fremont wrote:

Eeyore wrote:
Greg Neill wrote:

It doesn't know anything about bits or files.

What IS all this 'file' talk about anyway ?

"file registers", haven't you heard of them before? No doubt it's a silly
name, but an 805x expert should know these things.
Intel don't use the term 'file'. The 8051 has the usual working registers plus
the all important 'special function registers' that determine many aspect of
how the internals work - such as seeting up timers (TCON and TMOD), UARTs,
interrupts and the like.

Graham
 
Anthony Fremont wrote:

Eeyore wrote:
ian field wrote:
snip
EECON1 EQU 8 ;EEPROM control register1
EECON2 EQU 9 ;EEPROM control register2
RD EQU 0 ;read bit in EECON1
WR EQU 1 ;Write bit in EECON1
WREN EQU 2 ;Write enable bit in EECON1

How does the assembler tell the difference between a file and a bit?

Since when has a BIT had a value of 2 ?

Looks like sloppy documentation to me.

In PIC assembler, if you want to let's say set the LSBit of a byte in RAM,
you'd code something like this:
BSF locsym, 0
the MSBit would be set by:
BSF locsym, 7

BSF stands for "Bit Set f". "f" is Microchip's stand-in for "register
file". The first operand is the RAM location you want to modify, the second
operand is the physical bit position (7 to 0).
In PL/M I might set an entire SFR (special function register) thus .....

TCON = 00101100B; or TCON = 02CH; or TCON = 44;
I like to set them using binary though (except for counter timer count values)
since you can quickly transpose the value to the individual bits.

or an individual bit of a register (for the bit-adressable ones) like this
.......

EA = 1; (or 01B for that matter - default is decimal)

Graham
 
"Eeyore" <rabbitsfriendsandrelations@hotmail.com> wrote in message
news:47BE090C.804A6D9B@hotmail.com...
ian field wrote:

the PIC in Practice book and the datasheet
makes no mention of this that I can find, or for that matter the WREN
label
which is also EQU 2

I assume it means a value of 0000010B. Calling that a 'bit' is highly
misleading.

That book sounds dodgy to me.

Graham
I could be a bad workman and blame my tools, but there seem to be a few
omissions that seem to present irresolvable problems until how it works is
explained.
 
"petrus bitbyter" <pieterkraltlaatditweg@enditookhccnet.nl> wrote in message
news:47be2648$0$28180$e4fe514c@dreader22.news.xs4all.nl...
"ian field" <dai.ode@ntlworld.com> schreef in bericht
news:pwivj.2311$g81.1768@newsfe3-gui.ntli.net...
In a sample fragment of code (EQU section) of a program example from the
book PIC in Practice:


TMR0 EQU 1 ;TMR0 is FILE 1.
PORTA EQU 5 ;PORTA is FILE 5.
PORTB EQU 6 ;PORTB is FILE 6.
STATUS EQU 3 ;STATUS is FILE3.
ZEROBIT EQU 2 ;ZEROBIT is Bit 2.
COUNT EQU 0CH ;USER RAM LOCATION.
EEADR EQU 9 ;EEPROM address register
EEDATA EQU 8 ;EEPROM data register
EECON1 EQU 8 ;EEPROM control register1
EECON2 EQU 9 ;EEPROM control register2
RD EQU 0 ;read bit in EECON1
WR EQU 1 ;Write bit in EECON1
WREN EQU 2 ;Write enable bit in EECON1

How does the assembler tell the difference between a file and a bit?

The lines starting with ZEROBIT and WREN do not seem to have anything to
distinguish them from file EQUs.

TIA.


Read my answer in ABSE.

You'd better crosspost next time.

petrus bitbyter
Thanks all - I got my brain out of the endless loop now.
 
On Thu, 21 Feb 2008 18:53:19 GMT, "ian field" <dai.ode@ntlworld.com>
wrote:

"me" <me@here.net> wrote in message
news:Xns9A4B7EB195C8Cmeherenet@38.119.97.3...
"ian field" <dai.ode@ntlworld.com> wrote in
news:bTivj.2312$g81.1350@newsfe3-gui.ntli.net:


"Michael" <news@bigtoes.com> wrote in message
news:47bdb89f$0$1092$4c368faf@roadrunner.com...
ian field wrote:
In a sample fragment of code (EQU section) of a program example from
the book PIC in Practice:


TMR0 EQU 1 ;TMR0 is FILE 1.
PORTA EQU 5 ;PORTA is FILE 5.
PORTB EQU 6 ;PORTB is FILE 6.
STATUS EQU 3 ;STATUS is FILE3.
ZEROBIT EQU 2 ;ZEROBIT is Bit 2.
COUNT EQU 0CH ;USER RAM LOCATION.
EEADR EQU 9 ;EEPROM address register
EEDATA EQU 8 ;EEPROM data register
EECON1 EQU 8 ;EEPROM control register1
EECON2 EQU 9 ;EEPROM control register2
RD EQU 0 ;read bit in EECON1
WR EQU 1 ;Write bit in EECON1
WREN EQU 2 ;Write enable bit in EECON1

How does the assembler tell the difference between a file and a bit?

The lines starting with ZEROBIT and WREN do not seem to have
anything to distinguish them from file EQUs.

TIA.
It doesn't. Essentially it just wants to convert its operands to
numbers. You could substitute WR whenever you wanted to use bit 1 of
file register 1 or the value 1, the assembler wouldn't care.
However, the human viewing the program would probably be very
confused :).

Well it worked - I am confused!

Perhaps my question should have been - is the example wrong/badly
written and if so how do I do it correctly?



It is the same as;

x=7
y=2

It has the benefit of making changes easy and giving an easier to
decipher source code. By using WR or RD you can tell what the code is
doing instead of 0 or 1...

Yes - I know what the EQU section does, but how does the assembler know
"ZEROBIT EQU 2 ;Zerobit is bit 2" means a bit and not a file -
especially when nothing specifies which file it means bit 2 of?
ZEROBIT doesn't mean a file or a bit. It means 2.

Whether it refers to a file, a bit, or a rom address depends on the
contexts it might be used it. Same as for "2"

John
 
On Feb 21, 11:01 am, "Greg Neill" <gneill...@OVEsympatico.ca> wrote:
"ian field" <dai....@ntlworld.com> wrote in message

news:zMjvj.4836$d62.2643@newsfe6-gui.ntli.net



Yes - I know what the EQU section does, but how does the assembler
know "ZEROBIT    EQU    2 ;Zerobit is bit 2" means a bit and not a
file - especially when nothing specifies which file it means bit 2 of?

It doesn't know anything about bits or files.  All it
knows is that you have assigned the constant 2 to a
symbol ZEROBIT.  It doesn't know or care what you
subsequently do with that symbol.

However... when it comes across that symbol in code
that you write (code that generates instruction
sequences), it will substitute the number 2 for the
symbol in the context in which it is found.  It's up
to you to use the symbol in the appropriate context.
So how does (COUNTER EQU 20h) differ from (ZEROBIT EQU 02h) ?
The first (COUNTER) is a file register located at address 20h and can
be loaded with some value. Why is ZEROBIT any different? Is it not a
file register located at address 02 without any value assigned?

-Bill
 
"John Larkin" <jjlarkin@highNOTlandTHIStechnologyPART.com> wrote in message
news:d1avr35qn25p41ird3dak6ogs0dnb2r37t@4ax.com...
On Thu, 21 Feb 2008 18:53:19 GMT, "ian field" <dai.ode@ntlworld.com
wrote:


"me" <me@here.net> wrote in message
news:Xns9A4B7EB195C8Cmeherenet@38.119.97.3...
"ian field" <dai.ode@ntlworld.com> wrote in
news:bTivj.2312$g81.1350@newsfe3-gui.ntli.net:


"Michael" <news@bigtoes.com> wrote in message
news:47bdb89f$0$1092$4c368faf@roadrunner.com...
ian field wrote:
In a sample fragment of code (EQU section) of a program example from
the book PIC in Practice:


TMR0 EQU 1 ;TMR0 is FILE 1.
PORTA EQU 5 ;PORTA is FILE 5.
PORTB EQU 6 ;PORTB is FILE 6.
STATUS EQU 3 ;STATUS is FILE3.
ZEROBIT EQU 2 ;ZEROBIT is Bit 2.
COUNT EQU 0CH ;USER RAM LOCATION.
EEADR EQU 9 ;EEPROM address register
EEDATA EQU 8 ;EEPROM data register
EECON1 EQU 8 ;EEPROM control register1
EECON2 EQU 9 ;EEPROM control register2
RD EQU 0 ;read bit in EECON1
WR EQU 1 ;Write bit in EECON1
WREN EQU 2 ;Write enable bit in EECON1

How does the assembler tell the difference between a file and a bit?

The lines starting with ZEROBIT and WREN do not seem to have
anything to distinguish them from file EQUs.

TIA.
It doesn't. Essentially it just wants to convert its operands to
numbers. You could substitute WR whenever you wanted to use bit 1 of
file register 1 or the value 1, the assembler wouldn't care.
However, the human viewing the program would probably be very
confused :).

Well it worked - I am confused!

Perhaps my question should have been - is the example wrong/badly
written and if so how do I do it correctly?



It is the same as;

x=7
y=2

It has the benefit of making changes easy and giving an easier to
decipher source code. By using WR or RD you can tell what the code is
doing instead of 0 or 1...

Yes - I know what the EQU section does, but how does the assembler know
"ZEROBIT EQU 2 ;Zerobit is bit 2" means a bit and not a file -
especially when nothing specifies which file it means bit 2 of?


ZEROBIT doesn't mean a file or a bit. It means 2.

Whether it refers to a file, a bit, or a rom address depends on the
contexts it might be used it. Same as for "2"

John
Why is this concept so hard for people to understand? Do they think that the
letters used in the word before the EQU directive have any meaning to the
assembler?

Bob
 
"Bill Bowden" <wrongaddress@att.net> wrote in message
news:56cd16ad-78e5-4f13-80fb-9a532152eabd@41g2000hsc.googlegroups.com
On Feb 21, 11:01 am, "Greg Neill" <gneill...@OVEsympatico.ca> wrote:
"ian field" <dai....@ntlworld.com> wrote in message

news:zMjvj.4836$d62.2643@newsfe6-gui.ntli.net



Yes - I know what the EQU section does, but how does the assembler
know "ZEROBIT EQU 2 ;Zerobit is bit 2" means a bit and not a
file - especially when nothing specifies which file it means bit 2
of?

It doesn't know anything about bits or files. All it
knows is that you have assigned the constant 2 to a
symbol ZEROBIT. It doesn't know or care what you
subsequently do with that symbol.

However... when it comes across that symbol in code
that you write (code that generates instruction
sequences), it will substitute the number 2 for the
symbol in the context in which it is found. It's up
to you to use the symbol in the appropriate context.

So how does (COUNTER EQU 20h) differ from (ZEROBIT EQU 02h) ?
The first (COUNTER) is a file register located at address 20h and can
be loaded with some value. Why is ZEROBIT any different? Is it not a
file register located at address 02 without any value assigned?
Presumably you intended both symbols to be
EQUivalent to 02h in this example.

There is no difference between them. You could use
symbols interchangeably in the code (much to the
consternation of anyone later trying to debug it)
and the resulting binary code generated by the
assembler would be identical. There is no special
meaning attached to any non reserved word symbol.

What a given defined symbol "means" is entirely up
to the programmer, and is made manifest by how and
where it is used, that is, what code generating
instructions it appears in and in what context
(operand, constant, offset, register number,
memory address...).
 
In article <zMjvj.4836$d62.2643@newsfe6-gui.ntli.net>,
ian field <dai.ode@ntlworld.com> wrote:
"me" <me@here.net> wrote in message
news:Xns9A4B7EB195C8Cmeherenet@38.119.97.3...
"ian field" <dai.ode@ntlworld.com> wrote in
news:bTivj.2312$g81.1350@newsfe3-gui.ntli.net:


"Michael" <news@bigtoes.com> wrote in message
news:47bdb89f$0$1092$4c368faf@roadrunner.com...
ian field wrote:
In a sample fragment of code (EQU section) of a program example from
the book PIC in Practice:


TMR0 EQU 1 ;TMR0 is FILE 1.
PORTA EQU 5 ;PORTA is FILE 5.
PORTB EQU 6 ;PORTB is FILE 6.
STATUS EQU 3 ;STATUS is FILE3.
ZEROBIT EQU 2 ;ZEROBIT is Bit 2.
COUNT EQU 0CH ;USER RAM LOCATION.
EEADR EQU 9 ;EEPROM address register
EEDATA EQU 8 ;EEPROM data register
EECON1 EQU 8 ;EEPROM control register1
EECON2 EQU 9 ;EEPROM control register2
RD EQU 0 ;read bit in EECON1
WR EQU 1 ;Write bit in EECON1
WREN EQU 2 ;Write enable bit in EECON1

How does the assembler tell the difference between a file and a bit?

The lines starting with ZEROBIT and WREN do not seem to have
anything to distinguish them from file EQUs.

TIA.
It doesn't. Essentially it just wants to convert its operands to
numbers. You could substitute WR whenever you wanted to use bit 1 of
file register 1 or the value 1, the assembler wouldn't care.
However, the human viewing the program would probably be very
confused :).

Well it worked - I am confused!

Perhaps my question should have been - is the example wrong/badly
written and if so how do I do it correctly?



It is the same as;

x=7
y=2

It has the benefit of making changes easy and giving an easier to
decipher source code. By using WR or RD you can tell what the code is
doing instead of 0 or 1...

Yes - I know what the EQU section does, but how does the assembler know
"ZEROBIT EQU 2 ;Zerobit is bit 2" means a bit and not a file -
especially when nothing specifies which file it means bit 2 of?

It doesn't. The usage of label is the determinant. For example this is a
perfectly valid instruction:

btfsz ZEROBIT,ZEROBIT

The first usage of ZEROBIT is a file register, the second a bit number.

BAJ
 
On Feb 23, 6:18 am, "Greg Neill" <gneill...@OVEsympatico.ca> wrote:
"Bill Bowden" <wrongaddr...@att.net> wrote in message

news:56cd16ad-78e5-4f13-80fb-9a532152eabd@41g2000hsc.googlegroups.com





On Feb 21, 11:01 am, "Greg Neill" <gneill...@OVEsympatico.ca> wrote:
"ian field" <dai....@ntlworld.com> wrote in message

news:zMjvj.4836$d62.2643@newsfe6-gui.ntli.net

Yes - I know what the EQU section does, but how does the assembler
know "ZEROBIT    EQU    2 ;Zerobit is bit 2" means a bit and not a
file - especially when nothing specifies which file it means bit 2
of?

It doesn't know anything about bits or files.  All it
knows is that you have assigned the constant 2 to a
symbol ZEROBIT.  It doesn't know or care what you
subsequently do with that symbol.

However... when it comes across that symbol in code
that you write (code that generates instruction
sequences), it will substitute the number 2 for the
symbol in the context in which it is found.  It's up
to you to use the symbol in the appropriate context.

So how does (COUNTER   EQU    20h) differ from (ZEROBIT   EQU   02h) ?
The first (COUNTER) is a file register located at address 20h and can
be loaded with some value. Why is ZEROBIT any different? Is it not a
file register located at address 02 without any value assigned?

Presumably you intended both symbols to be
EQUivalent to 02h in this example.

There is no difference between them.  You could use
symbols interchangeably in the code (much to the
consternation of anyone later trying to debug it)
and the resulting binary code generated by the
assembler would be identical.  There is no special
meaning attached to any non reserved word symbol.

What a given defined symbol "means" is entirely up
to the programmer, and is made manifest by how and
where it is used, that is, what code generating
instructions it appears in and in what context
(operand, constant, offset, register number,
memory address...).- Hide quoted text -

- Show quoted text -
Yes, I get it now. I tried a short program with (BIT EQU 02h) and then
the instruction (bsf PORTB,BIT) and the result was PORTB changed
value to 4 which is right. I've been having trouble with variable bit
assignments and just
used the hard values (bsf PORTB,2) to make it work, but this makes it
much more elegant.

Thanks,

-Bill
 

Welcome to EDABoard.com

Sponsor

Back
Top