'PIC 16F628A with 2 line * 16 char LCD 'used for freq measurement dev 26/07/08 AllDigital Symbol menukey = PORTA.1 Symbol inckey = PORTA.2 Symbol deckey = PORTA.3 Symbol acceptkey = PORTA.5 Dim b2avall As Byte Dim b2avalm As Byte Dim b2avalh As Byte Dim ascbfr7 As Byte Dim ascbfr6 As Byte Dim ascbfr5 As Byte Dim ascbfr4 As Byte Dim ascbfr3 As Byte Dim ascbfr2 As Byte Dim ascbfr1 As Byte Dim ascbfr0 As Byte Dim temp1 As Byte Dim temp2 As Byte Dim cntr1 As Byte Dim cntr2 As Byte Dim tmr0_cnt As Byte Dim tmr1_cnt As Byte Dim sim As Byte TRISB = 0x40 'PB.6 is ext pulses input pin #12 T1CON = 0x30 T1CON.TMR1CS = 0 Define SIMULATION_WAITMS_VALUE = 1 Define LCD_LINES = 2 Define LCD_CHARS = 16 Define LCD_BITS = 4 Define LCD_DREG = PORTB Define LCD_DBIT = 0 Define LCD_RSREG = PORTB Define LCD_RSBIT = 4 Define LCD_EREG = PORTB Define LCD_EBIT = 5 Define LCD_RWREG = PORTB Define LCD_RWBIT = 7 Define LCD_READ_BUSY_FLAG = 1 INTCON.GIE = 0 INTCON.PEIE = 0 PIE1.TMR1IE = 0 PIR1.TMR1IF = 0 Lcdinit frequency: Lcdout "Freq Counter V1" ASM: movlw 0x06 'T1 ext osc sync off,external clk, timer1 off ASM: movwf T1CON 't1 ext clock input via RC0 ASM: bsf STATUS,RP0 ASM: movlw 0x86 'timer 1:128, pu off ASM: movwf OPTION_REG ASM: bcf STATUS,RP0 nxt_freq: ASM: movlw 0x07 'T1 ext osc sync off,timer1 on ASM: movwf T1CON tmr0_cnt = 25 '1 sec count 25 ASM: clrf tmr1_cnt ASM: clrf TMR0 ASM: bcf INTCON,2 ASM: bcf PIR1,0 'clr tmr1 INTF ASM: clrf TMR1L 'zero timer1 ASM: clrf TMR1H timer1: ASM: btfss PIR1,0 Goto timer0 'no timer1 overflow ASM: bcf PIR1,0 'clr tmr1 INTF ASM: incf tmr1_cnt,F 'inc tmr1 cntr timer0: ASM: btfss INTCON,2 Goto timer1 'no timer0 overflow ASM: bcf INTCON,2 'clr TMR0 INTF ASM: decfsz tmr0_cnt,F 'dec tmr0 cntr Goto timer1 'Not zero so loop again ASM: movlw 0x00 'its zero ASM: movwf T1CON 'stop tmr1 b2avall = TMR1L b2avalm = TMR1H b2avalh = tmr1_cnt Gosub bin2asc Lcdcmdout LcdLine2Home Lcdout ascbfr7, ascbfr6, ascbfr5, ascbfr4, ascbfr3, ascbfr2, ascbfr1, ascbfr0, " hZ" WaitMs 250 Goto nxt_freq End 'this is used for freq 'convert 24bit bin To 8 asci in ascbfr0 bin2asc: ASM: clrf ascbfr7 ASM: clrf ascbfr6 ASM: clrf ascbfr5 ASM: clrf ascbfr4 ASM: clrf ascbfr3 ASM: clrf ascbfr2 ASM: clrf ascbfr1 ASM: clrf ascbfr0 ASM: movlw .24 ASM: movwf temp1 bitlp2: ASM: rlf b2avall,F ASM: rlf b2avalm,F ASM: rlf b2avalh,F ASM: movlw ascbfr0 ASM: movwf FSR ASM: movlw 0x8 ASM: movwf temp2 adjlp2: ASM: rlf INDF,F ASM: movlw 0x0a ASM: subwf INDF,W ASM: btfsc STATUS,C ASM: movwf INDF ASM: decf FSR,F ASM: decfsz temp2,F Goto adjlp2 ASM: decfsz temp1,F Goto bitlp2 ASM: movlw 0x30 ASM: iorwf ascbfr7,F ASM: iorwf ascbfr6,F ASM: iorwf ascbfr5,F ASM: iorwf ascbfr4,F ASM: iorwf ascbfr3,F ASM: iorwf ascbfr2,F ASM: iorwf ascbfr1,F ASM: iorwf ascbfr0,F If ascbfr7 = 0x30 Then ascbfr7 = 0x20 Else Goto skipz Endif If ascbfr6 = 0x30 Then ascbfr6 = 0x20 Else Goto skipz Endif If ascbfr5 = 0x30 Then ascbfr5 = 0x20 Else Goto skipz Endif If ascbfr4 = 0x30 Then ascbfr4 = 0x20 Else Goto skipz Endif If ascbfr3 = 0x30 Then ascbfr3 = 0x20 Else Goto skipz Endif If ascbfr2 = 0x30 Then ascbfr2 = 0x20 Else Goto skipz Endif If ascbfr1 = 0x30 Then ascbfr1 = 0x20 Endif skipz: Return