Frequency measurement in assember (ASM) for PIC

Status
Not open for further replies.

casemod

Member level 1
Joined
Sep 21, 2013
Messages
34
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,618
Hi,

I am working on a microchip Application note that is written in assember and need some help implementing a frequency counter.

The frequency to measure should be between 0 and 2700Hz and the result in a 11bit variable (0b00000000000 to 0b11111111111).

Wondering if someone can post a few code examples and tips to give me an idea of where to start. I can program in C but ASM is all new to me.

Regards
 
Last edited:

hello

an example for 16F84
2 ranges of measure
extended range use a special divider by 256 for VHF


Code:
; 30 mars 2013  
; Bug decouvert dans sub Delays lors de la compile par Milan Karakas (croatie)
; alors que je n'ai AUCUN WARNING
; Project 
;    build options
;        wct8_LCD_16F84A_2_Ranges_1x16cars_130329.asm
;    MPASM assembler
;        categorie
;             output
;                diagnostic level
;                    errors only
;                        file format INHX8M 
; avec option : /x"$(BINDIR_)$(INFILEBASE).xrf" /w2 /aINHX8M
; apres activation
; errors and warnings and message
; option: /x"$(BINDIR_)$(INFILEBASE).xrf" /aINHX8M
; j'ai bien un warning 202 si usage de movlw 243
; correctifs:
; usage de movlw 243  e> movlw 43h , car Radix DEC passé en commentaire !
; modif  movlw D'243' => movlw F3h ..OK
;============================
;;@@@ 16 mars 2013	
; Version LCD 1 ligne de 16 cars
; pour PB affichage 1Hz par defaut 
;dans debut comptage, supprimé ceci :
;	bsf PORTA,2 	;toggle TMR0 pin
;	bcf PORTA,2
; => maintenant affiche RIEN si pas de frequence d'entree!
; Icprogr Checksum = 4A72
; sensibilite 1V cr cr seulement avec le JFET  BF245A
;27/02/2013
; LCD 1L de 16cars  (ou 2L de 16cars)  mais pas 1L de 2x8 cars
; Ajust correction +0µS  version pour LCD 1x16 car checksum ICPROGR = 76B6
; 25/02/2013  modif Titre 1ere ligne LCD
; 23/02/2013
; Test sous MPLAB sim point d'arret sur 
; debut
; 019F   3008           00739         movlw 8
; 01A0   0686           00740         xorwf PORTB     ; clignote Led a chaque boucle
; stimulus de RA4 ON/OFF pour remplacer la liaison RA2 vers RA4 via le NAND 74HCT32
; 017B   0000 00688   nop   ;<- stimulus RA4 ici pour test led avec MPLAB Sim
; Stimulus: SCL file "C:\_Mplab8\_Mesprojets_ASM\_Freq\Freqmeter_Simule_RA2.scl" generated successfully.
; label RA2pulse  RA4  LOw 1cy   High 2cy Begib at PC=017A
; rev 16/02/2013  Rajout led sur RB3
; Rappel  : POK508 + Bloc alim + IC-Progr 1.05 pour reprogrammer le 16F84
;14/02/2013
; montage sur CI et test : automesure sur Quartz 4Mhz -> 4.000.064 Hz
; mesure sur horloge 40MHz -> 40,0011 MHz
; mesure sur 76KHz -> 75999Hz
; rev 7/02/2013 pour pic16F84A
; 26/01/2012 
; quartz PIC : 4Mhz 
; modif affichage et usage de 2 gammes
; affichage jusqu'a 7 digits poour F < 9.999.999 Hz 
; add corrections = + 20 µS dans la boucle externe "gate" + 16µS en final			
;resultats :
; REF       Mesure      Gamme   erreur
;Q=4MHz		4000065 Hz	FREQ	-0,002%
;25Khz		25000	Hz 	FREQ	0,000%
;234375Hz	234374	Hz	FREQ	0,000%
;Q=60 MHz	59.9993 Mhz VHF		0,001%
;Q=20 Mhz	19,9998	Mhz VHF		0,001%
;
;23/01/2012
; Rajout diviseur UHF MB506 ( 1/256) => 2 gammes , choix via input RA.1
; RA.1=1 gamme Freq  1 --- 9,999.999 Hz  
; RA.1=0 gamme VHF  10.0000 MHz -- >999.9999 Mhz
;
; avec rajout +20µS dans la boucle de comptage qui passe de 20 a 40µS
; wct7_LCD4bits_Q4Mhz_a.asm
; pour F.input de 60Mhz -> MB506 / 256 => 234.375 Khz Theoriques
; resultats :
; Freq =233.91Khz gamme 1 
; test 60Mhz: VHF = 594.00 Khz (PB de virgule)soit 59.40 Mhz
;
; rajout +21µS dans la boucle de comptage
; wct7_LCD4bits_Q4Mhz_a.asm
; pour F.input de 60Mhz -> MB506 / 256 => 234.375 Khz Theoriques
; resultats :
; Freq =239.73Khz gamme 1 
; VHF = 606.68 Khz 
;
;16/01/2012 rajout Freq devant la mesure .. mais =>digit saute en LSB de MHz
; a voir : lecture Hz + 1 ?  bug ?
; update 12/01/2012
; mode LCD 4 bits au lieu de 8 bits
; remplacement des adresses en dur dans le programme , par des labels
;Using TMR0 with External Clock
;paragraph 6.2 specsheet DS30430C page 29
;Therefore, it is necessary for T0CKI to have a
;period of at least 4Tosc (plus a small RC delay) divided
;by the prescaler value. The only requirement on T0CKI
;high and low time is that they do not violate the
;minimum pulse width requirement of 10 ns.
;
;parameter 40   High pulse width 30nS
;parameter 41   Low pulse width  20nS
;parameter 42   periode  (Tcy+40)/N     N=prescaler
; La valeur du quartz intervient beaucoup sur la periode mini (42)
; si Q=4Mhz  avec Tcy= 4/Fosc=> 1µS
;   periode mini = (1000+40)/256= ~4nS soit 250Mhz
; si Q=20Mhz  periode mini (200 + 40)/256 => < 1nS ! 1Ghz!?  pas glop,il y a VIOL!
; En se basant sur les limites (40 et 41)etat H=30ns + etat L=20ns => periode 50nS
;  => 20Mhz ! TRES PLAUSIBLE puisque reellement mesuré (avec quartz de 4Mhz)
; En se basant sur les limites absolues (antiviol!) de 10 + 10 ns=> 20nS
;  => 50Mhz, ce qui est decrit dans la note ci-dessous

