Pic32 hardware initialization – Digilent 410-216P-KIT User Manual

Page 10

Advertising
background image

chipKIT Basic I/O Shield Reference Manual

www.digilentinc.com

page 10 of 15

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.

PIC32 Hardware Initialization


The following function initializes the PIC32 hardware for talking to the display. It initializes the SPI
controller and sets the control pins to be outputs.

/* ------------------------------------------------------------ */
/*** OledHostInit
**
**

Parameters:

**

none

**
**

Return Value:

**

none

**
**

Errors:

**

none

**
**

Description:

**

Perform PIC32 device initialization to prepare for use

**

of the OLED display.

**

This example is hard coded for the chipKIT Uno32 and

**

SPI2.

*/

void
OledHostInit()

{

unsigned int

tcfg;


/* Initialize SPI port 2.

*/

SPI2CON = 0;

SPI2BRG = 15;

//8Mhz, with 80Mhz PB clock

SPI2STATbits.SPIROV = 0;

SPI2CONbits.CKP = 1;

SPI2CONbits.MSTEN = 1;

SPI2CONbits.ON = 1;


/* Make pins RF4, RF5, and RF6 be outputs.

*/

PORTSetBits(IOPORT_F, bitVddCtrl|bitVbatCtrl|bitDataCmd);

PORTSetPinsDigitalOut(prtDataCmd, bitDataCmd);

//Data/Command# select

PORTSetPinsDigitalOut(prtVddCtrl, bitVddCtrl);

//VDD power control (1=off)

PORTSetPinsDigitalOut(prtVbatCtrl, bitVbatCtrl);

//VBAT power control (1=off)


/* Make the RG9 pin be an output. On the Basic I/O Shield, this pin

** is tied to reset.

*/

PORTSetBits(prtReset, bitReset);

PORTSetPinsDigitalOut(prtReset, bitReset);


}

Advertising