; ********************************************************************** ; * File Demo_INT.asm board: GPC 554 with SXA51 * ; * GRIFO(R) via Dell'Artigiano 8/6 40016 S. Giorgio di Piano (BO) * ; * Tel. +39 051 892052 Fax. +39 051 893661 * ; * http://www.grifo.it http://www.grifo.com * ; * by Alessio Francesconi 06.10.04 * ; ********************************************************************** ; This program has to comunicate with PC and work with serial interrupts. ; With any pressure of "development system" keys, the reception serial ; interrupt is actived, and the received character is put in a circolar buffer ; composed by ten memory locations. ; It prints to monitor both the ASCII code each characters, and a ; counter of serial interrupts. ; For cursor movement and positioning, are used some command sequences ; with ADDS Viewpoint standard (see GET51 manual). ; ; Initialization of constant data ; STCODE EQU 2050H ;FMO52 address for user RAM STDATA EQU 3000H ;beginning address for external data RAM ; TXCHAR EQU 0DH ;variable with the value for the transmission UNITY EQU 0EH ;variable with the value of unity TENS EQU 0FH ;variable with the value of tens HUNDREDS EQU 10H ;variable with the value of hundreds DELAY EQU 12H ;variable used in delay subroutine POINT_W EQU 11H ;variable with write pointer to circular buffer POINT_R EQU 13H ;variable with read pointer to circular buffer TRA_OK BIT 16H ;variable that follows behaviour of TI COUNT EQU 17H ;counter variable for received chr number ; ; Start of main program ; ORG STCODE ;beginning of code in STCODE AJMP MAIN ; ORG STCODE+0023H ;redirect interrupt serial vector AJMP INTERRUPT ; ORG STCODE+0100H ;shift the code to reserve space for interrupt vectors ; MAIN: MOV SP,#2FH ;initialize the first free location pointer of the stack CLR RS0 ;select the registers bank 0 (00H-07H) CLR RS1 ACALL SERIAL ;initialize serial line SETB IP.4 ;enable serial interrupts priority SETB IE.4 ;enable serial interrupts SETB IE.7 ;enable all interrupts CLR TRA_OK ;set to 0 the reflect TI flag MOV DPTR,#HEADING ;print to monitor the "HEADING" string ACALL STRING MOV POINT_W,#00 ;initialize to 0 the write pointer MOV POINT_R,#00 ;initialize to 0 the read pointer MOV COUNT,#00 ;initialize the receiver chr counter ; ; Start of main program cycle ; CYCLE: MOV A,POINT_R ;check if read pointer and write pointer are CJNE A,POINT_W,DIFFERENT ;in the same location, if so there isn't SJMP CYCLE ;new received chararcter DIFFERENT: MOV DPL,POINT_R ;put read pointer in DPTR MOV DPH,HIGH BUFFER MOVX A,@DPTR ;get character from circolar buffer INC POINT_R ;increase read pointer MOV TXCHAR,#1AH ;cursor up ACALL TRASMSER ACALL ASCII ;translate binary code to ASCII code ACALL TRASCII ;send to serial the obtained ASCII code MOV TXCHAR,#0AH ;cursor down ACALL TRASMSER MOV A,COUNT ;send to serial the interrupts counter ACALL ASCII ACALL TRASCII MOV A,POINT_R ;check if read pointer arrives to CJNE A,#10,CYCLE ;tenth location of buffer to make it MOV POINT_R,#00 ;circular AJMP CYCLE ; ; Serial initialization procedure ; SERIAL: PUSH PSW ;save PSW MOV SCON,#50H ;select mode 1, active reception MOV TH1,#253 ;initialize to 19200 baud ANL PCON,#7FH ;reset the bit 7 of PCON (SMOD) POP PSW ;restore PSW RET ; ; Serial transmission of a string contained in external data memory ; STRING: PUSH PSW ;save registers used by this procedure PUSH ACC PUSH TXCHAR STRINGLOOP: MOVX A,@DPTR ;load into A the memory contents pointed by DPTR JZ ENDSTRING ;if the last reading character is void (00H),jump to end MOV TXCHAR,A ;put the current character into the variable for the transmission ACALL TRASMSER ;transmit the character INC DPTR ;increase the pointer to be ready SJMP STRINGLOOP ;for the following character ENDSTRING: POP TXCHAR ;restore registers used by procedure POP ACC POP PSW RET ; ; Serial transmission's procedure ; TRASMSER: PUSH PSW ;save PSW TRASM1: JBC TRA_OK,TRASM2 ;jump to TRASM2 if TRA_OK = 1 and reset it SJMP TRASM1 ;jump to TRASM1 because TRA_OK = 0 ;and serial is still in transmission TRASM2: MOV SBUF,TXCHAR CLR TRA_OK POP PSW ;restore PSW RET ; ; Procedure that transform the acquire code from ports to decimal code ; ASCII: PUSH PSW ;save the registers used by procedure PUSH ACC PUSH B MOV B,#100 DIV AB ;divide A to 100 to determine hundreds ADD A,#30H ;add to hundreds 30H to trensform it in ASCII code MOV HUNDREDS,A ;save the hundreds MOV A,B ;reload on A the value MOV B,#10 DIV AB ;divide A to 10 to determine tens ADD A,#30H ;add to tens 30H to transform it in ASCII code MOV TENS,A ;save the tens MOV A,B ;reload on A the value ADD A,#30H ;add to unity 30H to transform it in ASCII code MOV UNITY,A ;save the unity POP B ;restore the register used by procedure POP ACC POP PSW RET ; ; Procedure for sending value on screen through serial port ; TRASCII: PUSH PSW ;save the registers used by procedure PUSH ACC PUSH TXCHAR MOV A,HUNDREDS ;check the hundreds are different to '0' CLR F0 ;reset the flag F0 MOV TXCHAR,A ;hundreds in TXCHAR CJNE A,#48,ASCII1 ;if they are different jump to ASCII1 MOV TXCHAR,#20H ;otherwise send a space SETB F0 ;show that hundreds were equal to '0' ASCII1: ACALL TRASMSER MOV A,TENS ;check the tens are different to '0' MOV TXCHAR,A ;tens in TXCHAR CJNE A,#48,ASCII2 ;if they are different send the tens JNB F0,ASCII2 ;otherwise if hundreds were to '0' MOV TXCHAR,#20H ;send a space ASCII2: ACALL TRASMSER MOV TXCHAR,UNITY ;transmit the unity ACALL TRASMSER MOV TXCHAR,#08H ;transmit three shift to left ACALL TRASMSER ACALL TRASMSER ACALL TRASMSER POP TXCHAR ;restore the register used by procedure POP ACC POP PSW RET ; ; Interrupt subroutine ; INTERRUPT: PUSH PSW ;save registers used by subroutine PUSH ACC PUSH DPH PUSH DPL JNB RI,NO_RI ;check if is arrived chr or end of transmission CLR RI ;if rx int.: reset it, INC COUNT ;increase received chr counter MOV DPL,POINT_W ;put write pointer on DPTR MOV DPH,HIGH BUFFER MOV A,SBUF ;load the received chr on ACC MOVX @DPTR,A ;point to buffer location for writing INC POINT_W ;increase write pointer MOV A,POINT_W ;check if write pointer is arrived CJNE A,#10,NO_RI ;to tenth location to make it circular MOV POINT_W,#00 NO_RI: JNB TI,ENDINT SETB TRA_OK ;set the reflect TI flag CLR TI ;reset TI ENDINT: POP DPL ;restore registers used by subroutine POP DPH POP PSW POP ACC RETI ; ; HEADING: DB 0CH,'Program for serial interrupts: ----waiting for characters----',1DH,1DH,'ASCII code character: ',1DH,'Received character number: ',00H ; ORG STDATA ;beginning address for external data RAM BUFFER: DS 10 ;define circular buffer END