[ บทความ : ตัวอย่างสำหรับ CP-SB31 V2 ตอนที่ 9 ] ทดสอบติดต่อกับ LCD กราฟิกส์ ด้วย CP-SB31V2

ตัวอย่างซอร์สโค้ดสำหรับติดต่อกับ LCD แบบกราฟิกส์ กับบอร์ด CP-SB31V2 ที่ติดตั้ง ET-DEBUG31 เป็นดังนี้



;/****************************************/;
;/* Demo Program For Graphic LCD DV12864 */;
;/* Hardware  :  ET-CPSB31 V2.0          */;
;/* Complier  :  Cross-32  V2.0          */;
;/* Function  : Show Font Thai/English   */;
;/****************************************/;

;/***************************************/;
;/* Equate List Port I/O ET-CPSB31 V2.0 */;
;/***************************************/;
;
WR_COMM1   EQU     0E0C4H                  ; Write Instruction Page1
RD_COMM1   EQU     0E0C5H                  ; Reda Busy flag & Address Page1
WR_DATA1   EQU     0E0C6H                  ; Write Data Page1
RD_DATA1   EQU     0E0C7H                  ; Read Data Page1
;
WR_COMM2   EQU     0E0C8H                  ; Write Instruction Page2
RD_COMM2   EQU     0E0C9H                  ; Reda Busy flag & Address Page2
WR_DATA2   EQU     0E0CAH                  ; Write Data Page2
RD_DATA2   EQU     0E0CBH                  ; Read Data Page2

            ORG     22H                     ; Start CPU-RAM Buffer

X_ADDR1:    DS     1                       ; X-Address1 Buffer
X_ADDR2:    DS     1                       ; X-Address2 Buffer
Y_ADDR1:    DS     1                       ; Y-Address1 Buffer
Y_ADDR2:    DS     1                       ; Y-Address2 Buffer
LINE_CNT:   DS     1                       ; Line LCD Counter
POST_CNT:   DS     1                       ; Write LCD Position Counter

            ORG     2200H                   ; Strat Program For "ET-DEBUG31"

MAIN:       MOV     R2,#02H                 ; Power-on Delay
PWR_DLY1:   MOV     R3,#00H
PWR_DLY2:   MOV     R4,#00H
            DJNZ    R4,$
            DJNZ    R3,PWR_DLY2
            DJNZ    R2,PWR_DLY1
            ;
            LCALL   INITGLCD                ; Initial Graphic LCD
            MOV     LINE_CNT,#8             ; Counter Line
            MOV     DPTR,#TAB_FONT          ; Table Font Thai & English
            ;
NEW_LINE:   LCALL   SET_X1                  ; Set X_Address Page1
            LCALL   SET_Y1                  ; Set Y_Address Page1
            MOV     POST_CNT,#64            ; Counter Y Position Page1
WR_PAGE1:   LCALL   BUSY_LCD1
            CLR     A
            MOVC    A,@A+DPTR               ; Get Data-Font
            PUSH    DPH
            PUSH    DPL
            MOV     DPTR,#WR_DATA1          ; Write Data Page1
            MOVX    @DPTR,A
            POP     DPL
            POP     DPH
            INC     DPTR
            DJNZ    POST_CNT,WR_PAGE1
            ;
            LCALL   SET_X2                  ; Set X_Address Page2
            LCALL   SET_Y2                  ; Set Y_Address Page2
            MOV     POST_CNT,#64            ; Counter Y Position Page2
WR_PAGE2:   LCALL   BUSY_LCD2
            CLR     A
            MOVC    A,@A+DPTR               ; Get Data-Font
            PUSH    DPH
            PUSH    DPL
            MOV     DPTR,#WR_DATA2          ; Write Data Page2
            MOVX    @DPTR,A
            POP     DPL
            POP     DPH
            INC     DPTR
            DJNZ    POST_CNT,WR_PAGE2
            ;
            INC     X_ADDR1                 ; Next Line Page1
            INC     X_ADDR2                 ; Next Line Page2
            DJNZ    LINE_CNT,NEW_LINE
            SJMP    $

