00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #define lcdEnable PTG_PTG5
00022 #define lcdRS PTG_PTG4
00023 #define lcdReset PTG_PTG6
00024 #define LCD_BUS_0 PTG_PTG0
00025 #define LCD_BUS_1 PTG_PTG1
00026 #define LCD_BUS_2 PTG_PTG2
00027 #define LCD_BUS_3 PTG_PTG3
00028 #define LCD_BUS_4 PTH_PTH2
00029 #define LCD_BUS_5 PTH_PTH1
00030 #define LCD_BUS_6 PTH_PTH0
00031 #define LCD_BUS_7 PTJ_PTJ0
00032 #define NULL 0
00033
00034 void LCD_strobe() {
00035 lcdEnable = 1;
00036 lcdEnable = 0;
00037 }
00038
00039 void LCD_reset() {
00040 lcdReset=0;
00041 lcdReset=1;
00042 }
00043
00044 void LCD_set_reg(int func, int val) {
00045 lcdRS=1;
00046 LCD_BUS_0 = (func & 0x01);
00047 LCD_BUS_1 = (func & 0x02) >> 1;
00048 LCD_BUS_2 = (func & 0x04) >> 2;
00049 LCD_BUS_3 = (func & 0x08) >> 3;
00050 LCD_BUS_4 = (func & 0x10) >> 4;
00051 LCD_BUS_5 = (func & 0x20) >> 5;
00052 LCD_BUS_6 = (func & 0x40) >> 6;
00053 LCD_BUS_7 = (func & 0x80) >> 7;
00054 LCD_strobe();
00055
00056 lcdRS=0;
00057 LCD_BUS_0 = (val & 0x01);
00058 LCD_BUS_1 = (val & 0x02) >> 1;
00059 LCD_BUS_2 = (val & 0x04) >> 2;
00060 LCD_BUS_3 = (val & 0x08) >> 3;
00061 LCD_BUS_4 = (val & 0x10) >> 4;
00062 LCD_BUS_5 = (val & 0x20) >> 5;
00063 LCD_BUS_6 = (val & 0x40) >> 6;
00064 LCD_BUS_7 = (val & 0x80) >> 7;
00065 LCD_strobe();
00066 }
00067
00068 void LCD_set_mode(int mode) {LCD_set_reg(0,mode);}
00069 void LCD_char_pitch(int cpitch) {LCD_set_reg(1,cpitch);}
00070 void LCD_set_nchar(int nchar) {LCD_set_reg(2,nchar);}
00071 void LCD_set_time_div(int Nx) {LCD_set_reg(3,Nx);}
00072 void LCD_set_cursor(int Np) {LCD_set_reg(4,Np);}
00073 void LCD_set_daddl(int daddl) {LCD_set_reg(8,daddl);}
00074 void LCD_set_daddu(int daddu) {LCD_set_reg(9,daddu);}
00075 void LCD_set_caddl(int caddl) {LCD_set_reg(10,caddl);}
00076 void LCD_set_caddu(int caddu) {LCD_set_reg(11,caddu);}
00077 void LCD_write_data(int data) {LCD_set_reg(12,data);}
00078
00079 void LCD_set_char_add(int row, int col) {
00080 int abs, lower, upper;
00081 abs=row*40+col;
00082 lower=abs%256;
00083 upper=abs-lower;
00084 upper=upper >> 8;
00085 LCD_set_caddl(lower);
00086 LCD_set_caddu(upper);
00087 }
00088
00089 void LCD_print_string(char *str) {
00090 while (*str != NULL) {
00091 LCD_write_data(*str);
00092 str++;
00093 }
00094 }
00095
00096 void LCD_putchar(char toput) {
00097 LCD_write_data(toput);
00098 }
00099
00100 void LCD_graphic_ini() {
00101 int counter;
00102 LCD_set_time_div(127);
00103 LCD_set_mode(50);
00104 LCD_char_pitch(7);
00105 LCD_set_nchar(29);
00106 LCD_set_daddl(0);
00107 LCD_set_daddu(0);
00108 LCD_set_caddl(0);
00109 LCD_set_caddu(0);
00110 for (counter = 0; counter < 4096; counter++) {
00111 LCD_write_data(0x00);
00112 }
00113 LCD_set_caddl(0x00);
00114 LCD_set_caddu(0x00);
00115 }
00116
00117 void LCD_char_ini() {
00118 int counter;
00119 LCD_set_time_div(127);
00120 LCD_set_cursor(167);
00121 LCD_char_pitch(165);
00122 LCD_set_nchar(38);
00123 LCD_set_mode(48);
00124 LCD_set_daddl(0);
00125 LCD_set_daddu(0);
00126 LCD_set_caddl(0);
00127 LCD_set_caddu(0);
00128 for (counter = 0; counter < 4096; counter++) {
00129 LCD_write_data(0x00);
00130 }
00131 LCD_set_caddl(0);
00132 LCD_set_caddu(0);
00133 }
00134
00135 void LCD_clr_scr_char(int screen) {
00136 int row=screen*12;
00137 int i;
00138 LCD_set_char_add(row,0);
00139 for (i=0; i<12; i++) {
00140 LCD_print_string(" ");
00141 }
00142 }