[讨论]
用msp430单片机的内部ADC芯片驱动模块c语言程序分享一下
- //mod p5.3
- //wr p5.0
- //rd p5.1
- //ce p5.2
- #include "msp430x44x.h"
- #define uchar unsigned char
- #define uint unsigned int
- uint i=0;
- Out_com(uchar com)
- {P5OUT=0XF9;
- P1DIR=0x00;
- while((P1IN&0x03)!=0x03);
- P1DIR=0xff;
- P5OUT=0XFA;
- P1OUT=com;
- }
- Out_data(uchar dat)
- {P5OUT=0XF9;
- P1DIR=0x00;
- while((P1IN&0x03)!=0x03);
- P1DIR=0xff;
- P5OUT=0XF2;
- P1OUT=dat;
- }
- Out_data2_com(uchar dat1,uchar dat2,uchar com1)
- {Out_data(dat1);
- Out_data(dat2);
- Out_com(com1);
- }
- Chars_dis(uchar Line_num,uchar Rank_num,uchar *s)
- {uchar i;
- Out_data2_com(Line_num*16+Rank_num,0x00,0x24);
- Out_com(0xb0);
- for(i=0;s!='\0';i++)
- Out_data(s-0x20);
- Out_com(0xb2);
- }
- Chars_dic(uchar Line_num,uchar Rank_num,uint i)
- {uchar s[10]="0123456789";
- Out_data2_com(Line_num*16+Rank_num,0x00,0x24);
- Out_com(0xb0);
- Out_data(s[i/1000]-0x20);
- Out_data(s[i/100%10]-0x20);
- Out_data(s[i/10%10]-0x20);
- Out_data(s[i%10]-0x20);
- Out_com(0xb2);
- }
- Chars_dit(uchar Line_num,uchar Rank_num,uchar *s)
- {uchar m;
- for(m=0;m<32;m++)
- {if(m%2==0)
- {Out_com(0xb2);
- Out_data2_com(2*Rank_num+16*m/2,0x04+Line_num,0x24);
- Out_com(0xb0);
- }
- Out_data(s[m]);
- }
- Out_com(0xb2);
- }
- Clear()
- {uint i;
- Out_data2_com(0x00,0x00,0x24);
- Out_com(0xb0);
- for(i=0;i<129;i++)
- Out_data(0x00);
- Out_com(0xb2);
- Out_data2_com(0x00,0x04,0x24);
- Out_com(0xb0);
- for(i=0;i<1025;i++)
- Out_data(0x00);
- Out_com(0xb2);
- }
- void main()
- {WDTCTL = WDTPW + WDTHOLD;
- P3OUT=0x00;
- P5DIR=0xff;
- Out_data2_com(0x00,0x00,0x40);
- Out_data2_com(0x10,0x00,0x41);
- Out_data2_com(0x00,0x04,0x42);
- Out_data2_com(0x10,0x00,0x43);
- Out_com(0x80);
- Out_com(0x9c);
- Clear();
- P6SEL|=0x07;
- ADC12CTL1=SHP+CONSEQ_1;
- ADC12MCTL0=INCH_0;
- ADC12MCTL1=INCH_1;
- ADC12MCTL2=INCH_2+EOS;
- ADC12CTL0=ADC12ON+ENC+MSC;
- while(1)
- {ADC12CTL0|=ADC12SC;
- while(~ADC12IFG & BIT2);
- Chars_dic(1,0,ADC12MEM0);
- Chars_dic(2,0,ADC12MEM1);
- Chars_dic(3,0,ADC12MEM2);
- }
- }
暂无评论,赶紧抢沙发吧