View previous topic :: View next topic |
Author |
Message |
ATTIgeek
Joined: 17 Feb 2021 Posts: 5 Location: US
|
Port Output |
Posted: Wed Feb 17, 2021 4:43 pm |
|
|
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
|
|
Posted: Wed Feb 17, 2021 5:26 pm |
|
|
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
|
|
Posted: Thu Feb 18, 2021 12:39 am |
|
|
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
|
|
Posted: Thu Feb 18, 2021 5:50 am |
|
|
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
|
|
Posted: Thu Feb 18, 2021 8:34 am |
|
|
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. |
|
|
|