#include #include #include #include #define SPI_COMMAND 0x600 int spidev; unsigned char lcdram[6][84] = {0}; unsigned char *lcdram_ptr = &lcdram[0][0]; void spi_command(unsigned char command) { ioctl(spidev, SPI_COMMAND, &command); } void cursorxy(int x, int y) { spi_command(0x40 | (y & 0x07)); spi_command(0x80 | (x & 0x7f)); } void updateram() { cursorxy(0, 0); write(spidev, lcdram_ptr, 504); } void init() { spi_command(0x21); // Extended instruction set spi_command(0x80 | 70); // LCD contrast voltage spi_command(0x13); // LCD bias spi_command(0x20); // Normal instruction set spi_command(0x0C); // Display normal updateram(); } void speedtest() { unsigned char *p = lcdram_ptr; int i; for (i = 0; i < 504; i++) { p++; if (i % 5 == 4) *p = 0; else *p = font_data[i / 5 + 32][i % 5]; } int x, y, carry, oldcarry, count = 0, sleep; while (1) { for (x = 0; x < 84; x++) { carry = (lcdram[5][x] & 0x80) >> 7; for (y = 0; y < 6; y++) { oldcarry = carry; carry = (lcdram[y][x] & 0x80) >> 7; lcdram[y][x] = (lcdram[y][x] << 1) | oldcarry; } } updateram(); sleep = abs(250000 - (count % 500000)) / 100; count += sleep; printf("%d\n", sleep); usleep(sleep); } } int main() { spidev = open("/dev/spi", O_RDWR); init(); speedtest(); }