;=============================================================================== ; Filename: freq_628.asm ; Date: 23/03/2004 ; File Version: 1.0 ; Orig. Files: Peter Halicky OM3CPH & Peter Halicky Jr., OM2PH ex OM2APH ; Rewrite: Vila Real para QRP BR ask from PY2RLM - RENATO ;================================================================================ ; Files required: vdisplay.inc ;================================================================================ ; Notes: ; Remoção das rotinas de Lcd, inclusão da vdisplay.inc ; Correção da diretiva Radix ; Inclusão de pag. de memória ; Relocação de variáveis ; Recálculo de T1=241,T2=5 ,T3=46,T4=7,Z=2 p/ 20MHz ; T1=252,T2=11,T3=4 ,T4=2,Z=3 p/ 4MHz ;================================================================================ ;================================================================================ ;DIRETIVAS DE COMPILAÇÃO ;================================================================================ LIST P=16F628 ;list directive to define processor #INCLUDE ;processor specific variable definitions __IDLOCS 2003 ;dados a serem gravados na EEPROM ERRORLEVEL -302 ;suppress bank selection messages RADIX DEC ;set to decimal __CONFIG _CP_OFF&_PWRTE_ON&_WDT_OFF&_XT_OSC&_BODEN_OFF&_LVP_OFF ;================================================================================= ;VARIABLE DEFINITIONS ;================================================================================= CBLOCK 0x20 ;endereço inicial p/ variáveis Index ;dummy register Count ;inkremental register Help ;dummy register LED0 LED1 LED2 LED3 LED4 LED5 LED6 TimerH ;the highest byte of SW counter LowB ;low byte of resulted frequency MidB ;middle byte of resulted frequency HigB ;high byte of resulted frequency TEMP ;temporary register HIndex ;index register LEDIndex ;LED pointer R1 ;Timing counters R2 R3 temp w_temp ;variable used for context saving status_temp ;variable used for context saving tmpLcdRegister ;devem permanecer no final LcdDelayCounter ;pois ocupam 4 bytes ENDC ;================================================================================= ;PAGINAÇÃO DE MEMÓRIA ;================================================================================= #DEFINE BANK0 BCF STATUS,RP0 ;seta bank0 de memória #DEFINE BANK1 BSF STATUS,RP0 ;seta bank1 de memória ;================================================================================= ;Timing Loop values ; QRP BR - AQUI SÃO OS AJUSTES ;================================================================================= T1 equ 252 ;first timing loop T2 equ 11 ;second timing loop T3 equ 4 ;third timing loop T4 equ 2 ;last timing loop ;================================================================================= ;Vetor de Reset ;================================================================================= org 0x00 goto Init ;================================================================================= ;Inicialização ;================================================================================= Init clrf STATUS ; Do initialization, Select bank 0 clrf INTCON ; Clear int-flags, Disable interrupts clrf PCLATH ; Keep in lower 2KByte clrf PORTA ; ALL PORT output should output Low. clrf PORTB clrf Index clrf LEDIndex clrf LED0 clrf LED1 clrf LED2 clrf LED3 clrf LED4 clrf LED5 clrf LED6 clrf LowB clrf MidB clrf HigB bsf STATUS,RP0 movlw b'00010000' ; RA0..RA3 outputs movwf TRISA ; RA4 input movlw 0xF0 ; RB0..RB3 outputs, rest inputs movwf TRISB bsf OPTION_REG,NOT_RBPU ; Disable PORTB pull-ups clrwdt movlw b'10100111' ; Prescaler -> TMR0, movwf OPTION_REG ; 1:256, rising edge bcf STATUS,RP0 ; BANK1 movlw 0x0F andwf TRISB,W movwf TRISB ; Set Port for output BANK0 ;================================================================================= ;Initialization of LCD display call LcdInit call ShowLoad call ShowName call ShowHello call LcdClear call ShowName ;================================================================================= goto Start ;================================================================================= ; Numeric routines ;================================================================================= ; 3 byte substraction of the constant from the table which sets carry if ; result is negative ;================================================================================= Subc24 clrf TEMP ; it will TEMPorary save C movf Index,W ; pointer to low byte of constant movwf HIndex ; W -> HIndex call DecTable ; W returned with low byte of constant bsf STATUS,C ; set C subwf LowB,F ; LowB - W -> LowB ; if underflow -> C=0 btfsc STATUS,C goto Step1 bsf STATUS,C movlw 1 subwf MidB,F ; decrement MidB ; if underflow -> C=0 btfsc STATUS,C goto Step1 bsf STATUS,C movlw 1 subwf HigB,F ; decrement HigB btfsc STATUS,C ; if underflow -> C=0 goto Step1 bsf TEMP,C ; set C Step1 decf HIndex,F movf HIndex,W ; pointer to middle byte of const call DecTable bsf STATUS,C subwf MidB,F ; MidB - W -> MidB btfsc STATUS,C ; if underflow -> C=0 goto Step2 bsf STATUS,C movlw 1 subwf HigB,1 ; decrement HigB btfsc STATUS,C ; if underflow -> C=0 goto Step2 bsf TEMP,C ; set C Step2 decf HIndex,F movf HIndex,W ; pointer to middle byte of constatnt call DecTable bsf STATUS,C subwf HigB,F ; HigB - W -> HigB btfsc STATUS,C ; if underflow -> C=0 goto ClearCF bsf STATUS,C goto SubEnd ClearCF rrf TEMP,C ; C -> STATUS SubEnd retlw 0 ;================================================================================= ; 3 byte addition of the constant from the table which sets carry if ; result overflows ;================================================================================= Addc24 clrf TEMP ; register for TEMPorary storage of C movf Index,W ; pointer to lower byte of const into W movwf HIndex ; save it into HIndex call DecTable ; W contains low byte of const bcf STATUS,C ; clear C addwf LowB,1 ; W + LowB -> LowB btfss STATUS,C ; test overflow goto Add2 bcf STATUS,C ; clear C movlw 1 addwf MidB,F ; increment MidB btfss STATUS,C goto Add2 bcf STATUS,C movlw 1 addwf HigB,F ; increment HigB btfss STATUS,C ; test overflow goto Add2 bsf TEMP,C ; store C Add2 decf HIndex,F ; pointer to middle byte into W movf HIndex,W call DecTable bcf STATUS,C addwf MidB,1 ; W + MidB -> MidB btfss STATUS,C goto Add3 bcf STATUS,C ; clear C movlw 1 addwf HigB,1 ; increment HigB btfss STATUS,C goto Add3 bsf TEMP,C Add3 decf HIndex,F ; pointer to higher byte into W movf HIndex,W call DecTable bsf STATUS,C addwf HigB,F ; W + HigB -> HigB, btfss STATUS,C goto ClarCF bsf STATUS,C goto AddEnd ClarCF rrf TEMP,C ; C -> STATUS AddEnd retlw 0 ;================================================================================= ;Tables for 3 byte constants ;Table of decades ;================================================================================= DecTable addwf PCL,F ; W + PCL -> PCL retlw 0 ; 10 retlw 0 ; retlw 0Ah ; retlw 0 ; 100 retlw 0 ; retlw 064h ; retlw 0 ; 1 000 retlw 03h ; retlw 0E8h ; retlw 0 ; 10 000 retlw 027h ; retlw 010h ; retlw 01h ; 100 000 retlw 086h ; retlw 0A0h ; retlw 0Fh ; 1 000 000 retlw 042h ; retlw 040h ; ;================================================================================= ;Entry point for main cycle ;================================================================================= ;Routine for the conversion of 3 byte number into 7 decimal numbers ;================================================================================= Start movlw 6*3-1 ; pointer to dec. table movwf Index ; 6*3-1 -> Index movlw 9 ; maximum of substractions movwf Count ; 9 -> Count clrf Help movlw 6 movwf LEDIndex Divide call Subc24 ; substract untill result is negative, btfsc STATUS,C ; add last substracted number goto Add24 ; next digit incf Help,F decf Count,F btfss STATUS,Z goto Divide movlw 3 subwf Index,F goto Next Add24 call Addc24 movlw 03h subwf Index,F Next movlw 9 movwf Count movlw LED1 ; LED1 -> W addwf LEDIndex,W ; LED1 + LEDIndex -> W movwf TEMP decf TEMP,F ; LEDIndex+LED1-1 -> TEMP movf TEMP,W movwf FSR ; W -> FSR movf Help,W ; Help -> W clrf Help ; save result at LEDx movwf INDF ; W -> LED(6..1) decf LEDIndex,F movlw 1 addwf Index,W btfss STATUS,Z goto Divide movf LowB,W movwf LED0 ; the rest -> LED0 ;================================================================================= ;registers LED0..LED6 are filled with values - ready to be displayed ;================================================================================= movlw 6 movwf LEDIndex movlw 10H ;Locate LCD cursor on row 1, col 0 call LcdLocate LEDCycle movlw LED0 ;LED0 -> W addwf LEDIndex,W ;LED1 + LEDIndex -> W movwf FSR ;W -> FSR movf INDF,W ;LED(0..6) -> W iorlw 030h call LcdSendData ;Display character ;movlw 5 ;test for decimal point movlw 5 ;test for decimal point bsf STATUS,Z subwf LEDIndex,W btfss STATUS,Z goto NoDot movlw '.' ;this can be ' ' or ',' ...... call LcdSendData ;Display character NoDot decfsz LEDIndex,F goto LEDCycle ;continue with next number movlw LED0 ;LED0 -> W addwf LEDIndex,W ;LED0 + LEDIndex -> W movwf FSR ;W -> FSR movf INDF,W ;[FSR] -> W iorlw 030h call LcdSendData ;Display character movlw ' ' call LcdSendData ;Display character movlw 'M' call LcdSendData ;Display character movlw 'H' call LcdSendData ;Display character movlw 'z' call LcdSendData ;Display character movlw 10H ;Locate LCD cursor on row 1, col 0 call LcdLocate ;================================================================================= ;It is time to prepare new measuring cycle ;================================================================================= clrf TimerH clrf TMR0 nop ;it is SUGGESTED... nop clrf LEDIndex movlw T1 ;set initial counter values movwf R1 movlw T2 movwf R2 movlw T3 movwf R3 clrf INTCON ;global INT disable, TMR0 INT disable ;clear TMR0 overflow bite ;================================================================================= ;Start measurement: RA3 + RA4 set input ;================================================================================= movlw b'00010000' ;all ports set L, RA4 set H movwf PORTA bsf STATUS,RP0 movlw b'00011111' ;RA0..RA4 input movwf TRISA bcf STATUS,RP0 ;================================================================================= ;It is opened now... ;================================================================================= Cycle btfss INTCON,2 ;1 Test for TMR0 overflow goto Nothing ;3 incf TimerH,F ;3 bcf INTCON,2 ;4 goto Nxt ;6 Nothing nop ;4 nop ;5 nop ;6 Nxt decfsz R1,F ;7 goto Cycle ;9 movlw T1 ;9*T1 movwf R1 ;9*T1+1 decfsz R2,F ;9*T1+2 goto Cycle ;9*T1+4 movlw T2 ;9*T1+4)*T2 movwf R2 ;(9*T1+4)*T2+1 decfsz R3,F ;(9*T1+4)*T2+2 goto Cycle ;(9*T1+4)*T2+4 ;================================================================================= ;Final test for TMR0 overflow ;================================================================================= movlw T4 ;((9*T1+4)*T2+4)*T3 movwf Help ;((9*T1+4)*T2+4)*T3+1 Cycle2 btfss INTCON,2 ;1 goto Not2Do ;3 incf TimerH,F ;3 bcf INTCON,2 ;4 goto Nx ;6 Not2Do nop ;4 nop ;5 nop ;6 Nx decfsz Help,F ;7 goto Cycle2 ;9 nop ;((9*T1+4)*T2+4)*T3+1+9*T4+Z ;================================================================================= ; Z times fine tuning nops ; altere aqui os nop para calibrar, aumentando nop ; ou diminuindo. nop nop ;================================================================================= ; Stop the measurement ;================================================================================= clrw ;1 movwf PORTB ;2 movlw b'00010000' ;3 RA0..RA3 = 0 movwf PORTA ;4 W -> PORTA ;((9*T1+4)*T2+4)*T3+1+9*T4+Z+4 bsf STATUS,RP0 ; movlw b'00010111' ;RA3 output movwf TRISA ;RA0..RA2,RA4 input bcf STATUS,RP0 ; ;================================================================================= ; Analyse precounter and store counted value in registers ;================================================================================= movf TMR0,W movwf MidB ;TMR0 -> MidB movf TimerH,W movwf HigB ;TimerH -> HigB clrf TEMP CountIt incf TEMP,F bsf PORTA,3 ;_| false impulz bcf PORTA,3 ;|_ bcf INTCON,2 movf TMR0,W ;actual TMR0 -> W bcf STATUS,Z subwf MidB,W btfsc STATUS,Z goto CountIt incf TEMP,F comf TEMP,F incf TEMP,F incf TEMP,W movwf LowB goto Start ;start new cycle ;================================================================================ ;Include Files ;================================================================================ #INCLUDE END