A51 MACRO ASSEMBLER  SPOT_WELDER                                                          10/16/2011 00:43:52 PAGE     1


MACRO ASSEMBLER A51 V8.00b
OBJECT MODULE PLACED IN Spot_Welder.OBJ
ASSEMBLER INVOKED BY: C:\Keil\C51\BIN\A51.EXE Spot_Welder.a51 SET(SMALL) DEBUG EP

LOC  OBJ            LINE     SOURCE

                       1     ; Firmware for Welder Synchron Timer 1-99 Halfwaves
                       2     ; AT89C2051
                       3     ; Konstantin Gilsenberg 
                       4     ; slowolitus@rambler.ru 
                       5     ; 20.07.2011 
                       6     
                       7     ; ---------constants-----------
  0063                 8     MAXTIME         EQU 99          ;
  0001                 9     MINTIME         EQU  1      ;
                      10     ;PEDDB       EQU 10             ;pedal debounce constante
  0005                11     KEYDB       EQU 5               ;key debounce delay    (x10mS)
  0046                12     KEYDA           EQU 70          ;key autorepeat delay  (x10mS)   
  000F                13     KEYARR      EQU 15              ;autorepeat rate       (x10mS)          
  0007                14     KEYFARR         EQU 7           ;fast autorepeat rate  (x10mS)
  000A                15     ARCOUNT         EQU 10          ;autorepeat to fast autorepeat count
                      16     
                      17     ; ----------ports--------------
  0092                18     SEG_A   EQU P1.2                ;indicators segment A
  0093                19     SEG_B   EQU P1.3                ;indicators segment B
  0094                20     SEG_C   EQU P1.4                ;indicators segment C
  0095                21     SEG_D   EQU P1.5                ;indicators segment D
  0096                22     SEG_E   EQU P1.6                ;indicators segment E
  0097                23     SEG_F   EQU P1.7                ;indicators segment F
  00B7                24     SEG_G   EQU P3.7                ;indicators segment G
                      25     
  00B1                26     SCAN0   EQU TXD                 ;display scan digit 1
  00B0                27     SCAN1   EQU RXD                 ;display scan digit 2
  00B4                28     KEY_UP  EQU T0                  ;UP   key
  00B3                29     KEY_DN  EQU INT1                ;DOWN key
  00B5                30     PED_IN  EQU T1          ;Pedal input
  00B2                31     FIRE    EQU INT0                ;Fire out
  00B6                32     CP      EQU P3.6                ;comparator
                      33     ;---------- Bit addressing memory
  0020                34     FLAGS   EQU 020H                ;flags
  0021                35     TIME    EQU 021H            ;time set
  0022                36     COUNT   EQU 022H                ;time counter
  0023                37     ZERO    EQU 023H                ;zero crossing register
  0024                38     COMP    EQU 024H        ;comparator state
  0025                39     PED_ST  EQU 025H                ;pedal state prev/curr
  0026                40     KEYDBT  EQU 026H                ;key debounce timer
  0027                41     KEYTM   EQU 027H                ;key timer
  0028                42     PREV    EQU 028H                ;previous key code
  0029                43     REPCNT  EQU 029H                ;repeat counter
                      44     ;---------- Byte addressing memory
  0030                45     UNITS   EQU 030H
  0031                46     TENS    EQU 031H
                      47     ;---------- Flags-----------------
  0000                48     ON_OFF  EQU FLAGS.0     ;timer ON/OFF bit
  0001                49     PRESS   EQU FLAGS.1     ;keyboard press bit
  0002                50     DIGIT   EQU FLAGS.2 ;digit
                      51     ;PEDAL   EQU FLAGS.3 ;pedal press bit
  0004                52     HWAVE   EQU FLAGS.4 ;previous halfwave polarity 
                      53     ;----------- Work registers------ 
  REG                 54     PEDDBT  EQU R6
  REG                 55     INTEG   EQU R7
                      56     ;--------- Vectors Area ------------
0000                  57     org     0000h
0000 8029             58                     jmp Begin           ;reset vector
A51 MACRO ASSEMBLER  SPOT_WELDER                                                          10/16/2011 00:43:52 PAGE     2

