Pic16f84 et dialogue rs232 en mode interrupt et spooling

Soyez le premier à donner votre avis sur cette source.

Snippet vu 21 306 fois - Téléchargée 29 fois

Contenu du snippet

Lecture d'un ADC 12bits LTC1286
dialogue RS232 pour mise à l'heure du RTC DS1302 avec menu
saisi de caractere sur interruption RB0, puis en mode spooling.
nota: c'est beaucoup plus facile avec un PIC16F628
voir ici:
http://paulfjujo.free.fr

Source / Exemple :


;rev 13 juin 05 pour LTC1286
; attention Resonateur ceramique de 3,58Mhz et NON 4MHz => RS232 out
; modif tempos -> DelaisfQ.inc  f(quartz)!
; routine reception avec delais tres precis à respecter!
; rev 09/12/03= rtc1302g.asm
; re-arrangement E/S pour utiliser interrupt sur RB0 pour detecter
; appui touche clavier et decodage touche
; traitement valeur touche dans la boucle de fond
; inclure ces fichiers : bcd32toT.inc , Delais.inc
; rev 29/11/02 PF
; V.O.rtc1302.ASM 
; 
; Acquisition Temperature LM35DZ 10mV/°C 
; Conversion LTC1286 12 bits => 250 mV => affichage 25.0°C
; RS232 baud rate  parity  data bits  stop bits               
;       4800        n       8          1
; Dallas DS1302 circuit horloge temps reel en BCD via communication 3 fils
;       year    month   day     hour    minute second  
;       yyyy    mm      dd      hh      mm      ss      
;pin descriptions
; 16f84   pin     In/Out  function   
; ra0     17      O     serial out  ----> 11 ICL232 -> Tx
; ra1     18      O     rtc     /rst pin5
; ra2     1       I/O   rtc     data pin6    
; ra3     2       O     rtc     clk	pin7
; ra4     3       O     
; 
; rb0     6       I	RB0 serial in <---  12 ICL232 --< Rx
; rb1     7       O 	RB1 -> CS   5 LTC1286  
; rb2     8       I 	RB2 <- DATA 6 LTC1286
; rb3     9       O     RB3 -> CLCK 7 LTC1286
; rb4     10      I     not used
; rb5     11      I     not used  
; rb6     12      I     not used     
; rb7     13      I	not used
;
;-----------------

	ERRORLEVEL      -302
	Processor       16F84
	Radix           DEC
	EXPAND
      processor 16f84
__16F84__   equ     1
__14BIT__   equ     1
            __maxram 0xaf
            __badram 0x07,0x50-0x7f,0x87

LOWRAM      equ     0x0c
HIGHRAM     equ     0x50

;#define Quartz 4
#define Quartz 3.58	;Mhz
;#define Quartz 32

; ----- I/O registers ------------

irp	    equ     7
indf        equ     0x00
tmr0        equ     0x01
pcl         equ     0x02
status      equ     0x03
fsr         equ     0x04
porta       equ     0x05
portb       equ     0x06
eedata      equ     0x08
eeadr       equ     0x09
pclath      equ     0x0a
intcon      equ     0x0b
option_reg	equ	0x81
trisa       equ     0x85
trisb       equ     0x86
eecon1      equ     0x88
eecon2      EQU     0x89

eeif        EQU     H'0004'
wrerr       EQU     H'0003'
rp1     	EQU     H'0006'
rp0	      EQU     H'0005'
wren        EQU     H'0002'
WR          EQU     H'0001'
RD          EQU     H'0000'
z           EQU     H'0002'
dc          EQU     H'0001'
c           EQU     H'0000'

intf		equ	1
inte		equ 	4
gie		equ	7
same 		EQU 	1

_CP_ON          EQU     H'000F'
_CP_OFF         EQU     H'3FFF'
_PWRTE_ON       EQU     H'3FF7'
_PWRTE_OFF      EQU     H'3FFF'
_WDT_ON         EQU     H'3FFF'
_WDT_OFF        EQU     H'3FFB'
_LP_OSC         EQU     H'3FFC'
_XT_OSC         EQU     H'3FFD'
_HS_OSC         EQU     H'3FFE'
_RC_OSC         EQU     H'3FFF'

;-----------------------------
	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC                

;-----------------------------

#define 	bank0	bcf status,rp0
#define 	bank1	bsf status,rp0

eerd		equ     0               ;eeprom eecon1,0 read bit
eewr		equ     1               ;eeprom eecon1,1 write bit

_rst		equ     1               ;5 restart or CS
dataq		equ     2               ;6 data line (=I/O)
clk		equ     3               ;7 clock 
IR_read		equ     4

Rs_Tx		equ     0     		;rs232 tx line 
Rs_Rx		equ     0      		;rs232 rx line 

