thedarkshade Posted November 13, 2011 Posted November 13, 2011 (edited) Hey everyone. I've been working for quite a while on this one. I've been trying to make a VT100 terminal emulator through serial port (RS232 standard) using Easy8051A development board. I've written down the entire code for writing from hyperterminial (yeah, I nedded XP for that) to a 2x16 LCD (8-bit mode) and also for writing from the board to hyperterminal, but I got stuck trying to bring the two together. I know I must somehow use serial interrupts to check whether a key has been pressed or not but I can't just quite figure it out. I'll post the code down here, just in case anyone has any bit of idea of how could I proceed. This is the code to write to the LCD (control codes including): ESC EQU 1BH ORG 0000H LJMP MAIN ORG 0023H MAIN: BUSY BIT P0.7 E BIT P2.4 RS BIT P2.2 RW BIT P2.3 MOV A, PCON SETB ACC.7 MOV PCON, A MOV SCON, #52h MOV TMOD, #20h MOV TH1, #-35 SETB EA SETB ES SETB PS SETB TR1 CALL LCD_INIT; PRANO: JNB RI, $ ; KONTROLLO A ESHTE SHRYPUR NDOJE KARAKTER CLR RI MOV A, SBUF CHECK_DEL: CJNE A, #7FH, CONTINUE LJMP CLEAR_LCD LJMP NEXT CONTINUE: CJNE A, #ESC, NO_ESC1 CLR P1.7 JNB RI, $ CLR RI MOV A, SBUF CJNE A, #'[', NO_KLLAPA JNB RI, $ CLR RI MOV A, SBUF CJNE A, #'C', CHECK_D LCALL MOVE_LEFT LJMP NEXT CHECK_D: CJNE A, #'D', CHECK_A LCALL MOVE_RIGHT LJMP NEXT CHECK_A: CJNE A, #'A', CHECK_B LCALL MOVE_UP LJMP NEXT CHECK_B: CJNE A, #'B', NEXT LCALL MOVE_DOWN LJMP NEXT NO_ESC1: LJMP NO_ESC MOVE_LEFT: MOV A, #14H ACALL COMMAND RET MOVE_RIGHT: MOV A, #10H ACALL COMMAND RET MOVE_UP: LCALL READY MOV A, P0 ANL A,#00111111B MOV R7, A MOV A, #40H SUBB A, R6 MOV R6, A MOV A, R7 SETB ACC.7 ACALL COMMAND RET MOVE_DOWN: LCALL READY MOV A, P0 ANL A, #00111111B MOV R6, A MOV A, #40H ADD A, R6 MOV R7, A MOV A, R7 SETB ACC.7 ACALL COMMAND RET CLEAR_LCD: MOV A, #01H CALL COMMAND NO_KLLAPA: LJMP NEXT ;****************************************************************** LCD_INIT: ;* MOV A, #38H ; 2 Linja 5x7 ;* ACALL COMMAND ;* MOV A, #0DH ;Aktivizimi i Kursorit (Blinkues) ;* ACALL COMMAND ;* MOV A, #01H ;Fshirja e ekranit ;* ACALL COMMAND ;* MOV A, #06H ;Vendosja e Kursorit Ne Te Djathe ;* ACALL COMMAND ;* RET ;* ;* \ ;*=================\ COMMAND: ;*==================\ ACALL READY ;*==================/ Pergaditja e LCD-se MOV P0, A ;*=================/ CLR RS ;* / CLR RW ;* SETB E ;* CLR E ;* RET ;* ;* ;* ;* READY: ;* SETB BUSY ;* MOV P0, #0FFH ;* CLR RS ;* SETB RW ;* BACK: ;* CLR E ;* SETB E ;* JB BUSY, BACK ;* RET ;* ;* ;****************************************************************** NO_ESC: LCALL LCD_DISPLAY CPL A MOV P1,A NEXT: SETB P1.7 LJMP PRANO LCD_DISPLAY: ACALL READY CLR E MOV P0, A SETB RS CLR RW SETB E CLR E RET STOP: END This is the code for hyperterminal-to-board: ORG 0000H MOV A, PCON ;| SETB ACC.7 ;|------->Mundesimi i Dyfishimit te Baud-Rate (SMOD=1) MOV PCON, A ;| ;----------------| MOV SCON, #52H ;Pori Serik, Modi 1 MOV TMOD, #20H ;Timeri-i 1, Modi 2 MOV TH1, #-35 ; 1200 baud-rate SETB TR1 ; Starton timer-in 1 WRITE_TO_TERMINAL: JB P0.0, CHECK_B WRITE_A: MOV A, #41H CALL OUTCHR CHECK_B:JB P0.1, CHECK_C WRITE_B: MOV A, #42H CALL OUTCHR CHECK_C:JB P0.2, CHECK_D WRITE_C: MOV A, #43H CALL OUTCHR CHECK_D:JB P0.3, CHECK_E WRITE_D: MOV A, #44H CALL OUTCHR CHECK_E: JB P0.4, CHECK_F WRITE_E: MOV A, #45H CALL OUTCHR CHECK_F:JB P0.5, CHECK_G WRITE_F: MOV A, #46H CALL OUTCHR CHECK_G:JB P0.6, CHECK_H WRITE_G: MOV A, #47H CALL OUTCHR CHECK_H:JB P0.7, CHECK_I WRITE_H: MOV A, #48H CALL OUTCHR CHECK_I:JB P1.0, CHECK_J WRITE_I: MOV A, #49H CALL OUTCHR CHECK_J: JB P1.1, CHECK_K WRITE_J: MOV A, #04AH CALL OUTCHR CHECK_K: JB P1.2, CHECK_L WRITE_K: MOV A, #04BH CALL OUTCHR CHECK_L: JB P1.3, CHECK_M WRITE_L: MOV A, #04CH CALL OUTCHR CHECK_M: JB P1.4, CHECK_N WRITE_M: MOV A, #04DH CALL OUTCHR CHECK_N: JB P1.5, CHECK_O WRITE_N: MOV A, #04EH CALL OUTCHR CHECK_O: JB P1.6, CHECK_P WRITE_O: MOV A, #04FH CALL OUTCHR CHECK_P: JB P1.7, CHECK_Q WRITE_P: MOV A, #50H CALL OUTCHR CHECK_Q: JB P2.0, CHECK_R WRITE_Q: MOV A, #51H CALL OUTCHR CHECK_R: JB P2.1, CHECK_S WRITE_R: MOV A, #52H CALL OUTCHR CHECK_S: JB P2.2, CHECK_T WRITE_S: MOV A, #53H CALL OUTCHR CHECK_T: JB P2.3, CHECK_U WRITE_T: MOV A, #54H CALL OUTCHR CHECK_U: JB P2.4, CHECK_V WRITE_U: MOV A, #55H CALL OUTCHR CHECK_V: JB P2.5, CHECK_W WRITE_V: MOV A, #56H CALL OUTCHR CHECK_W: JB P2.6, CHECK_X WRITE_W: MOV A, #57H CALL OUTCHR CHECK_X: JB P2.7, CHECK_Y WRITE_X: MOV A, #58H CALL OUTCHR CHECK_Y: JB P3.2, CHECK_Z WRITE_Y: MOV A, #59H CALL OUTCHR CHECK_Z: JB P3.3, CHECK_SPACE WRITE_Z: MOV A, #05AH CALL OUTCHR CHECK_SPACE: JB P3.4, CHECK_AGAIN WRITE_SPACE: MOV A, #' ' CALL OUTCHR CHECK_AGAIN: LCALL WRITE_TO_TERMINAL OUTCHR: JNB TI, OUTCHR CLR TI CALL VONESA MOV SBUF, A CALL WRITE_TO_TERMINAL VONESA: MOV R6, #0FFH MOV R7, #05FH PERS: MOV R5, #0FFH DJNZ R5, $ DJNZ R7, $ DJNZ R6, PERS RET STOP: END and this is how I've tried to bring the two together (unsuccessfully): ESC EQU 1BH ORG 0000H LJMP MAIN ORG 0023H LJMP ISR ORG 0030H MAIN: BUSY BIT P0.7 E BIT P2.4 RS BIT P2.2 RW BIT P2.3 MOV A, PCON SETB ACC.7 MOV PCON, A MOV SCON, #52h MOV TMOD, #20h MOV TH1, #-35 SETB EA SETB ES SETB PS SETB TR1 CALL LCD_INIT; PRANO: JNB RI, $ ; KONTROLLO A ESHTE SHRYPUR NDOJE KARAKTER CLR RI JNB P1.0, GO_INT_I JNB P1.1, GO_INT_J JNB P1.2, GO_INT_K JNB P1.3, GO_INT_L JNB P1.4, GO_INT_M JNB P1.5, GO_INT_N JNB P1.6, GO_INT_O JNB P1.7, GO_INT_P MOV A, SBUF JMP CHECK_DEL GO_INT_I: CLR P1.0 MOV IE, #90H JMP PRANO GO_INT_J: CLR P1.1 MOV IE, #90H JMP PRANO GO_INT_K: CLR P1.2 MOV IE, #90H JMP PRANO GO_INT_L: CLR P1.3 MOV IE, #90H JMP PRANO GO_INT_M: CLR P1.4 MOV IE, #90H JMP PRANO GO_INT_N: CLR P1.5 MOV IE, #90H JMP PRANO GO_INT_O: CLR P1.6 MOV IE, #90H JMP PRANO GO_INT_P: CLR P1.7 MOV IE, #90H JMP PRANO CHECK_DEL: CJNE A, #7FH, CONTINUE LJMP CLEAR_LCD LJMP NEXT CONTINUE: CJNE A, #ESC, NO_ESC1 CLR P1.7 JNB RI, $ CLR RI MOV A, SBUF CJNE A, #'[', NO_KLLAPA JNB RI, $ CLR RI MOV A, SBUF CJNE A, #'C', CHECK_D LCALL MOVE_LEFT LJMP NEXT CHECK_D: CJNE A, #'D', CHECK_A LCALL MOVE_RIGHT LJMP NEXT CHECK_A: CJNE A, #'A', CHECK_B LCALL MOVE_UP LJMP NEXT CHECK_B: CJNE A, #'B', NEXT LCALL MOVE_DOWN LJMP NEXT NO_ESC1: LJMP NO_ESC MOVE_LEFT: MOV A, #14H ACALL COMMAND RET MOVE_RIGHT: MOV A, #10H ACALL COMMAND RET MOVE_UP: LCALL READY MOV A, P0 ANL A,#00111111B MOV R7, A MOV A, #40H SUBB A, R6 MOV R6, A MOV A, R7 SETB ACC.7 ACALL COMMAND RET MOVE_DOWN: LCALL READY MOV A, P0 ANL A, #00111111B MOV R6, A MOV A, #40H ADD A, R6 MOV R7, A MOV A, R7 SETB ACC.7 ACALL COMMAND RET CLEAR_LCD: MOV A, #01H CALL COMMAND NO_KLLAPA: LJMP NEXT ;****************************************************************** LCD_INIT: ;* MOV A, #38H ; 2 Linja 5x7 ;* ACALL COMMAND ;* MOV A, #0DH ;Aktivizimi i Kursorit (Blinkues) ;* ACALL COMMAND ;* MOV A, #01H ;Fshirja e ekranit ;* ACALL COMMAND ;* MOV A, #06H ;Vendosja e Kursorit Ne Te Djathe ;* ACALL COMMAND ;* RET ;* ;* \ ;*=================\ COMMAND: ;*==================\ ACALL READY ;*==================/ Pergaditja e LCD-se MOV P0, A ;*=================/ CLR RS ;* / CLR RW ;* SETB E ;* CLR E ;* RET ;* ;* ;* ;* READY: ;* SETB BUSY ;* MOV P0, #0FFH ;* CLR RS ;* SETB RW ;* BACK: ;* CLR E ;* SETB E ;* JB BUSY, BACK ;* RET ;* ;* ;****************************************************************** NO_ESC: LCALL LCD_DISPLAY CPL A MOV P1,A NEXT: MOV P1, #0FFH LJMP PRANO LCD_DISPLAY: ACALL READY CLR E MOV P0, A SETB RS CLR RW SETB E CLR E RET ISR: WRITE_TO_TERMINAL: CHECK_I:JB P1.0, CHECK_J WRITE_I: MOV A, #49H CALL OUTCHR CHECK_J: JB P1.1, CHECK_K WRITE_J: MOV A, #04AH CALL OUTCHR CHECK_K: JB P1.2, CHECK_L WRITE_K: MOV A, #04BH CALL OUTCHR CHECK_L: JB P1.3, CHECK_M WRITE_L: MOV A, #04CH CALL OUTCHR CHECK_M: JB P1.4, CHECK_N WRITE_M: MOV A, #04DH CALL OUTCHR CHECK_N: JB P1.5, CHECK_O WRITE_N: MOV A, #04EH CALL OUTCHR CHECK_O: JB P1.6, CHECK_P WRITE_O: MOV A, #04FH CALL OUTCHR CHECK_P: JB P1.7, CHECK_AGAIN WRITE_P: MOV A, #50H CALL CHECK_AGAIN CHECK_AGAIN: RETI OUTCHR: JNB TI, OUTCHR CLR TI CALL VONESA MOV SBUF, A CLR EA RETI VONESA: MOV R6, #0FFH MOV R7, #05FH PERS: MOV R5, #0FFH DJNZ R5, $ DJNZ R7, $ DJNZ R6, PERS RET END I know it's exceedingly boring to go through it all (neither I expext you to) but I'd really appreciate every idea on how to bring the two together. Regards, TDS Edited November 13, 2011 by thedarkshade
moth Posted November 14, 2011 Posted November 14, 2011 Is your keyboard connected to the 8051 or your PC? If you could add some comments to your code it will make it a little easier to sort out.
thedarkshade Posted November 14, 2011 Author Posted November 14, 2011 No no, I'm using pushbuttons on the board as keys. I got it to work lasht night actually. I seem to have been carrying a bit from the ISR routine that was causing me trouble. P.s. I apologize for lack of comments (not a good programmer). Some of the labels too are in my native language
thedarkshade Posted November 14, 2011 Author Posted November 14, 2011 Oh, and btw is there something like "8051 LCD command list" like the 'enter command' or 'backspace'? The ones I have above (move_left, move_right, del,...) I collected from several books I happen to have on microcontrollers, but I feel my project's lacking a taste of completeness.
moth Posted November 15, 2011 Posted November 15, 2011 No no, I'm using pushbuttons on the board as keys. O.K. I was wondering why there's no translation from keyboard scan codes to ascii. You've probably seen the sample code from this page already, but just in case here's a link.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now