应用电子威廉希尔官方网站
BIT NAME | LOCATION | FUNCTION | RANGE | RESET | READ/WRITE ACCESS |
ERTCI | EIE.5 | RTC Interrupt Enable | 0 | Unrestricted | |
PRTCI | EIP.5 | RTC Interrupt Priority | 0 | Unrestricted | |
RTASS.7-0 | RTASS | RTC Alarm Subsecond | 0-FFh | Unchanged | Unrestricted |
RTAS.5-0 | RTAS | RTC Alarm Second | 0-3Bh | Unchanged | Unrestricted |
RTAM.5-0 | RTAM | RTC Alarm Minute | 0-3Bh | Unchanged | Unrestricted |
RTAH.4-0 | RTAH | RTC Alarm Hour | 0-17H | Unchanged | Unrestricted |
RTCSS.7-0 | RTCSS | RTC Subsecond | 0-FFh | Unchanged | Read: only if RTCRE=1. Cannot be written. Cleared when RTCWE 1<0 |
RTCS.5-0 | RTCS | RTC Second | 0-3Bh | Unchanged | Read: only if RTCRE=1. Write: only if RTCWE=1. 1ms Read/Write window |
RTCM.5-0 | RTCM | RTC Minute | 0-3Bh | Unchanged | |
RTCH.4-0 | RTCH.4-0 | RTC Hour | 0-17h | Unchanged | |
DOW2-0 | RTCH.7-5 | RTC Day of Week | 0-7h | Unchanged | |
RTCD1.7-0 RTCD0.7-0 |
RTCD1, (MSB) RTCD0, (LSB) |
RTC Day | 0-FFFFh | Unchanged | |
SRCE | RTCC.7 | RTC Subsecond Compare enable |
Unchanged | Unrestricted | |
SCE | RTCC.6 | RTC Second Compare Enable |
Unchanged | Unrestricted | |
MCE | RTCC.5 | RTC Minute Compare Enable |
Unchanged | Unrestricted | |
HCE | RTCC.4 | RTC Hour Compare Enable |
Unchanged | Unrestricted | |
RTCRE | RTCC.3 | RTC Read Enable | 0 | Unrestricted | |
RTCWE | RTCC.2 | RTC Write Enable | 0 | Read: Unrestricted Write: Timed Access | |
RTCIF | RTCC.1 | RTC Interrupt Flag | 0 | Unrestricted | |
RTCE | RTCC.0 | RTC Enable | Unchanged | Read: Unrestricted Write: Timed Access | |
E4K | TRIM.7 | External 4096Hz RTC Signal Enable |
0 | ||
X12/ /6\ | TRIM.6 | RTC Crystal Capacitance Select |
Unchanged | ||
TRM2-0 | TRIM.5 TRIM.3 TRIM.1 |
RTC Trim Bit 2-0 | Unchanged | Read: Unrestricted Write: Timed Access | |
/0 - TRM2\ | TRIM.4 TRIM.2 TRIM.0 |
RTC Inverted Trim Bit 2-0 |
Unchanged | Read: Unrestricted Write: Timed Access Must be inverse of TRM2-0 |
Alarm Subsecond (RTASS) | 00 subseconds | = 00h |
Alarm Second (RTAS) | 00 seconds | = 00h |
Alarm Minute (RTAM) | 45 minutes | =2Dh |
Alarm Hour (RTAH) | 11 hours | =0Bh |
Clock Control (RTCC) | subsecond compare | = F1h |
second compare | ||
minute compare | ||
hour compare |
In the above example, the subsecond, second, and minute registers are programmed and the corresponding compare enable bits are set, even though only a match on the minute register is desired. This is because a don't care is always treated as a match for the purposes of evaluating alarms. If the SSCE and SCE bits were cleared to 0 (don't care) in the above example, then a match (and interrupt) would occur during every subsecond of the minute in which the RTAM register matched. This would cause 15,360 interrupts, which is most likely not the desired effect. In general, when specifying a recurring alarm, all the compare bits below the largest time increment should be enabled and the corresponding alarm registers loaded with 00h or a known value.
Alarm Subsecond (RTASS) 00 subseconds = 00h Alarm Second (RTAS) 00 seconds = 00h Alarm Minute (RTAM) 30 minutes = 1Eh Alarm Hour (RTAH) 11 hours =00h Clock Control (RTCC) subsecond compare = E1h second compare minute compare RTC enable
;Program DATALOGR.ASM ; ;This program demonstrates how to use the RTC to periodically service an ;external device. The device halts in Stop mode until awoken by an RTC interrupt ;every half hour. It then reads the temperature from a DS1620 Digital ;Thermostat and transmits it, with a time stamp, to the host via serial port 1. ;Register equate table SP equ 81h ;Stack Pointer PCON equ 87h ;Power Control Register TCON equ 88h ;Timer Control Register TMOD equ 89h ;Timer Mode Register TH1 equ 8Dh ;Timer 1 MSB CKCON equ 8Eh ;Clock Control Register P1 equ 90h ;Port 1 EXIF equ 91h ;External Interrupt Flag Register SCON0 equ 98h ;Serial Port 0 Control Register SBUF0 equ 99h ;Serial Port 0 Data Buffer P3 equ 0B0h ;Port 3 SCON1 equ 0C0h ;Serial Port 1 Control Register SBUF1 equ 0C1h ;Serial Port 1 Data Buffer TA equ 0C7h ;Timed Access Register WDCON equ 0D8h ;Watchdog Control Register ACC equ 0E0h ;Accumulator RTASS equ 0F2h ;Real-time Alarm Subsecond Register RTAS equ 0F3h ;Real-time Alarm Second Register RTAM equ 0F4h ;Real-time Alarm Minute Register RTCC equ 0F9h ;Real-time Clock Control RTCM equ 0FCh ;Real-time Clock Minute Register RTCH equ 0FDh ;Real-time Clock Hour Register ;Bit equate table RI0 equ 098h TI0 equ 099h REN0 equ 09Ch EA equ 0AFh TI1 equ 0C1h ERTCI equ 0Edh DS1620_RST equ 090h ;DS1620 reset pin is tied to DS87C530 P1.0. WR_CONFIG equ 0Ch ;DS1620 Write Configuration command. RD_TEMP equ 0AAh ;DS1620 Read Temperature command. START_CONV equ 0EEh ;DS1620 Start Conversion command. cseg at 0 ;Reset vector. LJMP START cseg at 6Bh ;Real-time clock Interrupt vector. LJMP RTC_INT ; cseg at 100H ;Beginning of code segment. START: MOV SP, #40h ;Initialize Stack pointer. MOV EXIF, #0Ah ;Enable ring oscillator restart from Stop mode. MOV P3, #03h ;Set P3.1 & P3.0 high to use serial port 0. MOV SCON0, #20h ;Set serial port mode 0, 4 tclk. MOV P1, #0Ch ;Set P1.2 & P1.3 high to use serial port 1. ;Clear P1.0 to reset DS1620. MOV SCON1, #40h ;Set serial port mode 1. MOV TMOD, #20h ;Configure timer 1 for 9600 baud MOV TH1, #0FDh ; at 11.0592MHz. MOV TCON, #40h ;Start timer. ;Configure the DS1620 SETB DS1620_RST ;Remove DS1620 reset to start operation. MOV A, #WR_CONFIG ;Send command to address configuration byte. CALL OUT_1620 MOV A, #03h ;Set Configuration byte = CPU & 1-Shot Mode. CALL OUT_1620 CLR DS1620_RST ;Assert DS1620 to end operation. ;Set up the RTC MOV RTAM, #00h ;Clear all alarm registers. Alarm will ring MOV RTAS, #00h ; on the next hour to start temperature MOV RTASS, #00h ; conversion. MOV RTCC, #081h ;Set alarms so we get a reading at start. SETB ERTCI ;Enable RTC interrupt. SETB EA ;Global interrupt enable. MAIN: ORL PCON, #02h ;Set STOP bit to enter Stop mode. JMP MAIN ;End of main program loop. Program will return ; here after RTC interrupt is complete. ;*************************************************************************** ;RTC_INT - This ISR reads the temp from the DS1620 and outputs the data to ; serial port 1. The routine starts the conversion, and waits for 1 ; second to allow conversion to complete and crystal to stabilize. ; When the conversion is complete, the device will read the temperature ; and send the hour, minute and temperature to the host. The RTAM ; register will be modified to alarm again in 30 minutes. ;*************************************************************************** RTC_INT: MOV RTCC, #081h ;Clear RTCI flag and second compare enable ; bit to generate another alarm in 1 second. PUSH ACC ;Save accumulator. SETB DS1620_RST ;Remove DS1620 reset to start operation. MOV A, #START_CONV ;Initiate first temp conversion. CALL OUT_1620 CLR DS1620_RST ;Assert DS1620 to end operation. ORL RTCC, #08h ;Enable RTC read process, and delay 4 machine CJNE A, ACC, $ ; cycles for time registers to stabilize. MOV R7, RTCM ;Save minute and hour so we can transmit MOV R6, RTCH ; them as soon as crystal has stabilized. ANL RTCC, #0F7h ;Reenable time register updates. WAIT: MOV A, RTCC ;Wait for RTC interrupt flag to be set, JNB ACC.1, WAIT ; indicating that conversion is done. The ; one second delay will be sufficient for the ; crystal to stabilize, so switch to it now. XRL RTAM, #1Eh ;Change alarm to ring on next half hour. MOV RTCC, #0E1h ;Clear RTCI flag, and set compare bits ; so next alarm will be generated in 30 min. MOV A, #'!' ;Transmit start character. CALL OUT_HOST MOV A, R6 ;Transmit the hour. CALL OUT_HOST MOV A, R7 ;Transmit the minute. CALL OUT_HOST SETB DS1620_RST ;Remove DS1620 reset to start operation. MOV A, #RD_TEMP ;Conversion is done. Send command to read temp. CALL OUT_1620 CALL IN_1620 ;Read LSB of temperature and send it to host. CALL IN_1620 ;Read MSB of temperature and send it to host. CLR DS1620_RST ;Assert DS1620 to end operation. POP ACC ;Restore accumulator and go back to sleep. RETI ;************************************************************************ ;OUT_HOST - This routine sends data to the host system via serial port 1. ;************************************************************************ OUT_HOST: MOV SBUF1, A ;Move out byte. JNB TI1, $ ;Wait until data has been transmitted. CLR TI1 ;Clear TI1. RET ;************************************************************************ ;OUT_1620 - This routine sends data to the DS1620 via serial port 0. ;************************************************************************ OUT_1620: MOV SBUF0, A ;Move out byte. JNB TI0, $ ;Wait until data has been transmitted. CLR TI0 ;Clear TI1. RET ;************************************************************************ ;IN_1620 - This routine reads a byte from the DS1620 and echoes it back ; through serial port 1. ;************************************************************************ IN_1620: SETB REN0 ;Enable receiver to clock in data. JNB RI0, $ ;Wait until data has been received. CLR REN0 ;Disable receiver to prevent reception. CLR RI0 ;Clear RI. MOV A, SBUF0 ;Echo data through serial port 1. CALL OUT_HOST RET
;*************************************************************************** ;Program RTC_UTIL.ASM ; ;This program responds to commands received over the serial port to set ;and read the date, time and alarm information in the DS87C530 Real-time Clock. ;The program initializes the serial port for operation at 28800 baud with an ;11.0592MHz clock. ;*************************************************************************** ;Register equate table SP equ 81h ;Stack Pointer DPL equ 82h ;Data pointer low register DPH equ 83h ;Data pointer high register PCON equ 87h ;Power Control Register TCON equ 88h ;Timer Control Register TMOD equ 89h ;Timer Mode Register TH1 equ 8Dh ;Timer 1 MSB EXIF equ 91h ;External Interrupt Flag Register SCON0 equ 98h ;Serial Port 0 Control Register SBUF0 equ 99h ;Serial Port 0 Data Buffer P3 equ 0B0h ;Port 3 TA equ 0C7h ;Timed Access Register ACC equ 0E0h ;Accumulator B equ 0F0h ;B Register RTASS equ 0F2h ;Real-time Alarm Subsecond Register RTAS equ 0F3h ;Real-time Alarm Second Register RTAM equ 0F4h ;Real-time Alarm Minute Register RTAH equ 0F5h ;Real-time Alarm Hour Register EIP equ 0F8h ;Extended Interrupt Priority Register RTCC equ 0F9h ;Real-time Clock Control RTCSS equ 0FAh ;Real-time Clock Subsecond register RTCS equ 0FBh ;Real-time Clock Second RTCM equ 0FCh ;Real-time Clock Minute RTCH equ 0FDh ;Real-time Clock Hour RTCD0 equ 0FEh ;Real-time Clock Day Register 0 RTCD1 equ 0FFh ;Real-time Clock Day Register 1 ;Bit equate table RI0 equ 98h ;Serial Port 0 Receiver Interrupt Flag TI0 equ 99h ;Serial Port 0 Transmitter Interrupt Flag EA EQU 0AFh ;Global Interrupt Enable. ERTCI equ 0EDh ;Real-time Clock Interrupt Enable. ;Constant equate table CR equ 0Dh LF equ 0Ah cseg at 0 ;Reset vector. LJMP START cseg at 6BH ;Real-time clock Interrupt vector. LJMP RTC_INT cseg at 100H ;Beginning of code segment. ;Data & string tables. HEX_TABLE: DB '0123456789ABCDEF' NEW_LINE: DB CR, LF, 0 YES: DB 'Y ', 0 N DB 'N ', 0 COMPARE: DB CR, LF, 'Compare enabled: ', 0 COMPARE_Q: DB ' Enable compare (Y/N)? ', 0 ALARM_MSG: DB CR, LF, 'Alarm: ', 0 TT_BANNER: DB CR, LF, CR, LF, 'DS87C530 RTC UTILITY' DB CR, LF, ' A - Set Alarm, T -Set Time' DB CR, LF, ' any other key to show registers' DB CR, LF, CR, LF, 'RTC registers: ', 0 ALM_BANNER: DB CR, LF, 'Alarm register: ', 0 NEW_BANNER: DB CR, LF, CR, LF, 'Enter new alarm register settings:',0 SET_BANNER: DB CR, LF, 'Enter new time:', 0 SS_BANNER: DB CR, LF, 'Subsecond: ', 0 S_BANNER: DB CR, LF, 'Second: ', 0 M_BANNER: DB CR, LF, 'Minute: ', 0 H_BANNER: DB CR, LF, 'Hour: ', 0 DW_BANNER: DB CR, LF, 'Day of Week: ', 0 DC_BANNER: DB CR, LF, 'Day Count: ', 0 DW_STRING: DB 'Disabled ',0,'Sunday ',0,'Monday ',0,'Tuesday ', 0 DB 'Wednesday',0,'Thursday ',0,'Friday ',0,'Saturday ', 0 ;Initialize part. START: MOV SP, #80h ;Set up stack pointer. MOV P3, #0Bh ;Set RXD0, TXD0 & INT1 as inputs. MOV RTAM, #00h ;Initialize alarm registers to known values. MOV RTAS, #00h MOV RTASS, #00h MOV TA, #0AAh ;Timed access write to enable RTC. MOV TA, #55h MOV RTCC, #01h MOV SCON0, #050h ;Set serial port 0 for Mode 1, divide by 12. MOV TH1, #0FEh ;Timer 1 value for 28800 baud at 11.0592MHz. MOV TMOD, #20h ;Set timer 1 to 8-bit auto reload and start it. MOV TCON, #40h ORL PCON, #80h ;Set SMOD bit to get 28800 baud. SETB ERTCI ;Enable RTC interrupts. SETB EA LJMP TELL_TIME ;Display the time. ;*************************************************************************** ;This is the main program loop. It waits for a character on serial port 0, ;and then takes the appropriate action. ;*************************************************************************** CHAR_TEST: JNB RI0, $ ;Wait for incoming command character. CLR RI0 MOV A, SBUF0 ;Test to see what to do. CHECKT: CJNE A, #'T', CHECKA ;T - set time. LJMP SET_TIME CHECKA: CJNE A, #'A', TT_JUMP ;A - set alarm. LJMP SET_ALARM TT_JUMP: LJMP TELL_TIME ;else display time. ;*************************************************************************** ;SET_TIME sets the current time. ;*************************************************************************** SET_TIME: MOV DPTR, #SET_BANNER ;Display set time banner. CALL OUT_STRING MOV DPTR, #H_BANNER ;Get hour & save temp copy. CALL OUT_STRING CALL IN_TIME ANL A, #1Fh ;Make sure day of week bits are 0. MOV R4, A MOV DPTR, #M_BANNER ;Get minute & save temp copy. CALL OUT_STRING CALL IN_TIME MOV R5, A MOV DPTR, #S_BANNER ;Get second & save temp copy. CALL OUT_STRING CALL IN_TIME MOV R6, A MOV DPTR, #DC_BANNER ;Get day count(2 bytes) & save temp copies. CALL OUT_STRING CALL IN_TIME MOV R2, A CALL IN_TIME MOV R3, A MOV DPTR, #DW_BANNER ;Get day of week value and add it on to CALL OUT_STRING ; the upper 3 bits of the hour register. CALL IN_TIME SWAP A RL A ANL A, #0E0h ORL A, R4 XCH A, R4 MOV DPTR, #NEW_LINE ;Add a blank line for esthetics. CALL OUT_STRING MOV TA, #0AAh ;We have all the values, now save them. MOV TA, #055h ;Perform a timed access to write to ORL RTCC, #04h ; set new time & date. CJNE A, ACC, $ ;Delay 4 machine cycles. MOV RTCSS, R7 MOV RTCS, R6 MOV RTCM, R5 MOV RTCH, R4 MOV RTCD0, R3 MOV RTCD1, R2 MOV TA, #0AAh ;Clear RTCWE bit to prevent accidental MOV TA, #055h ; changes to time registers. ANL RTCC, #0FBh LJMP CHAR_TEST ;Return and wait for another event. ;*************************************************************************** ;TELL_TIME displays the current time, alarm registers, and alarm status. ;*************************************************************************** TELL_TIME: MOV DPTR, #TT_BANNER ;Display current time. CALL OUT_STRING CALL OUT_TIME MOV DPTR, #ALM_BANNER;Display alarm registers. CALL OUT_STRING MOV R7, RTASS MOV R6, RTAS MOV R5, RTAM MOV R4, RTAH CALL DISP_TIME MOV DPTR, #COMPARE ;Now display the compare bits. CALL OUT_STRING MOV A, RTCC CALL DISP_COMP ;Display Hour compare bit. RR A CALL DISP_COMP ;Display Minute compare bit. RR A CALL DISP_COMP ;Display Second compare bit. RR A CALL DISP_COMP ;Display Subsecond compare bit. ORL RTCC, #08h ;Set the read bit to stop RTC update. CJNE A, ACC, $ ;Delay 4 machine cycles. MOV R4, RTCH ;Read the hour register. MOV R3, RTCD0 ;Read the day count registers. MOV R2, RTCD1 ANL RTCC, #0F7h ;Clear the read bit to restart RTC. MOV DPTR, #DW_BANNER ;Output Day of Week banner. CALL OUT_STRING ; the upper 3 bits of the hour register. MOV A, R4 ;Day of week is stored in upper 3 bits SWAP A ; of hour register. Move it to bits 2-0 RR A ; and multiply by 10 to get location ANL A, #07h ; within day of week table to start. MOV B, #0Ah MUL AB MOV DPTR, #DW_STRING ;Now add offset to starting address ADD A, DPL ; of data table to calculate new JNC NO_INC ; data pointer location. INC DPH NO_INC: MOV DPL, A CALL OUT_STRING MOV DPTR, #DC_BANNER ;Output day count banner. CALL OUT_STRING MOV A, R2 ;Send both registers of day count. CALL OUT_DIGIT MOV A, R3 CALL OUT_DIGIT MOV DPTR, #NEW_LINE ;Add a blank line for aesthetics. CALL OUT_STRING LJMP CHAR_TEST ;Return and wait for another event. ;This routine displays the status of the compare enable bit. DISP_COMP: JNB ACC.4, NO_COMP ;Display the hour compare bit. MOV DPTR, #YES JMP OUT_COMP NO_COMP: MOV DPTR, #NO OUT_COMP: CALL OUT_STRING RET ;This routine outputs the current time. OUT_TIME: ORL RTCC, #08h ;Set the read bit to stop RTC update. CJNE A, ACC, $ ;Delay 4 machine cycles. MOV R7, RTCSS ;Grab the current time / date and store MOV R6, RTCS ; them temporarily in working registers. MOV R5, RTCM MOV R4, RTCH ANL RTCC, #0F7h ;Clear the read bit to restart RTC. DISP_TIME: MOV A, R4 ;Output hour. ANL A, #01Fh ;Mask off day of week bits. CALL OUT_DIGIT MOV A, R5 ;Output Minute. CALL OUT_CDIGIT MOV A, R6 ;Output second. CALL OUT_CDIGIT MOV A, R7 ;Output subsecond. CALL OUT_CDIGIT RET ;*************************************************************************** ;SET_ALARM sets the alarm registers. ;*************************************************************************** SET_ALARM: CLR ERTCI ;Disable RTC interrupt and clear flag ANL RTCC, #0Fh ; during this section so that alarms will ; not be called while enables are changing. MOV DPTR, #NEW_BANNER CALL OUT_STRING MOV DPTR, #H_BANNER CALL OUT_STRING CALL IN_TIME ;Get hour & save temp copy. MOV R4, A CALL QUERY JNC ASK_M ORL RTCC, #10h ;Enable hour compare ASK_M: MOV DPTR, #M_BANNER CALL OUT_STRING CALL IN_TIME ;Get minute & save temp copy. MOV R5, A CALL QUERY JNC ASK_S ORL RTCC, #20h ;Enable minute compare ASK_S: MOV DPTR, #S_BANNER CALL OUT_STRING CALL IN_TIME ;Get second & save temp copy. MOV R6, A CALL QUERY JNC ASK_SS ORL RTCC, #40h ;Enable second compare ASK_SS: MOV DPTR, #SS_BANNER CALL OUT_STRING CALL IN_TIME ;Get subsecond & save temp copy. MOV R7, A CALL QUERY JNC ASK_X ORL RTCC, #80h ;Enable subsecond compare. ASK_X: MOV DPTR, #NEW_LINE CALL OUT_STRING MOV RTASS, R7 ;Save new alarm values. MOV RTAS, R6 MOV RTAM, R5 MOV RTAH, R4 ANL RTCC, #0FDh ;Clear the RTCI flag in case it was ; accidentally set while we were ; manipulating compare bits. SETB ERTCI ;Reenable RTC interrupt. LJMP CHAR_TEST QUERY: MOV DPTR, #COMPARE_Q CALL OUT_STRING JNB RI0, $ CLR RI0 MOV A, SBUF0 CALL OUT_CHAR ;Echo it. CJNE A, #'Y', NO_ENABLE ;If user wants compare, set flag. SETB C RET NO_ENABLE: CLR C ;User does not want compare, clear flag. RET ;****************************************************************** ;Output routines. ;****************************************************************** ;This subroutine outputs an ASCII string. The starting point of the string ;is in DPTR, and the terminating character is '0'. OUT_STRING: PUSH ACC ;Save accumulator. CHAR_LOOP: CLR A ;Clear accumulator for next instruction. MOVC A, @A + DPTR Get the next character from the JNZ NXT_CHAR ; string, and if 0, exit. POP ACC ;Restore accumulator. RET NXT_CHAR: CALL OUT_CHAR ;Next character is valid, so transmit INC DPTR ; it. Increment the data pointer JMP CHAR_LOOP ; to the next position and loop ; back to send character. ;This subroutine outputs a leading colon for the minute, second, and subsecond ; when displaying the time. When done, it falls through to OUT_DIGIT. OUT_CDIGIT: MOV SBUF0, #':' ;Display a colon. JNB TI0, $ CLR TI0 ;This subroutine outputs a hex number in ASCII format through serial port 0. OUT_DIGIT: MOV DPTR, #HEX_TABLE MOV R0, A ;Make another copy of value SWAP A ;Do high nibble fist ANL A, #0Fh ;Clear unused nibble MOVC A, @A+DPTR ;Get character from table CALL OUT_CHAR ;Transmit the character. MOV A, R0 ;Now do low nibble. ANL A, #0Fh ;Clear unused nibble MOVC A, @A+DPTR ;Get character from table CALL OUT_CHAR ;Transmit the character. RET ;Done OUT_CHAR: MOV SBUF0, A ;Transmit the character out the serial JNB TI0, $ ; port and wait until complete. CLR TI0 RET ;****************************************************************** ;Input routines. ;****************************************************************** ;IN_TIME takes two decimal characters from the serial port, and formats them ; as a hexadecimal number. IN_TIME: CALL IN_CHAR ;Get tens digit. MOV B, #0Ah ;Multiply first digit by 10 and save to MUL AB ; add to ones digit. XCH A, B CALL IN_CHAR ;Get ones digit and add it. ADD A, B ;Acc now has hex value of 2 decimal digit RET ; number. Exit. IN_CHAR: JNB RI0, $ ;Wait for character. CLR RI0 MOV A, SBUF0 CALL OUT_CHAR ;Echo character back. PUSH ACC ;Save copy of A. ANL A, #0F0h ;If bits 7-4 are not 3h, then character CJNE A, #30h, IN_CHAR ; is not 0-9. Get another character. POP ACC ;Restore A. ANL A, #0Fh ;Acc now contains 0-9 RET ;*************************************************************************** ;RTC_INT - This ISR notifies the user that an alarm has occurred, and gives ; the time of the alarm. ;*************************************************************************** RTC_INT: ANL RTCC, #0FDh ;Clear RTC Interrupt flag. MOV DPTR, #ALARM_MSG ;Display alarm message and time of alarm. CALL OUT_STRING CALL OUT_TIME RETI ;Return
MANUFACTURER | MODEL | CL | PACKAGE |
Epson Crystal Corp. | MC-306 32.768K E | 6.0pF | SMT |
MC-306 32.768K A | 12.5pF | SMT | |
KDS America | DT-26S 32.768kHz | 6.pF | Cylinder |
DT-26S 32.768kHz | 12.5pF | Cylinder | |
DMX-26 32.768kHz | 6.pF | SMT | |
DMX-26 32.768kHz | 12.5pF | SMT | |
AVX/Kyocera | KF-38G-12P5200 | 12.5pF | Cylinder |
KS-309G-12P5200 | 12.5pF | SMT |
;*************************************************************************** ;Program RTC_CALB.ASM ; ;This program configures the DS87C530 so that the internal RTC frequency can ;be measured. A 4kHz signal, derived by dividing the 32.768kHz RTC by 8, ;will be asserted on pin P1.7. The device will step through the 8 settings of ;the RTC trim bits, displaying the current contents of the trim register on ;port 3. A delay of approximately 15 seconds (at 25MHz) is inserted between ;each setting to allow time to record the frequency. ; ;To calibrate the RTC capacitance, connect a frequency counter to pin P1.7 and ;execute this program. Record the frequency from the counter and the trim bit ;settings as shown on port 3 as it steps through the 8 possible trim settings. ;The setting that produces a frequency closest to 4096Hz is the most accurate ;setting of RTC capacitance. ;*************************************************************************** RTCC equ 0F9h ;Real-time Clock Control TA equ 0C7h ;Timed Access Register TRIM equ 96h ;RTC Trim Register P3 equ 0B0h ;Port 3 Latch ;These definitions are for 6pF crystal calibration. TRIM0 equ 95h ;First trim bit setting (6pF) TRIM1 equ 96h ;Second trim bit setting (6pF) TRIM2 equ 99h ;Third trim bit setting (6pF) TRIM3 equ 9Ah ;Fourth trim bit setting (6pF) TRIM4 equ 0A5h ;Fifth trim bit setting (6pF) TRIM5 equ 0A6h ;Sixth trim bit setting (6pF) TRIM6 equ 0A9h ;Seventh trim bit setting (6pF) TRIM7 equ 0AAh ;Eighth trim bit setting (6pF) ;These definitions are for 12.5pF crystal calibration. ;TRIM0 equ 0D5h ;First trim bit setting (12.5pF) ;TRIM1 equ 0D6h ;Second trim bit setting (12.5pF) ;TRIM2 equ 0D9h ;Third trim bit setting (12.5pF) ;TRIM3 equ 0DAh ;Fourth trim bit setting (12.5pF) ;TRIM4 equ 0E5h ;Fifth trim bit setting (12.5pF) ;TRIM5 equ 0E6h ;Sixth trim bit setting (12.5pF) ;TRIM6 equ 0E9h ;Seventh trim bit setting (12.5pF) ;TRIM7 equ 0EAh ;Eighth trim bit setting (12.5pF) ; cseg at 0 ;Reset vector. LJMP START cseg at 100H ;Start of program ; START: MOV P3, #0AAh ;I'm alive message. MOV TA, #0AAh ;Timed access. MOV TA, #55h MOV RTCC, #01h ;Start RTC and clear RTC interrupt flag. LCALL HALFSEC ;Delay to give RTC oscillator time to ; warm up. ; End of initialization. Now step through all the settings of the trim bits. MOV R0, #TRIM0 ;Trim setting 0 LCALL NEXT_SETTING MOV R0, #TRIM1 ;Trim setting 1 LCALL NEXT_SETTING MOV R0, #TRIM2 ;Trim setting 2 LCALL NEXT_SETTING MOV R0, #TRIM3 ;Trim setting 3 LCALL NEXT_SETTING MOV R0, #TRIM4 ;Trim setting 4 LCALL NEXT_SETTING MOV R0, #TRIM5 ;Trim setting 5 LCALL NEXT_SETTING MOV R0, #TRIM6 ;Trim setting 6 LCALL NEXT_SETTING MOV R0, #TRIM7 ;Trim setting 7 LCALL NEXT_SETTING MOV P3, #0FFh ;Turn on all port 3 pins to signal DONE: JMP DONE ; we're done. ;*************************************************************************** ;NEXT_SETTING - This subroutine writes the new setting to the RTC trim register, ; displays the value of the trim register on port 3 for reference, ; and delays for a period to give time to record the data ;*************************************************************************** NEXT_SETTING: MOV TA, #0AAH ;Timed access. MOV TA, #55h MOV TRIM, R0 ;Set E4K and new trim setting. NOP MOV P3, TRIM ;Output value of trim register. SEC30: MOV R3, #30 ;15 second delay with 25MHz crystal. SECLOOP: LCALL HALFSEC DJNZ R3,SECLOOP RET ;*************************************************************************** ;HALFSEC - This subroutine generates a delay of approximately 0.5 second with ; a 25MHz crystal. ;*************************************************************************** HALFSEC: MOV R0,#25 OUTER: MOV R1,#125 MIDDLE: MOV R2,#249 INNER: NOP DJNZ R2,INNER DJNZ R1,MIDDLE DJNZ R0,OUTER RET
全部0条评论
快来发表一下你的评论吧 !