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 CCS Technical Support

Port Output

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



Joined: 17 Feb 2021
Posts: 5
Location: US

View user's profile Send private message

Port Output
PostPosted: Wed Feb 17, 2021 4:43 pm     Reply with quote

I'm more of a hardware guy than software and I am trying out the demo CCS compiler coming from the Atmel world. To modify bits in the Atmel world I would use:

entry = 0x55;

PORTB |= entry ;

and:

PORTB &= ~(entry);

to set those same multiple bits low.

Is there an EASY way to do a similar thing with the CCS Compiler? Setting bits one-by-one using:

output_low(pin);
output_high(pin);

seems extremely inefficient.

Suggestions?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 17, 2021 5:26 pm     Reply with quote

You can do the same byte-wide operations with CCS as with Atmel.
Just put the following line of code above main(). This will get the
address of Port B from the compiler's database and assign it to
the PORTB symbol.
Code:
#byte PORTB = getenv("SFR:PORTB")

You didn't tell us your PIC. If you're using 18F, then you should use LATB
instead of PORTB. Also, some of the newer 16F PICs have LATx registers.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Thu Feb 18, 2021 12:39 am     Reply with quote

and (of course), the standard byte-wide functions, are output_a, output_b
etc..
The 'advantage' of these, is that they know to talk to the lat registers for
output, and to the port registers for input.
If 'fast_io' is selected, the output instruction behaves exactly the same as
the direct access PCM shows, except 'knowing' which register to use.
If it isn't, then the compiler adds TRIS settings to the operation. This is why
using the direct access may be advantageous, since it allows you to leave
'standard_io' selected, which means the compiler will automatically setup
the TRIS for all the I/O ports, but you can then do direct writing to the
port bypassing this.
temtronic



Joined: 01 Jul 2010
Posts: 9224
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Feb 18, 2021 5:50 am     Reply with quote

also...
Have a read of the FAQ section of the manual. It lightly explains a lot of 'stuff'. AS well scan some of the examples in the 'examples' folder. It'll help you get your head into how CCS codes PICs.
If you use MPLAB 8v92, pressing F11 will magically open the manual, making it real easy to search for how to use CCS functions, #USEs, etc.
ATTIgeek



Joined: 17 Feb 2021
Posts: 5
Location: US

View user's profile Send private message

PostPosted: Thu Feb 18, 2021 8:34 am     Reply with quote

A big thanks to everyone for your insight. I should have posted the device I was using (18F4520) so thanks for pointing out the 'LATB' correction.
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