;/***********************/;
;/* Initial Graphic LCD */;
;/***********************/;
;
INITGLCD:   LCALL   BUSY_LCD1               ; Wait LCD Busy
            MOV     DPTR,#WR_COMM1          ; Write Instruction1
            MOV     A,#3FH                  ; Display on-off1  X=1 ON,X=0 OFF
            MOVX    @DPTR,A
            ;
            LCALL   BUSY_LCD2               ; Wait LCD Busy
            MOV     DPTR,#WR_COMM2          ; Write Instruction2
            MOV     A,#3FH                  ; Display on-off2  X=1 ON,X=0 OFF
            MOVX    @DPTR,A
            ;
            LCALL   BUSY_LCD1               ; Wait LCD Busy
            MOV     DPTR,#WR_COMM1          ; Write Instruction1
            MOV     A,#0C0H                 ; Display Strat Page1
            MOVX    @DPTR,A
            ;
            LCALL   BUSY_LCD2               ; Wait LCD Busy
            MOV     DPTR,#WR_COMM2          ; Write Instruction2
            MOV     A,#0C0H                 ; Display Strat Page2
            MOVX    @DPTR,A
            ;
            CLR     A
            MOV     X_ADDR1,A               ; Start X-Address1 = 0
            MOV     X_ADDR2,A               ; Start X-Address2 = 0
            MOV     Y_ADDR1,A               ; Start Y-Address1 = 0
            MOV     Y_ADDR2,A               ; Start Y-Address2 = 0
            RET

;/*******************/;
;/* Set X-Address1  */;
;/* Input : X_ADDR1 */;
;/*       : (0..7)  */;
;/*******************/;
;
SET_X1:     PUSH    ACC
            LCALL   BUSY_LCD1               ; Wait LCD busy
            MOV     A,X_ADDR1
            ANL     A,#07H
            ORL     A,#0B8H
            PUSH    DPH
            PUSH    DPL
            MOV     DPTR,#WR_COMM1          ; Set X-Address Page1
            MOVX    @DPTR,A
            POP     DPL
            POP     DPH
            POP     ACC
            RET

;/*******************/;
;/* Set X-Address2  */;
;/* Input : X_ADDR2 */;
;/*       : (0..7)  */;
;/*******************/;
;
SET_X2:     PUSH    ACC
            LCALL   BUSY_LCD2               ; Wait LCD busy
            MOV     A,X_ADDR2
            ANL     A,#07H
            ORL     A,#0B8H
            PUSH    DPH
            PUSH    DPL
            MOV     DPTR,#WR_COMM2          ; Set X-Address Page2
            MOVX    @DPTR,A
            POP     DPL
            POP     DPH
            POP     ACC
            RET

;/*******************/;
;/* Set Y-Address1  */;
;/* Input : Y_ADDR1 */;
;/*       : (0..63) */;
;/*******************/;
;
SET_Y1:     PUSH    ACC
            LCALL   BUSY_LCD1       ; Wait LCD busy
            MOV     A,Y_ADDR1
            ANL     A,#63
            ORL     A,#40H
            PUSH    DPH
            PUSH    DPL
            MOV     DPTR,#WR_COMM1          ; Set Y-Address Page1
            MOVX    @DPTR,A
            POP     DPL
            POP     DPH
            POP     ACC
            RET

;/*******************/;
;/* Set Y-Address2  */;
;/* Input : Y_ADDR2 */;
;/*       : (0..63) */;
;/*******************/;
;
SET_Y2:     PUSH    ACC
            LCALL   BUSY_LCD2       ; Wait LCD busy
            MOV     A,Y_ADDR2
            ANL     A,#63
            ORL     A,#40H
            PUSH    DPH
            PUSH    DPL
            MOV     DPTR,#WR_COMM2          ; Set Y-Address Page2
            MOVX    @DPTR,A
            POP     DPL
            POP     DPH
            POP     ACC
            RET

;/***********************/;
;/* Read Busy Flag LCD1 */;
;/***********************/;
;
BUSY_LCD1:  PUSH    DPL
            PUSH    DPH
            PUSH    ACC
            MOV     DPTR,#RD_COMM1
BUSY1:      MOVX    A,@DPTR
            JB      ACC.7,BUSY1
            POP     ACC
            POP     DPH
            POP     DPL
            RET

