How To Check A Register Bit Fiddling
Re: Fleck manipulation 2020/12/02 03:08:02 (permalink)
Hello,
When using XC8 compiler, in that location is a file available for each type of Picture microcontroller,
with name for each register, field and bit, named every bit documented in the datasheet for the device,
When Movie microcontroller blazon have been selected in MPLAB,
and then the 'device back up file' is made bachelor in your source lawmaking file by typing:
#include <xc.h>
in the source file.
The "chip field" structs have this form: REGISTERbits.BIT or REGISTERbits.FIELD, where yous supersede the capital names with actual register and fleck names, as documented in the datasheet.
Case:
LATC = 0; // Clear all bits of this annals to zero.
LATCbits.LATC6 = 1; // Fix a single flake.
ANSELC = 0; // Enable Digital Inputs for all pins on port C, only for microcontrollers that have Analog features on this port.
TRISCbits.TRISC3 = 1; // Set tristate control chip to input for pin RC3.
TRISCbits.TRISC4 = ane; // Set tristate control bit to input for pivot RC4.
TRISCbits.TRISC6 = 0; // Clear tristate control bit for output on pivot RC6.
In that location are bit macro definitions that may be used in mask and shift operations:
while ((SSPCON2 & ( _SSPCON2_SEN_MASK | _SSPCON2_RSEN_MASK | _SSPCON2_PEN_MASK | _SSPCON2_RCEN_MASK | _SSPCON2_ACKEN_MASK))
|| (SSPSTAT & _SSPSTAT_R_nW_MASK))
NOP;
In that location also are shorthand macro definitions available for many register bits.
Some SFR bits are placed in different registers in unlike device families.
It may be easier to type:
SSP1IF = 0; // Clear interrupt flag
SSP1IE = ane; // Enable interrupt
BCL1IF = 0;
BCL1IE = 1;
Instead of:
#if defined _16F1718
PIR1bits.SSP1IF = 0; // Clear interrupt flag
PIE1bits.SSP1IE = ane; // Enable interrupt
PIR2bits.BCL1IF = 0;
PIE2bits.BCL1IE = one;
#elif defined _16F18875 // Different device have unlike annals layout:
PIR3bits.SSP1IF = 0; // Articulate interrupt flag
PIE3bits.SSP1IE = 1; // Enable interrupt
PIR3bits.BCL1IF = 0;
PIE3bits.BCL1IE = 1;
0 Response to "How To Check A Register Bit Fiddling"
Post a Comment