]> git.tdb.fi Git - model-railway-devices.git/commitdiff
Make LCD output selectable at runtime through an extra I/O pin
authorMikko Rasa <tdb@tdb.fi>
Mon, 15 Nov 2010 21:07:41 +0000 (21:07 +0000)
committerMikko Rasa <tdb@tdb.fi>
Mon, 15 Nov 2010 21:07:41 +0000 (21:07 +0000)
firmware/s88w-r.c

index 730ac10f3a5337ba2ec31e51ef79a3e8fbac27b6..d2a21092adc82756ad6b99b545dff4e19e64637f 100644 (file)
@@ -34,6 +34,8 @@ D5 - S88 RESET
 #define LOAD     PIND4
 #define RESET    PIND5
 
+#define LCD_DISABLE PINB4
+
 #define BIT(n)   (1<<(n))
 
 void receive(uint8_t);
@@ -44,6 +46,7 @@ volatile uint8_t rx_buf[7];
 volatile uint8_t rx_fill = 0xFF;
 volatile uint8_t input[128] = { 0 };
 volatile uint8_t latch[128] = { 0 };
+volatile uint8_t lcd_enabled = 0;
 uint8_t log_row = 0;
 uint8_t log_col = 0;
 
@@ -65,14 +68,11 @@ int main()
 
        sei();
 
-       lcd_clear();
-       for(i=0; i<20; ++i)
-               lcd_write('0');
-
        while(1)
        {
-               uint8_t d_pins;
+               uint8_t b_pins, d_pins;
 
+               b_pins = PINB;
                d_pins = PIND;
 
                if(d_pins&BIT(CLOCK))
@@ -113,6 +113,28 @@ int main()
                        for(i=0; i<128; ++i)
                                latch[i] = input[i];
                }
+
+               if(b_pins&BIT(LCD_DISABLE))
+               {
+                       if(lcd_enabled)
+                       {
+                               lcd_enabled = 0;
+
+                               lcd_clear();
+                       }
+               }
+               else if(!lcd_enabled)
+               {
+                       lcd_enabled = 1;
+                       log_row = 0;
+                       log_col = 0;
+
+                       lcd_clear();
+                       for(i=0; i<20; ++i)
+                               lcd_write(hexdigit(input[9-i/2]>>(4-i%2*4)));
+                       lcd_gotoxy(0, 1);
+                       lcd_write(255);
+               }
        }
 }
 
@@ -145,9 +167,12 @@ void receive(uint8_t c)
                                        latch[j/2] = input[j/2];
                                }
 
-                               lcd_gotoxy(19-offset-nibbles, 0);
-                               for(i=0; i<=nibbles; ++i)
-                                       lcd_write(rx_buf[3+i]);
+                               if(lcd_enabled)
+                               {
+                                       lcd_gotoxy(19-offset-nibbles, 0);
+                                       for(i=0; i<=nibbles; ++i)
+                                               lcd_write(rx_buf[3+i]);
+                               }
                        }
                }
                rx_fill = 0xFF;
@@ -160,18 +185,21 @@ void receive(uint8_t c)
                        rx_fill = 0xFF;
        }
 
-       lcd_gotoxy(log_col, 1+log_row);
-       lcd_write(c);
-       ++log_col;
-       if(log_col>=20)
+       if(lcd_enabled)
        {
-               log_col = 0;
-               ++log_row;
-               if(log_row>=3)
-                       log_row = 0;
                lcd_gotoxy(log_col, 1+log_row);
+               lcd_write(c);
+               ++log_col;
+               if(log_col>=20)
+               {
+                       log_col = 0;
+                       ++log_row;
+                       if(log_row>=3)
+                               log_row = 0;
+                       lcd_gotoxy(log_col, 1+log_row);
+               }
+               lcd_write(255);
        }
-       lcd_write(255);
 }
 
 SERIAL_SET_CALLBACK(receive)