教你将android手机变成蓝牙无线示波器,Android手机+蓝牙扩展电路=示波器

本文介绍了一个项目,通过将Android手机与蓝牙扩展电路结合,将其转化为一款无线示波器。作者分享了完整的源码,并提出了移植到其他单片机的建议,期待有人能制作成套件。代码主要包括初始化设置、端口配置、ADC初始化、定时器配置以及串行通信等功能。
摘要由CSDN通过智能技术生成

本帖最后由 kejiren123 于 2012-5-15 10:10 编辑

强烈建议logicgreen 大移植到LGT单片机上,如果能出套件相信很多人会买。我愿意出100元买一个LGT单片机的示波器套件(预估材料成本在40-60元)。

我看了,代码不复杂。以下为全部源码。

************************************

Bluetooth Oscilloscope

yus - projectproto.blogspot.com

September 2010

*************************************/

#include "main.h"

_FOSCSEL(FNOSC_FRC);        // Select Internal FRC at POR

_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF);        // Enable Clock Switching and Configure

_FICD(ICS_PGD1 & JTAGEN_OFF);

int main(void)

{

unsigned char c;

osc_init();

port_init();

ser_init();

adc_init();

timer1_init();

//initial values;

ch1_position = 120;

ch2_position = 120;

ch1_gain = VOLT_PER_DIV[4];

ch2_gain = VOLT_PER_DIV[5];

while(1)

{

if(ser_isrx()){

led_off();

c = ser_getch();                //get 1 character from receive buffer

switch(c){

case REQ_DATA:

store_raw_data();

ser_putch(DATA_START);

send_data();

ser_putch(DATA_END);

break;

case ADJ_HORIZONTAL:

c = ser_getch();

if( (c<13) ){        // refer to "timer.h"

set_sampling_period( PERIODS[c] );

}

break;

case ADJ_VERTICAL:

c = ser_getch();                // refer to "adc.h"

if(c==CHANNEL1)                        ch1_gain = VOLT_PER_DIV[ser_getch()];

else if(c==CHANNEL2)        ch2_gain = VOLT_PER_DIV[ser_getch()];

break;

case ADJ_POSITION:

c = ser_getch();

if(c==CHANNEL1)                        ch1_position = (long)ser_getch() * 6;

else if(c==CHANNEL2)        ch2_position = (long)ser_getch() * 6;

break;

default:

break;

} // switch(command)

led_on();

}//if-ser_isrx()

}//while-true

}

void osc_init(void)

{

// Configure PLL prescaler, PLL postscaler, PLL divisor

PLLFBD = 41; // M = 43

CLKDIVbits.PLLPOST=0; // N1 = 2

CLKDIVbits.PLLPRE=0; // N2 = 2

// Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)

__builtin_write_OSCCONH(0x01);

__builtin_write_OSCCONL(0x01);

// Wait for Clock switch to occur

while (OSCCONbits.COSC != 0b001);

// Wait for PLL to lock

while(OSCCONbits.LOCK!=1) {};

}

void port_init(void)

{

// LED Pin Configuration:I/O Port RC3; pin 5

PORTCbits.RC3 = 0;                                // Configure as Output

TRISCbits.TRISC3 = 0;                        // Configure as Output

LATCbits.LATC3 =

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值