; note microchip AN592.pdf
;The PIC16C5X has one 8-bit timer (Timer0), which can be used with
;an 8-bit prescaler. The prescaler runs asynchronously, hence it can
;count a very high frequency. The minimum rise and fall times of the input
;frequency are speci?ed to be 10 ns, so the fastest clock rate the TMR0
;can count is 50 MHz.

; 07 juin 2003 .. testé OK avec Gene a quartz et sur emetteur 27,125Mhz de Radiocommande
; affichage 7 digits   mode LCD 8 bits data
; 1hz a 50MHz (theorique)  comptage sur 24 bits
; resolution 1Hz
;http://www.piclist.com/techref/piclist/weedfreq/WCT6.htm
;*************************************************************
; FREQUENCY COUNTER
; Model : WTCNT ; Author : Terry J. Weeder ; Date :November 18, 1993 ; Version:1.0
; WWW.WEEDTECH.COM  Ported to 16f84 by  Peter Cousens  October 1998
; lines 337 to 453 ..supprimees
;*************************************************************

	list
	ERRORLEVEL      -302
	Processor       16F84A

#include <../common/p16F84A_.inc>


;	Radix           DEC
	EXPAND

	__CONFIG  0x3FF1	; _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

;  --- Hardware ---
; Quartz 4Mhz encadre de 2x 33pF
; LCD 1x16			PIC16F84
; 1  	    0V
; 2	    +5V
; 3	    R de 390 ohms au 0V
; 4 	    Enable			RA0  pin 17
; 5       R/W	0V			RA1	 pin 18 choix de gamme
; 6 	    RS  			RA2	 pin 1

