This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

用软件CCSV5在MSP430编写一个测电阻的程序



这是要求,尽量容易看懂,尽量简单,最好有注释。谢谢了。

下面是我的程序,不对,有时测出的电阻是负值,而且N1,N2也是负值,不知道错误。

/*
* ======== Standard MSP430 includes ========
*/
#include <msp430.h>

/*
* ======== Grace related includes ========
*/
#include <ti/mcu/msp430/csl/CSL.h>

/*
* ======== main ========
*/
int main(int argc, char *argv[])
{
CSL_init(); // Activate Grace-generated configuration

// >>>>> Fill-in user code here <<<<<
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= 0x20;
_BIS_SR(CAPD0);
P1OUT=1;
__delay_cycles(100000);
_BIS_SR(CAPD5);
P1OUT=0;

volatile unsigned int time00,time01,N0;

TAR=0;
if(CAOUT==1)
{
time00=TAR;
}
else
time01=TAR;
N0=time01-time00;

__delay_cycles(100000);

P1DIR |= 0x01;
_BIS_SR(CAPD5);
P1OUT=1;
__delay_cycles(100000);
_BIS_SR(CAPD0);
P1OUT=0;
volatile unsigned int time10,time11,N1;
TAR=0;
if(CAOUT==1)
{
time10=TAR;
}
else
time11=TAR;
N1=time11-time10;
volatile float R;
R=0.993*N1/N0;
return (0);
}

这个程序是用RC法来测量电阻的,不知道哪不对,帮忙改改。