#define     SERIAL_TX	porta,Rs_Tx     ;rs232 serial transmit line
#define     SERIAL_RX	portb,Rs_Rx     ;rs232 serial Receive  line

#define     DS1302_RST 	porta,_rst	;RTC reset line LO=reset HI=active
#define     DS1302_DATA	porta,dataq	;RTC I/O data line
#define     DS1302_SCLK	porta,clk	;RTC clock line 

#define Ltc_CS		portb,_rst	;5 LTC186 chip select
#define Ltc_DATA	portb,dataq	;input	;6 LTC1286 Output Data line
#define Ltc_CLOCK	portb,clk	;output ;7 clock line

        cblock  0x0C
         	dummy                 	;dummy reg for *temporary* use
 	    	dummy1                  ;for 8bit rotates in/out
	    	dummy2 
	    	dummy3
	    	Drapeau;
	    	Cpt1		
	    	Cpt2
           	count1                  ;delay routines
           	count2                  ;delay routines
           	count3                  ;delay routines
           	count4                  ;
           	count5                  ;used in binary-to-bcd routine
    		Rdecal2                 ;per Mark Sullivan's code 25.7.96
 		second                  ;
           	minute                  ;
           	hour                    ;
           	date                    ;
           	month                   ;
           	day                     ;
           	year                    ;
	       	temp_f                  ;for outputting binary-held data to 
		w_temp
		status_temp 
		fsr_temp
		pclath_temp
           	buff_4                  ; bcd 32 bits -to- 10 digits ascii 
           	buff_3                  
           	buff_2
           	buff_1
           	temp_a
           	temp_b
           	temp_c
           	temp_d
           	temp_e
		RsBuffer
	     	RsByte
	     	RsCount
	     	RsCount2		; delay bit RS232
      		temp
     		bcent				; conversion BCD 4 digits -> ascii
		bdix	
		bun	
		btmp	
		btmp1	
		dixmil
		mille	
		cent	
		dix	
		un	
		valx:2
		val1:2
 		Lo_Temp			; Max187
	    	Hi_Temp 
        endc
        ;maxiram 4Fh  68 bytes of RAM avec PIC16F84
;-------------------------------------
                org     0x000
                goto    start
;-------------------------------------
                org     0x004
;------ routines interruption ---
ISR
	bcf	intcon,gie	; disable all interrupts
	nop

	movwf	w_temp	; save W
	swapf	status,W	; save status
	movwf	status_temp	; 
	clrf	status	; bank 0
	movfw	pclath	; save pclath
	movwf	pclath_temp	; 
	clrf	pclath	; page zero
	bank0
	movfw	fsr		; save: fsr
	movwf	fsr_temp	;

; test si interrupt sur RB0 ?
	btfss intcon,intf
	goto other_int

;Interrupt_RB0
 	bcf intcon,inte		;interdit interrupt RB0
	bcf intcon,intf		; raz drapeau
	call Read_RS

other_int

; restauration du contexte
	movfw	fsr_temp	
	movwf	fsr		
	movfw	pclath_temp
	movwf	pclath	
	swapf	status_temp,W	
	movwf	status		
	swapf	w_temp,F	
	swapf	w_temp,W	
	RETFIE		

;-------------------------------------
	nop

MSG	addwf pcl,f
	retlw 'P'
	retlw 'I'
	retlw 'C'
	retlw '1'
	retlw '6'
	retlw 'F'
	retlw '8'
	retlw '4'
	retlw '-'
	retlw '0'
	retlw '4'
	retlw ' '
	retlw 'V'
	retlw 'e'
	retlw 'r'
	retlw ':'
	retlw ' '
	retlw '2'
	retlw '6'
	retlw '0'
	retlw '6'
	retlw '0'
	retlw '5'
	retlw 13
	retlw 10
	retlw 'L'
	retlw 'M'
	retlw '3'
	retlw '5'
	retlw 'D'
	retlw 'Z'
	retlw ' '
	retlw '1'
	retlw '0'
	retlw 'm'
	retlw 'V'
	retlw '/'
	retlw '°'
	retlw 'C'
	retlw 13
	retlw 10
	retlw 'C'
	retlw 'o'
	retlw 'n'
	retlw 'v'
	retlw 'e'
	retlw 'r'
	retlw 's'
	retlw 'i'
	retlw 'o'
	retlw 'n'
	retlw ' '
	retlw 'A'
	retlw 'D'
	retlw 'C'
	retlw ' '
	retlw 'L'
	retlw 'T'
	retlw 'C'
	retlw '1'
	retlw '2'
	retlw '8'
	retlw '6'
	retlw ' '
	retlw ' '
	retlw '='
	retlw '>'
	retlw ' '
	retlw '2'
	retlw '5'
	retlw '0'
	retlw ' '
	retlw 'm'
	retlw 'V'
	retlw ' '
	retlw '='
	retlw '>'
	retlw ' '
	retlw 'a'
	retlw 'f'
	retlw 'f'
	retlw 'i'
	retlw 'c'
	retlw 'h'
	retlw 'a'
	retlw 'g'
	retlw 'e'
	retlw ' '
	retlw '2'
	retlw '5'
	retlw '.'
	retlw '0'
	retlw '°'
	retlw 'C'
	retlw 13
	retlw 10
	retlw 'D'
	retlw 'a'
	retlw 'l'
	retlw 'l'
	retlw 'a'
	retlw 's'
	retlw ' '
	retlw 'D'
	retlw 'S'
	retlw '1'
	retlw '3'
	retlw '0'
	retlw '2'
	retlw ' '
	retlw 'h'
	retlw 'o'
	retlw 'r'
	retlw 'l'
	retlw 'o'
	retlw 'g'
	retlw 'e'
	retlw ' '
	retlw 't'
	retlw 'e'
	retlw 'm'
	retlw 'p'
	retlw 's'
	retlw ' '
	retlw 'r'
	retlw 'e'
	retlw 'e'
	retlw 'l'
	retlw 13
	retlw 10
	retlw 'R'
	retlw 'S'
	retlw '2'
	retlw '3'
	retlw '2'
	retlw ' '
	retlw '4'
	retlw '8'
	retlw '0'
	retlw '0'
	retlw ','
	retlw '8'
	retlw ','
	retlw 'N'
	retlw ','
	retlw '1'
	retlw 13
	retlw 10
	retlw 0

