; rev 2 juillet 05 (p) ; ca y est,ca boucle ; rajout d'un delai de passage du bit STOP , afin deviter une interrupt parasite !!! ; rajout espion led BUSY ADC7896 : S=allume R=eteint ; corrigé un bug: des return dans la routine ISR ;faut etre con ! ; pourquoi ca ne boucle pas ? ;rev 30 juin 05 pour Adc7896 (o) ; ATTENTION reference tension AD7896 =5,00 et non pas 4,096V ; donc alim LE40CV regulateur de tension ; pour lecture directe en mV ; nota: changement de type ADC car mon LTC1286 est HS !!! ; PB mise à l'echelle temperature ; 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 Adc7896 12 bits => 250 mV => affichage 25.0°C ; RS232 baud rate parity data bits stop bits ; 4800 n 8 2 ; Dallas DS1302 circuit horloge temps reel en BCD via communication 3 fils ; year month day hour minute second ; yyyy mm dd hh mm ss ;hardware : voir schema "PIC16F84_DS1302_RS232_juillet_05.jpg" ;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 not used ; ; rb0 6 I RB0 serial in <--- 12 ICL232 --< Rx ; rb1 7 O RB1 -> CS 5 Adc7896 ; rb2 8 I RB2 <- DATA 6 Adc1286 ; rb3 9 O RB3 -> CLCK 7 Adc1286 ; rb4 10 I RB4 <- busy 8 Adc7896 ; rb5 11 O Led status ADC BUSY ; rb6 12 O not used ; rb7 13 O 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 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 Adc_CS portb,_rst ;output 6 Adc7896 chip select #define Adc_DATA portb,dataq ;input 5 Adc7896 Output Data line #define Adc_CLOCK portb,clk ;output 4 Adc7896 clock line #define Adc_Busy portb,4 ;input 8 Adc7696 busy line #define BUSY_led portb,5 ;output sur led visu etat ADC #define KELVIN 2730 + 0 ; 273øK*10mv =2730 + ajustage offset 0øC cblock 0x0C dummy ;dummy reg for *temporary* use dummy1 ;for 8bit rotates in/out dummy2 dummy3 dummy4 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 val2:2 Tamb:2 Lo_Temp ; Max187 Hi_Temp endc ;maxiram 4Fh 68 bytes of RAM avec PIC16F84 ;------------------------------------- org 0x000 goto start ;------------------------------------- org 0x004 goto ISR ;-------------------------------------- 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 'R' retlw 'T' retlw 'C' retlw '1' retlw '3' retlw '0' retlw '2' retlw 'r' retlw '.' retlw 'a' retlw 's' retlw 'm' retlw ' ' retlw '0' retlw '1' retlw '0' retlw '7' retlw '0' retlw '5' retlw 13 retlw 10 retlw 'L' retlw 'M' retlw '3' retlw '3' retlw '5' retlw ' ' retlw '1' retlw '0' retlw 'm' retlw 'V' retlw '/' retlw '°' retlw 'K' retlw 13 retlw 10 retlw 'A' retlw 'D' retlw 'C' retlw ' ' retlw 'A' retlw 'D' retlw '7' retlw '8' retlw '9' retlw '6' 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 'R' retlw 'T' retlw 'C' 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 '2' retlw 13 retlw 10 retlw 0 ;------ 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 nop bcf intcon,intf ; raz drapeau Clrf RsByte nop btfsc SERIAL_RX ; entree via interrupt sur RB0 front descendant (donc =0!) goto ISR_Rx_PB ; saute si=1 call delay_RS_Half ; se positionner au milieu du bit START Movlw H'08' ;Nb Data bit = 8 bit Movwf RsCount ISR_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 ISR_Rx_Loop call delay_RS_Half ; dernier demi bit <- rajout 1/07/05 call delay_RS ;laisse passer 1er bit de stop call delay_RS ;laisse passer 2em bit de stop <- rajout 1/07/05 bcf intcon,intf ; raz drapeau (oui, 2 fois ,mais boof!) goto other_int ISR_Rx_PB ; si on passe par là,c'est qu'il y a un probleme! movlw '?' call Send_Char Clrf RsByte 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 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,Ra1,Ra2,Ra3,Ra4=out movwf trisa movlw 00010101b ;Rb0,Rb2,Rb4 =inp , Rb1,Rb3,Rb5,Rb6,Rb7=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 bcf BUSY_led ;led ON 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 bsf BUSY_led ;led OFF 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 bcf BUSY_led ;led ON 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 cr_lf bsf Drapeau,2 clrf RsByte bsf BUSY_led ;led OFF main_loop1 call delay_100ms call Read_Clock btfss Drapeau,2 goto main_loop2 call crush_dump ;print one data dump only call cr_lf main_loop2 ; acces clavier autorisé dans cette portion de code bsf intcon,inte ; autorise interrupt RB0 bsf intcon,gie call delay_1s bcf intcon,gie bcf intcon,inte ;interdit interrupt RB0 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' ; Analog measure xorwf RsByte,W btfsc status,z goto Lecture_Ana ;Pour Debugging ......................................... movlw 'S' ; SET allume BUSY_led xorwf RsByte,W btfsc status,z bcf BUSY_led movlw 'R' ;RESET eteint BUSY_led xorwf RsByte,W btfsc status,z bsf BUSY_led ;--------------------------------------------------------- movlw 'T' ; Temp Measure xorwf RsByte,W btfsc status,z goto Affiche_Degres bcf Drapeau,2 movlw 'H' ;date & heure xorwf RsByte,W btfsc status,z goto main_loop3 bcf Drapeau,2 movlw '!' ; no comprendo CALL Send_Char goto main_loop1 main_loop3 bsf Drapeau,2 goto main_loop1 ;------------------- Lecture_Ana bsf BUSY_led 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 Affiche_valeur bsf Drapeau,1 call delay_100ms bsf BUSY_led 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 call cr_lf goto main_loop1 NOTESC movlw '!' CALL Send_Char clrf RsByte goto main_loop1 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 '*' call Send_Char return ;--------------------------- 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 Send_1 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 Send_1 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 btfss 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 Adc7896 movf Hi_Temp,W movwf val1 movf Lo_Temp,W movwf val1+1 ;mise à l'echelle mesure Ext base ZERO KELVIN 273 movlw (KELVIN >>8) ; 0A movwf val2 ; (msb) movlw (KELVIN-(KELVIN >> 8)*256); BE movwf val2+1 ; (lsb) movf val2+1,W ; source subwf val1+1,F ; dest movf val2,W btfss status,c incfsz val2,W subwf val1,F ;dest = dest - source, WITH VALID CARRY bcf Drapeau,7 btfss val1,7 goto UpperZero comf val1,f comf val1+1,f incf val1+1,f ; complement à 2 bsf Drapeau,7 ; negative value UpperZero movf val1,W movwf Tamb movf val1+1,W movwf Tamb+1 call bcd_temp_mV call cr_lf goto main_loop1 Affiche_valeur call Adc7896 movf Hi_Temp,W movwf val1 movf Lo_Temp,W movwf val1+1 call bcd_temp_mV call cr_lf return ;----------------- Adc7896 ; en mode 1 au repos CONVST=1 BUSY=0 SCLK=0 bcf Adc_CLOCK bcf Adc_CS ;Track CONVST=0 btfsc Adc_Busy bcf BUSY_led ; visu status BUSY AD7686 nop bsf Adc_CS ; track CONVST =1 clrf Lo_Temp clrf Hi_Temp call delay_25us ; TCONVERT 8µS min call A_clk call A_clk call A_clk call A_clk ; 4 pulses Zero data movlw 4 movwf Cpt2 Adc1 call A_clk ; 4 x pulses MSB rlf Hi_Temp,f btfss Adc_DATA bcf Hi_Temp,0 btfsc Adc_DATA bsf Hi_Temp,0 Decfsz Cpt2,f goto Adc1 movlw 8 movwf Cpt2 Adc2 call A_clk ;8 x pulses LSB rlf Lo_Temp,f btfss Adc_DATA bcf Lo_Temp,0 btfsc Adc_DATA bsf Lo_Temp,0 Decfsz Cpt2,f goto Adc2 return A_clk bcf Adc_CLOCK nop bsf Adc_CLOCK nop return ;------------------------------------ include ;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 25 ; 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 sub16 ;16 bit subtraction with borrow Rudy Wieser movf val2+1,W ; source subwf val1+1,F ; dest movf val2,W btfss status,c incfsz val2,W subwf val1,F ;dest = dest - source, WITH VALID CARRY return ;------------------------ org 0x2100 ; '1234567890123456' EE0 DT "Analog=",0 EE1 DT "Temper=",0 EE2 DT "Modif RTC",13,10 DT " AMJHM",13,10 DT "+ 97531",13,10 DT "- 86420",13,10,0 EE3 DT "Cde=",0 EE4 DT "RE" EE5 DT "SET",0 end ;============================== resultat avec TERMINAL.EXE : PIC16F84-04 RTC1302s.asm 010705 LM335 10mV/°K ADC AD7896 Dallas DS1302 horloge RTC RS232 4800,8,N,1 Analog= 2005/07/01 20:33:07 2005/07/01 20:33:08 2005/07/01 20:33:09 2005/07/01 20:33:09 2005/07/01 20:33:10 ? Analog=2383mV Analog=2383mV Temper=034,8.C Temper=034,6.C 2005/07/01 20:33:22 Analog=2384mV 2005/07/01 20:33:25 Analog=2384mV 2005/07/01 20:33:26 Temper=034,6.C 2005/07/01 20:33:27 Temper=034,5.C 2005/07/01 20:33:28 £ Modif RTC AMJHM + 97531 - 86420 Cde=1 2005/07/01 20:34:34 Cde=0 2005/07/01 20:33:34 Cde=1 2005/07/01 20:34:34 Cde=0 2005/07/01 20:33:34 Cde=3 2005/07/01 21:33:34 Cde=2 2005/07/01 20:33:34 Cde=? Analog=2383mV Analog=2383mV Analog=2384mV Analog=2385mV