Category : Assembly Language Source Code
Archive   : SIG8051.ZIP
Filename : CLOCK.ASM

 
Output of file : CLOCK.ASM contained in archive : SIG8051.ZIP
$PAGEWidth=120
$list
$paginate
$ap
$showincs
;--- clock.asm - VERSION 1.0- AUG 7, 1989
;
; COPYRIGHT (C) 1989 - SYTRONICS, INC. P.O. BOX 1087 MARS HILL, N.C. 28754
; 704-689-9739
; ALL RIGHTS RESERVED....
;
;
; THIS PROGRAM ILLUSTRATES SEVERAL FEATURES OF THE CHARGECARD MICROCONTROLLER.
; THE FILES IN THIS EXAMPLE ARE AS FOLLOWS:
;
; 1) CLOCK.ASM - ASSEMBLY LANGUAGE FILE (AVOCET AVMAC51 FORMAT)
; 2) CLOCK.OBJ - RESULTANT OBJECT FILE
; 3) CLOCK.HEX - LINKED OBJECT FILE IN INTEL .HEX FORMAT
; 4) CLOCK.BIN - BINARY IMAGE OF INTEL HEX FILE
; 5) CLOCK.DMP - ASCII IMAGE OF CLOCK.BIN
;
; THIS SHORT PROGRAM ILLUSTRATES THE FOLLOWING FEATURES:
;
; 1) - REAL TIME CLOCK WITH 10 mSEC CLICKS
; 2) - UART (RS-232) OUTPUT TO TERMINAL (POLLED)
; 3) - JUMP BACK TO MONITOR ROM UPON KEYPRESS AT TERMINAL.
;
; THE FOLLOWING INSTRUCTIONS SHOULD BE SENT TO THE CHARGECARD MICROCONTROLLER:
;
; >L 0140 (WHERE 0140 IS THE HEX LENGTH OF THE .BIN FILE)
;
; WHEN THE CHARGECARD MICROCONTROLLER RESPONDS WITH :
;
; " BEGIN UPLOAD IN ASCII FORMAT... "
;
; ACCESS THE UPLOAD FEATURE OF YOUR COMMUNICATIONS PROGRAM AND SPECIFY
; THE FILE "CLOCK.DMP"... (NOTE: IF YOU ARE USING PROCOMM, THE
; UPLOAD FEATURE IS ACCESSED VIA THE PgUp KEY. OPTION 4 IS ASCII
; UPLOAD. )
;
; AFTER THE UPLOAD IS COMPLETE, THE CHARGECARD MICROCONTROLLER WILL
; RESPOND WITH THE COMMAND PROMPT ">".
;
; AT THIS POINT, ENTER: "G 0000".
;
; THE PROGRAM WILL THEN BEGIN READING PORT 1 AND SENDING
; OUT ITS VALUE TO THE RS-232 PORT.
;
; ANY TASK WHICH IS DESIRED OF THE CHARGECARD MICROCONTROLLER
; MAY BE PLACED IN THE SECTION OF THE PROGRAM WHICH PERFORMS
; THE READ AND OUTPUT OF THE PORT. DIFFERENT SAMPLING PERIODS
; MAY BE OBTAINED BY INCREASING THE CLOCK TICK FREQUENCY OR
; BY USING THE MSECS VARIABLE INSTEAD OF THE SECONDS VARIABLE.
;





DEFSEG XASMSEG,ABSOLUTE
SEG XASMSEG

ROM_TOP EQU 1FFFH ; TOP ADDRESS IN PROM FOR 8K x 8

RAM_TOP EQU 1FFFH ; TOP ADDRESS IN RAM FOR 8K x 8

BAK_2_ROM EQU ROM_TOP-16 ; LOCATION WITH INSTRUCTIONS ON
; HOW TO GET BACK TO ROM...

ROM_DISABLE EQU P3.5 ; PORT LINE USED FOR ENABLING ROM

STACK EQU 80H ; BEGINS AT HEX 80 (indirect space)


; CONSTANTS FOR SELECTING DIFFERENT REGISTER BANKS