start
		bcf status,rp1
		bank1
		clrf intcon		;no interrupts
		bank0
;clear all ram registers
           movlw   0x0C            ;start of ram
           movwf   fsr
           clrf    indf            ;$-3 to here
           incf    fsr,f
           btfss   fsr,5
           goto    $-3             ;back to clrf indf                          
           bank1
	      movlw   00000000b		;Ra0=inp Ra1,Ra1,Ra2,Ra4=outp
            movwf   trisa             
            movlw   00000101b		;rb0,3 =inp  rb1,rb2,rb4..7=out
            movwf   trisb
		clrf option_reg
		bsf option_reg,7		; disable pull_up
		bcf option_reg,6		; int sur front descendant RB0
	      bank0
            movlw   00000000b
            movwf   porta

;----------

Presentation

		movlw 0		; W contient le deplacement dans la table message
Pres1
		MOVWF	dummy	; sauve index message 
		CALL	MSG
		ANDLW	0x0FF		; test sur (W)
		BTFSC	status,z	; zero= fin de message ?
		GOTO	Intro1  
		call 	Send_Char
		MOVF	dummy, W	; Pointe sur car suivant
		ADDLW	1
		GOTO	Pres1
Intro1		
		call delay_1s
		call cr_lf

		clrf Cpt1
Intro2
		movf Cpt1,w
		CALL read_EE
		incf	Cpt1,f
		ANDLW	0x0FF		
		BTFSC	status,z	
		GOTO	main_loop 	
		CALL Send_Char
		goto Intro2

main_loop   call cr_lf           
            call    delay_100ms
            call    Read_Clock      ;fetch the current contents of rtc itself
            bcf     second,7        ;clear `clock halt' CH bit
            bcf     hour,7          ;am/pm:24 -> 24 hr mode
            call    Write_Clock
	    	call    Enable_TRKL 	; valide la fonction chargeur
            call    delay_1s
        	call	Affiche_Degres
		call 	cr_lf
	
main_loop1
		clrf  RsByte
                call    delay_100ms
		call  Read_Clock
		call  crush_dump      ;print one data dump only
		call 	Affiche_Degres

; acces clavier autorisé dans cette portion de code
		bsf intcon,gie
		bsf intcon,inte		; autorise interrupt RB0
		call delay_1s
		bcf intcon,inte		;interdit interrupt RB0
		bcf intcon,gie

		movlw 0xFF
		andwf RsByte,w
		btfsc status,z
		goto main_loop1	; pas de caracteres dans RsByte

		bcf RsByte,5	; passe de minuscule à majuscule
		movlw 'M'		; Mise a l'heure?
		xorwf RsByte,W
		btfsc status,z
		goto Actualise
	
		movlw 'A'		; Mesure Analog
		xorwf RsByte,W
		btfsc status,z
		goto LectureAna
		
		movlw 'T'		; Mesure en degree
		xorwf RsByte,W
		btfsc status,z
		call 	Affiche_Degres
		goto main_loop1
			
		movlw '?'		; no comprendo
		CALL Send_Char
	
		goto main_loop1
		
	
;-------------------

LectureAna
		clrf Cpt1
		bcf Drapeau,1
Lect1
		movf Cpt1,w
		call read_EE
		incf	Cpt1,f
		ANDLW	0x0FF		; test sur (W)
		BTFSC	status,z	; zero= fin de message ?
		GOTO	Lect2  	
		call Send_Char
		goto Lect1
Lect2		call Aff2
		bsf Drapeau,1
		goto main_loop1

;------------------

Actualise
		call cr_lf
		movlw EE2-EE0
		MOVWF Cpt1
Actu0
		movf Cpt1,w
		CALL read_EE
		incf	Cpt1,f
		ANDLW	0x0FF		
		BTFSC	status,z	
		GOTO	Actu1 	
		CALL Send_Char
		goto Actu0
Actu1
		call cr_lf
 		movlw EE3-EE0	; Cde
		MOVWF Cpt1
Actu2
		movf Cpt1,w
		CALL read_EE
		incf	Cpt1,f
		ANDLW	0x0FF		
		BTFSC	status,z	
		GOTO	Actu3 	
		CALL Send_Char
		goto Actu2
		call    delay_100ms
Actu3
		call Read_RS	; lecture 1 car par pooling
		movf RsByte,w
		call Send_Char

		movlw '1'
		xorwf RsByte,w
		btfss status,z
		goto NOT1 
		call inc_minute_bcd
		goto LoopActu
NOT1	
		movlw '0'
		xorwf RsByte,w
		btfss status,z
		goto NOT0 
		call dec_minute_bcd
		goto LoopActu
NOT0	
		movlw '3'
		xorwf RsByte,w
		btfss status,z
		goto NOT3 
		call inc_hour_bcd 
		goto LoopActu
NOT3	
		movlw '2'
		xorwf RsByte,w
		btfss status,z
		goto NOT2 
		call dec_hour_bcd 
		goto LoopActu
NOT2	
		movlw '5'
		xorwf RsByte,w
		btfss status,z
		goto NOT5 
		call inc_date_bcd 
		goto LoopActu
NOT5	
		movlw '4'
		xorwf RsByte,w
		btfss status,z
		goto NOT4 
		call dec_date_bcd 
		goto LoopActu
NOT4	
		movlw '7'
		xorwf RsByte,w
		btfss status,z
		goto NOT7 
		call inc_month_bcd 
		goto LoopActu
NOT7	
		movlw '6'
		xorwf RsByte,w
		btfss status,z
		goto NOT6 
		call dec_month_bcd 
		goto LoopActu
NOT6	
		movlw '9'
		xorwf RsByte,w
		btfss status,z
		goto NOT9 
		call inc_year_bcd 
		goto LoopActu
NOT9	
		movlw '8'
		xorwf RsByte,w
		btfss status,z
		goto NOT8
		call dec_year_bcd 
		goto LoopActu
NOT8
		movlw .27		;esc
		xorwf RsByte,w
		btfss status,z
		goto NOTESC
		goto main_loop1
NOTESC		
		clrf RsByte
		movlw '?'
		CALL Send_Char
		goto main_loop1		;goto Actu1  @ <---

LoopActu	call modifie
		goto Actu1

modifie
		call    Write_Clock
         	call    crush_dump
		clrf	 RsByte
         	call    delay_100ms 
		return 

;---------------------------------------
; specific RTC ds1302 subroutines per Mark K Sullivan 25.7.96

Write_Clock  
	bcf     DS1302_SCLK            ;negate clock line
      nop
	nop
	nop
	nop
	nop
	nop
      bcf     DS1302_DATA
      bsf     DS1302_RST      	;negate RST
      bank1
      bcf     trisa,dataq		;I/O as output
      bank0
      movlw   0x8E            	;write control register
      call    wbyte
      movlw   0x00            	;turn off Write Protect in rtc
      call    wbyte
      movlw   7				;nb de registres à parcourir :  SS,MN,HH,DD,JJ,MM,AA
      movwf   dummy3
      movlw   0x80            	;rtc register address for `second'
      movwf   count4
      movlw   second		  	;fsr pointe sur zone stockage données Clock @ second
      movwf   fsr
wc1    
	bcf     DS1302_RST          	;assert RST
	nop
      bcf     DS1302_SCLK   		;negate clock
      nop
      nop
      bsf     DS1302_RST      	;negate RST
      nop
      movf    count4,W			;N° registre CLOCK
      call    wbyte			;envoie adresse du registre
      movf    indf,W
      call    wbyte
      incf    fsr,f			;incremente pointeur ram PIC
      incf    count4,f			;adresse registre modulo 2 car bit0 utilisé pour sens R/W
      incf    count4,f
      decfsz  dummy3,f			;decrement nb de registre à explorer
      goto    wc1
      bcf     DS1302_RST      	;assert RST
	nop
      return
