完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
#include "msp430g2553.h"
unsigned int admem[4]; unsigned long n; unsigned int invot=0; unsigned int inan=0; unsigned int otan=0; unsigned int outvot=0; void sys_Clock_Init() //时钟初始化为 1MHz; { BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation */ } void cai()//ad采样 { int*p=(int*)0x200; int i; P1DIR&=~BIT0+~BIT1+~BIT2+~BIT3; P1SEL|=BIT0+BIT1+BIT2+BIT3; WDTCTL = WDTPW + WDTHOLD;// Stop WDT ADC10CTL0 &= ~ENC; ADC10CTL1 = INCH_3 + CONSEQ_1+ADC10SSEL_2+SHS_0; // A3/A2/A1/A0, single sequence序列 单次 ADC10CTL0 = ADC10SHT_3 +MSC+ ADC10ON+SREF_0; ADC10DTC1 = 0x04; // 4 conversions ADC10AE0 |= BIT0+BIT1+BIT2+BIT3; // P1.3,2,1,0 ADC10 option select while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active ADC10SA = 0x200; // Data buffer start ADC10CTL0 |= ENC+ADC10SC; // Sampling and conversion start _delay_cycles(3000); for(i=0x00;i<4;i++) { admem[i]=*p; p++; } p=(int*)0x200; n=admem[0]*66; outvot=n/100; n=admem[1]*66; invot=n/102; n=admem[2]*30; inan=n/40; n=admem[3]*30; otan=n/40; return; } void xianshi ()//数码管按段显示 显示函数 { P2SEL=0X00; P2DIR=0XFF; unsigned int i; unsigned int j; unsigned int num; unsigned int x[3]={0x10,0x20,0x40}; unsigned int wei; unsigned int seg[3]; int yu=1; // int c; seg[0]=outvot/100; yu=outvot%100; seg[1]=yu/10; seg[2]=yu%10; //for( c=0;c<100;c++) //{ for(j=0x00;j<3;j++) { num=seg[j]; wei=x[j]; switch(num) {case 0 : for(i=0x0;i<0x6;i++) {P2OUT=wei+i; _delay_cycles(1000); } break; case 1: for(i=0x1;i<3;i++) { P2OUT=wei+i; _delay_cycles(1000);} break; case 2: for(i=0x0;i<0x2;i++) {P2OUT=wei+i; _delay_cycles(1000); } for(i=0x3;i<5;i++) {P2OUT=wei+i; _delay_cycles(1000); } for(i=0x6;i<0x7;i++) {P2OUT=wei+i; _delay_cycles(1000); } break; case 3: for(i=0x0;i<0x4;i++) {P2OUT=wei+i; _delay_cycles(1000); } i=6; P2OUT=wei+i;_delay_cycles(1000); break; case 4: for(i=0x1;i<0x3;i++) {P2OUT=wei+i; _delay_cycles(1000); } for(i=0x5;i<0x7;i++) {P2OUT=wei+i; _delay_cycles(1000); } break; case 5: i=0;P2OUT=wei+i;_delay_cycles(1000); for(i=0x2;i<0x4;i++) {P2OUT=wei+i; _delay_cycles(1000); } for(i=0x5;i<0x7;i++) {P2OUT=wei+i; _delay_cycles(1000); } break; case 6: i=0; P2OUT=wei+i;_delay_cycles(1000); for(i=0x2;i<0x7;i++) {P2OUT=wei+i; _delay_cycles(1000); } break; case 7: for(i=0x0;i<0x3;i++) {P2OUT=wei+i; _delay_cycles(1000); } break; case 8: for(i=0x0;i<0x7;i++) {P2OUT=wei+i; _delay_cycles(1000); } break; case 9: for(i=0x0;i<0x4;i++) {P2OUT=wei+i; _delay_cycles(1000); } for(i=0x5;i<0x7;i++) {P2OUT=wei+i; _delay_cycles(1000); } break;} } for(i=0x1;i<0x6;i++) {P2OUT=0x80+i; _delay_cycles(1000); } P2OUT=0X17; _delay_cycles(1000); } void main() { sys_Clock_Init(); WDTCTL = WDTPW + WDTHOLD; //BCSCTL1 = CALBC1_1MHZ; // Set range //DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation */ P1DIR |= BIT6; // p1.6 口 P1SEL |= BIT6; TA0CTL |= TASSEL_1+MC_3; TA0CCTL1 |= OUTMOD_7; //选择高电平模式的 PWM 输出 TA0CCR0=60;//TA1CCR0 写入 2000( 1MHZ/2000) 输出达到了 500HZ TA0CCR1=50; for(;;) { WDTCTL = WDTPW + WDTHOLD; cai(); xianshi (); if(outvot>310)//outvot 采样电压电压为3.1 { TA0CCR1++; } if(outvot<310) { TA0CCR1--; } } } |
|
相关推荐
2个回答
|
|
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
3045个成员聚集在这个小组
加入小组2951 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3645 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2354 浏览 1 评论
4822 浏览 1 评论
2582 浏览 1 评论
1348浏览 3评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3645浏览 2评论
2951浏览 1评论
1539浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-12 15:48 , Processed in 1.852965 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号