; LED Signal Meter for Nikko NT-790 FM Tuner ; This 13 LED bar takes its input from pin#13 of the LA1231 IF FM demodulator chip. Since the linearity of this ; voltage is somewhat lacking the comparator values reflect this. There are five comparisons which makes the jump ; from one LED to the next more fluid. Duty cycle changes from 1/16, 1/8, 1/4 and 1/2 to full on. The whole process ; takes about 1.1 ms. Every LED corresponds to a 5 dB change in signal level and every V level with 1 dB. Roughly. ; GPL Copyleft 2021 pic@polonai.se ; v0.0 210203 Start project ; v1.0 210204 Release ; v1.1 210206 Fix linearity after mod in Nikko ; v1.2 210206 Improve LED brightness smoothness by introducing extra delay (duty cycle) ; v1.3 210207 Added 14th LED LIST P=16F818, F=INHX8M #include <p16f818.inc> __CONFIG _WDT_OFF & _PWRTE_OFF & _INTRC_IO & _MCLR_ON & _BODEN_OFF & _LVP_OFF & _CPD_ON & _WRT_ENABLE_OFF & _DEBUG_OFF & _CCP1_RB2 & _CP_ALL ERRORLEVEL -302 ; remove compiler message about using proper bank ; Equates RESET_V EQU 0x00 ; Address of RESET Vector OSC_FREQ EQU D'4000000' ; Internal Oscillator Frequency is 4 MHz (OSCCON) ; Registers d1 EQU 0x21 ; Delay registers used during Lamp Test, LED duty cycle d2 EQU 0x22 ; Defines #define LED1 PORTB,0 #define LED2 PORTB,1 #define LED3 PORTB,2 #define LED4 PORTB,3 #define LED5 PORTB,4 #define LED6 PORTB,5 #define LED7 PORTB,6 #define LED8 PORTB,7 #define LED9 PORTA,6 #define LED10 PORTA,7 #define LED11 PORTA,1 #define LED12 PORTA,2 #define LED13 PORTA,3 #define LED14 PORTA,4 ; AN0 (PORTA,0 aka SIGMET) has no label defined ORG 0 GOTO START ORG 4 ; Interrupts ; There are none START ; Init stuff CLRF PORTB ; Make all PORT B outputs low to prevent LED flash CLRF PORTA ; Ditto PORT A CLRF STATUS ; Do initialization, select Bank 0 CLRF INTCON ; Clear int-flags, disable interrupts CLRF PCLATH ; Keep in lower 2KByte CLRF CCP1CON MOVLW B'00100001' BSF STATUS,RP0 ; Select Bank 1 MOVWF TRISA ; RA7,6,4-1 Outputs, MCLR,AN0 Input CLRF TRISB ; RB7-0 Outputs MOVLW B'00000110' ; Timer0, prescaler 1:128 MOVWF OPTION_REG MOVLW B'01100000' ; 4 MHz clock MOVWF OSCCON MOVLW B'00001110' ; AN0 Analog input, AN1-4 Digital IO, ADRESH only (ADRESL discarded) MOVWF ADCON1 BCF STATUS,RP0 ; Select Bank 0 MOVLW B'01000001' ; AD conv ON, AN0 Selected, Fosc/8 (T(AD)=1us) MOVWF ADCON0 ; Lamp Test! Yeah! BSF LED1 CALL LONGDLY BSF LED2 CALL LONGDLY BSF LED3 CALL LONGDLY BSF LED4 CALL LONGDLY BSF LED5 CALL LONGDLY BSF LED6 CALL LONGDLY BSF LED7 CALL LONGDLY BSF LED8 CALL LONGDLY BSF LED9 CALL LONGDLY BSF LED10 CALL LONGDLY BSF LED11 CALL LONGDLY BSF LED12 CALL LONGDLY BSF LED13 CALL LONGDLY BSF LED14 CALL LONGDLY BCF LED1 CALL LONGDLY BCF LED2 CALL LONGDLY BCF LED3 CALL LONGDLY BCF LED4 CALL LONGDLY BCF LED5 CALL LONGDLY BCF LED6 CALL LONGDLY BCF LED7 CALL LONGDLY BCF LED8 CALL LONGDLY BCF LED9 CALL LONGDLY BCF LED10 CALL LONGDLY BCF LED11 CALL LONGDLY BCF LED12 CALL LONGDLY BCF LED13 CALL LONGDLY BCF LED14 CALL LONGDLY MAIN BSF ADCON0,GO ; Start A/D (read SIGMET) CONV0 NOP BTFSC ADCON0,GO ; Test if A/D conversion done GOTO CONV0 MOVFW ADRESH ; Move 8 bit A/D result (SIGMET) to W V0 BCF LED1 ADDLW 0xF6 BTFSC STATUS,C ; Level > 0x09? BSF LED1 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED2 ADDLW 0xE9 BTFSC STATUS,C ; Level (etc.) BSF LED2 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED3 ADDLW 0xE0 BTFSC STATUS,C ; Level (etc.) BSF LED3 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED4 ADDLW 0xD2 BTFSC STATUS,C ; Level (etc.) BSF LED4 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED5 ADDLW 0xC4 BTFSC STATUS,C ; Level (etc.) BSF LED5 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED6 ADDLW 0xB9 BTFSC STATUS,C ; Level (etc.) BSF LED6 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED7 ADDLW 0xB0 BTFSC STATUS,C ; Level (etc.) BSF LED7 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED8 ADDLW 0xA4 BTFSC STATUS,C ; Level (etc.) BSF LED8 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED9 ADDLW 0x8F BTFSC STATUS,C ; Level (etc.) BSF LED9 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED10 ADDLW 0x74 BTFSC STATUS,C ; Level (etc.) BSF LED10 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED11 ADDLW 0x60 BTFSC STATUS,C ; Level (etc.) BSF LED11 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED12 ADDLW 0x50 BTFSC STATUS,C ; Level (etc.) BSF LED12 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED13 ADDLW 0x39 BTFSC STATUS,C ; Level (etc.) BSF LED13 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED14 ADDLW 0x1D BTFSC STATUS,C ; Level (etc.) BSF LED14 ; Yes MOVFW ADRESH ; Get SIGMET value V1 BCF LED1 ADDLW 0xF4 BTFSC STATUS,C ; Level (etc.) BSF LED1 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED2 ADDLW 0xE7 BTFSC STATUS,C ; Level (etc.) BSF LED2 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED3 ADDLW 0xDD BTFSC STATUS,C ; Level (etc.) BSF LED3 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED4 ADDLW 0xCF BTFSC STATUS,C ; Level (etc.) BSF LED4 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED5 ADDLW 0xC1 BTFSC STATUS,C ; Level (etc.) BSF LED5 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED6 ADDLW 0xB7 BTFSC STATUS,C ; Level (etc.) BSF LED6 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED7 ADDLW 0xAE BTFSC STATUS,C ; Level (etc.) BSF LED7 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED8 ADDLW 0xA0 BTFSC STATUS,C ; Level (etc.) BSF LED8 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED9 ADDLW 0x89 BTFSC STATUS,C ; Level (etc.) BSF LED9 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED10 ADDLW 0x6F BTFSC STATUS,C ; Level (etc.) BSF LED10 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED11 ADDLW 0x5D BTFSC STATUS,C ; Level (etc.) BSF LED11 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED12 ADDLW 0x4C BTFSC STATUS,C ; Level (etc.) BSF LED12 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED13 ADDLW 0x32 BTFSC STATUS,C ; Level (etc.) BSF LED13 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED14 ADDLW 0x18 BTFSC STATUS,C ; Level (etc.) BSF LED14 ; Yes MOVFW ADRESH ; Get SIGMET value V2 BCF LED1 ADDLW 0xF2 BTFSC STATUS,C ; Level (etc.) BSF LED1 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED2 ADDLW 0xE6 BTFSC STATUS,C ; Level (etc.) BSF LED2 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED3 ADDLW 0xDA BTFSC STATUS,C ; Level (etc.) BSF LED3 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED4 ADDLW 0xCC BTFSC STATUS,C ; Level (etc.) BSF LED4 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED5 ADDLW 0xBF BTFSC STATUS,C ; Level (etc.) BSF LED5 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED6 ADDLW 0xB5 BTFSC STATUS,C ; Level (etc.) BSF LED6 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED7 ADDLW 0xAC BTFSC STATUS,C ; Level (etc.) BSF LED7 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED8 ADDLW 0x9C BTFSC STATUS,C ; Level (etc.) BSF LED8 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED9 ADDLW 0x83 BTFSC STATUS,C ; Level (etc.) BSF LED9 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED10 ADDLW 0x6B BTFSC STATUS,C ; Level (etc.) BSF LED10 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED11 ADDLW 0x5B BTFSC STATUS,C ; Level (etc.) BSF LED11 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED12 ADDLW 0x47 BTFSC STATUS,C ; Level (etc.) BSF LED12 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED13 ADDLW 0x2D BTFSC STATUS,C ; Level (etc.) BSF LED13 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED14 ADDLW 0x13 BTFSC STATUS,C ; Level (etc.) BSF LED14 ; Yes CALL V2DELAY MOVFW ADRESH ; Get SIGMET value V3 BCF LED1 ADDLW 0xEF BTFSC STATUS,C ; Level (etc.) BSF LED1 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED2 ADDLW 0xE4 BTFSC STATUS,C ; Level (etc.) BSF LED2 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED3 ADDLW 0xD7 BTFSC STATUS,C ; Level (etc.) BSF LED3 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED4 ADDLW 0xC9 BTFSC STATUS,C ; Level (etc.) BSF LED4 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED5 ADDLW 0xBD BTFSC STATUS,C ; Level (etc.) BSF LED5 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED6 ADDLW 0xB3 BTFSC STATUS,C ; Level (etc.) BSF LED6 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED7 ADDLW 0xA9 BTFSC STATUS,C ; Level (etc.) BSF LED7 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED8 ADDLW 0x98 BTFSC STATUS,C ; Level (etc.) BSF LED8 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED9 ADDLW 0x7E BTFSC STATUS,C ; Level (etc.) BSF LED9 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED10 ADDLW 0x67 BTFSC STATUS,C ; Level (etc.) BSF LED10 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED11 ADDLW 0x58 BTFSC STATUS,C ; Level (etc.) BSF LED11 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED12 ADDLW 0x43 BTFSC STATUS,C ; Level (etc.) BSF LED12 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED13 ADDLW 0x27 BTFSC STATUS,C ; Level (etc.) BSF LED13 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED14 ADDLW 0x0E BTFSC STATUS,C ; Level (etc.) BSF LED14 ; Yes CALL V3DELAY MOVFW ADRESH ; Get SIGMET value V4 BCF LED1 ADDLW 0xEB BTFSC STATUS,C ; Level (etc.) BSF LED1 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED2 ADDLW 0xE2 BTFSC STATUS,C ; Level (etc.) BSF LED2 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED3 ADDLW 0xD4 BTFSC STATUS,C ; Level (etc.) BSF LED3 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED4 ADDLW 0xC6 BTFSC STATUS,C ; Level (etc.) BSF LED4 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED5 ADDLW 0xBA BTFSC STATUS,C ; Level (etc.) BSF LED5 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED6 ADDLW 0xB2 BTFSC STATUS,C ; Level (etc.) BSF LED6 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED7 ADDLW 0xA7 BTFSC STATUS,C ; Level (etc.) BSF LED7 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED8 ADDLW 0x94 BTFSC STATUS,C ; Level (etc.) BSF LED8 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED9 ADDLW 0x78 BTFSC STATUS,C ; Level (etc.) BSF LED9 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED10 ADDLW 0x63 BTFSC STATUS,C ; Level (etc.) BSF LED10 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED11 ADDLW 0x55 BTFSC STATUS,C ; Level (etc.) BSF LED11 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED12 ADDLW 0x3E BTFSC STATUS,C ; Level (etc.) BSF LED12 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED13 ADDLW 0x22 BTFSC STATUS,C ; Level (etc.) BSF LED13 ; Yes MOVFW ADRESH ; Get SIGMET value BCF LED14 ADDLW 0x09 BTFSC STATUS,C ; Level (etc.) BSF LED14 ; Yes CALL V4DELAY GOTO MAIN ; Subroutines LONGDLY ; 50 ms delay MOVLW 0x28 MOVWF d2 LONGDLY_0 DECFSZ d1,F GOTO $+2 DECFSZ d2,F GOTO LONGDLY_0 NOP RETURN V2DELAY ; 62 us delay MOVLW 0x15 MOVWF d1 DECFSZ d1,F GOTO $-1 RETURN V3DELAY ; 124 us delay MOVLW 0x40 MOVWF d1 DECFSZ d1,F GOTO $-1 RETURN V4DELAY ; 248 us delay MOVLW 0x91 MOVWF d1 DECFSZ d1,F GOTO $-1 RETURN END