;--------------------
Enable_TRKL  
	bcf     DS1302_SCLK            ;negate clock line
     	nop
    	bcf     DS1302_DATA
	nop
     	bsf     DS1302_RST          ;negate RST
  	bank1
     	bcf     trisa,dataq	;I/O as output
     	bank0
     	bsf     DS1302_RST          ;negate RST
	nop
	movlw   0x8E            ;write control register
     	call    wbyte
     	movlw   0x00            ;turn off Write Protect in rtc
     	call    wbyte
     	movlw   0x90            ;adresse registre Trickle
     	call    wbyte
      movlw   0xAD		;acces TCS diode 1 et diode 2 et Rs1=2K
      call    wbyte
      bcf     DS1302_RST      ;assert RST
	nop
    return
;-----------
;       The Read_Clock routine following, reads the whole lot in `burst mode'
;       and puts the values into seconds --->year fregs

Read_Clock
	bcf     DS1302_SCLK      ;negate clock
        bcf     DS1302_RST       ; bon depart avec RST=0 
        bank1
        bcf     trisa,dataq
        bank0
        nop
        nop
        nop
        bcf     DS1302_DATA         ;negate I/O
        bsf     DS1302_RST          ;negate RST
        movlw   0xBF            ; burst read mode for clock registers
        call    wbyte
        bank1
        bsf     trisa,dataq		; DS1302 I/O = output to read
        bank0
        movlw   second
        movwf   fsr			; pointer sur RAM PIC second
        call    rbyte			; lecture secondes
        call    rbyte			;lecture minutes
        call    rbyte			;lecture heure
        call    rbyte			;lecture date
        call    rbyte			;lecture mois
        call    rbyte			;lecture jour
        call    rbyte			;lecture annee
        bcf     DS1302_RST          ;assert RST
	nop
        return
;--------------------
wbyte   movwf   Rdecal2
        movlw   8
        movwf   dummy2
wbit    bcf     DS1302_SCLK
        btfss   Rdecal2,0
        bcf     DS1302_DATA
        btfsc   Rdecal2,0
        bsf     DS1302_DATA
        nop
        nop                    
        nop
        bsf     DS1302_SCLK
        rrf     Rdecal2,f
        decfsz  dummy2,f
        goto    wbit
        return
;-------------------
rbyte   movlw   8
        movwf   dummy1
rbit    bcf     DS1302_SCLK
        nop
        nop                     ;clock to data delay
        rrf     indf,f
        bcf     indf,7
        btfsc   DS1302_DATA
        bsf     indf,7
        bsf     DS1302_SCLK
        nop
        nop
        decfsz  dummy1,f
        goto    rbit
        incf    fsr,f
        return

;-----------------
crush_dump
		movlw   0x20       
                call Send_Char   
      	    	movlw   0x20    
                call Send_Char   
		call    Read_Clock    
                movlw   '2'
                call 	Send_Char       
                movlw   '0'
                call 	Send_Char      
                goto    crush_dump2
crush_dump2
                movf    year,w          
                call    packBCD_to_ascii     
                movlw   '/'          
                call 	Send_Char  
                movf    month,w
                call    packBCD_to_ascii  
                movlw   0x2F       
                call 	Send_Char 
                movf    date,w
                call    packBCD_to_ascii 
                movlw   ' '      
                call Send_Char    
                movlw   0x20       
                call Send_Char  
                movf    hour,w
                call    packBCD_to_ascii  
                movlw   0x3A  
                call Send_Char    
                movf    minute,w
                call    packBCD_to_ascii 
                movlw   0x3A    
                call Send_Char  
                movf    second,w
                call    packBCD_to_ascii       
                movlw   ' '
                call Send_Char   
		     movlw   ' '
                call Send_Char     
	        return
;---------------------------------
packBCD_to_ascii
;takes packed bcd byte in w -> ascii ->tx rs232 HI nibble first        
                movwf   dummy         ;eg w=98 dummy=98 for years, say
                movwf   dummy1
                swapf   dummy,f    	;eg dummy=89
                movlw   0x0F        ;mask nibble for years 10s
                andwf   dummy,f    	;eg dummy=09
                movlw   0x30        ;convert to ascii
                addwf   dummy,w     ;eg dummy=39 , produces years 10s , in ascii, in w
                call 	Send_Char   ;char out  HI nibble
                movf    dummy1,w    ;eg year=98
                movwf   dummy       ;eg dummy=98
                movlw   0x0F        ;mask nibble for years units               
                andwf   dummy,f     ;eg dummy=08
                movlw   0x30        ;convert to ascii
                addwf   dummy,w     ;eg dummy=38="8"
                call Send_Char      ;char out LO nibble
        return          

cr_lf           ;carriage return + line feed to rs232 port
                movlw   0x0D       ;CR
                call Send_Char
                movlw   0x0A      ;LF
                call Send_Char
                return          
;---------------------------
blancs      				;10 blancs sur la gauche
                movlw   0x0A
                movwf   dummy
                movlw   ' '  
                call Send_Char
                decfsz  dummy,f
                goto    $-3
        return  
;--------------------
incw_bcd        ;increment a packed bcd 8bit freg., enter with data in w
                ;ex T Scott Dattalo, 20/4/98
                movwf   dummy
                movlw   11111110b
                addlw   0x9A+1
                subwf   dummy,w
                rlf     dummy,f
                btfss   status,dc
                addlw   -0x06
                btfss   dummy,0
                addlw   -0x60
                rrf     dummy,f    ;result in w
	        return          

decw_bcd        ;decrement a packed bcd freg., enter sub with data in w
                ;ex T Scott Dattalo, 20/4/98
                movwf   dummy
                movlw   1
                subwf   dummy,w
                rlf     dummy,f
                btfss   status,dc
                addlw   -0x06   
                btfss   dummy,0
                addlw   -0x60
                rrf     dummy,f    ;result in w
      	  return

inc_minute_bcd  ;incr minutes reg by 1, check for not overflow 60s
                movf    minute,w
                sublw   0x60            ;59hex means 59dec in packed bcd
                btfsc   status,z
                return                  ;z got set if minutes=59,so don't incr
                movf    minute,w
                call    incw_bcd
                movwf   minute
        return

dec_minute_bcd  ;decrement minute reg, check for zero underflow
                movf    minute,w
                btfsc   status,z
                return                  ;underflow danger, don't decr
                call    decw_bcd
                movwf   minute
        return

inc_hour_bcd    ;incr hours, packed bcd representation
                movf    hour,w
                sublw   0x24
                btfsc   status,z
                return
                movf    hour,w
                call    incw_bcd
                movwf   hour
        return

dec_hour_bcd    ;decrement hour reg, check for zero underflow
                movf    hour,w
                btfsc   status,z
                return                  ;underflow danger, don't decr
                call    decw_bcd
                movwf   hour
        return

inc_date_bcd    ;incr date of month,packed bcd,cheat & assume all months <= 28days
                movf    date,w
                sublw   0x28
                btfsc   status,z
                return
                movf    date,w
                call    incw_bcd
                movwf   date
        return
dec_date_bcd    ;decrement date reg, check for zero underflow
                movf    date,w
                btfsc   status,z
                return                  ;underflow danger, don't decr
                call    decw_bcd
                movwf   date
        return

inc_month_bcd   ;incr month,packed bcd
                movf    month,w
                sublw   0x12
                btfsc   status,z
                return
                movf    month,w
                call    incw_bcd
                movwf   month
        return
dec_month_bcd   ;decrement date reg, check for zero underflow
                movf    month,w
                btfsc   status,z
                return                  ;underflow danger, don't decr
                call    decw_bcd
                movwf   month
        return

inc_year_bcd    ;incr year, packed bcd
                movf    year,w
                sublw   0x99
                btfsc   status,z
                return
                movf    year,w
                call    incw_bcd
                movwf   year
        return
dec_year_bcd    ;decrement date reg, check for zero underflow
                movf    year,w
                btfsc   status,z
                return                  ;underflow danger, don't decr
                call    decw_bcd
                movwf   year
        return

;specific bcd handling routines end

;-----------------------------------
;--------------------------------------------
;*General purpose 16F84 EEPROM register read/write
;The following `eprom write' routine requires that eeadr @ loc 0x009
;in bank0 contains the address of the eeprom data byte to be loaded.
;The data must be pre-loaded in eedata @ loc 0x008 in bank0
;In addition, the  eecon1,wren   bit in bank1 regs. must be set before 
;calling this routine. Then cleared after using it.

