⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpux_02.c

📁 Extended Memory Access Using IAR v3.42A and CCE v2
💻 C
字号:
//******************************************************************************
//  MSP430xG461x Demo - Software ptr, Rpt'd Blk to DAC0, Sine Out, TimerA0, DCO
//
// This program shows how a data table placed in extended memory is accessed via
// a 32-bit addr variable to move the data to DAC12 word by word. 
//
// Description: A 32 word Sine look-up table is stored in the extended memory 
// location 0x10000 onwards by interfacing C with assembly. A 32-bit address
// variable is used as a pointer to access the data from the extended  
// memory and transfer the contents of the Sine look-up table word-by-word as a  
// repeating block to DAC12_0. And DAC12_0 outputs on P6.6 a 1-kHz Sine wave.  
// Timer A operates in compare mode, where, TACCR0 sets the Clock period and 
// TACCR1 sets  the PWM duty cycle. To get a 1-kHz Sine wave out, Timer period is
// set to almost 32us (as 32us*32 words ~ 1ms) , with TimerA clock  running at 
// 1MHz. And During the TimerA0 ISR the data present at the addr stored in the 
// addr variable is then loaded to the DAC12_0DAT register for conversion and 
// the addr variable is incremented to point the next address. 
// DAC12_0 uses internal 1.5V reference.
// ACLK = 32kHz, MCLK = SMCLK = default DCO 8MHz, TACLK = SMCLK/8 = 1MHZ
//
//                MSP430xG461x
//             -----------------
//         /|\|              XIN|-
//          | |                 | 32kHz
//          --|RST          XOUT|-
//            |                 |
//            |        DAC0/P6.6|--> ~ 1-kHz sine wave output
//
//   Note 1: The linker command file for this project has to be modified to  
//           create a new memory segment (CONST_HIGH - in this example). The  
//           linker command -Z(CONST)CONST_HIGH=10000-1FFFF is used to create  
//           a new memory segment in the extended memory (0x10000 - 0x1FFFF).
//   Note 2: This code example interfaces C with Assembler code, therefore, the 
//           project must include assembly file "ASM_func.s43".
//
//   Bhargavi Nisarga
//   Texas Instruments Inc.
//   June 2007
//   Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************

#include "msp430xG46x.h"
#include "intrinsics.h"

extern unsigned long __Get_Address20(void); // Function prototype for ASM func
unsigned long Addr32;                       // 32-bit address variable
unsigned short Count, Size;

void main(void)
{
  volatile unsigned int i;	
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  
  //Set DCO freq = 8MHz
  FLL_CTL0 |= DCOPLUS + XCAP18PF;           // DCO+ set, freq = xtal x D x N+1
  SCFI0 |= FN_4;                            // x2 DCO freq, 8MHz nominal DCO
  SCFQCTL = 121;            

  ADC12CTL0 = REFON;                        // Internal 1.5V reference
  for (i = 0x3600; i; i--);                 // Delay for needed ref start-up.
                                            // See datasheet for details.
  
  /* Initialize address variable to the (ext memory) address of the Sine wave 
     data look-up table*/
  Addr32 = (unsigned long)__Get_Address20(); 
  Size = 0x0020;                            //Size in words 
  Count = 0;   
  
  // Configure  DAC12_0
  DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC;
                                            // amp and i/p range setting, 
                                            // DAC enable     
  
  // Configure Timer A
  TACCTL1 = OUTMOD_3;                       // TACCR1 set/reset
  TACCR1 = 1;                               // TACCR1 PWM Duty Cycle  
  TACCR0 = 30;                              // Clock period of TACCR0
  TACCTL0 = CCIE;                           // Interrupt enable
  TACTL = TASSEL_2 + MC_1 + TACLR + ID_3;   // SMCLK, upmode, (i/p clk/8)
  
  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, enable interrupts
    
}

// TimerA interrupt service routine
#pragma vector = TIMERA0_VECTOR
__interrupt void TA0_ISR(void)
{
    DAC12_0DAT = (unsigned short)__data20_read_short(Addr32); 
                                            // Get data at the address stored in  
                                            // addr variable to DAC data reg
    Addr32 += 0x02;                         // Incr addr var to point next addr
    if (++Count >= Size)                    // Chk if count within memory range
    {
      // Repeat Block transfer from extended memory to DAC12_0
      Addr32 = (unsigned long)__Get_Address20(); 
      Count = 0;
    }    
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -