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

I/O port problem

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



Joined: 11 Feb 2005
Posts: 24

View user's profile Send private message

I/O port problem
PostPosted: Sat Feb 12, 2005 6:39 am     Reply with quote

Hi,
Any one can help me? I am a new in CCS C compiler and have a few questions.

1. How to set PORTB as outputs?
2. can i use PORTB = 0xFF as in assembly language.

Thank in advanced,
AKO
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Feb 12, 2005 8:15 am     Reply with quote

Quote:
1. How to set PORTB as outputs?
Call output_b(value), this will automatically set PORTB as an output with every call to this function.
If you want to avoid the overhead of setting the I/O-direction register each time you can add:
Code:
#use FAST_IO(B)
SET_TRIS_B( 0x0F );
       // B7,B6,B5,B4 are outputs
       // B3,B2,B1,B0 are inputs
at the start of your program.

PORTB needs special care because it is mixed with several other internal devices like the A/D-converter which are sometimes enabled by default, this is different for each PIC model. It's good programming practice to make sure these devices are disabled, so always add setup_adc_ports(NO_ANALOGS) if you are not using the ADC.
Normally the CCS added startup code will configure the A/D-pins as all digital, but sometimes CCS screws up (for example v3.216 for the PIC18F2520 had a bug which configured AN1-AN11 as analog inputs, this was fixed without notice in v3.218).

Quote:
2. can i use PORTB = 0xFF as in assembly language.

Yes, but you have to define the name of PORTB first. CCS doesn't supply a header file with these names, but for some devices like the PIC18F452 users have posted these include files in this newsgroup.

Method 1, using #byte:
Code:
// Warning: Memory at x is not exclusive to this variable.
// Other variables may be located at the same location.
#byte PORTB = 0xF81
PORTB = 0xFF;    // Set port B as all inputs

Method 2, using #locate:
Code:
// #LOCATE works like #BYTE however in addition it prevents C from using the area.
unsigned char PORTB;
#locate PORTB = 0x0F81
*PORTB = 0xFF;    // Set port B as all inputs
akokyaw



Joined: 11 Feb 2005
Posts: 24

View user's profile Send private message

I/O port problem
PostPosted: Tue Feb 15, 2005 9:53 am     Reply with quote

Thank Ckielstra,
Thank, your info help me a lot.

Rgds,
AKO
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