|
|
View previous topic :: View next topic |
Author |
Message |
akokyaw
Joined: 11 Feb 2005 Posts: 24
|
I/O port problem |
Posted: Sat Feb 12, 2005 6:39 am |
|
|
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
|
|
Posted: Sat Feb 12, 2005 8:15 am |
|
|
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
|
I/O port problem |
Posted: Tue Feb 15, 2005 9:53 am |
|
|
Thank Ckielstra,
Thank, your info help me a lot.
Rgds,
AKO |
|
|
|
|
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
|