0003                  59     org     0003h
0003 32               60             reti
000B                  61     org     000Bh
000B 32               62             reti
0013                  63     org     0013h
0013 32               64                     reti
001B                  65     org     001Bh
001B 32               66                     reti
0023                  67     org     0023h
0023 32               68                     reti
                      69     ;---------- Main Program -----------
                      70     ;--------- Initialisation ----------
                      71     using           0
002B                  72     org             002Bh
002B C2AF             73     Begin:          clr EA                          ; interruptions disabled
002D 7590FF           74                     mov P1,#0FFh
0030 75B0FF           75                             mov P3,#0FFh
0033 752101           76                             mov TIME,#MINTIME
0036 852122           77                             mov COUNT,TIME
0039 90019F           78                             mov DPTR,#FONT
003C E4               79                             clr A
003D F528             80                             mov PREV,A
003F F524             81                             mov COMP,A
0041 F525             82                             mov PED_ST,A
0043 F520             83                             mov FLAGS,A
0045 D200             84                             setb ON_OFF
                      85     ;------------------------------------
0047 A2B6             86     MAIN:           mov C,CP                  ;zero crossing detection
0049 E524             87                             mov A,COMP              
004B 33               88                             rlc A
004C F524             89                             mov COMP,A                ;save comparator state in COMP
004E 302005           90                             jnb COMP.0,COM_0
0051 302105           91                             jnb COMP.1,FRONT
0054 80F1             92                             jmp MAIN
0056 3021EE           93             COM_0:  jnb COMP.1,MAIN                           
0059 300024           94             FRONT:  jnb ON_OFF,T_OFF  ;timer is on/off?
005C E525             95                             mov A,PED_ST      ;pedal processing
005E B40105           96                             cjne A,#01h,REF_1
0061 852122           97                             mov COUNT,TIME          ;Timer reload
0064 8007             98                             jmp REF_2
0066 B4031A           99             REF_1:  cjne A,#03h,SUBR
0069 E522            100                             mov A,COUNT                     ;time over?
006B 6016            101                             jz      SUBR
006D 302005          102             REF_2:  jnb COMP.0,NEG          ;check edges (polarity of halfwave)
0070 300410          103                             jnb HWAVE,SUBR          
0073 8003            104                             jmp REF_3
0075 20040B          105             NEG:    jb HWAVE,SUBR           ;negadiv edge detected!
0078 11A7            106             REF_3:  call PULSE                      ;thyristor fire
007A B204            107                             cpl HWAVE
007C 1522            108                             dec COUNT
007E 8003            109                             jmp SUBR
0080 2028EA          110     T_OFF:          jb PED_ST.0,REF_2     ;pedal is pressed?
0083 118B            111     SUBR:           call CK_PEDAL            ;if timer is off 
0085 11B7            112                             call CK_KEY               
0087 3152            113                             call INDIC
0089 80BC            114                             jmp MAIN
                     115     
                     116     ;--------- Pedal check----------
008B D2B5            117     CK_PEDAL:   setb PED_IN                                 ;debounce first step, high frequenc
                             y
008D 7E14            118                             mov     PEDDBT,#20
008F 7400            119                             mov A,#0
0091 A2B5            120     DEB0:           mov C,PED_IN
0093 3400            121                             addc A,#0
0095 DEFA            122                             djnz PEDDBT,DEB0
0097 940A            123                             subb A,#10
A51 MACRO ASSEMBLER  SPOT_WELDER                                                          10/16/2011 00:43:52 PAGE     3

                     124     
0099 4003            125                             jc DEB3
009B C3              126                             clr C
009C 8001            127                             jmp DEB4
                     128     
                     129     ;                       jc  DEB2
                     130     ;                       cjne INTEG,#0,DEB1                      ;debounce second step, inte
                             gration
                     131     ;                       clr C
                     132     ;                       jmp DEB4
                     133     ;  DEB1:    dec INTEG
                     134     ;                       ret
                     135     ;  DEB2:        mov A,#PEDDB
                     136     ;                   subb A,INTEG
                     137     ;                       jc      DEB3
                     138     ;                       inc INTEG
                     139     ;                       ret
                     140     
