本帖最后由 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 =