Jump to content
usafirmware

Can't I Assigned An Address Casting To A Sfr? See Example

Recommended Posts

What is wrong with this ....

 

 

#include <pic16F685.h>

 

#define BANK_0 0x0000

 

#define IOPORTC ((unsigned volatile *)(BANK_0 + PORTC))

#define IOTRISC ((unsigned volatile *)(BANK_0 + TRISC))

 

 

.. later on in a function definition ...

 

*IOTRISC &= ~SEGMENT_MASK; // By writing zero's to the bits that correspond to segments, we set them all to outputs

 

This generates a non descriptive error (general error).

 

The code is included as an attachment.

 

Thanks for the help...

7segment.zip

Share this post


Link to post
Share on other sites

Please don't use volatile and use intermediate temporary. Something like:

 

#define IOTRISB ((unsigned*)(BANK_0 + TRISB))

...

unsigned *tris = IOTRISB;
*tris &= ~SEGMENT_MASK;

 

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum 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...

×