009E D3              141             DEB3:   setb C
009F E525            142             DEB4:   mov A,PED_ST
00A1 33              143                     rlc A
00A2 5403            144                             anl A,#03h                                        
00A4 F525            145                             mov PED_ST,A                            ;PED_ST.0 current pedal sta
                             te, PED_ST.1 previous pedal state
00A6 22              146                             ret
                     147     ;-------- 6 ms pulse ------------
00A7 C2B2            148     PULSE:      clr FIRE
00A9 11AE            149                             call WAIT_6ms
00AB D2B2            150                             setb  FIRE
00AD 22              151                             ret
                     152     ;-------- Wait 6 ms -------------
00AE 7C0C            153     WAIT_6ms:   mov R4,#12
00B0 7BFF            154               REF2: mov R3,#255
00B2 DBFE            155               REF1: djnz R3,REF1
00B4 DCFA            156                             djnz R4,REF2
00B6 22              157                             ret
                     158     ;======== Keyboard check ========
                     159     
00B7 A2B4            160     CK_KEY:         MOV C,KEY_UP            ;keyboard check
00B9 82B3            161                             ANL C,KEY_DN
00BB 402B            162                             JC  NP                          ;jump if no press
00BD 74FF            163                             MOV A,#0FFH
00BF A2B4            164                             MOV C,KEY_UP
00C1 33              165                             RLC A
00C2 A2B3            166                             MOV C,KEY_DN
00C4 33              167                             RLC A
00C5 F4              168                             CPL A                           ;ACC.1 - UP, ACC.0 - DN
00C6 F8              169                             MOV R0,A
00C7 6528            170                             XRL A,PREV
00C9 701B            171                             JNZ ND
00CB E526            172                             MOV A,KEYDBT             ; Time over?
00CD 6004            173                             JZ DOV
00CF 1526            174                             DEC KEYDBT
00D1 801A            175                             SJMP W1                         ;jump if debounce delay is not over
00D3 B80102          176             DOV:    CJNE R0,#1,NDN
00D6 311B            177                             CALL DO_DN                      ;DOWN pressed
00D8 B80202          178             NDN:    CJNE R0,#2,NUP
00DB 11F4            179                             CALL DO_UP                      ;UP pressed
00DD B80302          180             NUP:    CJNE R0,#3,NUD
00E0 3142            181                             CALL DO_UD                      ;UP+DOWN pressed
00E2 D201            182             NUD:    SETB PRESS
00E4 8007            183                             SJMP W1
00E6 8828            184             ND:             MOV PREV,R0                     ;edge detected!
00E8 C201            185             NP:             CLR PRESS
00EA 752605          186                             MOV KEYDBT,#KEYDB       ;debounce timer load
                     187     
A51 MACRO ASSEMBLER  SPOT_WELDER                                                          10/16/2011 00:43:52 PAGE     4

00ED E527            188             W1:             MOV A,KEYTM
00EF 6002            189                             JZ W2
00F1 1527            190                     DEC KEYTM               ;advance key timer
00F3 22              191             W2:             RET
                     192     
                     193     ;UP key processing:
                     194     
00F4 200108          195     DO_UP:          JB PRESS,UPH    ;jump if key hold
00F7 752746          196                             MOV KEYTM,#KEYDA        ;first press, autorepeat delay load
00FA 752900          197                             MOV REPCNT,#0   ;autorepeat counter clear
00FD 8011            198                             SJMP UP_DO
00FF E527            199             UPH:    MOV A,KEYTM     ;KEYTM check
0101 7017            200                             JNZ UP_RET
0103 C3              201                             CLR C
0104 75270F          202                             MOV KEYTM,#KEYARR       ;load normal repeat rate
0107 E529            203                             MOV A,REPCNT
0109 940A            204                             SUBB A,#ARCOUNT ;REPCNT check
010B 4003            205                             JC UP_DO                ;jump if REPCNT < ARCOUNT
010D 752707          206                             MOV KEYTM,#KEYFARR      ;load fast repeat rate
0110 E521            207             UP_DO:  MOV A,TIME
0112 6463            208                             XRL A,#MAXTIME
0114 6004            209                             JZ UP_RET               ;jump if limit
0116 0521            210                             INC TIME                ;time inc.
0118 0529            211                             INC REPCNT      ;autorepeat counter inc.
011A 22              212             UP_RET: RET
                     213     
                     214     ;DOWN key processing:
                     215     