read_EE	
	movwf   eeadr           ; defini offset addresse
	bank1				; pour PIC16F628  only
	bsf     eecon1,eerd     ; mode lecture
	bank0
	movf    eedata,W       	; recupere lecture
	return

eeprom_wr                       ;write byte to eeprom loc.
        bcf     intcon,gie      ;make sure ints disabled, work on bank1
        btfsc   intcon,gie      ;to-be-suuuure
        goto    $-1
        bank1			  ;set to bank 1,see c84 para 7.2
        movlw   0x055           ;fairy-godmother value, given by uchip
        movwf   eecon2          ;-actually for diode pump charging hv cell drives-
        movlw   0x0AA           ;another fairy-godmother value
        movwf   eecon2
        bsf     eecon1,eewr     ;set write control bit & begin write
        btfsc   eecon1,eewr     ;poll write control bit until h/w resets it LO
        goto    $-1             ;write until job done
        bcf     eecon1,eeif     ;must clear this bit, don't know why??
        bank0
   ;enable global ints here, if using them.ie  bsf  intcon,gie
        return

;following routine requires eeadr to be pre-loaded with the eeprom location
;--like a pointer. The contents of the location are returned in eedata reg.
eeprom_rd                       ;read byte value from eeprom ->w reg
        bank1
        bsf     eecon1,eerd     ;ee read
        bank0
        return
