#include <3048f.h> /*I/OƒAƒNƒZƒX—pƒCƒ“ƒNƒ‹[ƒh*/ #define LCD_E P3.DR.BIT.B5 #define LCD_RS P3.DR.BIT.B4 #define LCD_DATA P3.DR.BYTE extern void wait(long); /************************************************************************* ; ; ‚k‚b‚c(‚Sƒrƒbƒg)‚PƒoƒCƒgƒf[ƒ^o—̓‹[ƒ`ƒ“ ; code:o—̓f[ƒ^ ; rs :1:•¶ŽšƒR[ƒh@0:§ŒäƒR[ƒh ;************************************************************************/ void lcd4_byte_out(int code, int rs) /* ‰t»o—Í */ { volatile int i; i = code; i = i >> 4; i = i & 0x0f; LCD_DATA = i; if (rs) LCD_RS = 1; LCD_E = 1; wait(1); LCD_E = 0; i = code; i = i & 0x0f; LCD_DATA = i; if (rs) LCD_RS = 1; LCD_E = 1; wait(1); LCD_E = 0; wait(60); /*40uS‚Ì‚v‚`‚h‚s*/ } /************************************************************************* ; ; ‚k‚b‚c(‚Sƒrƒbƒg)•\Ž¦ƒNƒŠƒAƒ‹[ƒ`ƒ“ ; ;************************************************************************/ void lcd4_cls() { lcd4_byte_out(0x01, 0); /*•\Ž¦ƒNƒŠƒA*/ wait(3200); /*2mS‚Ì‚v‚`‚h‚s*/ } /************************************************************************* ; ; ‚k‚b‚c(‚Sƒrƒbƒg)‚c‚c‚q‚`‚lƒAƒhƒŒƒXƒZƒbƒgƒ‹[ƒ`ƒ“ ; ;************************************************************************/ void lcd4_ddram_set(int address) { address = address | 0x80; lcd4_byte_out(address, 0); } /************************************************************************* ; ; ‚k‚b‚c(‚Sƒrƒbƒg)ƒf[ƒ^o—̓‹[ƒ`ƒ“ ; ;************************************************************************/ void lcd4_out(int address, char *data) { /*--------------‚Œ‚ƒ‚„ƒAƒhƒŒƒXo—Í------------*/ address = address | 0x80; lcd4_byte_out(address, 0); while(*data){ lcd4_byte_out(*data, 1); data++; } } /*;************************************************************************* ; ; ‚k‚b‚c(‚Sƒrƒbƒg)‰Šú‰»‰Šú‰»ƒ‹[ƒ`ƒ“(lcd4_init) ; PORT3(0-3) ;‚Œ‚ƒ‚„—pƒf[ƒ^o—Í ; PORT3(5) ;‚Œ‚ƒ‚„—pEo—Í ; PORT3(4) ;‚Œ‚ƒ‚„—pRSo—Í ;**************************************************************************/ void lcd4_init() { /*;-----‚Œ‚ƒ‚„ƒ|[ƒgÝ’è*/ P3.DDR = 0x3f; LCD_DATA = 0x00; wait(32000); /*‚Q‚O‚‚r‚Ì‚v‚`‚h‚s*/ LCD_DATA = 0x03; LCD_E = 1; wait(1); LCD_E = 0; wait(8000); /*5mS‚Ì‚v‚`‚h‚s*/ LCD_E = 1; wait(1); LCD_E = 0; wait(157); /*100uS‚Ì‚v‚`‚h‚s*/ LCD_E = 1; wait(1); LCD_E = 0; wait(60); /*40uS‚Ì‚v‚`‚h‚s*/ LCD_DATA = 0x02; LCD_E = 1; wait(1); LCD_E = 0; wait(60); /*40uS‚Ì‚v‚`‚h‚s*/ lcd4_byte_out(0x28, 0); /*ƒtƒ@ƒ“ƒNƒVƒ‡ƒ“ƒZƒbƒg*/ lcd4_byte_out(0x08, 0); /*•\Ž¦ƒIƒt*/ lcd4_byte_out(0x01, 0); /*•\Ž¦ƒNƒŠƒA*/ wait(3200); /*2mS‚Ì‚v‚`‚h‚s*/ lcd4_byte_out(0x06, 0); /*ƒGƒ“ƒgƒŠ[ƒ‚[ƒhƒZƒbƒg*/ lcd4_byte_out(0x0c, 0); /*•\Ž¦ƒIƒ“*/ }