OSDN Git Service

[IDLE] Swap write order of TMR0[H|L].
[openi2cradio/OpenI2CRadio.git] / ui.c
diff --git a/ui.c b/ui.c
index a1b3547..766fedc 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -1,14 +1,31 @@
 /*
  * OpenI2CRADIO
  * UI Handler
- * (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
- * License: GPL2
+ * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2,
+ *  or (at your option) any later version.
+ *  This library / program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *  See the GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this library; see the file COPYING. If not, write to the
+ *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  As a special exception, if you link this(includeed from sdcc) library
+ *  with other files, some of which are compiled with SDCC,
+ *  to produce an executable, this library does not by itself cause
+ *  the resulting executable to be covered by the GNU General Public License.
+ *  This exception does not however invalidate any other reasons why
+ *  the executable file might be covered by the GNU General Public License.
  */
 
-#include <sdcc-lib.h>
-#include <pic18fregs.h> /* ONLY FOR PIC18x */
-
-#include "iodef.h"
+#include "ui.h"
 
 keyin_defs keyin_old[2];
 keyin_defs keyin_now;
@@ -32,6 +49,10 @@ void keyin_init(void)
     keyin_counter = 0;
 
 }
+#if defined(pic18f23k22) || defined(pic18f24k22) || defined(pic18f25k22) || defined(pic18f26k22)
+/*
+ * For 28Pin PIC(18F2xK22), I2C lcd using.
+ */
 
 void keyin_ioinit(void)
 {
@@ -51,11 +72,86 @@ void keyin_ioinit(void)
     ANSELC = AN_C_VAL;
     TRISC = TRIS_C_VAL_O;
 }
+#endif
+
+#if defined(pic18f23k20) || defined(pic18f24k20) || defined(pic18f25k20) || defined(pic18f26k20)
+/*
+ * For 28Pin PIC(18F2xK20), I2C lcd using.
+ */
+
+void keyin_ioinit(void)
+{
+    /* Initialize IOPORTS*/
+    PORTA = 0x00;
+    LATA = 0x00;
+    ANSEL = 0x01; // Use RA0 AS ADC, Another is not used.
+    ANSELH = 0x00; //
+    TRISA = TRIS_A_VAL;
+
+    PORTB = 0x00;
+    LATB = 0x00;
+    TRISB = TRIS_B_VAL;
+
+    PORTC = 0x00;
+    LATC = 0x00;
+    TRISC = TRIS_C_VAL_O;
+}
+#endif
+
+#if defined(pic18f43k20) || defined(pic18f44k20) || defined(pic18f45k20) || defined(pic18f46k20)
+/*
+ * For 40Pin PIC(18F4xK20), paralell or I2C lcd using.
+ */
+void keyin_ioinit(void)
+{
+    /* Initialize IOPORTS*/
+    PORTA = 0x00;
+    LATA = 0x00;
+    ANSEL = 0x01; // Use RA0 AS ADC, Another is not used.
+    ANSELH = 0x00; //
+    TRISA = TRIS_A_VAL;
+
+    PORTB = 0x00;
+    LATB = 0x00;
+    TRISB = TRIS_B_VAL;
+
+    PORTC = 0x00;
+    LATC = 0x00;
+    TRISC = TRIS_C_VAL_O;
+
+    /*
+     * You can use PORTD,RE0-RE2 extention, when using I2C lcd.
+     */
+    PORTD = 0x00;
+    LATD = 0x00;
+    TRISD = TRIS_D_VAL;
+
+    PORTE = 0x00;
+    TRISE = TRIS_E_VAL;
+}
+#else
+void keyin_ioinit(void)
+{
+    /* Initialize IOPORTS*/
+    PORTA = 0x00;
+    LATA = 0x00;
+//    ANSEL = 0x01; // Use RA0 AS ADC, Another is not used.
+//    ANSELH = 0x00; //
+    TRISA = TRIS_A_VAL;
+
+    PORTB = 0x00;
+    LATB = 0x00;
+    TRISB = TRIS_B_VAL;
 
+    PORTC = 0x00;
+    LATC = 0x00;
+    TRISC = TRIS_C_VAL_O;
+}
+#endif
 /*
  * Push to keyin fifo; not used atomic-writing.
  */
-void push_keyinfifo(char b)
+void push_keyinfifo(char b) __critical
 {
     keyin_nowp++;
     if((keyin_nowp > 15) || (keyin_nowp < 0))keyin_nowp = 0;
@@ -67,7 +163,7 @@ void push_keyinfifo(char b)
 /*
  * Pop from keyin fifo; not used atomic-reading.
  */
-char pop_keyinfifo(void)
+char pop_keyinfifo(void) __critical
 {
     char c;
     if(keyin_counter <= 0) {
@@ -83,9 +179,103 @@ char pop_keyinfifo(void)
     return c;
 }
 
+void print_numeric(int i)
+{
+    if(i == 0){
+        unsigned char c;
+        c = '0';
+        _CURSOR_LEFT();
+        _PUTCHAR(c);
+        _CURSOR_RIGHT();
+    } else {
+        int l;
+        unsigned char supress = 0;
+         _CURSOR_LEFT();
+        if(i < 0){
+            _PUTCHAR('-');
+            i = -i;
+        }
+        l = i / 10000;
+        i = i % 10000;
+        if(l != 0) {
+            _PUTCHAR((l & 0x0f)+ '0');
+            supress = 1;
+        }
+        l = i / 1000;
+        i = i % 1000;
+        if(supress != 0){
+             _PUTCHAR((l & 0x0f)+ '0');
+        } else if(l != 0){
+             _PUTCHAR((l & 0x0f)+ '0');
+            supress = 1;
+
+        }
+        l = i / 100;
+        i = i % 100;
+        if(supress != 0){
+             _PUTCHAR((l & 0x0f)+ '0');
+        } else if(l != 0){
+             _PUTCHAR((l & 0x0f)+ '0');
+            supress = 1;
+
+        }
+        l = i / 10;
+        i = i % 10;
+        if(supress != 0){
+             _PUTCHAR((l & 0x0f)+ '0');
+        } else if(l != 0){
+             _PUTCHAR((l & 0x0f)+ '0');
+            supress = 1;
+
+        }
+        _PUTCHAR((i & 0x0f) + '0');
+        _CURSOR_RIGHT();
+    }
+
+}
+
+void printstr(char *s)
+{
+    int p = 0;
+    _CURSOR_RIGHT();
+    if(s == NULL) return;
+    do {
+        if(s[p] == '\0') break;
+        _PUTCHAR(s[p]);
+        p++;
+    } while(p < 255);
+}
+
+
+/*
+ * Set signal tune status led assigned to RC0.
+ * You should modify if you modify circuit.
+ */
+void setsignal_tune(unsigned char flag)
+{
+    if(flag != 0){
+        LATCbits.LATC0 = 1;
+    } else {
+        LATCbits.LATC0 = 0;
+    }
+}
+
+/*
+ * Set power of lcd backlight assigned to RB0.
+ * You should modify if you modify circuit.
+ */
+void set_backlight(unsigned char flag, unsigned int val)
+{
+    if(flag != 0){
+        LATBbits.LATB0 = 1;
+    } else {
+        LATBbits.LATB0 = 0;
+    }
+}
+
 
 /*
- * Read IOPORTS for KEY.
+ * Read IOPORTS for KEY. You should modify if you modify circuit.
  */
 void readkey_io(void)
 {