MSP430流水灯蜂鸣器实验报告

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

MSP430实验报告水位报警器姓名:丁宇昊学号:021210508一、实验目的:掌握msp430单片机的程序编写和运行过程。掌握IAREmbeddedWorkbench程序的编译和运行。二、实验内容:用继电器代替传感器输入模拟电压,用IED灯显示水位高度,当超过预定值时,蜂鸣器响,实现报警。三、使用串口:P1口,P2口四、电路实现:把继电器作为的AD的输入,通过AD转换,把电压分成16小分,每一份信号控制1个led,通过改变led两端电平高低,控制led亮灭。当到达预定值时,把蜂鸣器的接口设置为高电平。五、实验代码:#includemsp430.hvoiddelay(intj){doj--;while(j!=0);}intmain(void){WDTCTL=WDTPW+WDTHOLD;//StopWDTADC10CTL0=ADC10SHT_2+ADC10ON+ADC10IE;//ADC10ON,interruptenabledADC10CTL1=INCH_1+SREF0;//inputA1ADC10AE0|=BIT7;//PA.1ADCoptionselectP1DIR|=BIT0;//SetP1.0tooutputdirectionP1DIR|=BIT4;P1DIR|=BIT5;P2DIR|=0xff;P2OUT|=0xff;P2SEL&=0x00;for(;;){ADC10CTL0|=ENC+ADC10SC;//Samplingandconversionstart__bis_SR_register(CPUOFF+GIE);//LPM0,ADC10_ISRwillforceexitif(ADC10MEM960){P1OUT|=BIT4;P1OUT&=~BIT5;P2OUT=0xFE;}elseif(ADC10MEM900){P1OUT|=BIT4;P1OUT&=~BIT5;P2OUT=0xfc;}elseif(ADC10MEM840){P1OUT|=BIT4;P1OUT&=~BIT5;P2OUT=0xf8;}elseif(ADC10MEM780){P1OUT|=BIT4;P1OUT&=~BIT5;P2OUT=0xf0;}elseif(ADC10MEM660){P1OUT|=BIT4;P1OUT&=~BIT5;P2OUT=0xe0;}elseif(ADC10MEM600){P1OUT|=BIT4;P1OUT&=~BIT5;P2OUT=0xc0;}elseif(ADC10MEM540){P1OUT|=BIT4;P1OUT&=~BIT5;P2OUT=0x80;}elseif(ADC10MEM480){P1OUT|=BIT4;P1OUT&=~BIT5;P2OUT=0x00;}elseif(ADC10MEM420){P1OUT&=~BIT5;P2OUT=0x00;P1OUT|=BIT4;P2OUT=0x00;delay(20);P1OUT&=~BIT4;P2OUT=0xfe;P1OUT|=BIT5;P2OUT=0xfe;}elseif(ADC10MEM360){P1OUT&=~BIT5;P2OUT=0x00;P1OUT|=BIT4;P2OUT=0x00;delay(20);P1OUT&=~BIT4;P2OUT=0xfc;P1OUT|=BIT5;P2OUT=0xfc;}elseif(ADC10MEM300){P1OUT&=~BIT5;P2OUT=0x00;P1OUT|=BIT4;P2OUT=0x00;delay(20);P1OUT&=~BIT4;P2OUT=0xf8;P1OUT|=BIT5;P2OUT=0xf8;}elseif(ADC10MEM240){P1OUT&=~BIT5;P2OUT=0x00;P1OUT|=BIT4;P2OUT=0x00;delay(20);P1OUT&=~BIT4;P2OUT=0xf0;P1OUT|=BIT5;P2OUT=0xf0;}elseif(ADC10MEM180){P1OUT&=~BIT5;P2OUT=0x00;P1OUT|=BIT4;P2OUT=0x00;delay(20);P1OUT&=~BIT4;P2OUT=0xe0;P1OUT|=BIT5;P2OUT=0xe0;}elseif(ADC10MEM120){P1OUT&=~BIT5;P2OUT=0x00;P1OUT|=BIT4;P2OUT=0x00;delay(20);P1OUT&=~BIT4;P2OUT=0xc0;P1OUT|=BIT5;P2OUT=0xc0;P1DIR|=BIT6;P1OUT^=BIT6;delay(100);}elseif(ADC10MEM60){P1OUT&=~BIT5;P2OUT=0x00;P1OUT|=BIT4;P2OUT=0x00;delay(20);P1OUT&=~BIT4;P2OUT=0x80;P1OUT|=BIT5;P2OUT=0x80;P1DIR|=BIT6;P1OUT^=BIT6;delay(100);}else{P1OUT&=~BIT5;P2OUT=0x00;P1OUT|=BIT4;P2OUT=0x00;delay(20);P1OUT&=~BIT4;P2OUT=0x00;P1OUT|=BIT5;P2OUT=0x00;P1DIR|=BIT6;P1OUT^=BIT6;delay(100);}}}//ADC10interruptserviceroutine#pragmavector=ADC10_VECTOR__interruptvoidADC10_ISR(void){__bic_SR_register_on_exit(CPUOFF);//ClearCPUOFFbitfrom0(SR)}六、总结通过这次msp430单片机的实验,是我进一步的了解了单片机的远离,虽然在实验过程中遇到了一些问题,但我及时与同学讨论与老师沟通,解决了以上问题。在此次试验中,我充分的了解到了实践的重要性。

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功