; 7	D0  0V		RB0	 pin 6 not used
; 8	D1  0V		RB1	 pin 7 not used
; 9	D2  0V		RB2	 pin 8 not used
; 10 D3  0V		RB3	 pin 9 --- 750---A Led K ---0V
; 11 D4  		RB4	 pin 10
; 12	 D5  		RB5	 pin 11
; 13	 D6  		RB6	 pin 12
; 14  D7			RB7  pin 13
; conditionnement signal
;9 		    74HCT132	RA2  pin 1
;12,13,2	74HCT132	 	RA3  pin 2
;6		    74HCT132	RA4  pin 3 input
;11,10	    74HCT132
;3,4		74HCT132
;8,5		74HCT132
;1		    74HCT132	1Mohm +5V et 820K 0V  C=1µF	signal input
;14		    74HCT132	+5V
;7		    74HCT132	0V

FREQ			    EQU      .40000  ; Xtal frequency in kHz
LCD_DATA		    EQU 	PORTB	; LCD DATA 11,12,13,14  bits 4,5,6,7
LCD_DATA_TRIS   EQU 	TRISB	;
LCD_CTRL		    EQU 	PORTA	; LCD CTRL 4,5,6   	bits 0,1,2
LCD_RS		    EQU 	2	; LCD pin 4 : Ligne Selection Registres de l'afficheur
;LCD_RW		    EQU 	1	; LCD pin 5 reliée au 0V (not used)
LCD_E		          EQU 	0	; LCD pin 6 : Ligne ENABLED controle de l'afficheur

#define Gamme PORTA,1	; Choix de gamme 1-20Mhz ou 20-1200MHz
#define Led PORTB,3	; RB3 --750--- Led--0V

ind 	equ 0h
TMR0 	equ 1h
pc 		equ 2h
status 	equ 3h
fsr 	equ 4h
;port_c equ 7h
c 		equ 0h
dc 		equ 1h
z 		equ 2h
pd 		equ 3h
to 		equ 4h
MSB 	equ 7h
LSB 	equ 0h
cnt 	equ 2h
rs 		equ 2h
rw 		equ 1h
e 		equ 0h
o 		equ 7h

RP1				EQU     H'0006'
RP0				EQU     H'0005'
STATUS  		EQU     H'0003'
OPTION_REG     	EQU     H'0081'
TRISA          	EQU     H'0085'
TRISB          	EQU     H'0086'


EEPROM EQU 0x2100

;#define  TEST_LED    ; strap les tempos pour acceler la simulation

;*************
;  DATA bank0
;*************
	cblock 0x0C
gate
cnt1
cnt2
cnt3
calc1
calc2
calc3
sum1
sum2
sum3
timer_value
; registres pour les 7 digits
c1
c2
c3
c4
c5
c6
c7
count1
count2
count3
count4
Pointer_Msg
in_reg
addcnt
LCDtmp
LCDtmp1
Dcount1
Dcount2
Dcount3
gate2
dummy
   endc

LastBank0 EQU dummy
	IF ( LastBank0 >= 0x4F )
	ERROR   "Attention debordement zone RAM "
	ENDIF


	org 0x00
	goto start ;

	org 0x04
	nop
	nop
	retfie

;****************
; Tempos
;****************

delay_25us    
             ifdef TEST_LED
                goto minidelay
                endif
                movlw   0x01
                movwf   Dcount1
                movlw   0x01
                movwf   Dcount2
                movlw   0x05
                movwf   Dcount3
                goto    delay1

