📄 slaa319.c
字号:
/****************************************************************/
/* FILENAME: SLAA319.c */
/* DESCRIPTION: This program uses the MSP430F449 to write 256 */
/* samples to the DAC8814 EVM board. */
/* The samples are generated by sine/cosine functions */
/* AUTHOR: T. Hendrick, Data Acquisition Products, */
/* Dallas Texas */
/* CREATED 2005(C) BY TEXAS INSTRUMENTS INCORPORATED. */
/* VERSION: 01 */
/* Compiled on IAR Embedded Workbench V 4.0 */
/****************************************************************/
#include <msp430x44x.h>
#include <math.h>
#include "SBLCDA2.h"
/**************** Function prototypes ***********************************/
/* */
void init_sys(void); /* MSP430 Initialisation routine */
void setupClock(int);
void delay(int); /* Software delay */
void dac_convert(int); /* Do the adc conversion */
void display(void); /* Indicate Program complete */
void InitializeLCD( void );
void clearDisplay( void );
void sortMajor( unsigned int );
void displaySpecial( long int );
void displayMinor( int, int );
void displayHPA449(void);
void displayTest(void);
void InitTables(int);
/************************************************************************/
/* */
/* HPA449 variable declarations */
/* */
/************************************************************************/
#define Resonator (0)
//Define the following statemests as "true" (change zero to 1) based on serial port
// Note - Only one can be set true
#define SERIAL_A (1)
#define SERIAL_B (0)
/************************************************************************/
/* */
/* main() variable declarations */
/* */
/************************************************************************/
#define TABLE_SIZE 256
int sinetable[TABLE_SIZE];
short byte0, byte1, byte2;
int i, y;
/******************************************************************************\
* Function: InitTables()
* Description: Initializes Sine and Cosine Values
\******************************************************************************/
void main(void)
{
setupClock(Resonator);
init_sys(); // Initialise the MSP430
InitializeLCD();
clearDisplay();
displaySpecial(SoftBaugh|AL|AR|AU|AD);
InitTables(2);
displayTest();
displaySpecial(SoftBaugh|AR);
do {
for(i=0; i<TABLE_SIZE; i++)
{
dac_convert(sinetable[i]); // Do conversions from each channel
}
}
while (1); //
}
void InitTables(int period)
{
int y;
for (y = 0; y < TABLE_SIZE; y++)
{
sinetable[y] = (unsigned int)((sin(2 * __PI * period * y / TABLE_SIZE) + 1.0) * 32767);
}
}
/************************************************************/
/* Prototype - init_sys */
/* */
/* Description */
/* This prototype initialises the MSP430F149 */
/************************************************************/
void init_sys(void)
{
void setupports(void); /* Local function prototype */
void setupSPI(void); /* Local function prototype */
setupports();
setupSPI();
_EINT(); // Enable interrupts
}
/************************************************************/
/* Prototype - setupClock */
/* */
/* Description */
/* This prototype sets-up the XT2 oscillator and tests */
/* that it has settled before moving on */
/************************************************************/
void setupClock (int RES)
{
switch (RES)
{
case 0:
{ WDTCTL = WDTPW + WDTHOLD;
/* D=2, N=121, no mod */
SCFQCTL=121;
// SCFI0 = 0100 0100
SCFI0=0x44;
// DCOPLUS=1, XTS_FLL=0
// XCAPXPF=00
FLL_CTL0=0x80;
// SMCLK=0, XT2OFF=1, SELMX=00, SELS=0, FLL_DIVX=10
// FLL_CTL1= 0010 0010
FLL_CTL1=0x22;
}
break;
case 1:
{ WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FLL_CTL0&=XT2OFF; // Switch on the XT2 osc.
FLL_CTL1|=SELM_XT2+SELS; // Select XT2 osc. for
// Test the osc. flag bit
do {
IFG1 &= ~OFIFG; // Clear the OFIFG bit
} while (OFIFG&IFG1); //
}
break;
}
}
/************************************************************/
/* Prototype - setupports */
/* Description */
/* This prototype sets-up the GPIO ports as appropriate */
/************************************************************/
void setupports (void)
{
// SPI port for ADC
#if SERIAL_A
#define MSB 0x80 //p3.7
#define DAC_CS 0x20 //p3.5
#define LDAC 0x08 //p2.3
P3DIR = MSB + DAC_CS; // Set the MSB + DAC_CS as an output
P3OUT = MSB + DAC_CS;
P2DIR = LDAC; // Set the LDAC as an output
P2OUT = LDAC;
P3SEL = BIT3 + BIT1 + BIT0; // Select SPI function of port 3
#endif
#if SERIAL_B
#define MSB 0x40 //p2.6
#define DAC_CS 0x04 //p1.2
#define LDAC 0x08 //p2.3
P1DIR = DAC_CS; // Set the DAC_CS as an output
P1OUT = DAC_CS;
P2DIR = MSB + LDAC; // Set the MSB and LDAC as an output
P2OUT = MSB + LDAC;
P4SEL = BIT5 + BIT3 + BIT2; // Select SPI function of port 4
#endif
}
/************************************************************/
/* Prototype - setupSPI */
/* */
/* Description */
/* This prototype sets-up the P3 for communication via SPI */
/************************************************************/
void setupSPI (void)
{
#if SERIAL_A
// UART0 Setup
ME1 |= USPIE0; // Module Enable - SPI
U0CTL &= ~SWRST; // Make sure the RESET bit is off
U0CTL |= CHAR + SYNC + MM; // USART0 module operation
U0TCTL |= CKPH + SSEL0 + SSEL1 + STC; // USART0 Tranmit control register
U0BR0 = 0x02; // Divide SMCLK by 4 => transfer clock
U0BR1 = 0x00; //
U0MCTL = 0x00; // Modulation control - not used.
#endif
#if SERIAL_B
// UART1 Setup
ME2 |= USPIE1; // Module Enable - SPI
U1CTL &= ~SWRST; // Make sure the RESET bit is off
U1CTL |= CHAR + SYNC + MM; // USART1 module operation
U1TCTL |= CKPH + SSEL0 + SSEL1 + STC; // USART1 Tranmit control register
U1BR0 = 0x02; // Divide SMCLK by 4 => transfer clock
U1BR1 = 0x00; //
U1MCTL = 0x00; // Modulation control - not used.
#endif
}
/************************************************************/
/* Prototype - delay */
/* Description */
/* This prototype gives a delay of around 1 second */
/************************************************************/
void delay(int time)
{
unsigned int i;
for (i = 0; i < time; i++);
}
/************************************************************/
/* Prototype - convert */
/* Description */
/* This prototype does the adc conversion */
/************************************************************/
void dac_convert (value)
{
int i;
byte0 = (value)>>8;
byte1 = value >>0;
for (i=0; i<4; i++)
{
#if SERIAL_A
P3OUT &= ~(DAC_CS);
while ((IFG1 & UTXIFG0) == 0);
U0TXBUF = i; // Send clocks to the DAC, this shifts first byte
// Wait until all 8 bits have been received.
while ((IFG1 & UTXIFG0) == 0);
U0TXBUF = byte0; // Send clocks to the DAC, this shifts first byte
// Wait until all 8 bits have been received.
while ((IFG1 & UTXIFG0) == 0);
U0TXBUF = byte1; // Send clocks to the DAC, this shifts 2nd byte
// Wait until all 8 bits have been received.
delay(5);
P3OUT |= (DAC_CS);
#endif
#if SERIAL_B
P1OUT &= ~(DAC_CS);
while ((IFG1 & UTXIFG0) == 0);
U1TXBUF = i; // Send clocks to the DAC, this shifts first byte
// Wait until all 8 bits have been received.
while ((IFG1 & UTXIFG0) == 0);
U1TXBUF = byte0; // Send clocks to the DAC, this shifts first byte
// Wait until all 8 bits have been received.
while ((IFG1 & UTXIFG0) == 0);
U1TXBUF = byte1; // Send clocks to the DAC, this shifts 2nd byte
// Wait until all 8 bits have been received.
delay(5);
P1OUT |= (DAC_CS);
#endif
}
P2OUT &= ~(LDAC);
P2OUT |= (LDAC);
}
void displayTest(void)
{
displayMinor(5,UL_EIGHT);
displayMinor(4,UL_EIGHT);
displayMinor(3,UR_ONE);
displayMinor(2,UR_FOUR);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -