CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

IO problems ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
small_chick



Joined: 17 Jul 2012
Posts: 53

View user's profile Send private message

IO problems ?
PostPosted: Fri Dec 21, 2012 8:15 pm     Reply with quote

I program on dsPIC30F4011 and my code as follow:
Code:

#include     <30F4011.h>
#fuses XT_PLL4,NOWDT
#word     TRISB = 0x02C6
#word    PORTB = 0x02C8
#word    LATB = 0x02CA

#bit    TRISB8 = 0x02C6.8
#bit    TRISB7 = 0x02C6.7
#bit    TRISB6 = 0x02C6.6
#bit    TRISB5 = 0x02C6.5
#bit    TRISB4 = 0x02C6.4
#bit    TRISB3 = 0x02C6.3
#bit    TRISB2 = 0x02C6.2
#bit    TRISB1 = 0x02C6.1
#bit    TRISB0 = 0x02C6.0

#bit    RB0 = 0x02C8.0
#bit    RB1 = 0x02C8.1
#bit    RB2 = 0x02C8.2
#bit    RB3 = 0x02C8.3
#bit    RB4 = 0x02C8.4
#bit    RB5 = 0x02C8.5
#bit    RB6 = 0x02C8.6
#bit    RB7 = 0x02C8.7
#bit    RB8 = 0x02C8.8
 
 void main()
{
    ADPCFG = 0xFFFF;
     TRISB0 = 0;
     TRISB1 = 0;
     TRISB2 = 0;
     TRISB3 = 0;
     TRISB4 = 0;
     TRISB5 = 0;
     TRISB6 = 0;
     TRISB7 = 0;
     TRISB8 = 0;
 
    RB0 =1;
    RB1 =1;
    RB2 =1;
    RB3 =1;
    RB4 =1;
    RB5 =1;
    RB5 =1;
    RB6 =1;
    RB7 =1;
    RB8 =1;
 }


If I code as above, some pins on PORTB do not output high logic level, but if I change as follow, they work well:
Code:

void main()
{
    ADPCFG = 0xFFFF;
     TRISB0 = 0;
     RB0 =1;
     TRISB1 = 0;
      RB1 =1;
     TRISB2 = 0;
      RB2 =1;
     TRISB3 = 0;
      RB3 =1;
     TRISB4 = 0;
      RB4 =1;
     TRISB5 = 0;
      RB5 =1;
     TRISB6 = 0;
      RB6 =1;
     TRISB7 = 0;
      RB7 =1;
     TRISB8 = 0;
      RB8 =1;
 }

I mean they only work well if before RBx =1, there's a line TRISBx = 0.
However, I'd like to use the first case, not the second one. How can I do this ? ^~^
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 21, 2012 9:20 pm     Reply with quote

Change it so you're writing to LATB instead of PORTB.
small_chick



Joined: 17 Jul 2012
Posts: 53

View user's profile Send private message

PostPosted: Fri Dec 21, 2012 10:29 pm     Reply with quote

PCM programmer wrote:
Change it so you're writing to LATB instead of PORTB.

You mean I should use LATBx instead of RBx ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19346

View user's profile Send private message

PostPosted: Sat Dec 22, 2012 12:56 am     Reply with quote

Yes.
Do a search on PIC RMW problem, and it will explain what is happening.
Writing to the latch avoids this.

Best Wishes
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Dec 22, 2012 2:32 am     Reply with quote

PCM programmer wrote:
Change it so you're writing to LATB instead of PORTB.


You also need to specify #use fast_io when you are handling I/O direction otherwise the compiler can change it.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
small_chick



Joined: 17 Jul 2012
Posts: 53

View user's profile Send private message

PostPosted: Sat Dec 22, 2012 2:46 am     Reply with quote

thanks everybody!
now. it's well - done! i think i've got a big mistake about LATx and PORTx ! Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group