011B 200108          216     DO_DN:          JB PRESS,DNH    ;jump if key hold
011E 752746          217                             MOV KEYTM,#KEYDA        ;first press, autorepeat delay load
0121 752900          218                             MOV REPCNT,#0   ;autorepeat counter clear
0124 8011            219                             SJMP DN_DO
0126 E527            220             DNH:    MOV A,KEYTM     ;KEYTM check
0128 7017            221                             JNZ DN_RET
012A C3              222                             CLR C
012B 75270F          223                             MOV KEYTM,#KEYARR       ;load normal repeat rate
012E E529            224                             MOV A,REPCNT
0130 940A            225                             SUBB A,#ARCOUNT ;REPCNT check
0132 4003            226                             JC DN_DO                ;jump if REPCNT < ARCOUNT
0134 752707          227                             MOV KEYTM,#KEYFARR      ;load fast repeat rate
0137 E521            228             DN_DO:  MOV A,TIME
0139 6401            229                             xrl A,#MINTIME
013B 6004            230                             jz  DN_RET
013D 1521            231                             DEC TIME                ;time dec.
013F 0529            232                             INC REPCNT      ;autorepeat counter inc.
0141 22              233             DN_RET: RET
                     234     
                     235     ;UP+DOWN key processing:
                     236     
0142 20010C          237     DO_UD:          JB PRESS,UD_RET ;no hold mode
0145 200007          238                             jb ON_OFF,UD_OFF
0148 D200            239                             setb ON_OFF
014A 852122          240                         mov COUNT,TIME              ;Timer reload
014D 8002            241                             jmp UD_RET
014F C200            242             UD_OFF: clr ON_OFF
0151 22              243             UD_RET: RET
                     244     
                     245     ;------------------Indication-----------------------
0152 200008          246     INDIC:          jb ON_OFF,IND1
0155 75300A          247                             mov UNITS,#0Ah  ; "-"
0158 75310A          248                             mov TENS, #0Ah  ; "-"
015B 8012            249                             jmp IND2
015D E521            250     IND1:           mov A,TIME              ; BCD decoding
015F 75F00A          251                             mov B,#10
0162 84              252                             div AB
0163 7005            253                             jnz NZ
A51 MACRO ASSEMBLER  SPOT_WELDER                                                          10/16/2011 00:43:52 PAGE     5

0165 75310B          254                             mov TENS,#0Bh           ; blank code
0168 8002            255                             jmp UN
016A F531            256                     NZ: mov TENS,A
016C 85F030          257                     UN:     mov UNITS,B
016F 200209          258     IND2:       jb DIGIT,IND3
0172 E530            259                 mov A,UNITS          ; indicate units
0174 93              260                             movc A,@A+DPTR
0175 3185            261                             call IND
0177 C2B1            262                             clr  SCAN0
0179 8007            263                             jmp IND4        
017B E531            264             IND3:   mov A,TENS               ; indicate tens
017D 93              265                             movc A,@A+DPTR
017E 3185            266                             call IND
0180 C2B0            267                             clr  SCAN1
0182 B202            268             IND4:   cpl DIGIT       
0184 22              269                             ret
                     270     