delay_100us     
                ifdef TEST_LED
                goto minidelay
                endif
                      
                movlw   0x01
                movwf   Dcount1
                movlw   0x01
                movwf   Dcount2
                movlw   D'20'
                movwf   Dcount3
                goto    delay1

delay_2_5ms     
                ifdef TEST_LED
                goto minidelay
                endif
                
                movlw   0x01
                movwf   Dcount1
                movlw   0x02
                movwf   Dcount2
                movlw   D'243'
                movwf   Dcount3
                goto    delay1


delay_10ms      
                ifdef TEST_LED
                goto minidelay
                endif
                
                movlw   0x01
                movwf   Dcount1
                movlw   8
                movwf   Dcount2
                movlw   D'205'
                movwf   Dcount3
                goto    delay1

delay_100ms    
                ifdef TEST_LED
                goto minidelay
                endif
                movlw   0x01
                movwf   Dcount1
                movlw   D'79'
                movwf   Dcount2
                movlw   0x01
                movwf   Dcount3
                goto    delay1

delay_500ms
         ifdef TEST_LED
          goto minidelay
          endif

		movlw 2
		movwf Dcount1
		movlw D'135'
		movwf Dcount2
		movlw D'106'
		movwf Dcount3
		goto delay1

delay_3s
        ifdef TEST_LED
           goto minidelay
        endif
		movlw D'10'
		movwf Dcount1
		movlw D'40'
		movwf Dcount2
		movlw D'200'
		movwf Dcount3
		goto delay1

delay1
       decfsz  Dcount3,f
       goto    $-1
       decfsz  Dcount2,f
       goto    $-3
       decfsz  Dcount1,f
       goto    $-5
       return
      
minidelay
        nop
        nop
        nop
        nop
        return       
       
       

;**********************
;     LCD
;***********************
LCD_Cls
	movlw	D'01'			; effacage de l'ecran
	call	LCD_Cde
	goto	delay_2_5ms

;-----------------
LCD_Clear1				; effacage de la 1ere ligne
	movlw	D'16'
	movwf	LCDtmp1
	movlw	0x80		;LINE1
	call	LCD_Cde
	call	delay_2_5ms
LCDc111
	movlw	' '
	call	LCD_Putchar
	decfsz	LCDtmp1,f
	goto	LCDc111
LCD_Line1
	movlw	0x80		;LINE1
	call	LCD_Cde
	goto	delay_2_5ms
;--------------

LCD_Clear2				; effacage de la deuxieme ligne
	movlw	D'16'
	movwf	LCDtmp1
	movlw	0xC0		;LINE2
	call	LCD_Cde
	call	delay_2_5ms
LCDcl21
	movlw	' '
	call	LCD_Putchar
	decfsz LCDtmp1,f
	goto	LCDcl21

LCD_Line2
	movlw	0xC0
	call	LCD_Cde
	goto	delay_2_5ms

LCD_Home
	movlw	D'02'
	call	LCD_Cde
	goto delay_2_5ms

LCD_Putchar
	;bank0				; rajout 7/03/03
	movwf	LCDtmp
	call	delay_100us
	movlw   0x0f
	andwf   LCD_DATA,F
	movf    LCDtmp,w
	andlw   0xF0
	iorwf   LCD_DATA,F
;	bcf     LCD_CTRL, LCD_RW
	nop
	bsf     LCD_CTRL, LCD_RS
	nop
	bsf     LCD_CTRL, LCD_E
	call	delay_25us
	bcf     LCD_CTRL, LCD_E
	call	delay_25us
	movlw   0x0f
	andwf   LCD_DATA,F
	swapf   LCDtmp,W
	andlw   0xF0
	iorwf   LCD_DATA,F
	nop
	bsf     LCD_CTRL, LCD_E
	call	delay_25us
	bcf     LCD_CTRL, LCD_E
	call	delay_25us
	return

