⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 将A0~A7八通道模拟输入通道采集到的电压值显示在液晶屏上
💻 C
字号:
//******************************************************************************
// 说明:将A0~A7八通道模拟输入通道采集到的电压值显示在液晶屏上
//******************************************************************************
#include<msp430x14x.h>
#include"lcd12864.h"
// 全局变量
unsigned int A0results;
unsigned int A1results;
unsigned int A2results;
unsigned int A3results;
unsigned int A4results;
unsigned int A5results;
unsigned int A6results;
unsigned int A7results;
unsigned char A0[5] = {'x','x','x','x','\0'};
unsigned char A1[5] = {'x','x','x','x','\0'};
unsigned char A2[5] = {'x','x','x','x','\0'};
unsigned char A3[5] = {'x','x','x','x','\0'};
unsigned char A4[5] = {'x','x','x','x','\0'};
unsigned char A5[5] = {'x','x','x','x','\0'};
unsigned char A6[5] = {'x','x','x','x','\0'};
unsigned char A7[5] = {'x','x','x','x','\0'};
unsigned char title0[] = {"A0 Channel : "};
unsigned char title1[] = {"A1 Channel : "};
unsigned char title2[] = {"A2 Channel : "};
unsigned char title3[] = {"A3 Channel : "};
unsigned char title4[] = {"A4 Channel : "};
unsigned char title5[] = {"A5 Channel : "};
unsigned char title6[] = {"A6 Channel : "};
unsigned char title7[] = {"A7 Channel : "};
unsigned char number_tab[]={'0','1','2','3','4','5','6','7','8','9'};
// LED灯指示函数
void ledflash()
{
  unsigned int i = 10000;
  P1OUT ^= BIT1;
  while(i--);
}
// 分解位函数
void convert(unsigned int data,unsigned char *p)
{
  unsigned int a,b,c;
  p[0] = number_tab[data / 1000];
  a = data % 1000;
  p[1] = number_tab[a / 100];
  b = a % 100;
  p[2] = number_tab[b / 10];
  c = b % 10;
  p[3] = number_tab[c];
}
// 主函数
void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;          // Stop watchdog timer
  InitLCD();                         // 液晶屏初始化
  P1DIR |= BIT1;
  ShowString86(0,0,title0);          // 在第0行,从第0列开始显示
  ShowString86(1,0,title1);          // 在第1行,从第0列开始显示
  ShowString86(2,0,title2);          // 在第2行,从第0列开始显示
  ShowString86(3,0,title3);          // 在第3行,从第0列开始显示
  ShowString86(4,0,title4);          // 在第4行,从第0列开始显示
  ShowString86(5,0,title5);          // 在第5行,从第0列开始显示
  ShowString86(6,0,title6);          // 在第6行,从第0列开始显示
  ShowString86(7,0,title7);          // 在第7行,从第0列开始显示
  P6SEL = 0xFF;                      // Enable A/D channel inputs
  ADC12CTL0 = ADC12ON + MSC + SHT0_8;// Turn on ADC12, extend sampling time
                                     // to avoid overflow of results
  ADC12CTL1 = SHP + CONSEQ_3;        // Use sampling timer, repeated sequence
  ADC12MCTL0 = INCH_0;               // ref+=AVcc, channel = A0
  ADC12MCTL1 = INCH_1;               // ref+=AVcc, channel = A1
  ADC12MCTL2 = INCH_2;               // ref+=AVcc, channel = A2
  ADC12MCTL3 = INCH_3;               // ref+=AVcc, channel = A3
  ADC12MCTL4 = INCH_4;               // ref+=AVcc, channel = A4
  ADC12MCTL5 = INCH_5;               // ref+=AVcc, channel = A5
  ADC12MCTL6 = INCH_6;               // ref+=AVcc, channel = A6
  ADC12MCTL7 = INCH_7 + EOS;         // ref+=AVcc, channel = A7, end seq.
  ADC12IE = 0x80;                    // Enable ADC12IFG.8
  ADC12CTL0 |= ENC;                  // Enable conversions
  ADC12CTL0 |= ADC12SC;              // Start conversion
  _BIS_SR(LPM0_bits + GIE);          // Enter LPM0, Enable interrupts
}
// ADC12转中断端服务程序
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
  A0results = ADC12MEM0;             // Move A0 results, IFG is cleared
  A1results = ADC12MEM1;             // Move A1 results, IFG is cleared
  A2results = ADC12MEM2;             // Move A2 results, IFG is cleared
  A3results = ADC12MEM3;             // Move A3 results, IFG is cleared
  A4results = ADC12MEM4;             // Move A4 results, IFG is cleared
  A5results = ADC12MEM5;             // Move A5 results, IFG is cleared
  A6results = ADC12MEM6;             // Move A6 results, IFG is cleared
  A7results = ADC12MEM7;             // Move A7 results, IFG is cleared
  convert(A0results,A0);             // 将A0采集到的电压值分解成四个数
  convert(A1results,A1);             // 将A1采集到的电压值分解成四个数
  convert(A2results,A2);             // 将A2采集到的电压值分解成四个数
  convert(A3results,A3);             // 将A3采集到的电压值分解成四个数
  convert(A4results,A4);             // 将A4采集到的电压值分解成四个数
  convert(A5results,A5);             // 将A5采集到的电压值分解成四个数
  convert(A6results,A6);             // 将A6采集到的电压值分解成四个数
  convert(A7results,A7);             // 将A7采集到的电压值分解成四个数
  ShowString86(0,13,A0);             // 将A0采集到的电压值显示在液晶屏上
  ShowString86(1,13,A1);             // 将A1采集到的电压值显示在液晶屏上
  ShowString86(2,13,A2);             // 将A2采集到的电压值显示在液晶屏上
  ShowString86(3,13,A3);             // 将A3采集到的电压值显示在液晶屏上
  ShowString86(4,13,A4);             // 将A4采集到的电压值显示在液晶屏上
  ShowString86(5,13,A5);             // 将A5采集到的电压值显示在液晶屏上
  ShowString86(6,13,A6);             // 将A6采集到的电压值显示在液晶屏上
  ShowString86(7,13,A7);             // 将A7采集到的电压值显示在液晶屏上
  ledflash();                        // led灯指示
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -