Jump to content
Sign in to follow this  
Gaston Gagnon

Logic Operations On Port Bit

Recommended Posts

Hi,

First post :rolleyes: , New to BoostC :)

 

I wanted to change the bit value on bit 0 of PortA so I used:

...

volatile bit RA1 @PORTA.1;

...

RA0=RA0^1;

...

 

Which is usually well accepted in C.

 

Well that did not work and after a lot of fiddling and reading I finally realised that this syntaxe does not seem to be allowed (or is it?) but at the same time the compiler did not provide me any clue to that effect.

 

How could I have found this particularity ahead of time? Is there some place where all these little differences are collected?

 

Thank you,

Gaston

Share this post


Link to post
Share on other sites
...

RA0=RA0^1;

 

Which is usually well accepted in C.

...

 

This is not a valid C operand. What kind of C compiler accepts this?

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
This is not a valid C operand. What kind of C compiler accepts this?

 

Sorry my bad. Of course it's valid C. Can you provide a full and simple code that shows the problem.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
...

RA0=RA0^1;

 

Which is usually well accepted in C.

...

 

This is not a valid C operand. What kind of C compiler accepts this?

 

Thank you Paval for your fast answer.

Here is my test program:

--------------------------------------------------------

#include <system.h>

#include <boostc.h>

 

#pragma DATA _CONFIG, _CP_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC & _LVP_OFF & _BODEN_ON

 

#pragma CLOCK_FREQ 20000000

 

volatile bit RA0 @0x05.0;

 

void main(void){

cmcon=7;

ansel=0;

clear_bit(trisa, 0);

 

while(1){

RA0=RA0^1;

}

}

--------------------------------------------------------

And the .lst produced

--------------------------------------------------------

ORG 0x00000000

0000 2812 GOTO _startup

ORG 0x00000003

0003 main

; { main ; function begin

0003 3007 MOVLW 0x07

0004 1683 BSF STATUS, RP0

0005 1303 BCF STATUS, RP1

0006 009C MOVWF gbl_cmcon

0007 019B CLRF gbl_ansel

0008 1006 BCF gbl_trisb,0

0009 1005 BCF gbl_trisa,0

000A label268436498

000A 1283 BCF STATUS, RP0

000B 01A0 CLRF CompTempVar52

000C 0AA0 INCF CompTempVar52, F

000D 1820 BTFSC CompTempVar52,0

000E 1405 BSF gbl_RA0,0

000F 1C20 BTFSS CompTempVar52,0

0010 1005 BCF gbl_RA0,0

0011 280A GOTO label268436498

; } main function end

 

ORG 0x00000012

0012 _startup

0012 118A BCF PCLATH,3

0013 120A BCF PCLATH,4

0014 2803 GOTO main

ORG 0x00002007

2007 3F62 DW 0x3F62

 

Thank you Gaston

Share this post


Link to post
Share on other sites

Thanks for the code. This looks like a compiler bug. Try a workaround:

 

instead of

RA0=RA0^1;

use:

RA0^=1;

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