LCD_Init
	bcf     LCD_CTRL, LCD_E
	call 	delay_2_5ms
	bcf     LCD_CTRL, LCD_RS
	call 	delay_2_5ms
;	bcf     LCD_CTRL, LCD_RW
	call 	delay_2_5ms
	movlw	0x0f
	andwf	LCD_DATA,F
	movlw	0x030			; Commande pour interface 4 bits
	iorwf	LCD_DATA,F
	bank1
	movlw   0x0F
	andwf   LCD_DATA_TRIS,W
	movwf   LCD_DATA_TRIS		; Port en sortie
	bank0
	bsf     LCD_CTRL, LCD_E
	nop
	bcf     LCD_CTRL, LCD_E
	call 	delay_2_5ms
	bsf     LCD_CTRL, LCD_E
	nop
	bcf     LCD_CTRL, LCD_E
	call 	delay_2_5ms
	bsf     LCD_CTRL, LCD_E
	nop
	bcf     LCD_CTRL, LCD_E
	call 	delay_100ms		; tempo 100ms , remplace l'attente Wait_Busy de l'afficheur
	movlw   0x0f
	andwf   LCD_DATA,F
	movlw   0x020           ; Commande pour interface 4 bits
	iorwf   LCD_DATA,F
	bsf     LCD_CTRL, LCD_E
	nop
	bcf     LCD_CTRL, LCD_E
	movlw   0x028		; Envoi de la commande Fonction 4-bit , Font, Nombre de lignes
	call    LCD_Cde
	movlw   0x08		; display off
	call    LCD_Cde
	movlw   0x0C		; display on (0x0C sans curseur, 0x00E avec , 0x00F clign. )
	call    LCD_Cde
	movlw   0x06

LCD_Cde
	movwf   LCDtmp
	call 	delay_100ms  ; call	delay_100ms	remplace l'attente Wait_Busy de l'afficheur
	movlw   0x0f
	andwf   LCD_DATA,F
	movf    LCDtmp,w
	andlw   0xF0
	iorwf   LCD_DATA,F
;	bcf     LCD_CTRL,LCD_RW
	nop
	bcf     LCD_CTRL,LCD_RS
	nop
	bsf     LCD_CTRL,LCD_E
	nop
	bcf     LCD_CTRL,LCD_E
	movlw   0x0f
	andwf   LCD_DATA,F
	swapf   LCDtmp,W
	andlw   0xF0
	iorwf   LCD_DATA,F
	bsf     LCD_CTRL,LCD_E
	nop
	bcf     LCD_CTRL,LCD_E
	return

sub	bcf status,o	;clear overflow bit
	movf calc1,w	;subtract calc1 from cnt1
	subwf cnt1,f
	btfsc status,c
	goto sb1
	movlw 0x01 		;borrow from cnt2 if overflow
	subwf cnt2,f
	btfsc status,c
	goto sb1
	subwf cnt3,f 	;borrow from cnt3 if cnt2 overflow
	btfss status,c
	bsf status,o 	;set overflow bit if result is negative
sb1
	movf calc2,w 	;subtract calc2 from cnt2
	subwf cnt2,f
	btfsc status,c
	goto sb2
	movlw 0x01 		;borrow from cnt3 if cnt2 overflow
	subwf cnt3,f
	btfss status,c
	bsf status,o 	;set overflow bit if result is negative
sb2
	movf calc3,w 	;subtract calc3 from cnt3
	subwf cnt3,f
	btfss status,c
	bsf status,o 	;set overflow bit if result is negative
	retlw 0x00 		;
;---------------------------
add
	movf calc1,w 	;add calc1 to cnt1
	addwf cnt1,f
	btfss status,c
	goto ad1
	incfsz cnt2,f 	;add to cnt2 if cnt1 overflow
	goto  ad1
	incf cnt3 ,f 	;add to cnt3 if cnt2 overflow