;/***********************/;
;/* Read Busy Flag LCD2 */;
;/***********************/;
;
BUSY_LCD2:  PUSH    DPL
            PUSH    DPH
            PUSH    ACC
            MOV     DPTR,#RD_COMM2
BUSY2:      MOVX    A,@DPTR
            JB      ACC.7,BUSY2
            POP     ACC
            POP     DPH
            POP     DPL
            RET

;/****************************/;
;/* English Characters Fonts */;
;/****************************/;
;
TAB_FONT:   DB      000H,000H,000H,000H     ; BLANK
            DB      000H,000H,000H,000H
            DB      000H,000H,00EH,0BFH     ; !
            DB      00EH,000H,000H,000H
            DB      000H,000H,007H,000H     ; "
            DB      007H,000H,000H,000H
            DB      000H,024H,0FFH,024H     ; #
            DB      024H,0FFH,024H,000H
            DB      008H,054H,054H,0FEH     ; $
            DB      054H,054H,020H,000H
            DB      086H,046H,020H,010H     ; %
            DB      008H,0C4H,0C2H,000H
            DB      060H,094H,08EH,09AH     ; &
            DB      06EH,044H,0B0H,080H
            DB      000H,000H,000H,005H     ; '
            DB      003H,000H,000H,000H
            DB      000H,000H,03CH,042H     ; (
            DB      081H,000H,000H,000H
            DB      000H,000H,000H,081H     ; )
            DB      042H,03CH,000H,000H
            DB      000H,008H,02AH,01CH     ; *
            DB      01CH,02AH,008H,000H
            DB      000H,008H,008H,03EH     ; +
            DB      03EH,008H,008H,000H
            DB      000H,000H,000H,0A0H     ; ,
            DB      060H,000H,000H,000H
            DB      000H,008H,008H,008H     ; -
            DB      008H,008H,008H,000H
            DB      000H,000H,000H,0C0H     ; .
            DB      0C0H,000H,000H,000H
            DB      000H,0C0H,030H,018H     ; /
            DB      00CH,003H,000H,000H
            DB      000H,07CH,0A2H,0B2H     ; 0
            DB      09AH,08AH,07CH,000H
            DB      000H,000H,082H,0FFH     ; 1
            DB      080H,000H,000H,000H
            DB      000H,086H,0C1H,0A1H     ; 2
            DB      091H,089H,086H,000H
            DB      000H,042H,081H,089H     ; 3
            DB      089H,089H,076H,000H
            DB      060H,050H,048H,044H     ; 4
            DB      042H,0FFH,040H,000H
            DB      05FH,085H,085H,085H     ; 5
            DB      085H,049H,030H,000H
            DB      000H,07CH,092H,089H     ; 6
            DB      089H,089H,070H,000H
            DB      000H,003H,001H,0C1H     ; 7
            DB      031H,00DH,003H,000H
            DB      000H,076H,089H,089H     ; 8
            DB      089H,089H,076H,000H
            DB      000H,00EH,091H,091H     ; 9
            DB      091H,049H,03EH,000H
            DB      000H,000H,000H,066H     ; :
            DB      066H,000H,000H,000H
            DB      000H,000H,080H,076H     ; ;
            DB      036H,000H,000H,000H
            DB      000H,000H,018H,024H     ; <
            DB      042H,081H,000H,000H
            DB      000H,024H,024H,024H     ; =
            DB      024H,024H,000H,000H
            DB      000H,000H,081H,042H     ; >
            DB      024H,018H,000H,000H
            DB      000H,006H,009H,00DH     ; ?
            DB      0B5H,009H,006H,000H
            DB      0F8H,014H,012H,011H     ; A
            DB      012H,014H,0F8H,000H
            DB      081H,0FFH,089H,089H     ; B
            DB      089H,089H,076H,000H
            DB      000H,03CH,042H,081H     ; C
            DB      081H,081H,042H,000H
            DB      081H,0FFH,081H,081H     ; D
            DB      081H,042H,03CH,000H
            DB      081H,0FFH,089H,089H     ; E
            DB      09DH,081H,0E3H,000H
            DB      081H,0FFH,089H,009H     ; F
            DB      01DH,001H,003H,000H
            DB      000H,07EH,081H,081H     ; G
            DB      091H,051H,0F6H,000H
            DB      000H,0FFH,008H,008H     ; H
            DB      008H,008H,0FFH,000H
            DB      000H,000H,081H,0FFH     ; I
            DB      081H,000H,000H,000H
            DB      000H,040H,080H,080H     ; J
            DB      081H,07FH,001H,000H
            DB      081H,0FFH,089H,014H     ; K
            DB      022H,0C1H,081H,080H
            DB      000H,081H,0FFH,081H     ; L
            DB      080H,080H,0C0H,000H
            DB      0FFH,002H,004H,018H     ; M
            DB      004H,002H,0FFH,000H
            DB      081H,0FFH,083H,00CH     ; N
            DB      018H,061H,0FFH,001H
            DB      000H,07EH,081H,081H     ; O
            DB      081H,081H,07EH,000H
            DB      000H,081H,0FEH,091H     ; P
            DB      011H,011H,00EH,000H
            DB      000H,07EH,081H,091H     ; Q
            DB      0A1H,0C1H,07FH,080H
            DB      081H,0FFH,089H,019H     ; R
            DB      029H,0C9H,086H,080H
            DB      000H,0E6H,049H,089H     ; S
            DB      091H,092H,067H,000H
            DB      003H,001H,081H,0FFH     ; T
            DB      081H,001H,003H,000H
            DB      001H,07FH,081H,080H     ; U
            DB      080H,081H,07FH,001H
            DB      007H,018H,060H,080H     ; V
            DB      060H,018H,00FH,000H
            DB      03FH,0C0H,020H,010H     ; W
            DB      020H,0C0H,03FH,000H
            DB      0C3H,027H,018H,018H     ; X
            DB      018H,027H,0C3H,000H
            DB      001H,003H,084H,0F8H     ; Y
            DB      084H,003H,001H,000H
            DB      0C3H,0A1H,091H,089H     ; Z
            DB      085H,083H,0C1H,000H


