Jump to content
Sign in to follow this  
jiv

#pragma bit - converting code from CC5X

Recommended Posts

I am testing C2C and trying to develop an interrupt-driven routine with several different interrupt sources. In the interrupt routine, to identify the interrupt source I have the following code line :

 

;;;;;;;;#define TXIE 0x04

;;;;;;;;#define T0IF 0x02

;;;;;;;;#define TXIF 0x04

;;;;;;;;#define PIE1 0x8C

 

.......

 

;;;;;;;;if (((INTCON & TXIF) != 0) && ((PIE1 & TXIE) != 0))

 

which is compiled as :

 

movf INTCON, W

andlw D'4'

andlw 0xFF

andlw 0xFF

btfsc STATUS, Z

goto label_0003

movlw D'4'

andlw 0xFF

andlw 0xFF

btfsc STATUS, Z

goto label_0003

movlw 1

label_0003

sublw 0

btfsc STATUS, Z

goto label_0002

 

(label_0002 is the "else" address)

 

I think that this code is erroneous (PIE1 address (0x8C) does not even appear in the code).

 

Am I right ? Am I missing something ? Can I trust C2C ?

 

Thanks !

 

Joan

Share this post


Link to post
Share on other sites
Guest Pavel

Because you define PIE1 and TXIE as constants and later use them in the 'PIE1 & TXIE' expression, compiler optimizes such expression as:

 

PIE1 & TXIE same as

0x8c & 0x04 same as

0x04

 

That's why you don't see any 0x8c numbers in the generated assembler.

 

What you probably intended to do is to use the PIE1 and TXIE (and other) registers from C code. The proper way to do this is to use variables with fixed addresses. In this particular case the updated code will look like:

 

...

char txie@0x04, t0if@0x02, txif@0x04, pie1@0x8C;

 

if (((INTCON & txif) != 0) && ((pie1 & txie) != 0))

...

 

You also may need to declare the intcon variable using the same technic.

 

For more information look into the compiler help.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

I have some code that is normally compiled with the CC5X compiler, how can I convert the #pragma bit lines?

 

#pragma bit  SPEAKER @ PORTB.6

#pragma bit  BUTTON2 @ PORTB.7

#pragma bit  BUTTON1_HIT @ ButtonState.6

#pragma bit  BUTTON2_HIT @ ButtonState.7

 

void somefunc(void)

{

    SPEAKER = 1;

}

 

Paul

Share this post


Link to post
Share on other sites
Guest Pavel

#include <system.h>

#define SPEAKER 0x20

void somefunc(void)
{
   portb |= SPEAKER;
}

 

Regards,

Pavel

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...