Thats what I thought "bits" did. In the example on multiplexing in JPUG1 masking is used to change some bits without chaning others, is it done that way because they are changing several bits at once and want to avoid changing the non targeted ones?The use of the suffix bits just allows you to set/clear or test an individual bit of a variable.
TRISBbits.TRISB1=0; or TRISB&=0b11111101
TRISAbits.TRISA0 = 1;
PORTBbits.PORTB0 = 1;
PORTA|=0b00001010;
In JPUG#1 Multiplexing Charlieplexed Displays masking was discussed in the context of charlieplexing. The text regarding masking is discussed in the section: setLatA(), setTrisA() on page 5.
Triode said:Thats what I thought "bits" did. In the example on multiplexing in JPUG1 masking is used to change some bits without chaning others, is it done that way because they are changing several bits at once and want to avoid changing the non targeted ones?
#define LED_MASK 0xC1
// LEDs on A0,A6,A7
// LED index 0 1 2 3 4 5
const byte valA[]={0x01,0x40,0x40,0x80,0x80,0x01};
const byte dirA[]={0x80,0x80,0x01,0x01,0x40,0x40};
Triode said:Yeah, i remember it demonstrated a method of using those commands to turn bits on or off in a single command without effecting the ones you don't intend to change. I can use it by copying it. But i'm not sure yet what LatA refers to.
#define STATUS_LED LATAbits.LATA0
#define STATUS_LED_TRIS TRISAbits.TRISA0
Then in your code write
STATUS_LED_TRIS = 0; // for output
and
STATUS_LED = 1; // to source a LED
We have talked about generating multiple PWM signals here several times.
Depending on the device selected, there are either five
ports or three ports available. Some pins of the I/O
ports are multiplexed with an alternate function from
the peripheral features on the device. In general, when
a peripheral is enabled, that pin may not be used as a
general purpose I/O pin.
Each port has three registers for its operation. These
registers are:
• TRIS register (data direction register)
• PORT register (reads the levels on the pins of the
device)
• LAT register (output latch)
The data latch (LAT register) is useful for read-modifywrite
operations on the value that the I/O pins are
driving
PORTA is a 7-bit wide, bi-directional port. The corresponding
Data Direction register is TRISA. Setting a
TRISA bit (= 1) will make the corresponding PORTA pin
an input (i.e., put the corresponding output driver in a
Hi-Impedance mode). Clearing a TRISA bit (= 0) will
make the corresponding PORTA pin an output (i.e., put
the contents of the output latch on the selected pin).
Reading the PORTA register reads the status of the
pins, whereas writing to it will write to the port latch.
The Data Latch register (LATA) is also memory
mapped. Read-modify-write operations on the LATA
register reads and writes the latched output value for
PORTA.
But I would not recommend it in most cases.
Only in that code written to use it requires your version of the modified pxxfxxxx.h file for your code to work. For the sake of sanity do not use the original file name! It would also cause the file to be a bit harder to read because the reader would have to look to the .h file to see the nonstandard name. Neither is a big deal, but I suggest it should be done with a good reason, not because you can.The reason being that it makes your code less portable right?
The way I have found to learn what i don't no is to look at some of the boostC examples and then change it to C18Can anyone point me to a good demo or tutorial of using the timers and/or capture compare in
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?