;/*************************/;
;/* Thai Characters Fonts */;
;/*************************/;
;
KAI:        DB      000H,0FAH,005H,001H
            DB      001H,001H,0FEH,000H
KHAI:       DB      000H,002H,005H,0FEH
            DB      080H,07FH,000H,000H
BUFFALO:    DB      0FEH,021H,011H,029H
            DB      011H,001H,0FEH,000H
RAKANG:     DB      062H,095H,0F2H,029H
            DB      046H,080H,0FFH,000H
NGU:        DB      000H,010H,020H,042H
            DB      085H,0FEH,000H,000H
JAN:        DB      002H,001H,009H,015H
            DB      079H,081H,0FEH,000H
CHING:      DB      012H,0E9H,0B1H,041H
            DB      021H,0FEH,0A0H,040H
CHANG:      DB      004H,0F2H,08AH,086H
            DB      084H,0FAH,001H,001H
SOO:        DB      002H,005H,002H,0FDH
            DB      082H,07DH,000H,000H
CHER:       DB      07AH,0A5H,041H,041H
            DB      0A1H,07EH,040H,0FFH
YING:       DB      07AH,0A5H,041H,001H
            DB      0FEH,080H,080H,0FFH
YINGLOW:    DB      000H,000H,000H,000H
            DB      006H,006H,004H,002H
CHADA:      DB      042H,0A5H,079H,001H
            DB      001H,001H,0FEH,080H
CHADALOW:   DB      000H,000H,002H,005H
            DB      002H,005H,007H,000H
PATAK:      DB      042H,0A5H,079H,001H
            DB      081H,001H,0FEH,000H
PATAKLOW:   DB      002H,005H,002H,005H
            DB      002H,004H,007H,000H
TORTAN:     DB      000H,002H,015H,02DH
            DB      0F5H,085H,07AH,001H
TORTANLOW:  DB      010H,028H,010H,028H
            DB      014H,02AH,01EH,000H
MONTO:      DB      002H,0E5H,012H,009H
            DB      006H,002H,0FFH,000H
TORTHOA:    DB      0FEH,011H,02AH,052H
            DB      0A2H,07EH,040H,0BFH
NANE:       DB      07AH,0A5H,041H,0FEH
            DB      040H,0FFH,0A0H,040H
