; Test Board 1 ; $NOMOD51 $INCLUDE (S8252.MCU) $TITLE(APRS Device) ;=============================================== ; HISTORY ; ; 01 LCD driver ; ;=============================================== BUZZER EQU P1.0 LCD_E EQU P3.5 LCD_RS EQU P2.0 CSEG ;******************************************************* ;***** Reset Here ;******************************************************* ORG 0000h ; Restart JMP Main ORG 0003h ; External 0 JMP Int_EXT0 ORG 000Bh ; Timer 0 JMP Int_TMR0 ORG 0013h ; External 1 JMP Int_EXT1 ORG 001Bh ; Timer 1 JMP Int_TMR1 ORG 0023h ; Serial Port JMP Int_SER ORG 002Bh ; Timer or External 2 JMP Int_INT2 ;******************************************************* ;***** Interrupts ;******************************************************* Int_EXT0: Int_TMR1: Int_TMR0: Int_EXT1: Int_SER: Int_INT2: RETI ;******************************************************* ;******************************************************* ;******************************************************* ;***** Main Program starts here ;******************************************************* ;******************************************************* ;******************************************************* Main: MOV IE,#00h ; No Interrupt MOV P1,#0FFh CALL Serial_Init CALL Beep CALL LCD_Init MOV A,#10000000b CALL LCD_Com_S ; MOV DPTR,#Text_Startup ; CALL LCD_Text ; MOV DPTR,#STxt_AT ; CALL RS232_Text MOV DPTR,#STxt_ATE0 ; Disable ECHO CALL RS232_Text CALL Wait_1Sec ; Wait and CLR RI ; flush serial MOV DPTR,#STxt_AT+CGMI CALL RS232_Text Main_Loop: CALL RS232_In CALL LCD_Chr JMP Main_Loop ;******************************************************* ;***** Subs ;******************************************************* ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Serial Baud Rate is 19200 baud using Timer 2 on 24 MHz Xtal MODE 1 ; 24000000/32 /39 = 19230 Baud ; 65536-39=65497 =FFD9 Serial_Init: MOV SCON,#01010000b MOV RCAP2H,#0FFh ; Reload value MOV RCAP2L,#0D9h MOV T2CON,#034h ; Baudrate for Tx and Rx CLR RI ; Clear reception flag. SETB TI ; Enable Tx RET RS232_Text: CLR A MOVC A,@A+DPTR JZ End_RS232_Text PUSH DPL PUSH DPH CALL RS232_Chr POP DPH POP DPL INC DPTR SJMP RS232_Text End_RS232_Text: RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Write Accumulator as HEX to RX232 RS232_Hex: PUSH ACC SWAP A CALL RS232_Nibble POP ACC RS232_Nibble: ANL A,#00Fh ADD A,#246 JC RS232_Hex_Out ADD A,#58 SJMP RS232_Chr RS232_Hex_Out: ADD A,#65 SJMP RS232_Chr ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Write Accumulator to RX232, Clear TI during init !!! RS232_Chr: JNB TI,$ ; Wait for transmitt ready (TI set) CLR TI MOV SBUF,A ; Send character RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Write Accumulator to RX232, put dot for > 127 or <32 RS232_ASC: JB ACC.7,RS232_ASC_I ; Anything with bit 7 is unprintable INC A JB ACC.7,RS232_ASC_I ; Also 127 (Delete) DEC A JB ACC.6,RS232_Chr ; Bits 6 or 5 set is 32 to 127 is printable JB ACC.5,RS232_Chr RS232_ASC_I: MOV A,#191 ; Upside down ? in most fonts !!! JMP RS232_Chr ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Receive RS232 into Accumulator RS232_In: JNB RI,$ ;Wait until character received. MOV A,SBUF ;Read input character. CLR RI ;Clear reception flag. RET ; ; ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Beep Beep: MOV R1,#150 Beep_Loop: CLR BUZZER MOV R0,#100 Bp_Lp_1: DJNZ R0,Bp_Lp_1 SETB BUZZER MOV R0,#100 Bp_Lp_2: DJNZ R0,Bp_Lp_2 DJNZ R1,Beep_Loop RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Wait 40 usec S_Wait: MOV R0,#40 ; Wait 40us S_W_L: DJNZ R0,S_W_L RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Wait for 2000usec Wait_2000: L_Wait: MOV R0,#22 ; Wait 2000us L_WL_1: MOV R1,#100 ; 100 * 20 L_WL_2: DJNZ R1,L_WL_2 ; 2 cycles=1us at 24MHz DJNZ R0,L_WL_1 RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Wait for 1 msec Wait_1000: MOV R0,#5 ; Wait 1500us W10_WL_1: MOV R1,#100 ; 100 * 15 W10_WL_2: DJNZ R1,W10_WL_2 ; 2 cycles=1us at 24MHz DJNZ R0,W10_WL_1 RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Wait for 1.5 msec Wait_1500: MOV R0,#15 ; Wait 1500us W15_WL_1: MOV R1,#100 ; 100 * 15 W15_WL_2: DJNZ R1,W15_WL_2 ; 2 cycles=1us at 24MHz DJNZ R0,W15_WL_1 RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Wait for 20 msec Wait_20m: MOV R0,#200 ; Wait 20 000 us W20_WL_1: MOV R1,#100 ; 100 * 200 W20_WL_2: DJNZ R1,W20_WL_2 ; 2 cycles=1us at 24MHz DJNZ R0,W20_WL_1 RET ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ; Wait for 1 second Wait_1Sec: MOV R0,#25 ; Wait 25 x 40000us W1S_1: MOV R1,#200 ; 200 x 200us W1S_2: MOV R2,#200 W1S_3: DJNZ R2,W1S_3 DJNZ R1,W1S_2 ; 2 cycles=1us at 24MHz DJNZ R0,W1S_1 RET LCD_Text: CLR A MOVC A,@A+DPTR JZ End_LCD_Text PUSH DPL PUSH DPH LCALL LCD_Chr POP DPH POP DPL INC DPTR SJMP LCD_Text End_LCD_Text: RET ; Add HEX to LCD Buffer LCD_Hex: PUSH ACC SWAP A CALL LCD_Nibble POP ACC LCD_Nibble: ANL A,#00Fh ADD A,#246 JC LCD_Hex_Out ADD A,#58 SJMP LCD_Chr LCD_Hex_Out: ADD A,#65 SJMP LCD_Chr LCD_Init: CLR LCD_E CALL L_Wait MOV A,#00111000B ; 8bit, 2lines, font5x7 CALL LCD_Com MOV A,#00001111B ; display on, cursor, blink CALL LCD_Com MOV A,#00000001B ; Clear Disp CALL LCD_Com RET LCD_Com: CLR LCD_RS MOV P0,A ; Use Add/Data for LCD Data SETB LCD_E NOP NOP CLR LCD_E CALL L_WAIT RET LCD_Com_S: CLR LCD_RS MOV P0,A SETB LCD_E NOP NOP CLR LCD_E CALL S_WAIT CALL S_WAIT RET LCD_Chr: SETB LCD_RS MOV P0,A SETB LCD_E NOP NOP CLR LCD_E CALL S_Wait RET Text_Startup: DB "LCD Module",0 Stxt_AT: DB "AT",13,0 STxt_ATE0: DB "ATE0",13,0 END