0185 D2B1            271     IND:            setb SCAN0
0187 D2B0            272                             setb SCAN1
0189 13              273                             RRC A
018A 9292            274                             MOV SEG_A,C
018C 13              275                             RRC A
018D 9293            276                             MOV SEG_B,C
018F 13              277                             RRC A
0190 9294            278                             MOV SEG_C,C
0192 13              279                             RRC A
0193 9295            280                             MOV SEG_D,C
0195 13              281                             RRC A
0196 9296            282                             MOV SEG_E,C
0198 13              283                             RRC A
0199 9297            284                             MOV SEG_F,C
019B 13              285                             RRC A
019C 92B7            286                             MOV SEG_G,C
019E 22              287                             RET
                     288     
                     289     ;Font table
                     290     ;                   GFEDCBA
019F                 291     FONT:
019F C0              292                             DB 11000000B    ;code 00H, character 0
01A0 F9              293                             DB 11111001B    ;code 01H, character 1
01A1 A4              294                             DB 10100100B    ;code 02H, character 2
01A2 B0              295                             DB 10110000B    ;code 03H, character 3
01A3 99              296                             DB 10011001B    ;code 04H, character 4
01A4 92              297                             DB 10010010B    ;code 05H, character 5
01A5 82              298                             DB 10000010B    ;code 06H, character 6
01A6 F8              299                             DB 11111000B    ;code 07H, character 7
01A7 80              300                             DB 10000000B    ;code 08H, character 8
01A8 90              301                             DB 10010000B    ;code 09H, character 9
01A9 BF              302                             DB 10111111B    ;"-" 
01AA FF              303                             DB 11111111B    ;character blank
                     304     
                     305     END
A51 MACRO ASSEMBLER  SPOT_WELDER                                                          10/16/2011 00:43:52 PAGE     6

SYMBOL TABLE LISTING
------ ----- -------


N A M E             T Y P E  V A L U E   ATTRIBUTES

ARCOUNT. . . . . .  N NUMB   000AH   A   
B. . . . . . . . .  D ADDR   00F0H   A   
BEGIN. . . . . . .  C ADDR   002BH   A   
CK_KEY . . . . . .  C ADDR   00B7H   A   
CK_PEDAL . . . . .  C ADDR   008BH   A   
COMP . . . . . . .  N NUMB   0024H   A   
COM_0. . . . . . .  C ADDR   0056H   A   
COUNT. . . . . . .  N NUMB   0022H   A   
CP . . . . . . . .  B ADDR   00B0H.6 A   
DEB0 . . . . . . .  C ADDR   0091H   A   
DEB3 . . . . . . .  C ADDR   009EH   A   
DEB4 . . . . . . .  C ADDR   009FH   A   
DIGIT. . . . . . .  B ADDR   0020H.2 A   
DNH. . . . . . . .  C ADDR   0126H   A   
DN_DO. . . . . . .  C ADDR   0137H   A   
DN_RET . . . . . .  C ADDR   0141H   A   
DOV. . . . . . . .  C ADDR   00D3H   A   
DO_DN. . . . . . .  C ADDR   011BH   A   
DO_UD. . . . . . .  C ADDR   0142H   A   
DO_UP. . . . . . .  C ADDR   00F4H   A   
EA . . . . . . . .  B ADDR   00A8H.7 A   
FIRE . . . . . . .  B ADDR   00B0H.2 A   
FLAGS. . . . . . .  N NUMB   0020H   A   
FONT . . . . . . .  C ADDR   019FH   A   
FRONT. . . . . . .  C ADDR   0059H   A   
HWAVE. . . . . . .  B ADDR   0020H.4 A   
IND. . . . . . . .  C ADDR   0185H   A   
IND1 . . . . . . .  C ADDR   015DH   A   
IND2 . . . . . . .  C ADDR   016FH   A   
IND3 . . . . . . .  C ADDR   017BH   A   
IND4 . . . . . . .  C ADDR   0182H   A   
INDIC. . . . . . .  C ADDR   0152H   A   
INT0 . . . . . . .  B ADDR   00B0H.2 A   
INT1 . . . . . . .  B ADDR   00B0H.3 A   
INTEG. . . . . . .    REG    R7          
KEYARR . . . . . .  N NUMB   000FH   A   
KEYDA. . . . . . .  N NUMB   0046H   A   
KEYDB. . . . . . .  N NUMB   0005H   A   
KEYDBT . . . . . .  N NUMB   0026H   A   
KEYFARR. . . . . .  N NUMB   0007H   A   
KEYTM. . . . . . .  N NUMB   0027H   A   
KEY_DN . . . . . .  B ADDR   00B0H.3 A   
KEY_UP . . . . . .  B ADDR   00B0H.4 A   
MAIN . . . . . . .  C ADDR   0047H   A   
MAXTIME. . . . . .  N NUMB   0063H   A   
MINTIME. . . . . .  N NUMB   0001H   A   
ND . . . . . . . .  C ADDR   00E6H   A   
NDN. . . . . . . .  C ADDR   00D8H   A   
NEG. . . . . . . .  C ADDR   0075H   A   
NP . . . . . . . .  C ADDR   00E8H   A   
NUD. . . . . . . .  C ADDR   00E2H   A   
NUP. . . . . . . .  C ADDR   00DDH   A   
NZ . . . . . . . .  C ADDR   016AH   A   
ON_OFF . . . . . .  B ADDR   0020H.0 A   
P1 . . . . . . . .  D ADDR   0090H   A   
P3 . . . . . . . .  D ADDR   00B0H   A   
PEDDBT . . . . . .    REG    R6          
PED_IN . . . . . .  B ADDR   00B0H.5 A   
PED_ST . . . . . .  N NUMB   0025H   A   
PRESS. . . . . . .  B ADDR   0020H.1 A   
A51 MACRO ASSEMBLER  SPOT_WELDER                                                          10/16/2011 00:43:52 PAGE     7

