在用proteus进行仿真是,发现怎么也采集不到电压(P6.1)的模拟信号,反而只能采集到电阻(P6.0)的模拟信号。前来求助!跪谢啊!
- #include<msp430x24x.h>
- #include"wanyongbiaodianzuceliang.h"
- #define P2_0_high P2OUT|=BIT0; //控制电阻端输出高电平
- #define P2_0_low P2OUT&=~BIT0; //控制电阻端输出低电平
- #define RS_high P4OUT|=BIT4; //RS端置为高电平
- #define RS_low P4OUT&=~BIT4; //RS端置为低电平
- #define RW_high P4OUT|=BIT5; //RW端置为高电平
- #define RW_low P4OUT&=~BIT5; //rw端置为低电平
- #define E_high P4OUT|=BIT6; //e端置为高点平
- #define E_low P4OUT&=~BIT6; //e端置为低电平
- float results[2];
- unsigned char adc;
- unsigned int output;
- unsigned char shi,ge,bai,qian,wan;
- unsigned char code[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,}; //0~9的端码
- /*
- lcd显示控制程序
- */
- void delay(unsigned int y)
- {
- for(;y>0;y--){;}
- }
- /*void fbusy()
- { //检查忙状态
- RS_low();RW_high();
- P5DIR=0X00;
- E_high();E_low();
- while(P5IN&0X80);
- delay();
- }*/
- void write_r(unsigned char j)
- { //写命令程序
- //fbusy();
- P3DIR=0XFF;
- E_low; RS_low;RW_low;
- E_high;
- P3OUT=j;
- _NOP();
- _NOP();
- E_low;
- delay(256);
- }
- void write_s(unsigned char j)
- { //写数据程序
- //fbusy();
- P3DIR=0XFF;
- E_low; RS_high;RW_low;
- E_high;
- P3OUT=j;
- _NOP();
- _NOP();
- E_low;
- delay(256);
- }
- void lcd_init()
- {
- delay(2000);
- write_r(0x3c); //设置为8位 ,双行,5*7字型
- delay(200);
- write_r(0x3c); //设置为8位 ,双行,5*7字型
- write_r(0x01); //清屏
- write_r(0x38); //设置为8位 ,双行,5*7字型
- write_r(0x0c); //显示开,光标开,字符不闪
- write_r(0x06); //光标右移
- }
- void adc_init()
- {
- adc=0; ge=shi=bai=0;
- P6SEL|=BIT0+BIT1;
- ADC12CTL0=ADC12ON+SHT0_2+MSC;
- ADC12CTL1=SHP+CONSEQ_1;
- ADC12MCTL0=INCH_0;
- ADC12MCTL1=INCH_1+EOS;
- ADC12IE|=BIT1;
- ADC12CTL0|=ENC;
- }
- /*
- 电阻测量主程序
- */
- void dianzuceliang()
- {
- lcd_init();
- if(P1IN==0x36) //2欧档
- {
- P2_0_low ;
- write_r(0x80); //第一行输出
- write_s('R');
- write_s('e');
- write_s('s');
- write_s(':');
- write_s(' ');
- write_s('0');
- write_s('~');
- write_s('~');
- write_s('2');
- write_s(0xf4);
-
- write_r(0xc4); //第二行第四列输出
- write_s('R');
- write_s(' ');
- write_s('=');
- write_s(' ');
- write_s(' ');
- write_s(' ');
- write_s(' ');
- write_s('(');
- write_s(0xf4);
- write_s(')');
- adc_init();
- _EINT();
- while(1)
- {
- ADC12CTL0|=ADC12SC;
- if(adc==1)
- {
- results[0]=(results[0]*33)/4096;
- output=(unsigned int)(results[0]*1000);
- output=20206-output;
- output=200-output;
- adc=0;
- }
- bai=output/100;
- shi=output%100/10;
- ge=output%10;
- write_r(0xc7);
- write_s(code[bai]);
- write_s('.');
- write_s(code[shi]);
- write_s(code[ge]);
- if(P1IN!=0X36) break; delay(60000);
- }
- }
- else if(P1IN==0x2e) //200欧档
- {
- P2_0_high;
- write_r(0x80); //第一行输出
- write_s('R');
- write_s('e');
- write_s('s');
- write_s(':');
- write_s(' ');
- write_s('2');
- write_s('~');
- write_s('~');
- write_s('2');
- write_s('0');
- write_s('0');
- write_s(0xf4);
-
- write_r(0xc4); //第二行第四列输出
- write_s('R');
- write_s(' ');
- write_s('=');
- write_s(' ');
- write_s(' ');
- write_s(' ');
- write_s(' ');
- write_s('(');
- write_s(0xf4);
- write_s(')');
- adc_init();
- _EINT();
- while(1)
- {
- ADC12CTL0|=ADC12SC;
- if(adc==1)
- {
- results[0]=(results[0]*33)/4096;
- output=(unsigned int)(results[0]*1000);
- adc=0;
- }
-
- if(10000<=output&&output<=20000)
- {
- wan=output/10000;
- qian=output%10000/1000;
- bai=output%1000/100;
- write_r(0xc7);
- write_s(code[wan]);
- write_s(code[qian]);
- write_s(code[bai]);
- write_s(' ');}
- else if(1000<=output&&output<10000)
- {
- qian=output/1000;
- bai=output%1000/100;
- shi=output%100/10;
- write_r(0xc7);
- write_s(code[qian]);
- write_s(code[bai]);
- write_s('.');
- write_s(code[shi]);}
- else if(100<=output&&output<1000)
- {
- bai=output/100;
- shi=output%100/10;
- ge=output%10;
- write_r(0xc7);
- write_s(code[bai]);
- write_s('.');
- write_s(code[shi]);
- write_s(code[ge]);
- }
- if(P1IN!=0x2e) break; delay(60000);
- }
- }
- else if(P1IN==0x1e) //2M档电阻
- {
- P2_0_high;
- write_r(0x80); //第一行输出
- write_s('R');
- write_s('e');
- write_s('s');
- write_s(':');
- write_s(' ');
- write_s('2');
- write_s('0');
- write_s('0');
- write_s('~');
- write_s('~');
- write_s('2');
- write_s('M');
- write_s(0xf4);
-
- write_r(0xc4); //第二行第四列输出
- write_s('R');
- write_s(' ');
- write_s('=');
- write_s(' ');
- write_s(' ');
- write_s(' ');
- write_s(' ');
- write_s(' ');
- write_s('(');
- write_s('k');
- write_s(0xf4);
- write_s(')');
- adc_init();
- _EINT();
- do
- {
- ADC12CTL0|=ADC12SC;
- if(adc==1)
- {
- results[0]=(results[0]*33)/4096;
- output=(unsigned int)(results[0]*1000);
- output=18014-output;
- output=output/9;
- output=2000-output;
- adc=0;
- }
- qian=output/1000;
- bai=output%1000/100;
- shi=output%100/10;
- ge=output%10;
- write_r(0xc7);
- if(qian!=0) {write_s(code[qian]);}
- write_s(code[bai]);
- write_s(code[shi]);
- write_s(code[ge]); delay(60000);
- }while(P1IN==0x1e);
- }
- }
- #pragma vector= ADC12_VECTOR
- __interrupt void ADC12ISR(void)
- {
- results[0]=ADC12MEM0;
- results[1]=ADC12MEM1;
- adc=1;
- }
- /*
- 电压测量主程序
- */
- void dianyaceliang() //直流电压
- {
- lcd_init();
- P2_2_high;
- write_r(0x80); //第一行输出
- write_s('D');
- write_s('C');
- write_s(' ');
- write_s('V');
- write_s('O');
- write_s('L');
- write_s(':');
- write_s(' ');
- write_s('0');
- write_s('~');
- write_s('~');
- write_s('2');
- write_s('0');
- write_s('V');
-
- write_r(0xC2); //第二行第四列输出
- write_s('V');
- write_s('O');
- write_s('L');
- write_s(' ');
- write_s('=');
- write_s(' ');
- write_s(' ');
- write_s(' ');
- write_s(' ');
- write_s(' ');
- write_s('(');
- write_s('V');
- write_s(')');
- adc_init();
- _EINT();
- do
- {
- ADC12CTL0|=ADC12SC;
- if(adc==1)
- {
- results[1]=(results[1]*33)/4096;
- output=(unsigned int)(results[1]*1000);
- adc=0;
- }
- if(output>=10000){
- wan=output/10000;
- qian=output%10000/1000;
- bai=output%1000/100;
- shi=output%100/10;
- write_r(0xc7);
- write_s(code[wan]);
- write_s(code[qian]);
- write_s('.');
- write_s(code[bai]);
- write_s(code[shi]);}
- else if(output<10000){
- qian=output%10000/1000;
- bai=output%1000/100;
- shi=output%100/10;
- ge=output%10;
- write_r(0xc7);
- write_s(code[qian]);
- write_s('.');
- write_s(code[bai]);
- write_s(code[shi]);
- write_s(code[ge]);} delay(60000);
- }while(P1IN==0x3d);
- }