DEK:        DB      0FEH,081H,049H,035H
            DB      019H,001H,0FEH,000H
TORTOA:     DB      0FEH,081H,049H,036H
            DB      019H,001H,0FEH,000H
TUNG:       DB      07AH,0A5H,041H,001H
            DB      001H,001H,0FEH,000H
TAHAN:      DB      002H,0F5H,00EH,004H
            DB      002H,001H,0FEH,000H
TONG:       DB      000H,002H,005H,0FDH
            DB      085H,085H,0FAH,001H
HNOO:       DB      002H,0F5H,08EH,040H
            DB      020H,0FFH,0A0H,040H
BAIMAI:     DB      002H,085H,0FEH,080H
            DB      080H,080H,0FFH,000H
PLARHIGH:   DB      000H,000H,000H,000H
            DB      000H,000H,0F0H,000H
PLAR:       DB      002H,005H,0FEH,080H
            DB      080H,080H,0FFH,000H
PUNG:       DB      000H,07EH,085H,042H
            DB      040H,080H,07EH,000H
PHAHIGH:    DB      000H,000H,000H,000H
            DB      000H,000H,0F0H,000H
PHA:        DB      000H,07EH,085H,042H
            DB      040H,080H,07FH,000H
PAN:        DB      002H,005H,0FEH,040H
            DB      030H,040H,0FFH,000H
FUNHIGH:    DB      000H,000H,000H,000H
            DB      000H,000H,0F0H,000H
FUN:        DB      002H,005H,0FEH,040H
            DB      030H,040H,0FFH,000H
POA:        DB      042H,0A5H,079H,001H
            DB      001H,001H,0FEH,000H
MAR:        DB      042H,0A5H,0FEH,020H
            DB      020H,040H,0FFH,000H
YAK:        DB      000H,06EH,095H,092H
            DB      080H,080H,0FFH,000H
SHIP:       DB      000H,002H,005H,005H
            DB      045H,0A5H,07AH,001H
LU:         DB      000H,07AH,0A5H,041H
            DB      001H,001H,0FEH,000H
LULOW:      DB      000H,000H,000H,000H
            DB      000H,000H,00FH,000H
LING:       DB      002H,071H,0A9H,045H
            DB      009H,011H,0FEH,000H
WAN:        DB      000H,002H,001H,001H
            DB      041H,0A1H,07EH,000H
SALAHIGH:   DB      000H,000H,000H,000H
            DB      000H,080H,050H,020H
SALA:       DB      07EH,081H,079H,015H
            DB      009H,001H,0FEH,000H
RUSI:       DB      002H,085H,0FEH,080H
            DB      098H,090H,0FFH,010H
TIGERHIGH:  DB      000H,000H,000H,000H
            DB      000H,080H,050H,020H
TIGER:      DB      002H,071H,0A9H,045H
            DB      009H,011H,0FEH,000H
HEEP:       DB      002H,0FDH,026H,010H
            DB      00AH,00DH,0FAH,000H
JURAHIGH:   DB      000H,000H,000H,000H
            DB      040H,0A0H,0C0H,020H
JURA:       DB      002H,0F5H,04EH,020H
            DB      020H,040H,0FFH,000H
ANG:        DB      000H,072H,0A9H,091H
            DB      081H,081H,07EH,000H
HOOKHIGH:   DB      000H,000H,000H,000H
            DB      000H,000H,0A0H,040H
HOOK:       DB      000H,072H,0ADH,095H
            DB      083H,081H,07EH,000H
SARAA:      DB      000H,066H,055H,0AAH
            DB      088H,044H,022H,000H
TOAKUB:     DB      000H,014H,014H,014H
            DB      014H,014H,000H,000H
SARAAR:     DB      000H,002H,001H,001H
            DB      001H,001H,0FEH,000H
SARAUMHIGH: DB      020H,050H,050H,020H
            DB      000H,000H,000H,000H
SARAUM:     DB      000H,002H,001H,001H
            DB      001H,001H,0FEH,000H
SARAAA:     DB      000H,07FH,0A0H,040H
            DB      000H,000H,000H,000H
SARAAIR:    DB      000H,07FH,0A0H,040H
            DB      07FH,0A0H,040H,000H
SARAOHIGH:  DB      010H,028H,0E8H,008H
            DB      008H,008H,000H,000H