PREV . . . . . . .  N NUMB   0028H   A   
PULSE. . . . . . .  C ADDR   00A7H   A   
REF1 . . . . . . .  C ADDR   00B2H   A   
REF2 . . . . . . .  C ADDR   00B0H   A   
REF_1. . . . . . .  C ADDR   0066H   A   
REF_2. . . . . . .  C ADDR   006DH   A   
REF_3. . . . . . .  C ADDR   0078H   A   
REPCNT . . . . . .  N NUMB   0029H   A   
RXD. . . . . . . .  B ADDR   00B0H.0 A   
SCAN0. . . . . . .  B ADDR   00B0H.1 A   
SCAN1. . . . . . .  B ADDR   00B0H.0 A   
SEG_A. . . . . . .  B ADDR   0090H.2 A   
SEG_B. . . . . . .  B ADDR   0090H.3 A   
SEG_C. . . . . . .  B ADDR   0090H.4 A   
SEG_D. . . . . . .  B ADDR   0090H.5 A   
SEG_E. . . . . . .  B ADDR   0090H.6 A   
SEG_F. . . . . . .  B ADDR   0090H.7 A   
SEG_G. . . . . . .  B ADDR   00B0H.7 A   
SUBR . . . . . . .  C ADDR   0083H   A   
T0 . . . . . . . .  B ADDR   00B0H.4 A   
T1 . . . . . . . .  B ADDR   00B0H.5 A   
TENS . . . . . . .  N NUMB   0031H   A   
TIME . . . . . . .  N NUMB   0021H   A   
TXD. . . . . . . .  B ADDR   00B0H.1 A   
T_OFF. . . . . . .  C ADDR   0080H   A   
UD_OFF . . . . . .  C ADDR   014FH   A   
UD_RET . . . . . .  C ADDR   0151H   A   
UN . . . . . . . .  C ADDR   016CH   A   
UNITS. . . . . . .  N NUMB   0030H   A   
UPH. . . . . . . .  C ADDR   00FFH   A   
UP_DO. . . . . . .  C ADDR   0110H   A   
UP_RET . . . . . .  C ADDR   011AH   A   
W1 . . . . . . . .  C ADDR   00EDH   A   
W2 . . . . . . . .  C ADDR   00F3H   A   
WAIT_6MS . . . . .  C ADDR   00AEH   A   
ZERO . . . . . . .  N NUMB   0023H   A   


REGISTER BANK(S) USED: 0 


ASSEMBLY COMPLETE.  0 WARNING(S), 0 ERROR(S)
