2432 views|1 replies

1140

Posts

0

Resources
The OP
 

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:

  1. /*
  2. * Simple low power multimeter
  3. */
  4. #include <msp430g2553.h>
  5. #include "LCD12864P.h"
  6. unsigned int ADC_flag,ADC_flag1,shua_xin;
  7. unsigned int ADC_data[8],ADC_result[8],mser,song,liang_cheng = 0,s,wen_pt,pt100 = 0,zu_zhi = 0;
  8. unsigned int data0,data1,data2,data3,data4,data5,data6,data7;
  9. //double data0,data1,data2,data3,data4,data5,data6,data7;
  10. unsigned int table[]={0x00,0x02,0x01,0x04,0x08,0xEF,0xdf,0xcf,0x80}; //Range selection [1] DC 10V [2] DC 1V [3] Resistance value 10k
  11. /*
  12. *initialization
  13. */
  14. void int_t()
  15. {
  16. WDTCTL = WDT_MDLY_8; // Initialization setting of watchdog timer
  17. IE1 |= WDTIE;
  18. Ini_Lcd(); //lcd initialization
  19. BCSCTL1 = CALBC1_8MHZ;
  20. DCOCTL = CALDCO_8MHZ;
  21. /*
  22. P1DIR &= BIT3+BIT4; /////////Set the key port as input
  23. P1REN |= BIT3+BIT4; ////////Turn on the pull-up resistor to generate a trigger edge from high level to low level
  24. P1IE |= 0X18; //////////Set key port interrupt
  25. P1IES |= 0X18; ////////////Falling edge interrupt. The interrupt is triggered only when the hand is released.
  26. */
  27. P1DIR &= BIT3; /////////Set the key port as input
  28. P1REN |= BIT3; ////////Turn on the pull-up resistor to generate a trigger edge from high level to low level
  29. P1IE |= 0X08; //////////Set key port interrupt
  30. P1IES |= 0X08; ////////////Falling edge interrupt. The interrupt is triggered only when the hand is released.
  31. P2DIR &= ~(BIT2+BIT3+BIT4+BIT5); /////////Set the function selection key to input 1. DC voltage 2. AC voltage 3. Resistance range 4. Capacitance measurement
  32. P1DIR |= BIT5 + BIT6 + BIT7 ; // Set the expansion port to output
  33. _EINT(); //Enable interrupts. This is an internal process supported by the C compiler.
  34. }
  35. /*
  36. * Key delay program
  37. */
  38. void delay(unsigned int n) //Function with parameters and return value
  39. {
  40. unsigned int i;
  41. unsigned int j;
  42. for(i=n;i>0;i--)
  43. for(j=100;j>0;j--)
  44. _nop();
  45. }
  46. /****************************************************** *************
  47. * Name: ADC()
  48. *Function: AD setting conversion interrupt
  49. *************************************************** ******************/
  50. void ADC()
  51. {
  52. P1SEL |= BIT0 + BIT1 + BIT2 + BIT4; //+ BIT3; //+ BIT4 + BIT5 + BIT6 + BIT7; //Set to analog input
  53. ADC10AE0 |= BIT0 + BIT1 + BIT2 + BIT4; // + BIT3; // + BIT4 + BIT5 + BIT6 + BIT7; // Open channels A1/A2/A4/A5/A6/A7
  54. ADC10CTL0|=ADC10ON+MSC+ADC10SHT_2+ADC10IE; //Turn on ADC conversion, enable ADC10, set the frequency to 16 cycles, and enable interrupts
  55. ADC10CTL0 |=SREF_1 + REFON + REF2_5V; //Open the internal reference voltage to 2.5V and enable interrupts
  56. ADC10CTL1|=CONSEQ_3+INCH_7; //Use dual (4) channels, circular acquisition mode
  57. ADC10DTC1|=0x08; //Continuously sample each channel once
  58. _BIS_SR(GIE);
  59. }
  60. /*
  61. *Function: AD data processing
  62. */
  63. void ADC_DATA()
  64. {
  65. unsigned char i;
  66. ADC10CTL0&=~ENC;
  67. while(ADC10CTL1&ADC10BUSY); //Check if AD is busy
  68. ADC10CTL0|=ENC+ADC10SC; //Start ADC
  69. 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.
  70. for(i=0;i<8;i++)
  71. {
  72. ADC_data =0;
  73. ADC_data =ADC_result ;
  74. // ADC_data = (ADC_data * 25) / 1023; // Convert ADC to actual voltage value
  75. }
  76. }
  77. /*
  78. * Programming of expansion chip 595
  79. */
  80. void kuo_zhan(unsigned int dat)
  81. {
  82. unsigned int i;
  83. for(i=0;i<8;i++)
  84. {
  85. if((dat<<i)&0x80)
  86. P1OUT|=BIT5;
  87. else
  88. P1OUT &= ~BIT5;
  89. P1OUT &= ~BIT7;
  90. _NOP();
  91. P1OUT |= BIT7;
  92. _NOP();
  93. }
  94. P1OUT &= ~BIT6;
  95. _NOP();
  96. P1OUT |= BIT6;
  97. _NOP();
  98. }
  99. /*
  100. * DC voltage detection
  101. */
  102. void zhi_liu()
  103. {
  104. unsigned int song_chao;
  105. lcd_pos(1,0);
  106. Disp_HZ("★Low power multimeter★",8);
  107. lcd_pos(2,0);
  108. Disp_HZ("DC voltage",4);
  109. lcd_pos(3,0);
  110. Disp_HZ("Measurement range",4);
  111. lcd_pos(4,0);
  112. Disp_HZ("Measurement voltage",4);
  113. if(liang_cheng == 1) //Data processing when the range is 10v
  114. {
  115. kuo_zhan(table[1]); //Open 10v channel
  116. song_chao = data0*5.8585*0.002443*100; //
  117. if(ADC_flag1 == 1)
  118. {
  119. ADC_flag1 = 0;
  120. lcd_pos(3,5);
  121. Disp_SZ(10/10);
  122. Disp_SZ(10%10);
  123. lcd_pos(3,6);
  124. Disp_HZ("V",1);
  125. lcd_pos(4,5);
  126. Disp_SZ(song_chao/1000);
  127. Disp_SZ(song_chao%1000/100);
  128. Disp_SZ(song_chao%100/10);
  129. Disp_SZ(song_chao%10);
  130. lcd_pos(4,7);
  131. Disp_HZ("V",1);
  132. }
  133. }
  134. else if(liang_cheng == 2) //Data processing when the range is 10v
  135. {
  136. kuo_zhan(table[2]); //Open 10v channel
  137. song_chao = data0*1.9825*0.002443*1000; //
  138. if(ADC_flag1 == 1)
  139. {
  140. ADC_flag1 = 0;
  141. lcd_pos(3,5);
  142. Disp_SZ(01/10);
  143. Disp_SZ(01%10);
  144. lcd_pos(3,6);
  145. Disp_HZ("V",1);
  146. lcd_pos(4,5);
  147. Disp_SZ(song_chao/1000);
  148. Disp_SZ(song_chao%1000/100);
  149. Disp_SZ(song_chao%100/10);
  150. Disp_SZ(song_chao%10);
  151. lcd_pos(4,7);
  152. Disp_HZ("V",1);
  153. }
  154. }
  155. else if(liang_cheng == 3) //Data processing when the range is 10v
  156. {
  157. kuo_zhan(table[3]); //Open 10v channel
  158. song_chao = data0*0.0891*0.002443*1000; //
  159. if(ADC_flag1 == 1)
  160. {
  161. ADC_flag1 = 0;
  162. lcd_pos(3,4);
  163. Disp_SZ(01/10);
  164. Disp_HZ(".",1);
  165. Disp_SZ(01%10);
  166. lcd_pos(3,6);
  167. Disp_HZ("V",1);
  168. lcd_pos(4,5);
  169. Disp_SZ(song_chao/1000);
  170. Disp_SZ(song_chao%1000/100);
  171. Disp_SZ(song_chao%100/10);
  172. Disp_SZ(song_chao%10);
  173. lcd_pos(4,7);
  174. Disp_HZ("V",1);
  175. }
  176. }
  177. }
  178. /*
  179. * AC voltage detection
  180. */
  181. void jiao_liu()
  182. {
  183. unsigned int chao_song;
  184. lcd_pos(1,0);
  185. Disp_HZ("★Low power multimeter★",8);
  186. lcd_pos(2,0);
  187. Disp_HZ("AC voltage",4);
  188. lcd_pos(3,0);
  189. Disp_HZ("Measurement range",4);
  190. lcd_pos(4,0);
  191. Disp_HZ("Measurement voltage",4);
  192. if(liang_cheng == 1) //Data processing when the range is 10v
  193. {
  194. chao_song = data1*3.5*0.002443*100; //
  195. if(ADC_flag1 == 1)
  196. {
  197. ADC_flag1 = 0;
  198. lcd_pos(3,4);
  199. Disp_SZ(10/10);
  200. Disp_SZ(10%10);
  201. lcd_pos(3,6);
  202. Disp_HZ("V",1);
  203. lcd_pos(4,5);
  204. Disp_SZ(chao_song/1000);
  205. Disp_SZ(chao_song%1000/100);
  206. Disp_SZ(chao_song%100/10);
  207. Disp_SZ(chao_song%10);
  208. lcd_pos(4,7);
  209. Disp_HZ("V",1);
  210. }
  211. }
  212. else if(liang_cheng == 2) //Data processing when the range is 10v
  213. {
  214. chao_song = data1*3.5*0.002443*1000; //
  215. if(ADC_flag1 == 1)
  216. {
  217. ADC_flag1 = 0;
  218. lcd_pos(3,4);
  219. Disp_SZ(01/10);
  220. Disp_SZ(01%10);
  221. lcd_pos(3,6);
  222. Disp_HZ("V",1);
  223. lcd_pos(4,5);
  224. Disp_SZ(chao_song/1000);
  225. Disp_SZ(chao_song%1000/100);
  226. Disp_SZ(chao_song%100/10);
  227. Disp_SZ(chao_song%10);
  228. lcd_pos(4,7);
  229. Disp_HZ("V",1);
  230. }
  231. }
  232. }
  233. /*
  234. * Resistance voltage detection
  235. */
  236. void dian_zu()
  237. {
  238. lcd_pos(1,0);
  239. Disp_HZ("★Low power multimeter★",8);
  240. lcd_pos(2,0);
  241. Disp_HZ("Resistance voltage",4);
  242. lcd_pos(3,0);
  243. Disp_HZ("Measurement range",4);
  244. lcd_pos(4,0);
  245. Disp_HZ("Measurement voltage",4);
  246. if(liang_cheng == 1) //Data processing when the range is 10v
  247. {
  248. kuo_zhan(table[5]);
  249. if(ADC_flag1 == 1)
  250. {
  251. zu_zhi = (data2*1.3125*10); //100 ohm data processing
  252. ADC_flag1 = 0;
  253. lcd_pos(3,5);
  254. Disp_SZ(10/10);
  255. Disp_SZ(10%10);
  256. lcd_pos(3,6);
  257. Disp_HZ("K",1);
  258. lcd_pos(4,5);
  259. Disp_SZ(zu_zhi/1000);
  260. Disp_SZ(zu_zhi%1000/100);
  261. Disp_SZ(zu_zhi%100/10);
  262. Disp_SZ(zu_zhi%10);
  263. lcd_pos(4,7);
  264. Disp_HZ("V",1);
  265. }
  266. }
  267. else if(liang_cheng == 2) //Data processing when the range is 10v
  268. {
  269. kuo_zhan(table[6]);
  270. if(ADC_flag1 == 1)
  271. {
  272. zu_zhi = ((data2*0.00125438)/(1-data2*0.00125438))*1870;; //100 ohm data processing
  273. ADC_flag1 = 0;
  274. lcd_pos(3,5);
  275. Disp_SZ(01/10);
  276. Disp_SZ(01%10);
  277. lcd_pos(3,6);
  278. Disp_HZ("K",1);
  279. lcd_pos(4,5);
  280. Disp_SZ(zu_zhi/1000);
  281. Disp_SZ(zu_zhi%1000/100);
  282. Disp_SZ(zu_zhi%100/10);
  283. Disp_SZ(zu_zhi%10);
  284. lcd_pos(4,7);
  285. Disp_HZ("V",1);
  286. }
  287. }
  288. else if(liang_cheng == 3) //Data processing when the range is 10v
  289. {
  290. kuo_zhan(table[7]);
  291. if(ADC_flag1 == 1)
  292. {
  293. zu_zhi = ((data2*0.001244895)/(1-data2*0.001244895))*4950; //10K ohm data processing
  294. ADC_flag1 = 0;
  295. lcd_pos(3,5);
  296. Disp_SZ(100%1000/100);
  297. Disp_SZ(100%100/10);
  298. Disp_SZ(100%10);
  299. lcd_pos(3,7);
  300. Disp_HZ("Ω",1);
  301. lcd_pos(4,5);
  302. Disp_SZ(zu_zhi/1000);
  303. Disp_SZ(zu_zhi%1000/100);
  304. Disp_SZ(zu_zhi%100/10);
  305. Disp_SZ(zu_zhi%10);
  306. lcd_pos(4,7);
  307. Disp_HZ("V",1);
  308. }
  309. }
  310. }
  311. /*
  312. * Temperature pt100 function
  313. */
  314. void wen_du()
  315. {
  316. wen_pt = ((32231.7975*data4+0.3150709*data4*data4)*0.000016); //Temperature data processing
  317. lcd_pos(2,4);
  318. Disp_SZ(wen_pt%1000/100);
  319. Disp_SZ(wen_pt%100/10);
  320. Disp_HZ(".",1); //Charging current
  321. Disp_SZ(wen_pt%10);
  322. lcd_pos(2,7);
  323. Disp_HZ("℃",1);
  324. }
  325. /*
  326. * Main function
  327. */
  328. void main()
  329. {
  330. int_t();
  331. ADC(); //AD function setting
  332. //ADC_DATA(); //AD conversion starts
  333. while(1)
  334. {
  335. ADC_DATA(); //AD conversion starts
  336. if(pt100 == 1)
  337. {
  338. pt100 = 0;
  339. wen_du();
  340. }
  341. if(P2IN & BIT2) //DC voltage detection position
  342. {
  343. zhi_liu(); //DC voltage range selection control
  344. }
  345. else if(P2IN & BIT3) //AC voltage detection gear
  346. {
  347. jiao_liu(); //DC voltage range selection control
  348. }
  349. else if(P2IN & BIT4) //resistance voltage detection gear
  350. {
  351. dian_zu(); //DC voltage range selection control
  352. }
  353. }
  354. }
  355. /**
  356. *Name Watchdog Timer Interrupt
  357. **/
  358. #pragma vector=WDT_VECTOR
  359. __interrupt void watchdog_timer(void)
  360. {
  361. shua_xin++;
  362. if(shua_xin >= 1000)
  363. {
  364. shua_xin = 0;
  365. ADC_flag1 = 1;
  366. s++;
  367. if(s >= 50)
  368. {
  369. pt100 = 1;
  370. }
This post is from Microcontroller MCU

Latest reply

Nice sharing   Details Published on 2019-10-9 09:15
 

2618

Posts

0

Resources
2
 

Nice sharing

This post is from Microcontroller MCU
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list