naming a pin or bit question

Status
Not open for further replies.
I've seen in some code the naming of a bit or pin. Could I get someone to show me the correct way to name a pin or bit in assembly?
Example:

bit 0 of OUTPUT file would be named LED
bit 1 of OUTPUT file would be named RELAY
etc.

pin 0 of PORTA would be SW1
pin 1 of PORTA would be SW2
etc.

Can I do this with Assm.?
I'm confused on how its going to recognize which pin of what file your actually naming.
 
Use the EQUate directive.

Code:
LED      EQU 0x00
RELAY    EQU 0x01
;...
OUTPUT   EQU PORTB
;...

Relay_On
         BSF OUTPUT, LED
         ;...
 
hotrodhed120 said:
so the LED EQU 0x00 just means 0 and is not specific to a certain port or register, correct?

0x00 means hexadecimal zero, although obviously zero is the same in all bases anyway.
 
I like to use the #define directive to assign pins.

For your example, it would be,
Code:
	#define	LED	PORTB,0
	#define	RELAY	PORTB,1

	#define	SW1	PORTA,0
	#define	SW2	PORTA,1

;turn on LED
	bsf	LED
;test SW1
	btfss	SW1

Personally, I like to indicate that the variable is a bit variable by preceding the name with b_ so, LED would become b_LED. In most projects I use bit variables quite a lot. In a recent project I had the following bit variables.
Code:
	cblock	0x20
Flags
	endc

	#define b_TempCarry	Flags,0
	#define b_NotLower	Flags,1
	#define b_BadNumber	Flags,2
	#define b_BadDate	Flags,3
	#define b_BadTime	Flags,4
	#define b_InDate	Flags,5
	#define b_AbortLoad	Flags,6
	#define b_WritingBuffer	Flags,7

Using the above code makes the code much more readable and hence easier to understand.

Mike.
 
If you are using MPLAB, use Help -> Topics -> MSASM Assembler. #Define is but one of many assembler directives. No need for them to be mysterious anymore.
 
I was just checking out the easypic4 that gramo has been talking about on www.mikroe.com and found some great online books on the subject. PIC Microcontrollers seems to be pretty staight forward and easy to reference. And its FREE!! Thanks, guys!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…