完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
|
|
|
|
#include
#include "HAL_Dogs102x6.h" #include "stdio.h" #include "stdlib.h" void Timer_init(); unsigned int overflow = 0; unsigned int pwm_start = 0; unsigned int pwm_end =0; unsigned long interval =0; int distance=0; char buff[25]; int i=0,n=0; volatile unsigned int a; volatile unsigned int b; volatile unsigned int c; volatile unsigned int d; volatile unsigned int *f; void main() { WDTCTL=WDTPW+WDTHOLD; /*****************Set up LCD**********************************/ Dogs102x6_init(); //初始化LCD Dogs102x6_backlightInit(); //背光初始化 Dogs102x6_setBacklight(8); //设置初始背光值 Dogs102x6_setContrast(5); //设置初始对比度值 Dogs102x6_clearScreen(); //清屏 Timer_init(); __enable_interrupt(); while(1){ a=distance/1000+48;//千 f=&a; Dogs102x6_charDraw(1,54,*f,0); b=distance%1000/100+48;//百 f=&b; Dogs102x6_charDraw(1,60,*f,0); c=distance%1000%100/10+48; f=&c; Dogs102x6_charDraw(1,66,*f,0); d=distance%1000%100%10+48; f=&d; Dogs102x6_charDraw(1,72,*f,0); } } #pragma vector=TIMER2_A0_VECTOR __interrupt void TAIV_ISR(void) { if(TA2CTL &TAIFG) { overflow=0; TA2CTL &= ~TAIFG; overflow++; P1OUT &=~ BIT2; } if(TA2CCTL0 & COV) { TA2CCTL0 &= ~COV; // P1OUT |= BIT3; } if((TA2CCTL0 & CCI)==0) //按键松开,上升沿触发 { P1OUT ^= BIT3; TA1CCTL0 &= ~CCIE; pwm_end = TA2CCR0; interval = (pwm_end-pwm_start);//+ overflow*65535 distance=interval*0.02125; TA2CCR0=0; overflow=0; } } void Timer_init() { TA0CTL = TASSEL_1 + ID_1 + MC_1 + TACLR + TAIE; // ACLK, contmode, clear TAR TA0CCR0 = 32767; P2DIR |= BIT0; P2OUT &= ~BIT0; P2REN |= BIT0; P2OUT |= BIT0; // P2SEL |= BIT3 ; //p2.3作为捕获CCIxA的输入 P2IES &= ~BIT0; P2IFG &= ~BIT0; P2IE |= BIT0; P2DIR |= BIT4 ; P1DIR |= BIT0+BIT2+BIT3; P1OUT &= ~BIT0; } // Timer0_A5 Interrupt Vector (TAIV) handler #pragma vector=TIMER0_A1_VECTOR __interrupt void TIMER0_A1_ISR(void) { switch(__even_in_range(TA0IV,14)) { case 0: break; // No interrupt case 2: break; // CCR1 not used case 4: break; // CCR2 not used case 6: break; // reserved case 8: break; // reserved case 10: break; // reserved case 12: break; // reserved case 14: // n++; // if(n==2){ P2OUT &=~BIT4; for(i=10;i>0;i--); P2OUT |=BIT4; for(i=20;i>0;i--); P2OUT &=~BIT4; // } break; default: break; } } // Port 1 interrupt service routine #pragma vector=PORT2_VECTOR __interrupt void Port_1(void) {if( P2IFG&BIT0==1 ) { P1OUT^=BIT0; TA2CTL = TASSEL_2 + ID_0 + MC_2+TACLR; //定时器取ACLK,无分频,连续计数 TA2CCTL0 = CM_3 + CCIS_0 + SCS + CAP+CCIE; //上下沿都触发捕捉,用于测脉宽,同步模式,使能中断 P2DIR &= ~BIT3 ; P2SEL |= BIT3; //p1.7作为捕获CCIxA的输入 P2REN |= BIT3; P2OUT |= BIT3; P2IFG &= ~BIT0; } } |
|
|
|
|
|
|
|
zhichilouzhu支持下
|
|
|
|
只有小组成员才能发言,加入小组>>
2921个成员聚集在这个小组
加入小组2672 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
2979 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2263 浏览 1 评论
4689 浏览 1 评论
2475 浏览 1 评论
935浏览 3评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
2979浏览 2评论
2673浏览 1评论
1067浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-23 10:15 , Processed in 1.422671 second(s), Total 99, Slave 78 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191