Z8 a 6 digit and 1/2, frequencymeter Th's a first part of the program, without running display alphanumeric 1x16 LCD. But is a demonstration with Zilog Z8 MCU, to measure the frequency. The maxim frequency is 1,7 Mhz with 10 Mhz crystal oscillator, using the timer T0 (100 Hz) and T1 (prescaler). The last part of the program, when to make complete frequencymeter. NOTE(*): It is necessary a little correction on the value PRE0 and SEC, because the INT0 has the priority on the INT1, and then a conseguent error on the FX counter. With SEC=82 the delay time is about 203 microsec, from to add the INT1. For 10 Mhz crystal oscillator the correct value is: PRE0=61, SEC=82 (81,97 Hz) and with 16 Mhz crystal PRE0=58, SEC=138 (137,93 Hz), FX max=2,7 Mhz. ;ASSEMBLER Z8 PROG. BY IK1WJQ - XTAL = 10 MHZ (*) ;FREQ.ASM Z86E04/8 - OUT T0 = 82 HZ READ ONE SECOND, FX (*) ;T1 = FX/100, PRECISION MEASURE MINIMUN DIGIT ;P31 INPUT FX - MAX FREQUENCY = 1,7 MHZ (6 DIGIT AND 1/2) ;P00 OUT LED RT1 EQU 17 ;COUNTER DELAY FLASH LED RT2 EQU 18 UNI EQU R15 ;1 (7 DIGIT ASCII IN MEMORY) DCN EQU R14 ;10 CEN EQU R13 ;100 MIG EQU R12 ;1.000 DMI EQU R11 ;10.000 CMI EQU R10 ;100.000 MIL EQU R9 ;1.000.000 SEC EQU R8 ;82 = 1 SEC. TIMER 0 ACC EQU R4 ;ACCUMULATOR REGISTER B EQU R5 ;AUXILIARY REGISTER CT EQU RR6 ;COUNTER 16 BIT R7 AND R6 ORG 0008H ;INT T0 81,97 HZ(*) WORD #INT0 ;JUMP IRQ4 = INT0 ORG 000AH ;INT T1 WORD #INT1 ;JUMP IRQ5 = INT1 ORG 000CH LD P01M,#4 ;P0 OUT MODE CLR RP ;R0-R3 ALSO P0-P3 CLR R0 LD SPL,#127 LD P3M,#1 ;P3 DIGITAL MODE LD P2M,#0 ;P2 OUT MODE LD PRE0,#11110101B ;PRE0=61 CLOCK INTERNAL, MODULO N (*) LD PRE1,#00000101B ;PRE1=1 CLOCK EXTERNAL, MODULO N LD T0,#250 ;XTAL/8/61/250 = 81,97 HZ IRQ4 (*) LD T1,#100 ;INPUT P31 / 100 = FX/100 IRQ5 OR TMR,#0FH ;LOAD AND ENABLE T0, T1 DI ;NO INT OR IMR,#30H ;ENABLE INT T0, T1 OR IPR,#3 ;IRQ4 > IRQ5 CLR R6 ;CLEAR CT CLR R7 LD SEC,#82 ;SET SEC = 82, ONE SECOND (*) EI ;ENABLE INT INI: CALL RIT ;FLASH LED OR R0,#1 CALL RIT AND R0,#6 JR INI INT0: DJNZ SEC,INTR AND TMR,#F5H ;STOP T0 AND T1 DI ;STOP ALL INT LD UNI,#48 ;PREPARE ALL 7 DIGIT ASCII = 0 LD DCN,#48 LD CEN,#48 LD MIG,#48 LD DMI,#48 LD CMI,#48 LD MIL,#48 LD ACC,#100 ;READ DIGIT 1 TO 2 LD B,T1 SUB ACC,B JR Z,FINE ;NO COUNTER CP ACC,#100 ;TEST T1 = 0 (100 HZ) JR NZ,CONT INCW CT ;CT + 100 HZ JR DEC2 CONT: INC ACC ;ACC + 1 CORRECTION DECX: DJNZ ACC,DEC1 JR DEC2 ;CONTINUE FOR 3 TO 7 DIGIT DEC1: INC UNI ;1 CP UNI,#58 JR NZ,DECX LD UNI,#48 INC DCN ;10 CP DCN,#58 JR NZ,DECX LD DCN,#48 JR DECX DEC2: LD ACC,R6 ;TEST CT = 0 OR ACC,R7 JR Z,FINE INC CEN ;100 CP CEN,#58 JR NZ,DCC LD CEN,#48 INC MIG ;1.000 CP MIG,#58 JR NZ,DCC LD MIG,#48 INC DMI ;10.000 CP DMI,#58 JR NZ,DCC LD DMI,#48 INC CMI ;100.000 CP CMI,#58 JR NZ,DCC LD CMI,#48 INC MIL ;1.000.000 DCC: DECW CT ;CT = CT-1 JR DEC2 FINE: OR TMR,#0FH ;ENABLE T0 E T1 LD SEC,#82 ;PREPARE SEC FOR NEW READING EI INTR: IRET ;RETURN INT IRQ4 INT1: INCW CT ;R7 AND R6 COUNTER 16 BIT IRET ;FX MAX. = 1,7 MHZ RIT: LD RT1,#125 ;DELAY PAU: CLR RT2 PAU1: NOP NOP DEC RT2 JR NZ,PAU1 PAU2: NOP NOP DEC RT2 JR NZ,PAU2 DEC RT1 JR NZ,PAU RET END Vai a Pagina1