#define LED PORTB.F7
#define SW_START PORTA.F4
#define SW_STOP PORTA.F5
#define ON 1
#define OFF 0
#define CR 0x0d
#define LF 0x0a
//**********************************************************************
void main()
{
//•Ï”‚Ì’è‹`
static char buf[50];
short cnt, channel, pnt;
unsigned ad;
long dataCnt;
//‚`^‚c•ÏŠ·‚ÌÝ’è
ADCON1.PCFG3 = 1;
ADCON1.PCFG2 = 0;
ADCON1.PCFG1 = 1;
ADCON1.PCFG0 = 1;
//ƒ|[ƒg‚ÌÝ’è
TRISA = 0b11111111;
TRISB = 0b00000000;
TRISC = 0b00000000;
//‚k‚b‚c‚̉Šú‰»
Lcd_Custom_Config(&PORTB,5,4,3,2,&PORTC,0,1,6);
Lcd_Custom_Cmd(LCD_CURSOR_OFF);
Lcd_Custom_Cmd(LCD_CLEAR);
for (cnt = 1; cnt <= 16; cnt++) {
Lcd_Custom_Chr(1, cnt, 0xFF);
LED = ON;
Delay_ms(50);
LED = OFF;
Delay_ms(50);
}
for (cnt = 1; cnt <= 16; cnt++) {
Lcd_Custom_Chr(2, cnt, 0xFF);
LED = ON;
Delay_ms(50);
LED = OFF;
Delay_ms(50);
}
Lcd_Custom_Cmd(LCD_CLEAR);
//
while (1) {
//ŠJŽnƒXƒCƒbƒ`‚ª‰Ÿ‚³‚ê‚é‚Ì‚ðƒ`ƒFƒbƒN‚·‚éB
while (SW_START == 1) {
Delay_ms(10);
}
dataCnt = 0;
//‚l‚l‚b‚̉Šú‰»
Spi_Init_Advanced(MASTER_OSC_DIV64, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);
if (!Mmc_Fat_Init(&PORTC, 2)) {
Spi_Init_Advanced(MASTER_OSC_DIV16, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);
Mmc_Fat_Assign("log.csv", 0xA0);
Mmc_Fat_Rewrite();
Mmc_Fat_Write("$START\r\n", 8);
//’âŽ~ƒXƒCƒbƒ`‚ª‰Ÿ‚³‚ê‚é‚܂ň—‚ðŒJ‚è•Ô‚·B
while (SW_STOP == 1) {
pnt = 0;
//‚Sƒ`ƒƒƒ“ƒlƒ‹•ª‚Ì‚`^‚c•ÏŠ·‚ðs‚¢A‚k‚b‚c‚É•\Ž¦‚·‚éB
for (channel = 0; channel < 4; channel++) {
ad = Adc_Read(channel);
ad = (double)ad * 4.8828125;
WordToStr(ad, &buf[pnt]);
switch (channel) {
case 0:
Lcd_Custom_Out(1, 1, "1:");
Lcd_Custom_Out(1, 3, &buf[pnt + 1]);
break;
case 1:
Lcd_Custom_Out(1, 9, "2:");
Lcd_Custom_Out(1, 11, &buf[pnt + 1]);
break;
case 2:
Lcd_Custom_Out(2, 1, "3:");
Lcd_Custom_Out(2, 3, &buf[pnt + 1]);
break;
case 3:
Lcd_Custom_Out(2, 9, "4:");
Lcd_Custom_Out(2, 11, &buf[pnt + 1]);
break;
}
pnt += 6;
}
buf[5] = ',';
buf[11] = ',';
buf[17] = ',';
buf[23] = CR;
buf[24] = LF;
//‚Sƒ`ƒƒƒ“ƒlƒ‹•ª‚Ü‚Æ‚ß‚Ä‚l‚l‚b‚É‘‚«ž‚ÞB
Mmc_Fat_Write(buf, 25);
//
LED = ON;
Delay_ms(100);
LED = OFF;
//
dataCnt++;
}
Mmc_Fat_Write("$STOP\r\n", 7);
//‘‚«ž‚ñ‚¾Œ”‚ð‚k‚b‚c‚É•\Ž¦‚·‚éB
LongToStr(dataCnt, buf);
Lcd_Custom_Cmd(LCD_CLEAR);
Lcd_Custom_Out(1, 1, buf);
//
for (cnt = 0; cnt < 10; cnt++) {
LED = ON;
Delay_ms(50);
LED = OFF;
Delay_ms(50);
}
}
}
}//~!