Hello,
I am making a programmable amplifier, the MCU I used is MSP430F5529 (This is its PDF: http://www.kynix.com/uploadfiles/pdf879 … 29IPNR.pdf )and the software is ccs7.0 . Now it has realized to send a fixed digital quantity to dac7811 by using spi communication. Please look the following program:
#include <msp430.h>
#include <msp430f5529.h>
/*
* main.c
*/
#define uint unsigned int
int codeArray[]={0x199,0xCC,0x88,0x66,0x51,0x51,0x44,0x3A,0x33,0x2D,0x28};
int i=0;
void spiwrite(int data12,int cmd)
{
int n,j;
int jj=cmd;
P3OUT |= 0x01; //SYNC high
for( n=0;n<200;n++);
P3OUT |= 0x02; //SCLK high
P3OUT &= ~0x01; //SYNC low CS enabled
for( n=0;n<200;n++);
for(j=0;j<4;j++)
{
for(n=0;n<100;n++);
P3OUT |= 0x02; //SCLK high
for(n=0;n<100;n++);
if((jj>>(3-j)) & 0x01)
P3OUT |= 0x04;//data high level
else
P3OUT &=~0x04;//data low level
for(n=0;n<100;n++);
P3OUT &= ~0x02; //SCLK low
}
for(j=0;j<12;j++)
{
for(n=0;n<100;n++);
P3OUT |= 0x02; //SCLK high
for(n=0;n<100;n++);
if((data12>>(11-j)) & 0x01)
P3OUT |= 0x04;//data high level
else
P3OUT &=~0x04;//data low level
for(n=0;n<100;n++);
P3OUT &= ~0x02; //SCLK low
}
for(n=0;n<100;n++);
P3OUT |= 0x02; //SCLK high
for(n=0;n<100;n++);
P3OUT |= 0x01; //SYNC high
for(n=0;n<200;n++);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR|=BIT0; //set p1.0 to be output
P1REN|=BIT1;
P1OUT|=BIT1;
P3OUT |= 0x07;//P3.0 - P3.2 analog SPI port
P3DIR |= 0x07;//P3.0->SYNC,P3.1->SCLK,P3.2->SDIN
//int code=0x28; //deline 20db,100 times 0x28.
//int code=0x800;
int code=codeArray[i];
int code1;
spiwrite(code,1);
while(1)
{
if(!(P1IN&0x02)){
delay(1);
if(!(P1IN&0x02)){
while(!(P1IN&0x02)){
P1OUT^=BIT0;
if(i<9)
i++;
code=codeArray[i];
}
}
}
code1 = code;
spiwrite(code1,1);
}
}
Now I want to ask a question:
Touching the key-pay p1.1 off,it can just change digital quantity one time and then it jumped to the ninth array directly. Why?
Thanks.