ad1
	movf calc2,w 	;add calc2 to cnt2
	addwf cnt2,f
	btfsc status,c
	incf cnt3,f 	;add to cnt3 if cnt2 overflow
	movf calc3,w 	;add calc3 to cnt3
	addwf cnt3,f
	retlw 0x00 ;
;-----------------------
cnvt
    movlw 0x07 ;7 digits in display
	movwf count1
	movlw c1 		;set fsr for MSB in display
	movwf fsr
	movlw 0x2F 		;one less that ASCII "0"
cnvt0
	movwf ind
	incf fsr ,f
	decfsz count1,f
	goto cnvt0
		
	movlw 0x0F 		;load "1,000,000" in calc1-3
	movwf calc3
	movlw 0x42
	movwf calc2
	movlw 0x40
	movwf calc1
;@@@ 16 mars 2013	
	bcf status,o	; rajout pour PB +1Hz
cnvt1
	call sub 		;subtract number from count
	incf c1 ,f		;increment 1,000,000's register
	movlw 0x3A
	xorwf c1,w
	btfsc status,z
	goto overflow
	btfss status,o 	;check if overflow
	goto cnvt1

	call add 		;add back last number
	movlw 0x01 		;load "100,000" in calc1-3
	movwf calc3
	movlw 0x86
	movwf calc2
	movlw 0xA0
	movwf calc1
cnvt2
	call sub 		;subtract number from count
	incf c2 ,f 		;increment 100,000's register
	btfss status,o 	;check if overflow
	goto cnvt2
	call add 		;add back last number	
	clrf calc3 		;load "10,000" in calc1-3
	movlw 0x27
	movwf calc2
	movlw 0x10
	movwf calc1
cnvt3
	call sub 		;subtract number from count
	incf c3,f 		;increment 10,000's register
	btfss status,o 	;check if overflow
	goto cnvt3
	call add 		;add back last number
	movlw 0x03 		;load "1,000" in calc1-3
	movwf calc2
	movlw 0xE8
	movwf calc1
cnvt4
	call sub 		;subtract number from count
	incf c4,f 		;increment 1,000's register
	btfss status,o 	;check if overflow
	goto cnvt4
	call add 		;add back last number
	clrf calc2 		;load "100" in calc1-3
	movlw 0x64
	movwf calc1
cnvt5
	call sub 		;subtract number from count
	incf c5 ,f 		;increment 100's register
	btfss status,o 	;check if overflow
	goto cnvt5
	call add 		;add back number
	movlw 0x0A 		;load "10" in calc1-3
	movwf calc1
cnvt6
	call sub 		;subtract number from count
	incf c6 ,f 		;increment 10's register
	btfss status,o 	;check if overflow
	goto cnvt6
	call add 		;add back last number
	movf cnt1,w 	;put remainder in 1's register
	addwf c7 ,f
	incf c7 ,f
	retlw 0x00 		;

Comptage
	bank1
	movlw b'00110111' ;0x37 TMR0 = ext, prescaler=1/256
	movwf OPTION_REG
	bank0
	bcf PORTA,3
	bcf PORTA,2
	clrf cnt3
	clrf TMR0
	clrf timer_value
;@@@ 16 mars 2013 pour PB affiche 1Hz @ zero frequence
;	bsf PORTA,2 	;toggle TMR0 pin
;	bcf PORTA,2
	movf gate,w 	;get gate time gate=0x14=20   20x250x20=100.000 cy =>100mS
	movwf count1    ;si gate= 0xC8 => 100x250x40=1.000.000 cy => 1 sec
	bsf PORTA,3 	;start count
fr4
	movlw 0xFA		; 250  was movf gate2,w
	movwf count2
	goto fr6
fr5 
	goto $+1	;2
	goto $+1	;4
	goto $+1	;6
	goto $+1	;8
	goto $+1	;10
	goto $+1	;12
	goto $+1	;14
	goto $+1	;16
	goto $+1	;18
	goto $+1	;20  
	goto $+1	;22 
	goto $+1	;24 
	goto $+1	;26
