?? main.c
字號:
#include "msp430x14x.h" // Standard Equations
#include "1602.h"
static unsigned int results[2]; // Needs to be global in this example
unsigned int i=0; // Otherwise, the compiler removes it
// because it is not used for anything.
void init_clk()
{
unsigned int i;
BCSCTL1 = 0X00; //將寄存器的內容清零
//XT2震蕩器開啟
//LFTX1工作在低頻模式
//ACLK的分頻因子為1
do
{
IFG1 &= ~OFIFG; // 清除OSCFault標志
for (i = 0x20; i > 0; i--);
}
while ((IFG1 & OFIFG) == OFIFG); // 如果OSCFault =1
BCSCTL2 = 0X00; //將寄存器的內容清零
BCSCTL2 += SELM1; //MCLK的時鐘源為TX2CLK,分頻因子為1
BCSCTL2 += SELS; //SMCLK的時鐘源為TX2CLK,分頻因子為1
}
/*
void shujiu()
{
flag1=(results[0]/4095)*3.3;
flag2=(results[1]/4095)*3.3;
temp=power*10;
tab1[0]=power/10;
tab1[1]=(int)power%10;
tab1[2]=temp%10;
temp=effcient*10;
tab2[0]=effcient/10;
tab2[1]=(int)effcient%10;
tab2[2]=temp%10;
GotoXY(0,0);
WriteLCD(DATA,tab1[0]+'0');
WriteLCD(DATA,tab1[1]+'0');
WriteLCD(DATA,tab1[2]+'0');
GotoXY(0,1);
WriteLCD(DATA,tab2[0]+'0');
WriteLCD(DATA,tab2[1]+'0');
WriteLCD(DATA,tab2[2]+'0');
}
*/
void main(void)
{
unsigned char tab1[3]={0,0,0};
unsigned char tab2[3]={0,0,0};
unsigned int temp;
float flag1,flag2;
float power,effcient;
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
init_clk();
LCD_Initial();
P6SEL = 0x03; // Enable A/D channel inputs
ADC12CTL0 = ADC12ON+MSC+SHT0_2; // Turn on ADC12, set sampling time
ADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, single sequence
ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0
ADC12MCTL1 = INCH_1+EOS; // ref+=AVcc, channel = A1
//ADC12MCTL2 = INCH_2+EOS; // ref+=AVcc, channel = A2,end seq.
ADC12IE = 0x02; // Enable ADC12IFG.3
ADC12CTL0 |= ENC; // Enable conversions
ADC12CTL0 |= ADC12SC;
_EINT();
while(1)
{
//ADC12CTL0 |= ADC12SC; // Start conversion
flag1=results[0];
flag2=results[1];
power=flag1/10;
effcient=flag2/10;
temp=power*10;
tab1[0]=power/10;
tab1[1]=(int)power%10;
tab1[2]=temp%10;
temp=effcient*10;
tab2[0]=effcient/10;
tab2[1]=(int)effcient%10;
tab2[2]=temp%10;
GotoXY(0,0);
WriteLCD(DATA,tab1[0]+'0');
WriteLCD(DATA,tab1[1]+'0');
WriteLCD(DATA,tab1[2]+'0');
GotoXY(0,1);
WriteLCD(DATA,tab2[0]+'0');
WriteLCD(DATA,tab2[1]+'0');
WriteLCD(DATA,tab2[2]+'0');
__delay_cycles(10000000);
}
}
#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR (void)
{
results[0] = ADC12MEM0; // Move results, IFG is cleared
results[1] = ADC12MEM1; // Move results, IFG is cleared
// results[2] = ADC12MEM2; // Move results, IFG is cleared
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -