/* * SDカードのサンプル */ void sd_test() { FRESULT rc; // DIR dir; /* Directory object */ // FILINFO fno; /* File information object */ UINT bw, br, i; char tmp[64]; f_mount(0, &Fatfs); /* Register volume work area (never fails) */ /* * SDカードのMESSAGE.TXTを開いてI2C液晶に表示します。英数カナのみ * 2行分のみ */ rc = f_open(&Fil, "MESSAGE.TXT", FA_READ); if (!rc){ i2c_cmd(0x80); // xprintf("\nType the file content.\n"); for (;;) { rc = f_read(&Fil, buff, sizeof(buff), &br); /* Read a chunk of file */ if (rc || !br) break; /* Error or end of file */ for (i = 0; i < br; i++){ if(i==0x10) i2c_cmd(0xC0); i2c_data(buff[i]); } xprintf("%s\n", buff); } if (rc) die(rc); rc = f_close(&Fil); } /* * ファイル書き込みテスト * SD0001.TXTファイルを作成し、Strawberry Linuxの文字を永遠に書き込む */ rc = f_open(&Fil, "SD0001.TXT", FA_WRITE | FA_OPEN_ALWAYS); f_lseek(&Fil, f_size(&Fil)); if (rc) die(rc); i = 0; // 無限ループでこの関数からは抜けない while(i < 100){ sprintf(tmp, "Strawberry Linux %d\r\n", i); rc = f_write(&Fil, tmp, strlen(tmp), &bw); if (rc) die(rc); xprintf("%s\n", tmp); // SDカードに書き出します。 f_sync(&Fil); i++; } // return; f_mount(0, NULL); }
uint32_t i2clcd_init( unsigned char contrast) { OUTPUT(1, I2C_LCD_RST); LOW(1, I2C_LCD_RST); wait_ms(10); HIGH(1, I2C_LCD_RST); wait_ms(40); i2c_cmd(0x38);//0b00111000); // function set i2c_cmd(0x39);//0b00111001); // function set i2c_cmd(0x14);//0b00010100); // interval osc i2c_cmd(0x70 | (contrast & 0xF)); // contrast Low //i2c_cmd(0b01011100 | ((contrast >> 4) & 0x3)); // contast High/icon/power i2c_cmd(0x5C | ((contrast >> 4) & 0x3)); // contast High/icon/power i2c_cmd(0x6C); // follower control wait_ms(300); i2c_cmd(0x38);//0b00111000); // function set i2c_cmd(0x0c);//0b00001100); // Display On i2c_cmd(0x01);//0b00000001); // Clear Display wait_ms(2); // Clear Display�͒lj��E�F�C�g���K�v return 0; }
uint8_t i2c_clear() { uint8_t re; re = i2c_cmd(0x01); if(re) return re; wait_ms(2); return 0; }
// LCDの初期化 void lcdInit() { wait_ms(40); i2c_cmd(0b00111000); // function set i2c_cmd(0b00111001); // function set i2c_cmd(0b00010100); // interval osc i2c_cmd(0b01110000 | (contrast & 0xF)); // contrast Low i2c_cmd(0b01011100 | ((contrast >> 4) & 0x3)); // contast High/icon/power i2c_cmd(0b01101100); // follower control wait_ms(300); i2c_cmd(0b00111000); // function set i2c_cmd(0b00001100); // Display On i2c_cmd(0b00000001); // Clear Display wait_ms(2); // Clear Displayは追加ウェイトが必要 }
//LCDの表示をクリア void lcdClear() { i2c_cmd(0b00000001); // Clear Display wait_ms(2); // Clear Displayは追加ウェイトが必要 }