OSDN Git Service

[IO] Add PIC18F4xK20 with parallel LCD, PIC18F2xK20 with I2C LCD.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 12 Jun 2013 11:40:33 +0000 (20:40 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Wed, 12 Jun 2013 11:40:33 +0000 (20:40 +0900)
iodef.h
ui.c

diff --git a/iodef.h b/iodef.h
index 5322a24..b5ab19e 100644 (file)
--- a/iodef.h
+++ b/iodef.h
@@ -56,23 +56,6 @@ extern "C" {
  */
 // If you use I2C-Type ACM1602, You should define, otherwise #undef.
 #undef _USE_I2C_1602
-/*
- * Default values, You should re-define in iodef.h if you need.
- */
-#ifndef _LCDPORT_DATA
-#define _LCDPORT_DATA PORTD
-#define _LCDPORT_TRIS_DATA TRISD
-#define _LCDPORT_LATCH_DATA LATD
-#endif
-
-#ifndef _LCDPORT_CONT
-#define _LCDPORT_CONT PORTE
-#define _LCDPORT_TRIS_CONT TRISE
-#define _LCDPORT_CONT_RS _PORTE_RE0
-#define _LCDPORT_CONT_RW _PORTE_RE1
-#define _LCDPORT_CONT_EN _PORTE_RE2
-#define _LCDPORT_CONT_LATCH LATE
-#endif
 
 /*
  * MAP OF IOPORT
@@ -93,6 +76,12 @@ extern "C" {
  *        RC5 : SLOT C
  *        RC3-RC4 : SCL/SDA
  *        RC6-RC7 : USART
+ * In addition, usage of PARALLEL-LCD,You should use 40Pin(or greater) PIC.
+ * PORTD: RD0-RD7 : LCD DATA(DB0-DB7)
+ * PORTE: RE0: LCD RS
+ *        RE1: LCD RW
+ *        RE2: LCD EN
+ *        RE3: VPP (ICSP Programing Voltage) / MCLR
  */
 
 #define TRIS_A_VAL 0b11111101
@@ -103,6 +92,10 @@ extern "C" {
 #define TRIS_C_VAL_I 0b11011000 /* FOR I2C-WRITE */
 #define AN_C_VAL 0b00000000
 
+#define TRIS_D_VAL 0b00000000 /* FOR OUTPUT, LCD(Optional) */
+#define TRIS_E_VAL 0b00000000 /* FOR OUTPUT, LCD(Optional), PSP=OFF */
+
+
 typedef  union {
     struct {
     unsigned BIT0A:1;
@@ -164,6 +157,23 @@ enum {
     charcode_s3, // Reserve
 };
 
+/*
+ * LCD Control: Default register values, You should re-define in iodef.h if you need.
+ */
+#ifndef _LCDPORT_DATA
+#define _LCDPORT_DATA PORTD
+#define _LCDPORT_TRIS_DATA TRISD
+#define _LCDPORT_LATCH_DATA LATD
+#endif
+
+#ifndef _LCDPORT_CONT
+#define _LCDPORT_CONT PORTE
+#define _LCDPORT_TRIS_CONT TRISE
+#define _LCDPORT_CONT_RS _PORTE_RE0
+#define _LCDPORT_CONT_RW _PORTE_RE1
+#define _LCDPORT_CONT_EN _PORTE_RE2
+#define _LCDPORT_CONT_LATCH LATE
+#endif
 
 #ifdef __cplusplus
 }
diff --git a/ui.c b/ui.c
index 984f6c3..12a3567 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -51,6 +51,9 @@ void keyin_init(void)
 }
 
 #if defined(__18F23K22) || defined(__18F24K22) || defined(__18F25K22) || defined(__18F26K22)
+/*
+ * For 28Pin PIC(18F2xK22), I2C lcd using.
+ */
 
 void keyin_ioinit(void)
 {
@@ -70,8 +73,34 @@ void keyin_ioinit(void)
     ANSELC = AN_C_VAL;
     TRISC = TRIS_C_VAL_O;
 }
-#elif defined(__18F43K20) || defined(__18F44K20) || defined(__18F45K20) || defined(__18F46K20)
+#elif defined(__18F23K20) || defined(__18F24K20) || defined(__18F25K20) || defined(__18F26K20)
+/*
+ * 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;
+}
+
+
+#elif defined(__18F43K20) || defined(__18F44K20) || defined(__18F45K20) || defined(__18F46K20)
+/*
+ * For 40Pin PIC(18F4xK20), paralell or I2C lcd using.
+ */
 void keyin_ioinit(void)
 {
     /* Initialize IOPORTS*/
@@ -88,6 +117,16 @@ void keyin_ioinit(void)
     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)
@@ -206,6 +245,11 @@ void printstr(char *s)
     } 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){
@@ -215,6 +259,10 @@ void setsignal_tune(unsigned char flag)
     }
 }
 
+/*
+ * 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){
@@ -226,7 +274,7 @@ void set_backlight(unsigned char flag, unsigned int val)
 
 
 /*
- * Read IOPORTS for KEY.
+ * Read IOPORTS for KEY. You should modify if you modify circuit.
  */
 void readkey_io(void)
 {