MSP430 single chip microcomputer makes intelligent digital multimeter circuit diagram + program
[Copy link]
For those who want to make a multimeter,
the circuit diagram is as follows:
The microcontroller source program is as follows:
- /*
- * Simple low power multimeter
- */
- #include <msp430g2553.h>
- #include "LCD12864P.h"
- unsigned int ADC_flag,ADC_flag1,shua_xin;
- unsigned int ADC_data[8],ADC_result[8],mser,song,liang_cheng = 0,s,wen_pt,pt100 = 0,zu_zhi = 0;
- unsigned int data0,data1,data2,data3,data4,data5,data6,data7;
- //double data0,data1,data2,data3,data4,data5,data6,data7;
- unsigned int table[]={0x00,0x02,0x01,0x04,0x08,0xEF,0xdf,0xcf,0x80}; //Range selection [1] DC 10V [2] DC 1V [3] Resistance value 10k
- /*
- *initialization
- */
- void int_t()
- {
- WDTCTL = WDT_MDLY_8; // Initialization setting of watchdog timer
- IE1 |= WDTIE;
- Ini_Lcd(); //lcd initialization
- BCSCTL1 = CALBC1_8MHZ;
- DCOCTL = CALDCO_8MHZ;
- /*
- P1DIR &= BIT3+BIT4; /////////Set the key port as input
- P1REN |= BIT3+BIT4; ////////Turn on the pull-up resistor to generate a trigger edge from high level to low level
- P1IE |= 0X18; //////////Set key port interrupt
- P1IES |= 0X18; ////////////Falling edge interrupt. The interrupt is triggered only when the hand is released.
- */
- P1DIR &= BIT3; /////////Set the key port as input
- P1REN |= BIT3; ////////Turn on the pull-up resistor to generate a trigger edge from high level to low level
- P1IE |= 0X08; //////////Set key port interrupt
- P1IES |= 0X08; ////////////Falling edge interrupt. The interrupt is triggered only when the hand is released.
- P2DIR &= ~(BIT2+BIT3+BIT4+BIT5); /////////Set the function selection key to input 1. DC voltage 2. AC voltage 3. Resistance range 4. Capacitance measurement
- P1DIR |= BIT5 + BIT6 + BIT7 ; // Set the expansion port to output
- _EINT(); //Enable interrupts. This is an internal process supported by the C compiler.
- }
- /*
- * Key delay program
- */
- void delay(unsigned int n) //Function with parameters and return value
- {
- unsigned int i;
- unsigned int j;
- for(i=n;i>0;i--)
- for(j=100;j>0;j--)
- _nop();
- }
- /****************************************************** *************
- * Name: ADC()
- *Function: AD setting conversion interrupt
- *************************************************** ******************/
- void ADC()
- {
- P1SEL |= BIT0 + BIT1 + BIT2 + BIT4; //+ BIT3; //+ BIT4 + BIT5 + BIT6 + BIT7; //Set to analog input
- ADC10AE0 |= BIT0 + BIT1 + BIT2 + BIT4; // + BIT3; // + BIT4 + BIT5 + BIT6 + BIT7; // Open channels A1/A2/A4/A5/A6/A7
- ADC10CTL0|=ADC10ON+MSC+ADC10SHT_2+ADC10IE; //Turn on ADC conversion, enable ADC10, set the frequency to 16 cycles, and enable interrupts
- ADC10CTL0 |=SREF_1 + REFON + REF2_5V; //Open the internal reference voltage to 2.5V and enable interrupts
- ADC10CTL1|=CONSEQ_3+INCH_7; //Use dual (4) channels, circular acquisition mode
- ADC10DTC1|=0x08; //Continuously sample each channel once
- _BIS_SR(GIE);
- }
- /*
- *Function: AD data processing
- */
- void ADC_DATA()
- {
- unsigned char i;
- ADC10CTL0&=~ENC;
- while(ADC10CTL1&ADC10BUSY); //Check if AD is busy
- ADC10CTL0|=ENC+ADC10SC; //Start ADC
- ADC10SA=(unsigned int)ADC_result; //Get the first address of ADC_result[]. First, sample A1 and A0, and put them into ADC_result[0] and ADC_result[1], and repeat the cycle.
- for(i=0;i<8;i++)
- {
- ADC_data =0;
- ADC_data =ADC_result ;
- // ADC_data = (ADC_data * 25) / 1023; // Convert ADC to actual voltage value
- }
- }
- /*
- * Programming of expansion chip 595
- */
- void kuo_zhan(unsigned int dat)
- {
- unsigned int i;
- for(i=0;i<8;i++)
- {
- if((dat<<i)&0x80)
- P1OUT|=BIT5;
- else
- P1OUT &= ~BIT5;
- P1OUT &= ~BIT7;
- _NOP();
- P1OUT |= BIT7;
- _NOP();
- }
- P1OUT &= ~BIT6;
- _NOP();
- P1OUT |= BIT6;
- _NOP();
- }
- /*
- * DC voltage detection
- */
- void zhi_liu()
- {
- unsigned int song_chao;
- lcd_pos(1,0);
- Disp_HZ("★Low power multimeter★",8);
- lcd_pos(2,0);
- Disp_HZ("DC voltage",4);
- lcd_pos(3,0);
- Disp_HZ("Measurement range",4);
- lcd_pos(4,0);
- Disp_HZ("Measurement voltage",4);
- if(liang_cheng == 1) //Data processing when the range is 10v
- {
- kuo_zhan(table[1]); //Open 10v channel
- song_chao = data0*5.8585*0.002443*100; //
- if(ADC_flag1 == 1)
- {
- ADC_flag1 = 0;
- lcd_pos(3,5);
- Disp_SZ(10/10);
- Disp_SZ(10%10);
- lcd_pos(3,6);
- Disp_HZ("V",1);
- lcd_pos(4,5);
- Disp_SZ(song_chao/1000);
- Disp_SZ(song_chao%1000/100);
- Disp_SZ(song_chao%100/10);
- Disp_SZ(song_chao%10);
- lcd_pos(4,7);
- Disp_HZ("V",1);
- }
- }
- else if(liang_cheng == 2) //Data processing when the range is 10v
- {
- kuo_zhan(table[2]); //Open 10v channel
- song_chao = data0*1.9825*0.002443*1000; //
- if(ADC_flag1 == 1)
- {
- ADC_flag1 = 0;
- lcd_pos(3,5);
- Disp_SZ(01/10);
- Disp_SZ(01%10);
- lcd_pos(3,6);
- Disp_HZ("V",1);
- lcd_pos(4,5);
- Disp_SZ(song_chao/1000);
- Disp_SZ(song_chao%1000/100);
- Disp_SZ(song_chao%100/10);
- Disp_SZ(song_chao%10);
- lcd_pos(4,7);
- Disp_HZ("V",1);
- }
- }
- else if(liang_cheng == 3) //Data processing when the range is 10v
- {
- kuo_zhan(table[3]); //Open 10v channel
- song_chao = data0*0.0891*0.002443*1000; //
- if(ADC_flag1 == 1)
- {
- ADC_flag1 = 0;
- lcd_pos(3,4);
- Disp_SZ(01/10);
- Disp_HZ(".",1);
- Disp_SZ(01%10);
- lcd_pos(3,6);
- Disp_HZ("V",1);
- lcd_pos(4,5);
- Disp_SZ(song_chao/1000);
- Disp_SZ(song_chao%1000/100);
- Disp_SZ(song_chao%100/10);
- Disp_SZ(song_chao%10);
- lcd_pos(4,7);
- Disp_HZ("V",1);
- }
- }
- }
- /*
- * AC voltage detection
- */
- void jiao_liu()
- {
- unsigned int chao_song;
- lcd_pos(1,0);
- Disp_HZ("★Low power multimeter★",8);
- lcd_pos(2,0);
- Disp_HZ("AC voltage",4);
- lcd_pos(3,0);
- Disp_HZ("Measurement range",4);
- lcd_pos(4,0);
- Disp_HZ("Measurement voltage",4);
- if(liang_cheng == 1) //Data processing when the range is 10v
- {
- chao_song = data1*3.5*0.002443*100; //
- if(ADC_flag1 == 1)
- {
- ADC_flag1 = 0;
- lcd_pos(3,4);
- Disp_SZ(10/10);
- Disp_SZ(10%10);
- lcd_pos(3,6);
- Disp_HZ("V",1);
- lcd_pos(4,5);
- Disp_SZ(chao_song/1000);
- Disp_SZ(chao_song%1000/100);
- Disp_SZ(chao_song%100/10);
- Disp_SZ(chao_song%10);
- lcd_pos(4,7);
- Disp_HZ("V",1);
- }
- }
- else if(liang_cheng == 2) //Data processing when the range is 10v
- {
- chao_song = data1*3.5*0.002443*1000; //
- if(ADC_flag1 == 1)
- {
- ADC_flag1 = 0;
- lcd_pos(3,4);
- Disp_SZ(01/10);
- Disp_SZ(01%10);
- lcd_pos(3,6);
- Disp_HZ("V",1);
- lcd_pos(4,5);
- Disp_SZ(chao_song/1000);
- Disp_SZ(chao_song%1000/100);
- Disp_SZ(chao_song%100/10);
- Disp_SZ(chao_song%10);
- lcd_pos(4,7);
- Disp_HZ("V",1);
- }
- }
- }
- /*
- * Resistance voltage detection
- */
- void dian_zu()
- {
- lcd_pos(1,0);
- Disp_HZ("★Low power multimeter★",8);
- lcd_pos(2,0);
- Disp_HZ("Resistance voltage",4);
- lcd_pos(3,0);
- Disp_HZ("Measurement range",4);
- lcd_pos(4,0);
- Disp_HZ("Measurement voltage",4);
- if(liang_cheng == 1) //Data processing when the range is 10v
- {
- kuo_zhan(table[5]);
- if(ADC_flag1 == 1)
- {
- zu_zhi = (data2*1.3125*10); //100 ohm data processing
- ADC_flag1 = 0;
- lcd_pos(3,5);
- Disp_SZ(10/10);
- Disp_SZ(10%10);
- lcd_pos(3,6);
- Disp_HZ("K",1);
- lcd_pos(4,5);
- Disp_SZ(zu_zhi/1000);
- Disp_SZ(zu_zhi%1000/100);
- Disp_SZ(zu_zhi%100/10);
- Disp_SZ(zu_zhi%10);
- lcd_pos(4,7);
- Disp_HZ("V",1);
- }
- }
- else if(liang_cheng == 2) //Data processing when the range is 10v
- {
- kuo_zhan(table[6]);
- if(ADC_flag1 == 1)
- {
- zu_zhi = ((data2*0.00125438)/(1-data2*0.00125438))*1870;; //100 ohm data processing
- ADC_flag1 = 0;
- lcd_pos(3,5);
- Disp_SZ(01/10);
- Disp_SZ(01%10);
- lcd_pos(3,6);
- Disp_HZ("K",1);
- lcd_pos(4,5);
- Disp_SZ(zu_zhi/1000);
- Disp_SZ(zu_zhi%1000/100);
- Disp_SZ(zu_zhi%100/10);
- Disp_SZ(zu_zhi%10);
- lcd_pos(4,7);
- Disp_HZ("V",1);
- }
- }
- else if(liang_cheng == 3) //Data processing when the range is 10v
- {
- kuo_zhan(table[7]);
- if(ADC_flag1 == 1)
- {
- zu_zhi = ((data2*0.001244895)/(1-data2*0.001244895))*4950; //10K ohm data processing
- ADC_flag1 = 0;
- lcd_pos(3,5);
- Disp_SZ(100%1000/100);
- Disp_SZ(100%100/10);
- Disp_SZ(100%10);
- lcd_pos(3,7);
- Disp_HZ("Ω",1);
- lcd_pos(4,5);
- Disp_SZ(zu_zhi/1000);
- Disp_SZ(zu_zhi%1000/100);
- Disp_SZ(zu_zhi%100/10);
- Disp_SZ(zu_zhi%10);
- lcd_pos(4,7);
- Disp_HZ("V",1);
- }
- }
- }
- /*
- * Temperature pt100 function
- */
- void wen_du()
- {
- wen_pt = ((32231.7975*data4+0.3150709*data4*data4)*0.000016); //Temperature data processing
- lcd_pos(2,4);
- Disp_SZ(wen_pt%1000/100);
- Disp_SZ(wen_pt%100/10);
- Disp_HZ(".",1); //Charging current
- Disp_SZ(wen_pt%10);
- lcd_pos(2,7);
- Disp_HZ("℃",1);
- }
- /*
- * Main function
- */
- void main()
- {
- int_t();
- ADC(); //AD function setting
- //ADC_DATA(); //AD conversion starts
- while(1)
- {
- ADC_DATA(); //AD conversion starts
- if(pt100 == 1)
- {
- pt100 = 0;
- wen_du();
- }
- if(P2IN & BIT2) //DC voltage detection position
- {
- zhi_liu(); //DC voltage range selection control
- }
- else if(P2IN & BIT3) //AC voltage detection gear
- {
- jiao_liu(); //DC voltage range selection control
- }
- else if(P2IN & BIT4) //resistance voltage detection gear
- {
- dian_zu(); //DC voltage range selection control
- }
- }
- }
- /**
- *Name Watchdog Timer Interrupt
- **/
- #pragma vector=WDT_VECTOR
- __interrupt void watchdog_timer(void)
- {
- shua_xin++;
- if(shua_xin >= 1000)
- {
- shua_xin = 0;
- ADC_flag1 = 1;
- s++;
- if(s >= 50)
- {
- pt100 = 1;
- }
|