MSP430 Learning Notes 10-ADC Collection 1602 Display

Publisher:science56Latest update time:2018-04-18 Source: eefocusKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This is also a routine in the development board, with explanations of the key points. The program is as follows:


  1. /********************************************************* 

  2. Program notes: 

  3. First, you can choose whether to turn on the internal reference voltage or use the external reference voltage 

  4. Each channel can independently select the reference voltage 

  5. If an external reference voltage is connected, be careful to turn off the internal reference voltage to prevent damage 

  6. Microcontroller 

  7.  

  8. Program function: The MCU's on-chip ADC converts the voltage of the P6.0 port 

  9.           The analog voltage value is displayed on the 1602 LCD. 

  10. ---------------------------------------------------------- 

  11. Dip switch setting: turn LCD to ON and other positions to OFF 

  12. Test instructions: Adjust the knob of potentiometer W1 and observe the changes in the numbers displayed on the LCD. 

  13. *********************************************************/  

  14. #include    

  15. #include  "cry1602.h"  

  16. #include  "cry1602.c"  

  17.   

  18. //typedef unsigned char uchar;  

  19. //typedef unsigned int  uint;  

  20.   

  21. #define   Num_of_Results   32  

  22.   

  23. fly shuzi[] = {"0123456789."};  

  24. uchar tishi[] = {"The volt is:"};  

  25.   

  26. static uint results[Num_of_Results]; //Array to save ADC conversion results                                                      

  27. void Trans_val(uint Hex_Val);             

  28. /****************************Main function********************************/  

  29. void main(void)  

  30. {  

  31.     WDTCTL = WDTPW+WDTHOLD; //Turn off the watchdog  

  32.   

  33.     /*The following six lines of code close all IO ports*/  

  34.     P1DIR = 0XFF;P1OUT = 0XFF;  

  35.     P2DIR = 0XFF;P2OUT = 0XFF;  

  36.     P3DIR = 0XFF;P3OUT = 0XFF;  

  37.     P4DIR = 0XFF;P4OUT = 0XFF;  

  38.     P5DIR = 0XFF;P5OUT = 0XFF;  

  39.     P6DIR = 0XFF;P6OUT = 0XFF;  

  40.   

  41.     P6DIR |= BIT2;P6OUT |= BIT2; //Disable level conversion  

  42.     LcdReset(); //Reset 1602 LCD  

  43.     DispNChar(2,0,12,tishi); //Display prompt information  

  44.     Disp1Char(11,1,'V'); //Display voltage unit  

  45.     P6SEL |= BIT0; // Enable ADC channel  

  46.     ADC12CTL0 = ADC12ON+SHT0_8+MSC; // Turn on ADC and set sampling time  

  47.     // The above configuration does not turn on the internal reference voltage  

  48.     //ADC12MCTLx is used to select the channel and reference voltage. This register is not configured to the default value.  

  49.     // The default value is that the reference voltage is selected as AVCC (3.3V), the channel is A0, so the measurement range is 0-3.3V  

  50.     ADC12CTL1 = SHP+CONSEQ_2; // Use sampling timer  

  51.     //When the register configuration sample hold trigger source is selected, ADC12SC is used to collect the signal generated by the sampling timing circuit.  

  52.     // The conversion mode is single-channel repeated conversion. The above settings must be set when ENC=0  

  53.     ADC12IE = BIT0; // Enable ADC interrupt  

  54.     ADC12CTL0 |= ENC; // Enable conversion  

  55.     ADC12CTL0 |= ADC12SC; // Start conversion  

  56.     _EINT(); // Enable global interrupt  

  57.     LPM0;  

  58. }  

  59.   

  60. /******************************************* 

  61. Function name: ADC12ISR 

  62. Function: ADC interrupt service function, here we use multiple averages 

  63.           Calculate the analog voltage value of P6.0 port 

  64. Parameters: None        

  65. Return value: None 

  66. ********************************************/  

  67. #pragma vector=ADC_VECTOR  

  68. __interrupt void ADC12ISR (void)  

  69. {  

  70.     static uint index = 0;  

  71.   

  72.     results[index++] = ADC12MEM0; // Store the conversion results into the array  

  73.     if(index == Num_of_Results) //If the array is full  

  74.     {  

  75.         flying i;  

  76.         unsigned long sum = 0;  

  77.   

  78.         index = 0; //Start saving from the beginning, the original data will be overwritten  

  79.     for(i = 0; i < Num_of_Results; i++) //Calculate and  

  80.     {  

  81.         sum += results[i];  

  82.     }  

  83.     sum >>= 5; //divide by 32  

  84.     Trans_val(sum);  

  85.     }  

  86. }  

  87.   

  88. /******************************************* 

  89. Function name: Trans_val 

  90. Function: Convert hexadecimal ADC data into three-digit decimal 

  91.           Real analog voltage data, and displayed on LCD 

  92. Parameter: Hex_Val--hexadecimal data 

  93.           n--The denominator of the transformation is equal to 2 to the power of n        

  94. Return value: None 

  95. ********************************************/  

  96. void Trans_val(uint Hex_Val)  

  97. {  

  98.     unsigned long caltmp;  

  99.     uint Curr_Volt;  

  100.     fly t1,i;  

  101.     float ptr[4];  

  102.   

  103.     caltmp = Hex_Val;  

  104.     caltmp = (caltmp << 5) + Hex_Val;           //caltmp = Hex_Val * 33  

  105.     caltmp = (caltmp << 3) + (caltmp << 1);     //caltmp = caltmp * 10  

  106.     Curr_Volt = caltmp >> 12;                   //Curr_Volt = caltmp / 2^n  

  107.     // The reference voltage is 3.3V, so the calculation formula should be Hex_val*3.3/2^n   

  108.     // Multiplication and division calculations can be performed by shifting to effectively improve program running efficiency  

  109.     ptr[0] = Curr_Volt / 100; //Hex->Dec conversion  

  110.     t1 = Curr_Volt - (ptr[0] * 100);  

  111.     ptr[2] = t1 / 10;  

  112.     ptr[3] = t1 - (ptr[2] * 10);  

  113.     ptr[1] = 10; //The 10th bit in the shuzi table corresponds to the symbol "."  

  114.     //Display the transformed result on the LCD  

  115.     for(i = 0;i < 4;i++)  

  116.         Disp1Char((6 + i),1,shuzi[ptr[i]]);  

  117. }  