;--------------------------------------
; Lecture octet sur port RS232 @ 4800bds
Read_RS  
	 Clrf RsByte
	 nop
         btfsc SERIAL_RX	; entree via interrupt sur RB0 front descendant (donc =0!)
         goto $-1		; boucle si=1
       	 call delay_RS_half 	; se positionner au milieu deu bit START
         Movlw  H'08'         	;Nb Data bit =  8 bit
         Movwf  RsCount
Rx_Loop  
	 call 	delay_RS	; milieu du bit suivant
         Bcf    status,c      	;Carry=0
         Btfsc  SERIAL_RX     	;lit et test l'entrée RB0
         Bsf    status,c      	;Rx =1, saute si Rx =0
         rrf    RsByte,f       
         Decfsz RsCount,f
         Goto   Rx_Loop 
         call   delay_RS  	   ;laisse passer bit de stop     
         Return   
Rx_PB	 movlw '*'

                 
;---------------------------
Send_Char
	 movwf	 RsBuffer
	 Movlw           .8            ;correspond à un byte de 8 bits
         Movwf           RsCount     ;place dans RsCount
         Bcf             SERIAL_TX   ;bit start à 0
         Call            delay_RS    ;wait valeur 1bit 4800 Bauds
         Rrf             RsBuffer,F  ;shift droite dans carry
         Btfsc           status,c    ;si carry 0 alors saute
         Goto            $+3         ;carry =1
         Bcf             SERIAL_TX   ;Tx =0
         Goto            $+2
         Bsf             SERIAL_TX   ;Tx =1
         Call            delay_RS  
         Decfsz          RsCount,F   ;RsCount =RsCount -1
         Goto            $-8
         Bsf             SERIAL_TX   ;bit de stop à 1
         Call            delay_RS    ;envoi du STOP
  	return
;--------------------------
; conv mot 16bits --> °C
bcd_temp_mV
	movf	val1,w
	movwf	valx
	movf	val1+1,w
	movwf	valx+1
	swapf  val1,w	
	iorlw  0xf0
	movwf  mille 
	addwf  mille,f 
	addlw  0xE2 
	movwf  cent 
	addlw  0x32 
	movwf  un 
	movf   val1,w 
	andlw  0x0F 
	addwf  cent,f 
	addwf  cent,f 
	addwf  un,f 
	addlw  0xE9 
	movwf  dix 
	addwf  dix,f 
	addwf  dix,f 
	swapf  val1+1,w 
	andlw  0x0F 
	addwf  dix,f 
	addwf  un,f 
	rlf    dix,f 
	rlf    un,f 
	comf   un,f 
	rlf    un,f 
	movf   val1+1,w 
	andlw  0x0F 
	addwf  un,f 
	rlf    mille,f 
	movlw  0x07 
	movwf  dixmil 
        movlw  0x0A
Lb1: 	addwf  un,f 
	decf   dix,f 
	btfss  status,c
	goto   Lb1 
Lb2:	addwf  dix,f 
	decf   cent,f 
	btfss  status,c
	goto   Lb2 
Lb3:	addwf  cent,f 
	decf   mille,f 
	btfss  status,c
	goto   Lb3 
Lb4:	addwf  mille,f 
      decf   dixmil,f 
	btfss  status,c
      goto   Lb4 
Lb5:
	movf   mille,w
	addlw  '0'
	call   Send_Char
	movf   cent,w
	addlw  '0'
	call   Send_Char
	movf   dix,w
	addlw  '0'
	call   Send_Char
	btfsc Drapeau,1
	goto Lb6
	movlw ','
	Call Send_Char
Lb6	movf   un,w
	addlw  '0'
	call   Send_Char
	btfss Drapeau,1
	goto Lb8
	movlw	'.'
	call Send_Char
	movlw 'C'
	call Send_Char
Lb7	movlw ' '
	call Send_Char
	return
Lb8	movlw	'm'
	call Send_Char
	movlw	'V'
	call Send_Char
	goto Lb7
;-----------------------
Affiche_Degres
	bsf Drapeau,1
	movlw EE1-EE0
	MOVWF Cpt1
Aff1
	movf Cpt1,w
	call read_EE
	incf	Cpt1,f
	ANDLW	0x0FF		; test sur (W)
	BTFSC	status,z	; zero= fin de message ?
	GOTO	Aff2  	
	call Send_Char
	goto Aff1
Aff2
	call Lect1286
	movf Hi_Temp,W
	movwf	val1
	movf Lo_Temp,W
	movwf	val1+1
	call 	bcd_temp_mV
	call cr_lf
	return

;-----------------
Lect1286
	bsf Ltc_CS
	nop
	bcf Ltc_CLOCK
	nop
	bcf Ltc_CS		; CS=0
	call delay_25us
	call delay_25us
	clrf Lo_Temp
	clrf Hi_Temp
	movlw 4
	movwf Cpt2
	call L_clk
	call L_clk
	call L_clk