fr6							;test for TMR0 rollover 
	movf TMR0,w 		    ;27	
	subwf timer_value ,f 	;28
	btfss status,z 		    ;29
	goto fr7			    ;31
	nop
	goto fr8
fr7
	btfsc status,c		    ;32
	incf cnt3,f 		    ;33
fr8
	movwf timer_value		;34
	nop				        ;35
	nop				        ;36
	nop				        ;37
	decfsz count2,f		    ;38
	goto fr5			    ;40
	goto $+1	;ajustement ;42µS
	goto $+1	;ajustement ;44
	goto $+1	;ajustement ;46
	goto $+1	;ajustement ;48
	goto $+1	;ajustement ;50
	goto $+1	;ajustement ;52
	goto $+1	;ajustement ;54
	goto $+1	;ajustement ;56
	goto $+1	;ajustement ;58
	goto $+1	;ajustement ;60µS
;	nop
	decfsz count1,f			; gate
	goto fr4
	; ajustement final 
;	nop         ;ajustement +1
;	nop         ;ajustement +2
;	nop         ;ajustement +3
;	nop         ;ajustement +4
;	goto $+1	;ajustement +6
;	goto $+1	;ajustement +8
;   goto $+1	;ajustement +10
;	goto $+1	;ajustement +12
;	goto $+1	;ajustement +14 
;	goto $+1	;ajustement +16 
;	goto $+1	;ajustement +18 
;	goto $+1	;ajustement +20
;	goto $+1	;ajustement +22
;	goto $+1	;ajustement +24
;	goto $+1	;ajustement +26
;	goto $+1	;ajustement +28

	bcf PORTA,3 	;stop count
	movf TMR0,w 	;get TMR0 count
	movwf cnt2
	subwf timer_value,f 	;test for TMR0 rollover
	btfss status,c
	goto fr9
	btfss status,z
	incf cnt3,f
fr9
	clrf cnt1 		;set to get prescaler count
fr10
	decf cnt1,f
	bsf PORTA,2 	;toggle TMR0 pin
	nop
  ifdef TEST_LED
	nop
	nop
	nop
	nop             ;<- stimulus RA4 ici pour test led avec MPLAB Sim
  endif
	bcf PORTA,2
	movf TMR0,w 	;test if TMR0 has changed
	xorwf cnt2,w
	btfsc status,z
	goto fr10
	retlw 0x00 ;



;********************************************
; main program

start
	clrf PORTA 	;instruction, write, enable low
	clrf PORTB
	bank1
	movlw b'00010010'  ; RA4 & RA1 as input others output
	movwf TRISA
	movlw b'00000000'  ; all outputs
	movwf TRISB
	bank0
	
	bsf PORTB,3			; allume led
	
	call delay_500ms
	call LCD_Init		; en mode 4 bits
	call delay_500ms
	;1er msg
	call LCD_Clear1
	movlw 0
	movwf Pointer_Msg
	Call AffNumMsgEeprom
	call	delay_3s
	;2em msg
	call LCD_Clear1
	movlw 1
	movwf Pointer_Msg
	Call AffNumMsgEeprom
	call	delay_3s
	;3em msg
	call LCD_Clear1
	movlw 2
	movwf Pointer_Msg
	Call AffNumMsgEeprom
	call	delay_3s
	call LCD_Clear1
	
	bcf PORTB,3			; eteint led

debut
	movlw 8
	xorwf PORTB,f     ; clignote Led a chaque boucle
	call delay_100ms
	
hz 	movlw D'0'		; 2,56 sec gate '0 equivaut à 256   -1=>255 -1=>254....) si commutateur de gamme  RA.1=0
	btfsc Gamme		; test RA.1
	movlw D'100'	; 1 sec si commutateur de game RA.1=1
	movwf gate		
hz00
	call Comptage
	call cnvt 		;convert binary to BCD
