完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
要怎样编辑才能实现目的 题目任务: 设计并制作一个温度测量与显示的电路。 基本要求: (1)通过单片机内部的温度传感器获得当前温度; (2)显示所获温度 (3)可以预设标准温度; (4)如果温度大于预设值或小于预设值,用LED通知。 发挥要求: long temp; long IntDegF; long IntDegC; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT ADC10CTL1 = INCH_10 + ADC10DIV_3; // Temp Sensor ADC10CLK/4 ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE; __enable_interrupt(); // Enable interrupts. TACCR0 = 30; // Delay to allow Ref to settle TACCTL0 |= CCIE; // Compare-mode interrupt. TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode. LPM0; // Wait for delay. TACCTL0 &= ~CCIE; // Disable timer Interrupt __disable_interrupt(); while(1) { ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start __bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled // oF = ((A10/1024)*1500mV)-923mV)*1/1.97mV = A10*761/1024 - 468 temp = ADC10MEM; IntDegF = ((temp - 630) * 761) / 1024; // oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278 temp = ADC10MEM; IntDegC = ((temp - 673) * 423) / 1024; __no_operation(); // SET BREAKPOINT HERE } } // ADC10 interrupt service routine #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR (void) { __bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR) } #pragma vector=TIMER0_A0_VECTOR __interrupt void ta0_isr(void) { TACTL = 0; LPM0_EXIT; // Exit LPM0 on return } 和 #include "msp430g2553.h" static unsigned int FirstADCVal; // holds 1st ADC result #define ADCDeltaOn 3 // ~ 2 Deg C delta for LED on void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog ADC10CTL1 = ADC10DIV_3 + INCH_10 + SHS_1 + CONSEQ_2; // TA trig., rpt, A10 ADC10CTL0 = SREF_1 + ADC10SHT_3 + REF2_5V + ADC10IE + REFON + ADC10ON; __enable_interrupt(); // Enable interrupts. TACCR0 = 30; // Delay to allow Ref to settle TACCTL0 |= CCIE; // Compare-mode interrupt. TACTL = TASSEL_2 | MC_1; // TACLK = SMCLK, Up mode. LPM0; // Wait for delay. TACCTL0 &= ~CCIE; // Disable timer Interrupt __disable_interrupt(); ADC10CTL0 |= ENC; TACCTL1 = OUTMOD_4; // Toggle on EQU1 (TAR = 0) TACTL = TASSEL_2 + MC_2; // SMCLK, cont-mode while (!(ADC10IFG & ADC10CTL0)); // First conversion? FirstADCVal = ADC10MEM; // Read out 1st ADC value P1OUT = 0x00; // Clear P1 P1DIR = 0x01; // P1.0 as output __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt } #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR (void) { if (ADC10MEM >= FirstADCVal + ADCDeltaOn) P1OUT |= 0x01; // LED on else P1OUT &= ~0x01; // LED off } #pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void) { TACTL = 0; LPM0_EXIT; // Exit LPM0 on return } |
|
相关推荐
1 个讨论
|
|
只有小组成员才能发言,加入小组>>
2937个成员聚集在这个小组
加入小组2680 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3003 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2273 浏览 1 评论
4703 浏览 1 评论
2484 浏览 1 评论
952浏览 3评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3004浏览 2评论
2681浏览 1评论
1082浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-9-2 06:18 , Processed in 1.274886 second(s), Total 44, Slave 36 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191