Keywords:MSP430 Reference address:MSP430 Learning Notes 10-ADC Collection 1602 Display

Previous article:MSP430 Study Notes 11- Eight-way ADC acquisition Nokia 5110 LCD display
Next article:MSP430 Study Notes 9-PS2 Keyboard Decoding

Recommended ReadingLatest update time:2024-11-23 04:54

Waveform Synthesizer Based on MSP430F499
Abstract: With MSP430F499 as the core, it is mainly composed of square wave oscillator circuit, frequency division and filtering module, phase shift circuit, amplifier circuit, adder, etc. The signal of the square wave oscillator is divided and filtered to generate sine waves of different frequencies. After phase sh
[Power Management]
Waveform Synthesizer Based on MSP430F499
MSP430的软硬件C延时程序设计
MSP430是超低功耗16位单片机,越来越受到电子工程师亲睐并得到广泛应用。C程序直观,可读性好,易于移植和维护,已被很多单片机编程人员所采用。MSP430集成开发环境(如IAR Embedded Workbench和AQ430)都集成了C编译器和C语言级调试器C—SPY。但是C语言难以实现精确延时,这一直困扰着很多MSP430单片机程序员。笔者在实际项目开发过程中,遇到很多需要严格时序控制的接口器件,如单总线数字温度传感器DSl8820、实时时钟芯片PCF8563(需要用普通]/o模拟12C总线时序)、三线制数字电位器AD8402、CF卡(Compact Flash Card)等都需要μs级甚至纳ns级精确延时;而一些慢速设备只需
[Microcontroller]
Five low power modes of MSP430 microcontroller
The five low power modes are LPM0~LPM4 (LOW POWER MODE), and the active state of the CPU is called AM (ACTIVE MODE). AM consumes the most power, and LPM4 consumes the least power, only 0.1uA. In addition, the influence of working voltage on power consumption: the lower the voltage, the lower the power consumption.
[Microcontroller]
MSP430_SPI_Master_Read_Write
/****************************************************************** **                                                        **  File : SPI.c     | Master Send Receive Interrupt |                                     **  Version : 1.0      ** Description: SPI interface TLC549                                          
[Microcontroller]
MSP430 Functional Module Detailed Explanation Series - FLASH Memory
1. Features of MSP430 MCU FLASH memory module  1.8~3.6V working voltage, 2.7~3.6V programming voltage; erasing/programming times can reach 100,000 times: data retention time ranges from 10 years to 100 years: 60KB space programming time 5 seconds: after the confidentiality fuse is burned out, it cannot be recover
[Microcontroller]
Application of MSP430 in power measurement, control and protection products
     MSP430F149 (hereinafter referred to as "F149") is an ultra-low power Flash 16-bit RISC instruction set microcontroller launched by Texas Instruments (TI). F149 has rich internal hardware resources and is an industrial-grade chip with extremely high cost performance. In application, F149 does not need to be expand
[Microcontroller]
Application of MSP430 in power measurement, control and protection products
Design of reversing radar based on TI MSP430
  With the increasing requirements for the intelligence of automobile assisted driving systems and the networking development of automobile electronic systems, new reversing radars should be able to continuously measure and display the distance to obstacles, and have communication functions to send data to the vehicle
[Microcontroller]
Design of reversing radar based on TI MSP430
MSP430F2131 reads and writes DS1991
0|-->LED // // A. Dannenberg // Texas Instruments , Inc // January 2006 // Built with IAR Embedded Workbench Version : 3.40A //*************************************************************************** #include "msp430x20x1.h" #define TM_OUT(level) P2OUT = ((unsigned int)level) ? (P2IN|BIT4) : (P
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号