Jump to content
Sign in to follow this  
mslaby

#define

Recommended Posts

I have been working with the SX chip for about a month now and was programming in assembly.  Sometimes I come accross things that are so easy to do in assembly that it seems a burden to do (or try to do) it in C.  I have been trying to use #define to help with some of this.

 

#define rb1 rb.1

 

asm clr rb1

 

or

 

asm clr _rb1

 

does not seem to work as you may do with a variable:

 

char rb1 = 0;

 

asm mov _rb1,w

 

This is getting to me since I am trying to do bit manipulation.  Usually in assembly coding I use:

 

 

bit1 = rb.1

bit2 = rd.2

.....

clr bit1

....

jnb bit2,loop

.....

movb bit1,bit2

 

That way if I change 'bit1' or 'bit2' to another pin or port I just change 'bit1' or 'bit2' as defined in the program.

 

I have been looking for alternatives in manual but always hit a wall.  With absolute adressing you only use char in examples.  I do not want variables or to use RAM space.  I also don't see how you can do a bit manipulation with that anyways.  With input_pin_port_a() I can only use #'s and would have to go through the program and change all of the a's to b's if I changed ports.  The only thing that I found that work as simply is:

 

instead of:

 

bit = rb.1

 

clr bit

 

In C I used:

 

#define bit 1

#define bit_port rb

 

clear_bit(bit_port,bit);

 

Of course if you supported macros I could write:

 

#define bit_high output_high_port_b(1)

#define bit_low ouput_low_port_b(1)

 

bit_high;

delay();

bit_low;

 

I just would like something as simple as:

 

instead of

 

loop

 jnb bit,loop

 

use

 

while(input(bit1) != 1);

 

 

 

I hope I made myself clear enough through all of this.  Adjusting is hard at times.  Can you help?

 

 

 

:)

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...