![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| Hi all, I wanted to ask in assembly of pic - the difference between EQU and # define. EQU I understood but confusion in # define as the following line in book says... " A #define on the other hand tells the assembler to substitute two values where it finds a certain word e.g. #define led portb.4 Wherever the assembler finds the word led, it substitutes 6.4 (or portb.4) in it's place. " Can anyone make me understand above statement... Main thing i understood that # define is used as generic - that we can make changes only at one part of program and all the program the values shall be changed automatically... Regards, Simran..
__________________ Simran.. 8051 Specialist.. | |
| |
| | (permalink) |
| #define led portb.4 Anywhere mpasm finds the word 'led' it will substitute the string 'portb.4' The part about '6.2' is simply because somwhere else 'portb' has already been set (probably in the procesor INC file) using portb EQU 6 - Why six? Because 6 is the address of portb in the data memory area. | |
| |
| | (permalink) |
| Hi, #define can be used for instructions, such as Code: #define on bsf PORTB, 0 #define off bcf PORTB, 0 These are my applications for equ and #define
__________________ Superman returns.. | |
| |
| | (permalink) |
| Hi Geko and Bananasiong... Thanks... I understood... One last question... EQU has two purposes... 1. Assigning names to registers 2. assigning values to variables.. Am i right... Regards, Simran..
__________________ Simran.. 8051 Specialist.. | |
| |
| | (permalink) |
| Hi, General purpose registers are used for storing variables as well. So basically they are the same. That equate directive is for us to differentiate the registers easier, instead of the memory location, we can equate the name.
__________________ Superman returns.. | |
| |
| | (permalink) |
| Ok... e.g. Sam EQU #3 ; it means that sam is a variable with constant value 3 ... and Sam EQU 3 ; it means that Sam is name given to register number 3 ... I hope i am right because i have more practice for C than assembly... Regards, Simran..
__________________ Simran.. 8051 Specialist.. | |
| |
| | (permalink) |
| Mostly a bit can identify with a define directive Code: # define LED PORTB,0 ;portB 0 bit is the LED Code: PORTB equ 06h ;SFR address is 06h TIME equ 20h ;your GPR address is 20h Code: C EQU 0 ;carry bit is the zero bit in STATUS R | |
| |
| | (permalink) | ||
| Quote:
Quote:
is it predefined that c always means carry in mp - assembler... Regards, Simran..
__________________ Simran.. 8051 Specialist.. | |||
| |
| | (permalink) | |||
| Quote:
Quote:
Quote:
Last edited by Gayan Soyza; 17th January 2008 at 10:00 AM. | ||||
| |
| | (permalink) | |
| Quote:
People seem to find equ and define difficult to understand?, but when you realise it's just a simple text substitution it becomes easy - think 'search and replace' from your word processor. | ||
| |
| | (permalink) |
| I got it sir... EQU is simply to match the register with its name.. and #define is almost same but we can actually give name to particular pins also... Problem was that - I misread one statement in Book... It was written '#define led Portb.6' while i read it as ' #define led Portb,6 ' Hence i got confused... Regards, Simran..
__________________ Simran.. 8051 Specialist.. | |
| |
| | (permalink) |
| This is from a file I am currently using (note the comma): #DEFINE LED_RED LATA,1 #DEFINE LED_GREEN LATA,2 #DEFINE LED_YELLOW LATA,3
__________________ Agustín Tomás In theory, there is no difference between theory and practice. In practice, however, there is. | |
| |
| | (permalink) | |
| Quote:
Hi, Do we have to put comma or Dot ... This is the main question... Note that in embedded C we usually put ' Dot ' .. Regards, Simran..
__________________ Simran.. 8051 Specialist.. | ||
| |
| | (permalink) |
| And what do you put in PIC assembler?, bear in mind this is simply a text substitution - substituting the wrong instructions isn't going to work. | |
| |
| | (permalink) |
| That means we are to put comma... I'll remember... Regards, Simran..
__________________ Simran.. 8051 Specialist.. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| Substituting a 16x2 LCD display for 16x1 LCD display? | Dawny | Electronic Projects Design/Ideas/Reviews | 19 | 11th October 2008 09:58 AM |
| Help needed ASM to HEX with MPLAB | Virus | Micro Controllers | 39 | 26th December 2007 04:30 PM |
| PIC12f675 | MERV | Micro Controllers | 18 | 10th December 2007 08:18 PM |
| RS232 Converter | e.chain | Micro Controllers | 0 | 6th October 2007 07:19 PM |
| Stepper motor circuit for PIC16f877 | flemmard | Electronic Projects Design/Ideas/Reviews | 6 | 28th September 2007 03:58 PM |