|
#include "msp430g2553.h"
#define uchar unsigned char
#define uint unsigned int
#define DIN_1 P1OUT|=BIT0
#define DIN_0 P1OUT&=~BIT0
#define SCLK_1 P1OUT|=BIT1
#define SCLK_0 P1OUT&=~BIT1
#define CS_1 P1OUT|=BIT2
#define CS_0 P1OUT&=~BIT2
//************************************************************************//精确定时程序
#define CPU_F ((double)8000000) //MCLK=8MHz
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
//************************************************************************
volatile unsigned int num,i;
void init_clk()//配置MCLK=8MHZ,SMCLK=8MHz
{
P1DIR=0x0F;
BCSCTL2=SELM_0+DIVM_0+DIVS_0;
if(CALBC1_8MHZ!=0xFF)
{
__delay_cycles(10000);
DCOCTL=0x00;
BCSCTL1=CALBC1_8MHZ;
DCOCTL=CALDCO_8MHZ;
}
BCSCTL1|=XT2OFF+DIVA_0;
}
void DA_conver(uint Dignum)
{
uint Dig=0;
uchar k=0;
SCLK_1;
CS_0;
for(k=0;k<12;k++) //写入16为Bit的控制位和数据
{
Dig=Dignum & 0x0800; //将Digum的高位放入Dig中,即Dig为Dignm的最高位
if(Dig)
{
DIN_1;
}
else
{
DIN_0;
}
SCLK_0;
_NOP(); // delay_us(100); //注意:这个延时会改变正弦波的频率
Dignum<<=1;
SCLK_1;
_NOP(); //delay_us(100);
}
SCLK_1;
CS_1; //片选无效
}
void main()
{
WDTCTL=WDTPW+WDTHOLD;
init_clk( );
P1REN|=BIT3; //使能引脚电阻,
P1OUT|=BIT3; //打开上拉电阻
P1IE|=BIT3;
P1IES&=~BIT3;
_EINT();
while(1){
DA_conver(num);
}
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void )
{
i=1500;
for(;i>0;i--);
while(!(P1IN&BIT3));
i=1500;
for(;i>0;i--);
P1IFG&=~BIT3;
if(num>4092)num=0;
else num+=50;
}
没有反应。各位给看看是什么问题。还有调试的时候如何进入按键中断呢?
|
|