Ltc1
	rlf Hi_Temp,f
	btfss Ltc_DATA
	bcf Hi_Temp,0
	btfsc Ltc_DATA
	bsf Hi_Temp,0
	call L_clk
	Decfsz Cpt2,f
	goto Ltc1

	movlw 8
	movwf Cpt2
Ltc2
	rlf Lo_Temp,f
	btfss Ltc_DATA
	bcf Lo_Temp,0
	btfsc Ltc_DATA
	bsf Lo_Temp,0
	call L_clk
	Decfsz Cpt2,f
	goto Ltc2
	bsf Ltc_CS
	nop
	return	
L_clk
	bsf Ltc_CLOCK
	nop
	nop
	nop
	bcf Ltc_CLOCK
	return
;------------------------------------
	include <bcd32toT.inc>
;bin2bcd
    ;Binary - BCD   32 bits :  FFFFFFFF -> 10 digits
    ;Input in buff_4|buff_3|buff_2|buff_1,
    ;Converts to *packed* bcd in temp_a, temp_b, temp_c, temp_d and temp_e
    ;with the MSD temp_a.
    ;Handles full range:  ff ff ff ff -> 4,294,967,296
    ;Also uses temp_f and count.
    ;2940 cycles including call and return.
;--------------------------

;delaisfQ.inc pour Fquartz=X 
;definition f(Quartz)
;à declarer dans le programme principale :
; #define Quartz 32  ; valeur du Quartz employé!
; count1	;delay routines
; count2 ;delay routines
; count3 ;delay routines
;delay_RS  ; f(quartz)
;delay1	; 5(count3-1)+1282(count2-1)+327684(count1-1)+6
;delay_25us
;delay_100us  
;delay_1ms 
;delay_10ms
;delay_25ms
;delay_100ms
;Delay_1sec 
;Delay_2sec 
;delay_10sec
;last update: 28 mars 2003
;---------------------

;special pour routine d'attente 4800 bauds si 3.58Mhz
delay_RS

         MOVLW           58            ;  pour 4800 bauds
         MOVWF           RsCount2	; 1000000/4800=208µS
         DECFSZ          RsCount2,F	; 1 cycle si pas de saut
         GOTO            $-1		; 2cycles
         Return				; 2 cycles 

delay_RS_half

          MOVLW           30            ;  pour 4800 bauds
         MOVWF           RsCount2	; 100µS
         DECFSZ          RsCount2,F 
         GOTO            $-1		
         Return				

delay_25us
	      movlw   0x01     
            movwf   count1
            movlw   0x01
            movwf   count2
             MOVLW           4         
  	    movwf   count3
         goto    delay1
        
delay_100us     movlw   0x01    
                movwf   count1
                movlw   0x01
                movwf   count2
                 MOVLW           18         
 	       movwf   count3
           goto    delay1
                
 
delay_1ms       movlw   0x01    
                movwf   count1
     	         MOVLW           1         
           movwf   count2
         MOVLW           179         
          movwf   count3
                goto    delay1

delay_10ms  movlw   10
d_10ms      movwf   count4	
d_10a      DECFSZ   count4,F
		goto d_10b
		return
d_10b		call delay_1ms
         	GOTO d_10a   
  			
		
delay_25ms  movlw   25
            goto d_10ms   

delay_100ms	movlw 100
		 goto d_10ms   

        
delay_1s       
 	
         	MOVLW           3 
    	       	movwf   count1
         	MOVLW           187 
 	       	movwf   count2
		movlw 1
            movwf   count3
            goto    delay1

delay_xS   ; nb de secondes dans W
      		movwf   count4	
d_xa      	DECFSZ   count4,F
		goto d_xb
		return
d_xb		call delay_1s
         	GOTO d_xa    	
                
delay1          decfsz  count3,f    
                goto    $-1          
                decfsz  count2,f  
                goto    $-3           
                decfsz  count1,f      
                goto    $-5          
        return 

;------------------------
	org 0x2100
;      '1234567890123456'
EE0 DT "RTC1302k ",13,10,0
EE1 DT "Temp=",0
EE2 DT "Modif RTC",13,10
    DT "  AMJHM",13,10
    DT "+ 97531",13,10
    DT "- 86420",13,10,0
EE3 DT "Cde=",0

        end
  
;==============================

Conclusion :


... à voir pourquoi je reste bloqué dans la lecture caractere, malgre la touche ESC
qui devrait permettre de revenir tourner en boucle sur l'affichage de l'heure
en attendant la reception d'un car , generant une interrupt RB0.

remerciement à Mark K Sullivan pour ses subroutines DS1302.

A voir également

Ajouter un commentaire

Commentaires

cs_hasem
Messages postés
1
Date d'inscription
vendredi 22 mars 2013
Statut
Membre
Dernière intervention
6 mai 2013
-
MERCI

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.