#include #include #include #define GPIO_DOUT (1<<1) #define GPIO_CLK (1<<2) #define GPIO_CS (1<<3) #define GPIO_DC (1<<7) int gpio_out; unsigned char lcdram[6][84] = {0}; unsigned char *lcdram_ptr = &lcdram[0][0]; void setpins(int dout, int clk, int cs, int dc) { unsigned int reg; read(gpio_out, ®, sizeof(reg)); if (dout) reg |= GPIO_DOUT; else reg &= ~GPIO_DOUT; if (clk) reg |= GPIO_CLK; else reg &= ~GPIO_CLK; if (cs) reg |= GPIO_CS; else reg &= ~GPIO_CS; if (dc) reg |= GPIO_DC; else reg &= ~GPIO_DC; write(gpio_out, ®, sizeof(reg)); usleep(1000); } void spi_writebyte(unsigned char byte, int dc) { int i, bit; setpins(0, 0, 0, dc); for (i = 7; i >= 0; i--) { bit = byte & (1 << i); // setpins(bit, 0, 0, dc); setpins(bit, 1, 0, dc); setpins(bit, 0, 0, dc); } } void cursorxy(int x, int y) { spi_writebyte(0x40 | (y & 0x07), 0); spi_writebyte(0x80 | (x & 0x7f), 0); } void updateram() { cursorxy(0, 0); unsigned char *p; for (p = lcdram_ptr; p < lcdram_ptr + 504; p++) { spi_writebyte(*p, 1); } } void init() { setpins(0, 0, 0, 0); usleep(10000); setpins(0, 0, 1, 0); spi_writebyte(0x21, 0); // Extended instruction set spi_writebyte(0xC2, 0); // LCD contrast voltage spi_writebyte(0x13, 0); // LCD bias spi_writebyte(0x20, 0); // Normal instruction set spi_writebyte(0x0C, 0); // Display normal updateram(); setpins(0, 0, 0, 0); } 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; 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(); usleep(20000); } } int main() { unsigned int reg; int gpioouten=open("/dev/gpio/outen",O_RDWR); read(gpioouten, ®, sizeof(reg)); reg |= GPIO_DOUT | GPIO_CLK | GPIO_CS | GPIO_DC; write(gpioouten, ®, sizeof(reg)); gpio_out = open("/dev/gpio/out", O_RDWR); init(); speedtest(); }