/* a simple example that just rotates the leds. */ #include "plasma.h" #define MemoryRead(A) (*(volatile unsigned long*)(A)) #define MemoryWrite(A,V) *(volatile unsigned long*)(A)=(V) #define MemoryWriteXor(A,V) *(volatile unsigned long*)(A)^=(V) const int LCD_D_SHIFT = 11; const int LCD_RS = 0x0400; const int LCD_RW = 0x0200; /* always low: we never read the LCD */ const int LCD_E = 0x0100; void delay1us(void) { int i; for (i = 3; i; --i) { } } void delay40us(void) { int i; for (i = 120; i; --i) { } } void delay1ms(void) { int i; for (i = 3125; i; --i) { } } void delay1s(void) { int i; for (i = 3125000; i; --i) { } } /* an unprecise delay function */ void delay(int value) { int i; for (; value ;--value) { for (i = 0xfff; i; --i) ; } } void pulse_e(void) { MemoryWriteXor(GPIO0_OUT, LCD_E); delay1us(); MemoryWriteXor(GPIO0_OUT, LCD_E); delay1us(); } void write_char_lcd(char ch) { int lcd_output; /* write upper nibble: */ lcd_output = (ch & 0xf0) << (LCD_D_SHIFT - 4); lcd_output |= LCD_RS; MemoryWrite(GPIO0_OUT, lcd_output); pulse_e(); /* write lower nibble: */ lcd_output = (ch & 0x0f) << LCD_D_SHIFT; lcd_output |= LCD_RS; MemoryWrite(GPIO0_OUT, lcd_output); pulse_e(); delay40us(); MemoryWriteXor(GPIO0_OUT, LCD_RS); } void write_command4_lcd(char ch) { int lcd_output; /* write lower nibble: */ lcd_output = (ch & 0x0f) << LCD_D_SHIFT; MemoryWrite(GPIO0_OUT, lcd_output); pulse_e(); } void write_command8_lcd(char ch) { int lcd_output; /* write upper nibble: */ lcd_output = (ch & 0xf0) << LCD_D_SHIFT; MemoryWrite(GPIO0_OUT, lcd_output); pulse_e(); /* write lower nibble: */ lcd_output = (ch & 0x0f) << LCD_D_SHIFT; MemoryWrite(GPIO0_OUT, lcd_output); pulse_e(); delay40us(); } void initialize_lcd(void) { int i; for (i=0; i<15; i++) { delay1us(); }; write_command4_lcd(3); for (i=0; i<5; i++) { delay1ms(); } write_command4_lcd(3); for (i=0; i<100; i++) { delay1us(); }; write_command4_lcd(3); for (i=0; i<40; i++) { delay1us(); }; write_command4_lcd(2); for (i=0; i<40; i++) { delay1us(); }; write_command8_lcd(0x28); write_command8_lcd(0x06); write_command8_lcd(0x0c); write_command8_lcd(0x01); delay1ms(); delay1ms(); } int main(void) { const int LEFT_LED_ON = 0x80; int led_value = LEFT_LED_ON; int i; initialize_lcd(); write_char_lcd(0x6c); write_char_lcd(0x65); write_char_lcd(0x6f); for (;;) { MemoryWrite(GPIO0_OUT, led_value); led_value >>= 1; if (led_value == 0) { led_value = LEFT_LED_ON; } for (i = 3125000; i; --i) { } // delay1s(); } return 0; }