;******************************************************************************** ;A digital dial up to 4,5 MHz on AT90S2313 microprocessor ;Quartz of 10 MHz ;The author: Ankudinov A.N. (UA3VVM), mail: ua3vvm@mail.ru ;Cycle of the score is organized on interruption from counter T/C1 ;LED indication of 5 discharge, possibility of magnification ;up to 10 discharge. The data on the digital indicator are gated out with usage ;the sequential code. ;******************************************************************************** .cseg .include "2313def.inc" .org 0 rjmp main_program .org ovf1addr ; Interrupt processing from T/C1 rjmp calculus .def zero=r24 .def f3=r3 .def f4=r4 ; To reset bits tov0 having installed it .def fm1=r10 ; Variables .def fm2=r11 ; for storage .def fm3=r12 ; outcome .def fm4=r13 ; scores of impulses .def odin=r14 ; the Increment for the score of impulses .def temp=r9 ; ******************************************************************************** ; Initial adjustments of the program ; ******************************************************************************** main_program: sei ; To resolve interruptions ldi r16, $df ; To adjust the beginning of the stack out spl, r16 ; on extremity SRAM ldi r18,0b11111 ; Inclusion of the sentry timer on reset through 2.048 second. out wdtcr, r18 ldi r16,0b00000110 ; Initialization of a port of a terminating connection out ddrb, r16 ; on a terminating connection the 3-wire busbar, bits 1,2 ports "b" works; bits "1" - clocking ; bits "2" - a data bit clr zero ; Value "0" clr fm1 clr fm2 clr fm3 clr fm4 ldi r19, $01 mov odin, r19 ; the Increment for the score of an amount of overfillings TCNT0 ldi r18, $02 mov f4, r18 ; f4 receives value a bat for adjustment TOV0 ; ******************************************************************************* ; Initialization of counter T/S1 for organization of period of the score of impulses 0.1 second. in r17, timsk ; To allow ori r17, $80 ; interruptions on out timsk, r17 ; to overflow T/C1 ldi r16, high ($ffff-15625) ; To consider from 0 up to 15625 out tcnt1h, r16 ldi r16, low ($ffff-15625) ; To consider from 0 up to 15625 out tcnt1l, r16 ldi r17, $03 ; the Adjustment of preliminary divider SK/64 ; ******************************************************************************** ; Initialization of counter T/C0 ; Base 32 program of the bit impulse counter ; Countable input terminal T0 of counter T/C0 ldi r20, $07 ; the Score of external impulses from input terminal ã0 out tifr, f4 ; we Shall reset bits TOV0, having installed it out tccr0, r20 ; we Start for counter T/C0 (entry impulses) out tccr1b,r17 ; we Start for counter T/C1 with the adjustment of interruption 0.1 second count: ; we Start the score of impulses before obtaining interruption from T/C1 cikl: in f3, tifr sbrc f3, $01 ; Skip if bits tov0 it is reset rjmp cikl2 rjmp count cikl2: add fm3, odin ; If timer T/C0 was overflew to add 1 adc fm2, zero ; To fulfil addition with transposition in high adc fm1, zero ; discharge& of the counter out tifr, f4 ; we Shall reset(dump) bits TOV0, having installed it rjmp count ; ******************************************************************************** ; The handler of the given countable registers calculus: out tccr0, zero ; we shall Stop the impulse counter on T/C0 in fm4, tcnt0 ; we shall Receive residual from empty timer T/C0 out tcnt0, zero ; To unset timer T/C0 ; ******************************************************************************* ; A subprogram of a subtraction of value of intermediate frequency " 500 KHz " ; ; ldi r18, $00 ; In rightmost tens Hz are displayed at period ; ldi r19, $00 ; scores in 0.1 second. 500 KHz = 50000 = C350h ; ldi r20, $C3 ; ldi r21, $50 ; ; sub fm4, r21; low ; sbc fm3, r20 ; sbc fm2, r19 ; sbc fm1, r18; high ; ******************************************************************************* ; A subprogram of addition of value of intermediate frequency " 500 KHz " ; ; ldi r18, $00 ; In rightmost tens Hz are displayed at period ; ldi r19, $00 ; scores in 0.1 second. 500 KHz = 50000 = C350h ; ldi r20, $C3 ; ldi r21, $50 ; ; add fm4, r21; low ; adc fm3, r20 ; adc fm2, r19 ; adc fm1, r18; higt ; ******************************************************************************* ; the PROGRAM of translation 16h-> 10 ; ; The initial number xxxxxxxxh fm1, fm2, fm3, fm4 ; The divider r18, r19, r20, r21 ; The answer r25 ; Workers r15, r17, r22, r23 clr r23 ; the Register of converting ldi r18, $3B ;:1 000 000 000=3B 9A CA 00 ldi r19, $9A ldi r20, $CA ldi r21, $00 rcall delen mov r0, r25 ; in R0 the data for the discharge #0 ldi r18, $05 ; 1 discharge ldi r19, $F5 ;:100 000 000=05 F5 E1 00 ldi r20, $E1 rcall delen mov r1, r25 ; in R1 the data for the discharge #1 ldi r18, $00 ; 2 discharge ldi r19, $98 ;:10 000 000=00 98 96 80 ldi r20, $96 ldi r21, $80 rcall delen mov r2, r25 ; in R2 the data for the discharge #2 ldi r18, $00 ; 3 discharge ldi r19, $0F ;:1 000 000=00 0F 42 40h ldi r20, $42 ldi r21, $40 rcall delen mov r3, r25 ; in R3 the data for the discharge #3 ldi r19, $01 ; 4 discharge ldi r20, $86 ;:100 000=00 01 86 A0h ldi r21, $A0 rcall delen mov r4, r25 ; in R4 the data for the discharge #4 ldi r19, $00 ; 5 discharge ldi r20, $27 ;:10 000=00 00 27 10h ldi r21, $10 rcall delen mov r5, r25 ; in R5 the data for the discharge #5 ldi r20, $03 ; 6 discharge ldi r21, $E8 ;:1 000=00 00 03 E8h rcall delen mov r6, r25 ; in R6 the data for the discharge #6 ldi r20, $00 ; 7 discharge ldi r21, $64 ;:100=00 00 00 64h rcall delen mov r7, r25 ; in R7 the data for the discharge #7 ldi r21, $0A ; 8 discharge rcall delen ;:10=00 00 00 0Ah mov r8, r25 ; in R8 the data for the discharge #8 mov r9, fm4 ; 9 discharge; in R9 the data for the discharge #9 ; ******************************************************************************* ; Recording decoded 10 - in 7 segment values in registers R0-R9 ldi r19,0b10000000 ; the Code of a decimal point mov r20, r0 rcall decoder mov r0, r21 mov r20, r1 rcall decoder mov r1, r21 mov r20, r2 rcall decoder mov r2, r21 mov r20, r3 rcall decoder mov r3, r21 mov r20, r4 rcall decoder mov r4, r21 mov r20, r5 rcall decoder mov r5, r21 mov r20, r6 rcall decoder mov r6, r21 mov r20, r7 rcall decoder add r21, r19 ;Inclusion of a decimal point in 8 discharge mov r7, r21 mov r20, r8 rcall decoder mov r8, r21 mov r20, r9 rcall decoder mov r9, r21 ; ******************************************************************************* ; A terminating connection to indication on 2 - the wire busbar (DATA, CK) 5 discharge ; Gauged frequency. ; In rightmost hundreds hertz of entry frequency are displayed. ; The point separates kilohertz. ; r8 - youngest registers containing 40 data bit for a terminating connection ; r7 ; r6 ; r5 ; r4 - oldest ldi r21, $8 ; the counter bits with decrement read_byte1: ror r8 brcs C1 ; passage if C=1 brcc C0 ; passage if C=0 C1: sbi portb, 2 ; to output in a port In a data bit rcall CK ; to output in a port In clocking impulse dec r21 brne read_byte1 rjmp A2 ; passage if the byte was completed; on 1, and the counter bits was unset C0: cbi portb, 2 ; to output in a port In a data bit rcall CK ; to output in a port In clocking impulse dec r21 brne read_byte1 A2: ldi r21, $8 ; the counter bits with decrement read_byte2: ror r7 brcs C2_1 ; passage if C=1 brcc C2_0 ; passage if C=0 C2_1: sbi portb, 2 ; to output in a port In a data bit rcall CK ; to output in a port In clocking impulse dec r21 brne read_byte2 rjmp A3 ; passage if the byte was completed; on 1, and the counter bits was unset C2_0: cbi portb, 2 ; to output in a port In a data bit rcall CK ; to output in a port In clocking impulse dec r21 brne read_byte2 A3: ldi r21, $8 ; the counter bits with decrement read_byte3: ror r6 brcs C3_1 ; passage if C=1 brcc C3_0 ; passage if C=0 C3_1: sbi portb, 2 ; to output in a port In a data bit rcall CK ; to output in a port In clocking impulse dec r21 brne read_byte3 rjmp A4 ; passage if the byte was completed; on 1, and the counter bits was unset C3_0: cbi portb, 2 ; to output in a port In a data bit rcall CK ; to output in a port In clocking impulse dec r21 brne read_byte3 A4: ldi r21, $8 ; the counter bits with decrement read_byte4: ror r5 brcs C4_1 ; passage if C=1 brcc C4_0 ; passage if C=0 C4_1: sbi portb, 2 ; to output in a port In a data bit rcall CK ; to output in a port In clocking impulse dec r21 brne read_byte4 rjmp A5 ; passage if the byte was completed; on 1, and the counter bits was unset C4_0: cbi portb, 2 ; to output in a port In a data bit rcall CK ; to output in a port In clocking impulse dec r21 brne read_byte4 A5: ldi r21, $8 ; the counter bits with decrement read_byte5: ror r4 brcs C5_1 ; passage if C=1 brcc C5_0 ; passage if C=0 C5_1: sbi portb, 2 ; to output in a port In a data bit rcall CK ; to output in a port In clocking impulse dec r21 brne read_byte5 rjmp all_leds ; passage if the byte was completed; on 1, and the counter bits was unset C5_0: cbi portb, 2 ; to output in a port In a data bit rcall CK ; to output in a port In clocking impulse dec r21 brne read_byte5 all_leds: wdr ; To reset the sentry timer rjmp main_program ; Repetition of cycle of the score with simultaneous indication ; ****************************************************************************** ; A division subroutine delen: ldi r25,-1 SUBii: inc r25 sub fm4, r21 ; low sbc fm3, r20 sbc fm2, r19 sbc fm1, r18 ; high brsh SUBi1 ; Passage if > 0 add fm4, r21 ; low adc fm3, r20 adc fm2, r19 adc fm1, r18 ; high ret SUBi1: ldi r23, $FF rjmp SUBii ; ******************************************************************************* ; A subprogram of decoding of 10 values in 7 segment ; ; __ hgfedcba - segments ; 0b00000000 - bits in the register ; decoder: cpi r20,0x00 breq SA cpi r20,0x01 breq S1 cpi r20,0x02 breq S2 cpi r20,0x03 breq S3 cpi r20,0x04 breq S4 cpi r20,0x05 breq S5 cpi r20,0x06 breq S6 cpi r20,0x07 breq S7 cpi r20,0x08 breq S8 cpi r20,0x09 breq S9 S1: ldi r21,0b11111001 ; Digit " 1 " - the inverted values rjmp DD S2: ldi r21,0b10100100 ; Digit " 2 " rjmp DD S3: ldi r21,0b10110000 ; Digit " 3 " rjmp DD S4: ldi r21,0b10011001 ; Digit " 4 " rjmp DD S5: ldi r21,0b10010010 ; Digit " 5 " rjmp DD S6: ldi r21,0b10000010 ; Digit " 6 " rjmp DD S7: ldi r21,0b11111000 ; Digit " 7 " rjmp DD S8: ldi r21,0b10000000 ; Digit " 8 " rjmp DD S9: ldi r21,0b10010000 ; Digit " 9 " rjmp DD SA: ldi r21,0b11000000 ; Digit " 0 " DD: ret ; ******************************************************************************** ; A subprogram clocking impulse CK: sbi portb, 1 ; to output in a port In clocking impulse nop nop nop nop nop nop cbi portb, 1 ret ;******************************************************************************** ;The program of a frequency meter - digital dial up to 4,5 MHz; ;Additional service functions are not realized, ;intermediate frequency is programmed at wearing the processor. ;It is corrected and organized 04 April 2004. ;********************************************************************************