完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
msp430g2553AD10采样正弦波峰值,为什么我显示的不是峰值而是一个不知道什么值,好像采的不是电压,单通道多次采样,谢谢大家指点~
#include #define uint unsigned int #define uchar unsigned char #define CS_H P2OUT|=BIT2 #define CS_L P2OUT&=~BIT2 #define SID_H P2OUT|=BIT1 #define SID_L P2OUT&=~BIT1 #define SCLK_H P2OUT|=BIT0 #define SCLK_L P2OUT&=~BIT0 uint aver[64]={0}; uchar flag=0; uchar zifu[10]={"0123456789"}; uint maxaver=0; uchar dis=0; double max=0,maxr=0; void delay(uchar z) { uint x,y; for(x = 110;x>0;x--) for(y = z;y>0;y--); } void PORT_init() { WDTCTL = WDTPW + WDTHOLD; P2DIR = 0XFF; P2OUT = 0XFF; } void Sys_init() { uchar i; WDTCTL = WDTPW + WDTHOLD; BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MHZ;//设置内部时钟8M do { IFG1 &= ~OFIFG; for(i = 0xff;i>0;i--); } while((IFG1 & OFIFG) != 0); // BCSCTL2 |= SELM_0; // BCSCTL2 |= DIVS_0; } void send_byte(uchar bbyte) { uchar i,temp; for(i=0;i<8;i++) { // P2DIR = 0xff; temp = bbyte & 0x80; if(temp) { SID_H; } else { SID_L; } SCLK_L; SCLK_H; bbyte = bbyte<<1; } } void LCD12864_write_cmd(uchar ddata) { uchar hdata,ldata; hdata = ddata & 0xf0; ldata = (ddata<<4) & 0xf0; CS_H; send_byte(0xf8); delay(5); send_byte(hdata); delay(1); send_byte(ldata); delay(1); CS_L; } void LCD12864_write_data(uchar ddata) { uchar hdata,ldata; hdata = ddata & 0xf0; ldata = (ddata<<4) & 0xf0; CS_H; send_byte(0xfa); delay(5); send_byte(hdata); delay(1); send_byte(ldata); delay(1); CS_L; } void LCD12864_init() { P2DIR |= BIT0 + BIT1 + BIT2; delay(10); CS_H; LCD12864_write_cmd(0x34); delay(1); LCD12864_write_cmd(0x30); delay(1); LCD12864_write_cmd(0x0c);// delay(1); LCD12864_write_cmd(0x01); delay(1); LCD12864_write_cmd(0x06); delay(1); } void LCD12864_pos(uchar x,uchar y) { uchar pos; switch(x) { case 1:pos = 0x80;break; case 2:pos = 0x90;break; case 3:pos = 0x88;break; case 4:pos = 0x98;break; default:pos = 0x80; } pos += y; LCD12864_write_cmd(pos); } void shuju() { uchar j; maxr = 0; maxaver = 0; for(j = 0;j < 64;j+=2) { if(aver[j]>maxaver && aver[j]<1024) { maxaver = aver[j]; } maxr = (maxaver*3.56)/1023; max = maxr*1000; dis = max; LCD12864_pos(2,2); LCD12864_write_data(zifu[dis/10000]); LCD12864_write_data('.'); LCD12864_write_data(zifu[dis/1000%10]); LCD12864_write_data(zifu[dis/100%10]); LCD12864_write_data(zifu[dis/10%10]); LCD12864_write_data(zifu[dis%10]); } } void ADC_init(void) { ADC10CTL0 = ADC10ON + ADC10SHT_3 + MSC + ADC10IE; ADC10CTL1 |= CONSEQ_2 + INCH_1; ADC10AE0 |= BIT0 + BIT1; ADC10DTC1 = 0x20; } void main(void) { WDTCTL = WDTPW + WDTHOLD; // IO_init(); LCD12864_init(); PORT_init(); Sys_init(); ADC_init(); _EINT(); while(1) { ADC10CTL0 &=~ENC; while(ADC10CTL1 & ADC10BUSY); ADC10SA = (unsigned int)aver; ADC10CTL0 |= ENC + ADC10SC; // ADC10CTL0&=~ADC10IFG; _BIS_SR(CPUOFF + GIE); } } #pragma vector=ADC10_VECTOR __interrupt void ADC10_ISR(void) { shuju(); // dis =ADC10MEM; _BIC_SR_IRQ(CPUOFF + GIE); } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
3015个成员聚集在这个小组
加入小组2898 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3414 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2329 浏览 1 评论
4786 浏览 1 评论
2560 浏览 1 评论
1298浏览 3评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3414浏览 2评论
2898浏览 1评论
1461浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-13 05:39 , Processed in 1.130653 second(s), Total 74, Slave 57 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号