SARAO:      DB      000H,000H,0FFH,0C0H
            DB      000H,000H,000H,000H
MAIMOONHIGH: DB      038H,034H,004H,0FCH
            DB      000H,000H,000H,000H
MAIMOON:    DB      000H,000H,000H,0FFH
            DB      0C0H,000H,000H,000H
MALAIHIGH:  DB      008H,010H,020H,010H
            DB      0F8H,000H,000H,000H
MALAI:      DB      000H,000H,000H,000H
            DB      0FFH,0C0H,000H,000H
YAMOK:      DB      000H,0F0H,0D0H,020H
            DB      010H,010H,0F0H,000H
YAMOKLOW:   DB      000H,000H,018H,004H
            DB      002H,002H,001H,000H
PAIYAN:     DB      008H,014H,010H,010H
            DB      008H,004H,0FEH,000H
SARAUH:     DB      000H,000H,000H,000H
            DB      004H,00AH,03CH,000H
SARAUU:     DB      000H,000H,000H,004H
            DB      00AH,03CH,020H,03EH
SARAI:      DB      000H,030H,048H,048H
            DB      048H,050H,060H,000H
SARAE:      DB      030H,028H,028H,028H
            DB      038H,03CH,000H,000H
SARAAU:     DB      000H,003H,048H,048H
            DB      048H,050H,068H,030H
SARAAUE:    DB      000H,030H,048H,048H
            DB      050H,058H,060H,078H
HUN:        DB      000H,030H,068H,050H
            DB      040H,040H,020H,010H
NAMFON:     DB      000H,018H,024H,024H
            DB      014H,008H,000H,000H
TAIKU:      DB      070H,048H,028H,028H
            DB      048H,068H,064H,000H
MAIAKE:     DB      000H,000H,000H,000H
            DB      000H,070H,000H,000H
MAITO:      DB      000H,040H,068H,058H
            DB      040H,040H,020H,010H
MAITEE:     DB      078H,048H,010H,018H
            DB      008H,078H,020H,01EH
JATAWA:     DB      000H,000H,010H,010H
            DB      07CH,010H,010H,000H
KARAN:      DB      000H,070H,050H,010H
            DB      010H,00CH,000H,000H
AKEUM:      DB      000H,030H,048H,048H
            DB      048H,030H,006H,000H
TOUM:       DB      002H,036H,04CH,04CH
            DB      04AH,031H,000H,000H
TEEUM:      DB      006H,035H,04AH,049H
            DB      04EH,034H,002H,001H
TAWAUM:     DB      000H,030H,048H,04AH
            DB      04AH,037H,002H,002H
AKEHAN:     DB      070H,050H,070H,040H
            DB      040H,04CH,020H,010H
TOHAN:      DB      070H,052H,076H,044H
            DB      044H,044H,022H,011H
TEEHAN:     DB      070H,057H,075H,042H
            DB      041H,047H,024H,017H
TAWAHAN:    DB      070H,050H,074H,044H
            DB      04EH,044H,020H,010H
AKEI:       DB      000H,060H,050H,050H
            DB      050H,050H,066H,000H
TOI:        DB      000H,060H,052H,056H
            DB      054H,054H,062H,001H
TEEI:       DB      000H,06EH,05AH,054H
            DB      052H,05EH,068H,007H
TAWAI:      DB      000H,060H,050H,052H
            DB      052H,057H,062H,002H
KARANI:     DB      000H,060H,050H,050H
            DB      050H,05CH,06AH,001H
AKEE:       DB      060H,050H,050H,050H
            DB      050H,050H,07BH,000H
TOE:        DB      060H,052H,056H,054H
            DB      054H,052H,079H,000H
TEEE:       DB      06EH,05AH,054H,052H
            DB      05EH,054H,07AH,001H
TAWAE:      DB      060H,050H,052H,052H
            DB      057H,052H,07AH,000H

            END


สามารถ download ไฟล์ตัวอย่างของบอร์ด พร้อม assembler ได้เลยครับ


เขียนโดย : ETT
Author : ETT team
e-mail : sales@etteam.com
วันที่ทำการปรับปรุง : ๒๘ ธ.ค. ๒๕๔๓