; ********************************************************************** ; * File S1DEB2.asm board: GPC 552 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 17.09.04 * ; ********************************************************************** ; DEB 01's example program of section 1, driven from a GPC 552. ; This section is composed by 16 keys conncted to 16 LEDs: ; the pressure of one or more of these keys, sets the logic state 0 on ; the line and the relative LED is lit by hardware. ; This program has to comunicate with the PC and visualize on monitor ; the decimal code (from 0 to 255) of the status of both ports: ; practically, pressing the DEB 01 keys, you can modify the represented ; status. ; For cursor movement and positioning, are used some command sequences ; with ADDS Viewpoint standard (see GET51 manual). ; The connection is realized through one 20 pins flat cable that interface ; CN2 connector of GPC 552 and CN15 connector of DEB 01. ; ; ; Addresses of on board peripherals ; PDA EQU 0FFF8H ;82c55's data register of port A PDC EQU 0FFFAH ;82c55's data register of port C CNT EQU 0FFFBH ;82c55's control and command register ; ; Initialization of constant data ; INIT EQU 99H ;mode 0;port A and C in input, B in output RXCHAR EQU 0CH ;variable with the value received on serial port TXCHAR EQU 0DH ;variable with the value for the transmission PORTA EQU 08H ;internal memory address with portA value PORTC EQU 09H ;internal memory address with portC value UNITY EQU 0EH ;variable with the value of unity TENS EQU 0FH ;variable with the value of tens HUNDREDS EQU 10H ;veriable with the value of hundreds RECEIVED EQU 01H ;reception bit of serial port:1 for received chr,0 for nothing ; ; Start of main program ; ORG 2050H ;beginning of executable part program MAIN: MOV SP,#2FH ;initialize the first free location pointer of the stack MOV DPTR,#CNT ;initialization of PPI 82c55 as indicated in INIT MOV A,#INIT MOVX @DPTR,A ;write to 82C55's control register control word CLR RS0 ;select the registers bank 0 (00H-07H) CLR RS1 ACALL SERIAL MOV DPTR,#HEADING ;print to monitor the "HEADING" string ACALL STRING ; ; Start of principal program cycle ; CYCLE: ACALL INPORTS ;read the ports A and C MOV TXCHAR,#1AH ;move cursor up ACALL TRASMSER MOV A,PORTA ACALL ASCII ;transform to ASCII code the PORTA value ACALL TRASCII ;transmission of PORTA value MOV TXCHAR,#0AH ;move cursor down ACALL TRASMSER MOV A,PORTC ACALL ASCII ;transform to ASCII code the PORTC value ACALL TRASCII ;transmission of PORTC value SJMP CYCLE ;jump to the reading of ports of DEB 01 ; ; Procedure that acquire the value of ports A and C ; INPORTS: PUSH PSW ;save the registers used by procedure PUSH DPL PUSH DPH PUSH ACC MOV DPTR,#PDA ;put the port A value MOVX A,@DPTR ;in PORTA variable MOV PORTA,A MOV DPTR,#PDC ;put the port C value MOVX A,@DPTR ;in PORTC variable MOV PORTC,A POP ACC ;restore the registers used by procedure POP DPH POP DPL POP PSW RET ; ; 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 TI,TRASM2 ;jump to TRASM2 if TI = 1 and reset TI SJMP TRASM1 ;jump to TRASM1 because TI = 0 ;and serial is still in transmission TRASM2: MOV SBUF,TXCHAR 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 ; ; HEADING: DB 0CH,' Writes on the monitor of the -development system- the status of both the ports.',1DH,1DH,'Port A: ',1DH,'Port C: ',00H END