#include #include #include "v25.h" /* #define CHECK_BUSYFLAG */ #define TEXTLCD 0x7A00 /* TEXT LCD Address */ /* TEXT LCD Instruction Set and Timimg Parameters (WRITE Control Register) */ #define CLS 0x01 /* Clear LCD -- 1.64ms */ #define RET_HOME 0x02 /* Return to Original Position -- 1.64ms */ #define ENTRYMODE 0x04 /* Entry Mode -- 40us */ #define EM_INC 0x02 /* Cursor Increment */ #define EM_DEC 0x00 /* Decrement */ #define EM_SHIFT 0x01 /* Accompanies DIsplay Shift */ #define DISPLAYCONTROL 0x08 /* Display Control -- 40us */ #define DC_ON 0x04 /* Display ON */ #define DC_CURSOR 0x02 /* Cursor ON */ #define DC_BLINK 0x01 /* Cursor Blink ON */ #define SHIFTMODE 0x10 /* Cursor or Display Shift -- 40us */ #define SM_DISPLAY 0x08 /* DIsplay Shift */ #define SM_CURSOR 0x00 /* Cursor Shift */ #define SM_RIGHT 0x04 /* Shift Right */ #define SM_LEFT 0x00 /* Shift Left */ #define FUNCTIONSET 0x20 /* Function Set */ #define FS_8BIT 0x10 /* 8 Bit Mode */ #define FS_4BIT 0x00 /* 4 Bit Mode */ #define FS_2LINE 0x08 /* 2 Lines */ #define FS_1LINE 0x00 /* 1 Line */ #define FS_5x10 0x04 /* 5 x 10 Dots */ #define FS_5x7 0x00 /* 5 x 7 Dots */ #define SET_CG_ADDR 0x40 /* Set CGRAM Address -- 40us */ #define SET_ADDRESS 0x80 /* Set DDRAM Address -- 40us */ /* TEXT LCD Status & Address (READ Control Register) */ /*#define CHECK_BUSYFLAG */ /* H/W Support Needed */ #define BUSY_FLAG 0x80 /* Busy Flag */ /* Port 0 - Bit Assignment */ #define TLCD_MASK 0xC0 /* Bits for TLCD */ #define TLCD_DATA 0x40 /* Bit 6 - 1 : data, 0 : Control */ #define TLCD_CTRL 0x00 #define TLCD_E 0x80 /* Bit 7 - 1 : Enable */ #define TLCD_SIZE 0x28 #define TLCD2_BASE 0x40 #define TLCDMODE (FUNCTIONSET | FS_8BIT | FS_2LINE | FS_5x7) #define DIS_ON 0x0F /* LCD ON, Cursor-Blink ON -- 40us */ #define TLCD_DIR 0x06 /* Cursor Increase */ #define TLCD_SHIFT 0x14 /* Move cursor, right */ #define CURSOR_ON 0x0F #define CURSOR_OFF 0x0C int TLCD_INITed = 0; void delay_4ms(void) { int i; for (i = 0; i < 10000; i++) ; } void TLCD_wait(void) { #ifdef CHECK_BUSYFLAG unsigned char other, status; other = peekb(V25_IRAM, V25_P0) & ~TLCD_MASK; /* Read Current P0 */ do { pokeb(V25_IRAM, V25_P0, other | TLCD_CTRL); pokeb(V25_IRAM, V25_P0, other | TLCD_CTRL | TLCD_E); status = inportb(TEXTLCD); pokeb(V25_IRAM, V25_P0, other | TLCD_CTRL); } while (status & BUSY_FLAG) ; #else int i; for (i = 0; i < 500; i++) ; #endif } void TLCD_data(unsigned char data) { unsigned char other; other = peekb(V25_IRAM, V25_P0) & ~TLCD_MASK; /* Read Current P0 */ pokeb(V25_IRAM, V25_P0, other | TLCD_DATA); pokeb(V25_IRAM, V25_P0, other | TLCD_DATA | TLCD_E); outportb(TEXTLCD, data); /* send command */ pokeb(V25_IRAM, V25_P0, other | TLCD_DATA); TLCD_wait(); } void TLCD_control(unsigned char control) { unsigned char other; other = peekb(V25_IRAM, V25_P0) & ~TLCD_MASK; /* Read Current P0 */ pokeb(V25_IRAM, V25_P0, other | TLCD_CTRL); pokeb(V25_IRAM, V25_P0, other | TLCD_CTRL | TLCD_E); outportb(TEXTLCD, control); pokeb(V25_IRAM, V25_P0, other | TLCD_CTRL); if (TLCD_INITed) TLCD_wait(); } void TLCD_putch(unsigned location, char ch) { if (location >= TLCD_SIZE) location += (TLCD2_BASE - TLCD_SIZE); TLCD_control(location | SET_ADDRESS); TLCD_data(ch); } void TLCD_puts(unsigned char location, char *buf) { while (*buf) TLCD_putch(location++, *buf++); } void TLCD_init(void) { pokeb(V25_IRAM, V25_PMC0, 0); /* Set port 0 Output */ pokeb(V25_IRAM, V25_PM0, 0); TLCD_control(TLCDMODE); delay_4ms(); printf("."); TLCD_control(TLCDMODE); delay_4ms(); printf("."); TLCD_control(TLCDMODE); delay_4ms(); printf("."); TLCD_INITed = 1; TLCD_control(TLCDMODE); TLCD_control(DISPLAYCONTROL); TLCD_control(CLS); TLCD_control(DISPLAYCONTROL | DC_ON ); TLCD_control(ENTRYMODE | EM_INC); } void main(void) { printf("\nTEXT LCD TEST "); TLCD_init(); printf("LCD Initialize DONE\n"); TLCD_puts(0, "Hansung University"); TLCD_puts(40, "Micro Processor LAB"); }