hz0
	Call Entete
	movlw 0x84 		;set display address
	call LCD_Cde
	movlw 0x07 		;output first 7 characters
	movwf count1
	movlw c1 		;MSD of freq
	movwf fsr
hz1
	movlw 0x30 		;test if "0"
	xorwf ind,w
	btfss status,z
	goto hz2
	movlw ' ' ;0x20 		;change preceeding "0's" to "space"
	call LCD_Putchar
	incf fsr,f
	decfsz count1,f
	goto hz1
	goto hz3
hz2
    movf ind,w
	call LCD_Putchar
	incf fsr,f
	btfsc Gamme
	goto hz21
	movlw 0x05
	xorwf count1,w	
	btfss status,z
	goto hz21
	movlw '.'	
	call LCD_Putchar
hz21	
	decfsz count1,f
	goto hz2
hz3
	movlw 0x20 		;"space"
	call LCD_Putchar
	btfsc Gamme
	goto hz4
	movlw 'M' 		;"M"
	call LCD_Putchar
	
hz4
	movlw 0x48 		;"H"
	call LCD_Putchar
	movlw 0x7A 		;"z"
	call LCD_Putchar
	movlw 0x20 		;"space"
	call LCD_Putchar
	btfss Gamme
	goto debut 	
	movlw 0x20 		;"space"
	call LCD_Putchar
	goto debut 		;

overflow
	movlw 0x01 		;clear display
	call LCD_Cde
	movlw 0x84 		;at colum 4 line 1
	call LCD_Cde
	movlw 0x4F 		;"O"
	call LCD_Putchar
	movlw 0x76 		;"v"
	call LCD_Putchar
	movlw 0x65 		;"e"
	call LCD_Putchar
	movlw 0x72 		;"r"
	call LCD_Putchar
	movlw 0x66 		;"f"
	call LCD_Putchar
	movlw 0x6C 		;"l"
	call LCD_Putchar
	movlw 0x6F 		;"o"
	call LCD_Putchar
	movlw 0x77 		;"w"
	call LCD_Putchar
	movlw 0x02 		;cursor at home
	call LCD_Cde
	call	delay_3s
	goto debut ;

Entete
	btfss Gamme
	goto Entete2
	call LCD_Home
	movlw 'F'
	call LCD_Putchar
	movlw 'r'
	call LCD_Putchar
	movlw 'q'
	call LCD_Putchar
;	movlw 'q'
;	call LCD_Putchar
;	movlw ' '
;	call LCD_Putchar
	return
Entete2
	call LCD_Home
	movlw 'V'
	call LCD_Putchar
	movlw 'H'
	call LCD_Putchar
	movlw 'F'
	call LCD_Putchar
;	movlw '-'
;	call LCD_Putchar
	return



; affiche Num Msg en eeprom
; terminaison par caractere null ou taille maxi de 16 cars
;==============================
AffNumMsgEeprom
		movf Pointer_Msg,w
		movwf cnt2
		bcf STATUS,C
		rlf cnt2,f
		rlf cnt2,f
		rlf cnt2,f
		rlf cnt2,f		; pointeur = Num Msg * 16
		clrf cnt3
affMsg_	
; sortie si 16em car ou rencontre de zero	
		movf	cnt3,w
		addwf 	cnt2,w
		MOVWF	EEADR
		bank1
		BSF 	EECON1,RD	;  bit 0
		bank0
		call delay_100us
		MOVF 	EEDATA,W
		XORLW   0             ; Is this the terminating char?
		BTFSC   STATUS,Z
		GOTO    EndAffNum
		call   LCD_Putchar
 		incf	cnt3,f
		btfss	cnt3,4		; 16em car ?
		goto 	affMsg_
EndAffNum
	return



	org 0x2100
signature
	   ;1234567890123456
	DT "WCT8_LCD_16F84  "
	DT "1-10Mhz 10-999Mz"
	DT "rev PF 130330   "
	DT "Overflow       ."
	
	end
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…