Inputs
Read pin
if (PORTBbits.RB0 == 0)
#define IO_EXTERNAL_POWER_PRESENT (!PORTBbits.RB0)
Read port
unsigned int MyVar = PORTB;
Outputs
Write pin
LATAbits.LATA6 = 1;
LATAbits.LATA7 = 0;
#define LED LATEbits.LATE1
#define CHARGE_OUTPUT(state) LATBbits.LATB0 = state
Write port
LATA = 0x0040; //Sets output latch. 0=low, 1=high
LATASET = 0x0040; //Sets high bits, without affecting other pins
LATACLR = 0x0040; //Clears high bits, without affecting other pins
Direction
#define PORTA_IO 0x0204 //Setup the IO pin type (0 = output, 1 = input)
TRISA = PORTA_IO;
TRISASET = (PORTA_IO); //Sets high bits as input, without affecting other pins
TRISACLR = (~PORTA_IO); //Sets high bits as output, without affecting other pins
#define KEYPAD_POWER_TRIS(state) TRISEbits.TRISE2 = state
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.