SELRB0 EQU 000H ; SELECT REGISTER BANK 0
SELRB1 EQU 008H ; SELECT REGISTER BANK 1 ...POKE TO PSW TO USE
SELRB2 EQU 010H ; SELECT REGISTER BANK 2 (I.E., MOV PSW,#SELRB2 )
SELRB3 EQU 018H ; SELECT REGISTER BANK 3

T0PERIOD EQU 9216 ; 100Hz (.01 SEC RESOLUTION)
BITRATE EQU 3 ; 3 = 9600, 6 = 4800, 12 = 2400, ETC.

CR EQU 0DH ; CARRIAGE RETURN
LF EQU 0AH ; LINE FEED
SPC EQU 20H ; SPACE

; REAL TIME CLOCK DATA STRUCTURE....

MSECS EQU 30H ; mSECONDS COUNTER IN 10 MSEC INTERVALS
SECONDS EQU 31H ; SECONDS
MINUTES EQU 32H ; MINUTES
HOURS_LSB EQU 33H ; 0..255 HOURS
HOURS_MSB EQU 34H ; 256..65537 HOURS


OLD_SECONDS EQU 35H ; A VARIABLE USED TO CALCULATE ELAPSED TIMES..





;---------==========----------==========---------=========---------
; PROCESSOR INTERRUPT AND RESET VECTORS
;---------==========----------==========---------=========---------



ORG 00H ; TOP OF PROM..RESET 0000h
JMP MAIN

ORG 000BH ; TIMER 0 OVERFLOW 000Bh
JMP T0_OVFLO

ORG 0023H ; SERIAL IO (UART) 0023h
JMP EXIT_ROUTINE


;---------==========----------==========---------=========---------
; SYSTEM SETUPS
;---------==========----------==========---------=========---------

SETUP: EQU $
CLR EA ; STOP ALL INTERRUPTS
CLR ES ; DISABLE SERIAL PORT
CLR RI
CLR TI

MOV MSECS,#00H ; INITIALIZE REAL TIME CLOCK
MOV SECONDS,#00H ; VARIABLES
MOV MINUTES,#00H ;
MOV HOURS_LSB,#00H ;
MOV HOURS_MSB,#00H ;

;--- SET TIMER 1 AS BIT RATE GENERATOR

MOV TCON,#00H ; SHUT DOWN TIMERS, IF RUNNING
MOV TMOD,#00100001B ; T1 IN MODE 2, T0 MODE 1
MOV TH1,#LOW -BITRATE ; SERIAL PORT BIT RATE
MOV TL1,#LOW -BITRATE ; ... SET UP FIRST CYCLE!

;----SET TIMER 0 AS A REAL TIME CLOCK....

MOV TH0,#HIGH -T0PERIOD ; FFFF-D6FF=2400H 2400X1.078uS=9.999 mSEC
MOV TL0,#LOW -T0PERIOD ; 11.0592 MHz TIMEBASE

;--- SET SERIAL PORT TO USE TIMER1 FOR BIT RATE, 8 DATA BIT MODE

MOV SCON,#01000000B ; MODE 1, CLEAR "READY" FLAGS

SETB TR1 ; TURN ON THE TIMERS
SETB TR0 ; TURN ON RTCLOCK
clr tf0

SETB REN
SETB ET0 ; ENABLE RS-232 INT...
SETB ES
SETB EA ;----ENABLE ALL INTERRUPTS.....

RET

;----------------------------------------------------------------
; TRANSMIT BYTE OUT THE RS232 HOSE - NOT INTERRUPT DRIVEN
;----------------------------------------------------------------
; PASS THE BYTE IN ACCUMULATOR, ...WAIT HERE UNTIL DONE....

CHAROUT: EQU $
clr es ; DISABLE serial interrupt
MOV SBUF,A ; PUT THE CHAR IN THE SERIAL BUFFER
CLR TI ; CLEAR TRASMITTER INT

CHARWAIT: JNB TI,CHARWAIT ; HANG TILL DONE...
CLR TI ; THEN CLEAR TRANS INT.

setb es ; re-enable serial interrupt
RET ; EXIT.....

;----------------------------------------------------------------
; TRANSMIT OUT THE RS232 HOSE
;----------------------------------------------------------------
CR_LF_SP: EQU $
CR_LF: PUSH ACC
MOV A,#CR
CALL CHAROUT
MOV A,#LF
CALL CHAROUT
POP ACC
RET

;----------------------------------------------------------------
; TRANSMIT HEX REPRESENTATION OF A BYTE OUT THE RS232
;----------------------------------------------------------------
; PASS THE BYTE IN ACCUMULATOR
; WAIT HERE UNTIL DONE....
; DESTROYS A AND B REGISTERS
HEX_OUT: EQU $

PUSH ACC
PUSH B
MOV B,A ; PUT THE BYTE IN B, TOO
SWAP A ; PUT HIGH NIBBLE IN LOW
CALL H_2_A ; CONVERT TO ASCII
CALL CHAROUT ; SEND IT OUT
MOV A,B ; GET THE ORIGINAL BYTE
CALL H_2_A ; CONVERT TO ASCII
CALL CHAROUT ; SEND IT OUT
POP B
POP ACC
RET ; EXIT

;---------------------------------------------------------------
; HEX TO ASCII ROUTINE
;---------------------------------------------------------------
; ACC CONTAINS HEX AND RETURNS ASCII VALUE (UPPER CASE)..
; RESTRICTIONS....SHOULD HAVE GOOD DATA..DOES NOT CHECK !!!
; ==== === ===== ===

H_2_A: EQU $
ANL A,#0FH ; MASK OUT HIGH BITS
CLR C ; CLEAR CARRY FOR FOLLOWING TESTS
SUBB A,#0AH ; IS IT LESS THAN A?
JC HA_1 ; YES, THEN JUST ADD 3Ah
ADD A,#07H ; OTHERWISE, ADD 3A AND 7 (41h)
HA_1: ADD A,#3AH
RET

;---------==========----------==========---------=========---------
; REAL TIME CLOCK....
;---------==========----------==========---------=========---------
; IF HERE, A CLOCK TICK HAS OCCURRED....10 MILLISECONDS
; HAS ELAPSED.....UPDATE MSECS, SECONDS, MINUTES, HOURS

T0_OVFLO: EQU $
REAL_TIME_CLOCK: EQU $
;
PUSH PSW ; SAVE CURRENT REGISTERS
MOV PSW,#SELRB2 ; SELECT REGISTER BANK 2, IN CASE WE WANT TO
; USE THE REGISTERS FOR ANYTHING...

PUSH ACC ; SAVE ACCUMULATOR

clr tr0 ; STOP AND RELOAD TIMER FOR REAL TIME CLOCK.
mov th0,#HIGH -T0PERIOD ; RELOAD TIMER
mov tl0,#LOW -T0PERIOD
clr tf0
setb tr0 ; RE-ENABLE TIMER

INC MSECS ; BUMP MILLISECONDS.
MOV A,MSECS
CJNE A,#64H,RTC_END ; 1000 MILLISECONDS PASSED?
MOV MSECS,#00H ; ELSE, INCREMENT SECONDS, REINIT MSECS
INC SECONDS
MOV A,SECONDS
CJNE A,#3CH,RTC_END
MOV SECONDS,#00H ; ELSE, INCREMENT MINUTES, REINIT SECONDS
INC MINUTES
MOV A,MINUTES
CJNE A,#3CH,RTC_END
MOV MINUTES,#00H ; ELSE, INCREMENT HOURS, REINIT MINUTES
INC HOURS_LSB
MOV A,HOURS_LSB ; 256 HOURS ELAPSED?
CJNE A,#0FFH,RTC_END ; GOTO END IF NO...
MOV HOURS_LSB,#00H ; RESET HOURS LSB
INC HOURS_MSB ; INC HOURS MSB (GOOD FOR 7.5 YEARS)

RTC_END: EQU $

POP ACC
POP PSW ; RESTORE AND RETURN ENVIRONMENT....

RETI ; RETURN FROM THIS INTERRUPT SERVICE ROUTINE


MAIN: EQU $
mov tcon,#00h ; MAKE SURE TIMERS ARE SHUT DOWN.

MOV SP,#080h ; SET UP STACK BEFORE ANY CALLS
mov psw,#selrb0 ; SELECT REGISTER BANK ONE ...
CALL SETUP ; SET UP EVERTHING ELSE


AGAIN: MOV OLD_SECONDS,SECONDS ; SET UP A DELAY.........



TIME_CHANGE:
MOV A,SECONDS ; WAIT HERE UNTIL SECONDS CHANGE...
CJNE A,OLD_SECONDS,DO_TASK
JMP TIME_CHANGE

DO_TASK: EQU $ ; THEN DO SOMETHING USEFUL



MOV A,P1 ; READ PORT 1
CALL HEX_OUT ; SEND OUT ITS HEX VALUE
call cr_lf ; AND A CARRIAGE RETURN/LINEFEED
ljmp again ; REPEAT ENDLESSLY...



;---------==========----------==========---------=========---------
; EXIT ROUTINE
;---------==========----------==========---------=========---------
; THIS ROUTINE IS DESIGNED TO SEND CONTROL BACK TO THE MONITOR
; ROM WHEN A KEY PRESS IS DETECTED AT THE TERMINAL.. IT IS SET UP
; AS AN INTERRUPT SERVICE ROUTINE FOR THE UART AND ALSO SHOWS
; HOW THIS IS DONE. A SUBROUTINE, UN_SETUP, IS USED TO TURN OFF
; THE REAL-TIME-CLOCK SO THAT IT WILL NOT INTERFERE WITH THE MONITOR
; SOFTWARE WHEN CONTROL RETURNS TO THE ROM.
;
; THIS ROUTINE STUFFS THE CODE NECESSARY TO RETURN BACK TO THE ROM
; IN A RESERVED LOCATION AT THE END OF RAM. IT THEN JUMPS TO THIS
; ADDRESS, DISABLES THE RAM AND FINDS ITS WAY BACK TO THE MONITOR
; SOFTWARE VIA INSTRUCTIONS CONTAINED IN THE CORRESPONDING LOCATION
; IN THE ROM....
;
;
EXIT_ROUTINE: EQU $ ; HOW TO RETURN TO ROM MONITOR
; WHEN A KEY IS PRESSED AT THE TERMINAL.

JB RI,EXIT1 ; IF THIS IS A TRANSMIT INTERRUPT, RETURN.
clr ti

RET

EXIT1: MOV DPTR,#BAK_2_ROM
MOV A,#0D2H ; OP CODE FOR SETB TO
MOVX @DPTR,A ; RE-ENABLE ROM (SETB ROM_ENABLE)
INC DPTR
MOV A,#0B5H ; BIT ADDRESS FOR P3.5 (T1)
MOVX @DPTR,A

CLR RI ; CLEAR THE RECEIVE INTERRUPT FLAG

CLR TR0 ; TURN OFF RTCLOCK

CALL UN_SETUP

JMP BAK_2_ROM


;---------==========----------==========---------=========---------
; UN_SETUP
;---------==========----------==========---------=========---------
; SETS UP CHARGECARD MICROCONTROLLER THE SAME WAY AS THE MONITOR PROGRAM DOES
; I.E., RESTORES CONFIGURATION PRIOR TO EXITING BACK TO MONITOR...


UN_SETUP: EQU $

CLR EA
CLR ES
CLR RI
CLR TI

;--- SET TIMER 1 AS BIT RATE GENERATOR

MOV TCON,#00H ; SHUT DOWN TIMERS, IF RUNNING
MOV TMOD,#00100001B ; T1 IN MODE 2, T0 MODE 1
MOV TH1,#LOW -BITRATE ; SERIAL PORT BIT RATE
MOV TL1,#LOW -BITRATE ; ... SET UP FIRST CYCLE!

;----SET TIMER 0 AS A REAL TIME CLOCK....

MOV TH0,#0D6H ; FFFF-D6FF=2400H 2400X1.078uS=9.999 mSEC
MOV TL0,#0FFH ; 11.0592 MHz TIMEBASE


;--- SET SERIAL PORT TO USE TIMER1 FOR BIT RATE, 8 DATA BIT MODE

MOV SCON,#01000000B ; MODE 1, CLEAR "READY" FLAGS

SETB TR1 ;--- TURN ON THE TIMERS

SETB EA ;----ENABLE ALL INTERRUPTS.....

SETB REN ; ----- ENABLE SERIAL RECEPTION
SETB ET0 ; ENABLE TIMER 0

RET


END




  3 Responses to “Category : Assembly Language Source Code
Archive   : SIG8051.ZIP
Filename : CLOCK.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/