; ********************************************************************** ; * File S1DEB9.asm board: GPC F2 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 05.08.04 * ; ********************************************************************** ; DEB 01's example program of section 1, driven from a GPC F2. ; 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 PC and shifts the lighting of one LED ; from the left to the right and the lighting of another LED from the right ; to the left. ; 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 F2 and CN15 connector of DEB 01. ; ; ; ; Addresses of on board peripherals ; PDA EQU 0FA00H ;82c55's data register of port A PDB EQU 0FA01H ;82c55's data register of port B PDC EQU 0FA02H ;82c55's data register of port C CNT EQU 0FA03H ;82c55's control and command register ; ; Initialization of constant data ; INIT EQU 82H ;mode 0;port A and C in output,port B in input TXCHAR EQU 0DH ;variable with the value for the transmission PORTA EQU 08H ;internal memory address with portA value PORTB EQU 0AH ;internal memory address with portB value PORTC EQU 09H ;internal memory address with portC value DELAY EQU 11H ;variable used in delay subroutine ; ; Start of main program ; ORG 8050H ;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 MOV PORTA,#0FEH ;put beginning values for both ports MOV PORTC,#07FH ; ; CYCLE: ACALL SHIFT ;execute shifts AJMP CYCLE ; ; Subroutine to show the acquire data on Port A ; OUTPORTAC: PUSH PSW ;save registers used by subroutine PUSH DPL PUSH DPH PUSH ACC MOV A,PORTA ;save the PORTA variable data on A MOV DPTR,#PDA ;load the Port A address MOVX @DPTR,A ;write data on port A MOV A,PORTC ;save the PORTC variable data on A MOV DPTR,#PDC ;load the Port C address MOVX @DPTR,A ;write data on Port C POP ACC ;restore registers used by subroutine 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 subroutine 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 subroutine 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 ; ; Subroutine for delay of 100 microseconds variable with R2 ; DELAY100: MOV DELAY,#60 ;60 cycles to obtain 100 usec delay DJNZ DELAY,$ ;defined by measure DJNZ R2,DELAY100 RET ; ; Subroutine to create the shifts ; SHIFT: MOV R0,#07 ;execute seven cycle to shift both ports SHIFT1: MOV R2,#50 ;50 is value to obtain msec delay MOV R3,#03 ;repeat 50 msec delay 3 times WAITH1: ACALL DELAY100 ;100 usec delay DJNZ R3,WAITH1 ACALL OUTPORTAC ;visualize PORTA and PORTC contents MOV A,PORTA RL A ;lighting LED shift left on port 0 MOV PORTA,A MOV A,PORTC RR A ;lighting LED shift right on port 1 MOV PORTC,A DJNZ R0,SHIFT1 ;reached last LED on port 0 MOV R0,#07 SHIFT2: MOV R2,#50 MOV R3,#03 ;repeat 50 msec delay 3 times WAITH2: ACALL DELAY100 ;100 usec delay DJNZ R3,WAITH2 ACALL OUTPORTAC ;visualize PORTA and PORTC contents MOV A,PORTA RR A ;lighting LED shift right on port 0 MOV PORTA,A MOV A,PORTC RL A ;lighting LED shift left on port 1 MOV PORTC,A DJNZ R0,SHIFT2 ;reached last LED on port 1 RET ; ; HEADING: DB 0CH,' Shifts the lighting of one LED from the left to the right and the lighting of',1DH,' another LED from the right to left.',00H END