void SetVCoreUp (unsigned int level) //设置MCU核心电压,初始化电源模块 {
//取得PMM寄存器写入权限 PMMCTL0_H = 0xA5;
// Make sure no flags are set for iterative sequences //while ((PMMIFG & SVSMHDLYIFG) == 0); //while ((PMMIFG & SVSMLDLYIFG) == 0); // Set SVS/SVM high side new level
SVSMHCTL = SVSHE + SVSHRVL0 * level + SVMHE + SVSMHRRL0 * level;
// Set SVM low side to new level
SVSMLCTL = SVSLE + SVMLE + SVSMLRRL0 * level; // Wait till SVM is settled
while ((PMMIFG & SVSMLDLYIFG) == 0); // Clear already set flags
PMMIFG &= ~(SVMLVLRIFG + SVMLIFG); // Set VCore to new level
PMMCTL0_L = PMMCOREV0 * level; // Wait till new level reached if ((PMMIFG & SVMLIFG))
while ((PMMIFG & SVMLVLRIFG) == 0);
21
// Set SVS/SVM low side to new level
SVSMLCTL = SVSLE + SVSLRVL0 * level + SVMLE + SVSMLRRL0 * level;
// Lock PMM registers for write access PMMCTL0_H = 0x00; }
// LDC BITMASKS
#define LDC1000_BIT_AMPLITUDE 0x18 #define LDC1000_BIT_RESPTIME 0x07 #define LDC1000_BIT_CLKSEL 0x02 #define LDC1000_BIT_CLKPD 0x01 #define LDC1000_BIT_INTMODE 0x07 #define LDC1000_BIT_PWRMODE 0x01 #define LDC1000_BIT_STATUSOSC 0x80 #define LDC1000_BIT_STATUSDRDYB 0x40 #define LDC1000_BIT_STATUSWAKEUP 0x20 #define LDC1000_BIT_STATUSCOMP 0x10
extern char p[2]; extern char freq[3];
22
extern int pMIN; extern int freqMIN;
extern int pMAX; extern int freqMAX;
extern int pTEMP; extern int freqTEMP;
char spi_readByte( char addr, char * data);
char spi_readWord(char addr, unsigned int * data); // Big Endian char spi_readBytes( char addr, char * buffer, unsigned char len); char spi_writeByte(char addr, char data);
char spi_writeWord(char addr, unsigned int data); // Big Endian char spi_writeBytes( char addr, char * buffer, unsigned char len); #endif
LDC1000.c文件:
#include \
static unsigned char txlen;
23
static unsigned char rxlen; static char *txbuf; static char *rxbuf; static char txaddr; static char wordbuf[2];
char p[2]; char freq[3];
int pMIN; int freqMIN;
int pMAX; int freqMAX;
int pTEMP; int freqTEMP;
char spi_readByte( char addr, char * data) {
24
rxlen = 1; rxbuf = data; txaddr = addr | 0x80; P4OUT &= ~BIT0;
while (!(UCB1IFG&UCTXIFG)); UCB1TXBUF = txaddr;
while (!(UCB1IFG&UCTXIFG)); UCB1TXBUF = 0;
while (UCB1STAT & UCBUSY); * rxbuf = UCB1RXBUF; while (UCB1STAT & UCBUSY); P4OUT |= BIT0; return 0; }
char spi_readWord(char addr, unsigned int * data) {
rxlen = 2;
rxbuf = &wordbuf[0]; txaddr = addr | 0x80;
25