; version REGUL_16F88_L.asm ...OK ; retour sur version MAJRTC du 30/12/09 .. OK ; Probleme HARDWARE! parasite relais ventilo : oubli du circuit RC sur le contact relais ;5/1/10 RAZ second sur MAJRTC , RAZ COMND si ELLIBLE durant Read_IR ;4/1/10 PB blocage horloge RTC ?? seconde="90" ou ">6" ; rajout hysteresis de +-0,2øC 20 points ;-PB sur MAJRTC d‚crem minute sur test COMND=0=decrement minute ; init CMD=99 en sortie de boucle pour eviter de boucler <- PAS BON ! ;- maj de bank0 pour relayage ; reorganisation filtrage de T.Amb et T.Ext dans une seul passe commune ;version Regul_16F88_g.asm avec DEBUGGING! ;30/12/09 modif : regul. QUE SI ON ATTEINT LE FILTRAGE (moyenne de 10 mes) ;29/12/2009 version Regul_16F88_f.asm presque OK ; bug sur calcul consigne adapte ; MAJ RTC ..OK , tmr0 NON UTILISE dans la boucle readIR ; remodif en pooling IR et exit via ELLIGIBLE 500mS ; chauffe mini 100øC sur ConsAccu en mode Jour, mais reste reglable ; prescaler TMR0 sur 1/4 ; 24/12/09 rajout ConsAccuAdaptee en 8em position ; consigne adaptee UTILISE seulement en mode NUIT, pas de chauff en mode JOUR ; ICProgr_106B checksum =7A55h ID= FFFFh Config= 2F21h ; Principe de base: Usage de l'interrupt RB0 valid‚e seulement dans la tempo ; principale de boucle, permettant ensuite de tester ensuite l'evolution de RB0 en polling ; ATTENTION version entierement remani‚e pour avoir : poids faible puis poids fort ; ex: avec LSB en val1 puis MSB en val1+1 ; pour respecter l'ordre de poids des SFR TMR1L , puis TMR1H ; decalage entre adresse Breakpoint et adresse PCL en mode Simul debug ; verifier forma INHX8M (was INHX32 prevu pur 18Fxxxx) ; et aussi PB si ligne trop longue ?? ; verifier les chemins d'acces directories ; verifier / activer via click droit sur le source (apres compilation) SET PC at CURSOR ; le depart programme doit etre … ORG 0000 surligne en VERT ; 18 dec 2009 ; passage au 16F88 pour extension programme et fonctions 4K soit 0xFFF maxi ; au lieu de 0x7FF pour le 16F628 ...car restait 77 bytes de code seulement ; usage adresse prog au dela de 0x0900 en page 1 => gestion PCLATH ; Attention: => sauvegarde PCLATH sur interruption ; Attention INITIALISATION config I/O ; special 16F628 et 16F88 ; movlw 0x07 ;turn comparators off and ; movwf CMCON ;enable pins for I/O functions -> CLRF ANSEL et 0x07 ;special 16F88 ; clrf ANSEL ; NO Analog, all Digital I/O ; Gestion de l'EEPROM differente (pas les memes BANK !) ; gestion JOUR/NUIT par horloge temps reel plutot que info contact J/N EDF externe ; ON NE CHAUFFE PAS au dessus de 100øC si pas en mode tarif JOUR ; sauf si trop grand froid ;-------------------------------------------------------------- ;Release build of project `C:\Mplab8\_Mesprojets\_16F88\16F88_Regul.mcp' started. ;Language tool versions: MPASMWIN.exe v5.34, mplink.exe v4.34 ;Thu Dec 31 20:10:08 2009 ;Clean: Deleting intermediary and output files. ;Clean: Done. ;Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F88 "Regul_16F88_h.asm" ;/l"Regul_16F88_h.lst" /e"Regul_16F88_h.err" /x"Regul_16F88_h.xrf" /aINHX8M ;Executing: "C:\Program Files\Microchip\MPASM Suite\mplink.exe" /p16F88 "Regul_16F88_h.o" ;/z__MPLAB_BUILD=1 /m"Regul_16F88_h.map" /w /aINHX8M /o"Regul_16F88_h.cof" /x ;MPLINK 4.34, Linker ;Copyright (c) 2009 Microchip Technology Inc. ;Errors : 0 ;Loaded C:\Mplab8\_Mesprojets\_16F88\Regul_16F88_h.cof. ;Thu Dec 31 20:10:11 2009 ;BUILD SUCCEEDED ;========= old version 16F628 ================================ ; voir 68reg11.asm ; gestion JOUR/NUIT par info contact J/N EDF externe ; non active car because PB de cablage !! ...... … suivre ;========================================================================= ; 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 ; 16f88 pin In/Out function ; ra0 18 O LCD RS pin4 ; ra1 17 0 LCD Enable pin6 ;--------------------------------------------- ; ra3 1 O MAX187 CS pin7 *avec R 4.7k tirage au +5v ; ra2 2 O RTC sclck pin5 ; ra4 3 O Relais1 chauffe ACCUMULATEUR---- fil bleu marine ---- BN2 platine relais ;------------------------------------------ ; rb0 6 I I.R Receiver TSOP 1738 ; rb0 6 I serial in <--TTL pin12 ICL232--< Rx RS232 ; rb1 7 I MAX187 DATA I/O pin6 ; rb2 8 I RTC DATA I/O pin6 ; rb3 9 O RELAIS pour les 2 Ventilos --- fil vert fce ---- BN3 platine relais ; rb4 10 O LCD D4 pin11 ; rb5 11 O LCD D5 pin12 ; rb6 12 O LCD D6 pin13 ; rb7 13 O LCD D7 pin14 ; rb4 10 O 4052 A pin10 ; rb5 11 O 4052 B pin9 ; rb6 12 O RTC clck pin7 ; rb6 12 O MAX187 clck pin8 ; rb7 13 O serial out pin11 ICL232 -> Tx ;---------------------------- ; lecture MAX187 ADC 12 bits ; rb6 12 -> CLCK 8 MAX187 ; ra3 1 -> CS 7 MAX187 ; rb2 8 <- DATA 6 MAX187 ; +Vdd -------- 1 MAX187 ; Gnd -------- 5 MAX187 ; Ain -------- 2 MAX187 ; Gnd ----||---- 4 Ref MAX187 ; +Vdd -------- 3 SHD MAX187 ;-------------------------------- ; Fosc = 4MHz ; Cycle_time = 1uSec ;************************************************************************************ ; Rev 0 original 19 fev 2006 PROCESSOR 16F88 ERRORLEVEL -302 ERRORLEVEL -306 Radix DEC EXPAND #include LIST ; ;Program Configuration Register 1 __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB3 & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_OFF & _XT_OSC ;Program Configuration Register 2 __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF ;-------------------- ;#DEFINE DEBUGGING ;-------------------- ;RamSTART 0x20 For 16f88 ;************************** ; Equates, I/O, vars ;************************** RESET_V EQU 0x0000 ; Address of RESET Vector ISR_V EQU 0x0004 ; Address of Interrupt Vector OSC_FREQ EQU D'4000000' ; Oscillator Frequency is 4 MHz InitValue1 EQU D'65535'-D'62500'-D'5' ; tempo de 62500 uS ;--------------------------------------------------------- w EQU 0 f EQU 1 ONE EQU B'00000001' ; 2-bit incoming pattern matches ZERO EQU B'00000010' ;----------------------- ; selecteur 2 vers 4 Entrees avec b4 b5 ; selection voie 3 du CD4052 => Lecture "etat" Jour Nuit >4000 points Sel_Taccu EQU 0x00 ; voie 0 Sel_Tamb EQU 0x10 ; voie 1 Sel_Texter EQU 0x20 ; voie 2 Sel_JN EQU 0x30 ; voie 3 Sel_Aucun EQU 0xCF ;----------------------------------------------------- #define SERIAL_TX PORTB,7 ;rs232 serial transmit line Rb7 #define SERIAL_RX PORTB,0 ;rs232 serial Receive line Rb0 #define IR_Sensor PORTB,0 ;Infra Red receive line Rb0 ;----------------------------------------------------- #define Relais_Ventilo PORTA,4 ; out -> relais Ventilos evacuation air chaud accumulateur #define Relais_Accu PORTB,3 ; out -> relais chauffage accumulateur 4Kw ;----------------------------------------------------- #define DS1302_RST PORTA,2 ;out -> 5 RTC reset port data line LO=reset HI=active #define DS1302_SCLK PORTB,6 ;out -> 7 RTC clock port data line #define DS1302_DATA PORTB,2 ;inp <- 6 RTC I/O port data line #define DS1302_SENS_IO TRISB,2 ;sens I/O port data line #define dataq 2 ;6 RTC bit data line ;---------------------------------------------------- #define Max_CS PORTA,3 ;out -> 7 Max select line Hi=reset LO=active #define Max_CLOCK PORTB,6 ;out -> 8 Max Clock line #define Max_DATA PORTB,1 ;inp <- 6 Max data line ;----------------------------------------------------- #define KELVIN 2730 + 20 ; 273øK*10mv=2730 +20= ajustage offset 0øC ;----------------------------------------------------- LCD_DATA EQU PORTB ; LCD: Port Data ( bits 4 … 7 ) LCD_DATA_TRIS EQU TRISB ; LCD: Port Data ( bits 4 … 7 ) LCD_CTRL EQU PORTA ; LCD: Port Ctrl LCD_CTRL_TRIS EQU TRISA ; LCD: Port Ctrl ;LCD_RW EQU 1 ; LCD: Ligne de Lecture/Ecriture de l'afficheur LCD_E EQU 1 ; LCD: Ligne de commande de controle de l'afficheur LCD_RS EQU 0 ; LCD: Ligne de selection de l'afficheur offset EQU 0 LINE1 EQU 0x080 ; Set display to line 1 character 0 LINE2 EQU 0x0C0 ; Set display to line 2 character 0 FUNCTION_SET EQU 0x028 ; 4 bits, 2 lines, 5x7 Font DISP_ON EQU 0x00C ; Display on DISP_ON_C EQU 0x00E ; Display on, Cursor on DISP_ON_B EQU 0x00F ; Display on, Cursor on, Blink cursor DISP_OFF EQU 0x008 ; Display off CLR_DISP EQU 0x001 ; Clear the Display ENTRY_INC EQU 0x006 ENTRY_INC_S EQU 0x007 ENTRY_DEC EQU 0x004 ENTRY_DEC_S EQU 0x005 DD_RAM_ADDR EQU 0x080 ; Least Significant 7-bit are for address DD_RAM_UL EQU 0x080 ; Upper Left coner of the Display ;------------------------------------------------- ; Drapeaux de 8 bits … usage multiple ; 7 signe Temperature Exterieur 1=negatif ; 6 mesures elligible=1 ; 5 bit image relais 2 ; 4 bit image relais 1 ; 3 Affichage mesure filtree ; 2 Traitement mesure Filtree T Exter 1=fait 0=en cours ; 1 Traitement mesure Filtree T Amb 1=fait 0=en cours ; 0 Mode_NUIT 1=NUIT #define ELLIGIBLE Drapeaux,6 #define Mode_NUIT Drapeaux,0 ;--------------------------------------------- ; Etat8bits : … usage multiple ; 7 ChoixCons ; ... ; 2 ChoixCons ; 1 Max_Debug ; 0 IR_Debug #define IR_Debug Etat8bits,0 #define Max_Debug Etat8bits,1 #define ChoixCons Etat8bits,2 ;------------------------------------------ ; MARANTZ RC5 200SR codage des touches #define BASSUP_ 22 #define BASSDOWN_ 23 #define VOLUP_ 16 #define VOLDOWN_ 17 #define MENUON_ 82 #define MENUOFF_ 83 #define MUTE_ 13 #define OSD_ 15 #define TV_ 63 #define UP_ 28 #define DOWN_ 29 #define LEFT_ 44 #define RIGHT_ 43 #define OK_ 87 ;---------------------------- ; macros ;---------------------------- DS1302_RD macro bank1 bsf DS1302_SENS_IO ; as input bank0 endm ; DS1302_WR macro bank1 bcf DS1302_SENS_IO ; as output bank0 endm ;****************************** ; definitions des variables ; rev 29 mars ConsTamb et Pointer_Msg ; rev 18 mars 03 passe SommeTAM et SommeTEX dans bank1 ; rev 07 mars 03 ; cblock 0x20 dummy dummy1 dummy2 dummy3 Cpt1 Cpt2 Cpt3 count0 count1 count2 count3 count4 count5 passe passe2 sequence up_count down_count Rdecal2 second minute hour date month day year Special_MAE buff_4 buff_3 buff_2 buff_1 temp_a temp_b temp_c temp_d temp_e temp_f RsBuffer RsByte RsCount Selecteur temp Drapeaux ; voir nota en fin de page TOGGLE ; The RC5 Toggle bit SYSTEM ; The RC5 System word COMND ; The RC5 Command word MZDATA ; The RC5 extra Data word Pointer_Msg ; Used in TABLE_MSG subroutine ASCII_O ; ASCII One's digit to print ASCII_T ; ASCII Ten's digit to print ASCII_H ; ASCII Hundred's digit to print BIT_COUNT ; Counter for incoming bits BYTE_COUNT ; Counter for buffer bytes TEMP ; Used by PARSE to hold the 2-bit pattern SERIAL_BUF ; Buffer for incoming bitstream SERIAL_2 SERIAL_3 SERIAL_4 SERIAL_5 SERIAL_6 FIELD PARSE_FLAGS ; DECODE returns its data in this MZ_FLAG ; Set if there is an extra data word LCDtmp LCDtmp1 Lo_Temp Hi_Temp tstsel Etat8bits ; IR_Debug reserve :10 lastbanque endc LastBank0 EQU lastbanque IF ( LastBank0 >= 0x70 ) ERROR "Attention debordement zone RAM bank0" ENDIF ;*************************************** ; VARIABLES ZONE COMMUNE * ;*************************************** ; Zone de 16 bytes cblock 0x70 W_temp STATUS_temp PCLATH_temp Flags endc ; #define ISmidnight Flags,0 ;*************************************** ; VARIABLES BANQUE 1 * ;*************************************** ; Zone de 80 bytes ; ---------------- CBLOCK 0xA0 ; Debut de la zone (0xA0 ..0xEF) Cpt10 ; Bcd ----------- Mcount bcent bdix bun btmp btmp1 dixmil mille cent dix un ; Hysteresis SommeTxX ; totalisateur de passe filtrage ; ;--- variables 16 bits avec ordre LSB puis MSB ConsTamb :2 ; consigne Tamb ConsTACC :2 ; consigne T Accumumateur de base ConsTAccuAdapt :2 ; consigne T Accumumateur adaptee valx :2 val1 :2 ; val1=LSB val1+1=MSB val2 :2 val3 :2 reste :2 result :2 TN_Accu :2 TN_Amb :2 TN_Ext :2 Mn_En_Cours :2 TF_Amb :2 TF_Ext :2 STF_Ext :2 STF_Amb :2 ENDC ;********************************* ; VARIABLES BANQUE 2 * ;********************************* ; Zone de 96 bytes ; ---------------- CBLOCK 0x110 ; Debut de la zone (0x110 a 0x16F) XB2 :80 ENDC ; Fin de la zone ;********************************* ; VARIABLES BANQUE 3 * ;********************************* ; Zone de 96 bytes ; ---------------- CBLOCK 0x190 ; Debut de la zone (0x190 a 0x1EF) XB3 :80 ENDC ; Fin de la zone ;=============================== ; Drapeaux de 8 bits a usage multiple ; 7 signe Temperature Exterieur 1=negatif ; 6 SP mesures elligible =1 ; 5 ; 4 ; 3 Affichage mesure filtree ; 2 Traitement mesure Filtree T Exter ; 1 Traitement mesure Filtree T Amb ; 0 JOUR/NUIT 1=NUIT ;****************************** ; Origine lancement de programme ; ORG 0x0000 RESET GOTO START ; ; Interrupt routine. ; ORG 0x0004 ; movwf W_temp swapf STATUS, W clrf STATUS movwf STATUS_temp ; sauve STATUS avec nibles inverses movf PCLATH,w ; special 16F88, car possible acces progr en page 1 movwf PCLATH_temp clrf PCLATH bank1 ; selectionner banque1 btfss PIE1,TMR1IE ; tester si interrupt autorisee goto IsitRBO_interrupt ; non, au suivant bank0 ; oui, selectionner banque0 btfss PIR1,TMR1IF ; oui, tester si Flag interrupt arme goto IsitRBO_interrupt ; non, au suivant ;---- traitement ISR_Timer1----- bcf T1CON,TMR1ON ; stop timer1 clrf TMR1L ; pour 4 sec en il faut 8 passes de 0,5s ( prescaler 8 x 62500 µS ) movlw HIGH InitValue1 ; MSB de 65535-62500-5 uS movwf TMR1H ;moins duree de traitement/4 => ~5 movlw LOW InitValue1 ; LSB de 3040 Movwf TMR1L ; soit interrupt toutes les 500.000uS =0,5Sec incf passe,f movlw .4 xorwf passe,w btfss STATUS,Z ; =4 ? goto Not_Yet ; 4x 0,5 sec ellapsed ! clrf passe bsf ELLIGIBLE ; arme drapeau eligibilite mesures incf passe2,f movlw .30 xorwf passe2,w btfss STATUS,Z ; =30 donc 30*2sec =1 minute ecoulee goto Not_Yet clrf passe2 bank1 incf Mn_En_Cours,f btfss STATUS,Z goto Not_Yet incf Mn_En_Cours+1,f Not_Yet bank0 movlw 0x31 ; reinit T1RUN=0 T1CKPC prescaler=11=>8 et arme TMR1ON=1 movwf T1CON ;TMR1CS=0=internal clock (Quartz/4) 1æS bcf PIR1,TMR1IF ; effacer flag interupt fin traitement ISR Timer1 IsitRBO_interrupt ; bank0 ; BTFSS INTCON,INT0IE ; interrupt RB0 autoris‚ee ? ; goto IsnotRB0 ; BTFSS INTCON,INT0IF ; drapeau interrupt RB0 arm‚ ? ; goto IsnotRB0 Rb0_int ; cal read_IR ; do the job ; bcf INTCON,INT0IF ; raz flag interrupt Rb0 ; bcf INTCON,INT0IE ; raz autorise int RB0 IsnotRB0 nop restorReg bank0 movf PCLATH_temp,W ; special 16F88 movwf PCLATH swapf STATUS_temp, W ;recupere copie STATUS movwf STATUS ;en remettant les nibles dans l'ordre initial swapf W_temp,f ;swap 1 fois la sauvegarde de W swapf W_temp,w ;swap 2 fois la sauvegarde ,donc en ordre dans W retfie ;============================================================= ; Table message : attention aux depassement frontiere de page!!! ;============================================================ TABLE_ST MOVWF PCL MSG_N DT "REGULATION ACCUMM" RETLW 0X00 MSG_Y DT "IRRC5-PT100 LM35 LM335" RETLW 0X00 ifdef DEBUGGING MSG_PRES DT "Regu16F88L_DEBUG" else MSG_PRES DT "Reg16F88L_100107" endif TABLE_END RETLW 0X00 IF ( (TABLE_ST & 0x0FF) >= (TABLE_END & 0x0FF) ) MESSG "Warning - Message table 'TABLE_ST' crosses page boundary" ENDIF ;************************************* ; Initialize processor registers ;************************************* START ; POWER_ON Reset (Beginning of program) CLRF STATUS ; Do initialization, Select bank 0 CLRF INTCON ; Clear int-flags, Disable interrupts CLRF PCLATH ; Keep in lower 2KByte CLRF PORTB CLRF PORTA ; ALL PORT outputs should output Low. bank1 ;special 16F88 movlw 0x07 ;turn comparators off and movwf CMCON ;enable pins for I/O functions ;special 16F88 clrf ANSEL ; NO Analog, all Digital I/O CLRF PIE1 CLRF PIE2 MOVLW 0x00 ; RA4-RA3-RA2-RA1-RA0 outputs MOVWF TRISA MOVLW B'00000111' ;RB7..3 outputs ; RB2..0 inputs MOVWF TRISB MOVLW B'00000001' ; Option register setup:prescaler 4 ; MOVLW B'00000010' ; Option register setup:prescaler 8 ; RBPU=0 Enable RB Pullups, ; INTEDG=0 falling edge RB0 ; T0CS=0 TMR0 clock Interne ,T0SE=0 clock interne (Quartz/4)pour timer0 ; PSA=0 Assign prescaler to TMR0 ; PS2:PS0=001 use 1/8 prescaling ratio MOVWF OPTION_REG ;------ Initialisations -------- ;clear all ram registers bank1 clrf PIE2 clrf PIE1 clrf INTCON bank0 movlw 0x20 ;start of ram movwf FSR Raz_reg clrf INDF ;$-3 to here incf FSR,F btfss FSR,6 ; 64 ? goto Raz_reg bank1 clrf SommeTxX clrf STF_Ext ;2 clrf STF_Ext+1 clrf STF_Amb ;2 clrf STF_Amb+1 movlw LOW .2000 movwf ConsTamb movlw HIGH .2000 ;20,00 degc movwf ConsTamb+1 movlw LOW .1000 movwf ConsTACC movlw HIGH .1000 ; init consigne ACCU a 100.0 degc movwf ConsTACC+1 movlw .20 ; 2øC movwf Hysteresis bank0 clrf Drapeaux bcf Relais_Ventilo ; 0=decolle le relais Ventilos nop bcf Relais_Accu ; 0=decolle le relais ACCU CALL delay_100ms CALL LCD_Init CALL LCD_Cls call LCD_Clear1 call Read_Clock ;modif 10/10/03 bcf second,7 ;clear `clock halt' CH bit bcf hour,7 ;am/pm:24 -> 24 hr mode call Write_Clock call LCD_Line1 call aff_Heure call delay_2_5s call LCD_Clear2 MOVLW MSG_N ; Point to message string CALL TABLE_MSG ; display message call delay_2_5s call LCD_Clear2 MOVLW MSG_Y CALL TABLE_MSG call delay_2_5s call LCD_Clear2 MOVLW MSG_PRES ; Point to message string CALL TABLE_MSG ; display message call delay_2_5s clrf COMND ; Cde IR=0 movlw .2 movwf sequence ;pointeur sequence clrf Pointer_Msg ;pointeur message Eprom movlw 0x31 ; TIMER1 16bits: T1CKPS1:PS0=11 predivise /8 movwf T1CON ; T1OSCEN=0 T1SYNC=0 TMR1CS=0 TMR1ON=1 ; mis … jour minute en cours MAJ_Mn_En_Cours movf hour,w andlw 0xF0 ; MSB BCD valeur ...0 … 2 movwf dummy bcf STATUS,C rrf dummy,f rrf dummy,f rrf dummy,f rrf dummy,w bank1 movwf val1 ; lsb clrf val1+1 ; msb movlw .10 movwf val2 ;lsb clrf val2+1 ;msb call mult16 ; val1= Diz heure *10 bank0 movf hour,w andlw 0x0F ; LSB BCD .. unite heure valeur 0 … 9 bank1 addwf val1,f ; ajout unite Heur … Diz Heure *10 movlw .60 ; val1=Nb Heures movwf val2 ; mul *60 clrf val2+1 call mult16 ; Nb d'heure exprimes en Minutes ; val1 contient le nb Heures*60 (en binaire) movf val1,w movwf val3 ; sauve Heures*60 movf val1+1,w movwf val3+1 bank0 movf minute,w ; diz de minute andlw 0xF0 movwf dummy bcf STATUS,C rrf dummy,f rrf dummy,f rrf dummy,f rrf dummy,w bank1 movwf val1 clrf val1+1 movlw .10 movwf val2 clrf val2+1 call mult16 ;diz de minutes *10 bank0 movf minute,w andlw 0x0F bank1 movwf val2 clrf val2+1 call add16 ; Diz de Mn + Unite de Mn ; val1 contient le Nb de Minutes en binaire movf val3,w ; recupere Nb heures*60 movwf val2 movf val3+1,w movwf val2+1 call add16 ; rejoute le Nb de Mn movf val1,w movwf Mn_En_Cours ; Numero de minute en cours movf val1+1,w movwf Mn_En_Cours+1 ; evolue de 0000 … 1439 bank0 clrf INTCON bcf INTCON,INT0IE ; Interdit interrupt RB0 bcf INTCON,TMR0IE ; interdit interrpt Timer0 bsf INTCON,PEIE ; autorise Interupt peripherie clrf PIR1 bank1 clrf PIE2 clrf PIE1 bsf PIE1,TMR1IE ; TMR1IE=1 overflow TMR1 bit interrupt enable bank0 ;********************************************************* bcf PCLATH,4 ; taille < 0FFF Main_Boucle bsf INTCON,GIE ; autorise IT generale (pour timer1) call Read_Clock call LCD_Line1 call aff_Heure bcf INTCON,GIE bsf PCLATH,3 ; acces progr en page 1 ( adresse > 7FF) call Is_itJN ; test si Minuit et JOUR ou NUIT bcf PCLATH,3 ; acces page 0 adresse <= 7FF bsf INTCON,GIE bank0 btfsc ELLIGIBLE ; eligibilite Mesures si =1 , saute si= 0 goto Traite_Mesures_Regul ; si oui strappe attente lecture IR Lect_Rb0 call Read_IR movlw 0xFF andwf COMND,W btfsc STATUS,Z goto Main_Boucle ; pas de cde IR recue dans COMNDCOMND ;---------------------- ; traite commande IR RC5 ;--------------------- ; si on est deja dans le menu gestion consignes, ; on teste uniquement les cde UP & DOWN movlw 4 ; affiche message 5 consignes Tamb ? xorwf Pointer_Msg,w btfsc STATUS,Z goto Ok2UpDown movlw 5 ; affiche message 6 consignes Tacc ? xorwf Pointer_Msg,w btfsc STATUS,Z goto Ok2UpDown goto NotUpDown Ok2UpDown movlw UP_ ; 28= up xorwf COMND,w btfsc STATUS,Z goto UpConsigne movlw DOWN_ ; 29= down xorwf COMND,w btfsc STATUS,Z goto DownConsigne ;si on est dans les autres cas, deplacement dans le menu ; via fleches Gauche & Droite NotUpDown movlw RIGHT_ ; 43= 0x2B droite xorwf COMND,w btfsc STATUS,Z goto aff_Seq_D movlw LEFT_ ;44= 0x2C gauche xorwf COMND,w btfsc STATUS,Z goto aff_Seq_G ; si on arrive ici => pas de changement de Menu, ; on reste sur celui en cours et on annule toute Traite_Mesures_Regul call MesTemper ; si=1 => mesures clrf COMND goto aff_S0 ;------------------------------------------------- ; sequencement choix affichage (evolue de 0 … 7) ; via touches < > telecde ;------------------------------------------------- aff_Seq_G movf sequence,w addlw -1 ; W-1 = negatif ? btfss STATUS,C goto aff_S0 decf sequence,f goto aff_S0 aff_Seq_D movf sequence,w sublw .8 ;8-w positif ? btfss STATUS,C goto aff_S0 incf sequence,f aff_S0 bank0 movf sequence,W ; sequence varie de 0 a 8 andlw 0x0F movwf sequence movlw .0 xorwf sequence,w btfsc STATUS,Z goto aff_Pres movlw .1 xorwf sequence,w btfsc STATUS,Z goto aff_ACCU movlw .2 xorwf sequence,w btfsc STATUS,Z goto aff_TA movlw .3 xorwf sequence,w btfsc STATUS,Z goto aff_TE movlw .4 xorwf sequence,w btfsc STATUS,Z goto aff_TT movlw .5 ; cons Tamb xorwf sequence,w btfsc STATUS,Z goto aff_ConsX movlw .6 ; cons Taccu xorwf sequence,w btfsc STATUS,Z goto aff_ConsX movlw .7 ; cons Taccu adaptee xorwf sequence,w btfsc STATUS,Z goto Aff_ConsTAccuAdapt movlw .8 xorwf sequence,w btfsc STATUS,Z goto aff_MAJRTC LostInSpace bank0 clrf COMND clrf sequence bcf ELLIGIBLE goto Main_Boucle ; was Lect_Rb0 ;-------------------------------- aff_Pres nop call LCD_Clear2 MOVLW MSG_PRES ; Point to message string CALL TABLE_MSG ; display message goto aff_fin ;--------------------------------- aff_ACCU call LCD_Clear2 clrf Pointer_Msg ;message #0 Call AffNumMsg16car_Eeprom clrf Special_MAE MOVLW LINE2 + 8 ;Position 8 CALL LCD_Cde ;Set cursor bank1 movf TN_Accu,W ;Temp Acccu movwf val1 movf TN_Accu+1,W movwf val1+1 call bcd_temp_r goto aff_fin ;---------------------- aff_TA bank0 call LCD_Clear2 movlw 1 ;;message #1 movwf Pointer_Msg Call AffNumMsg16car_Eeprom movlw 0x01 movwf Special_MAE MOVLW LINE2 + 8 ;Position 8 CALL LCD_Cde ;Set cursor bank1 movf TN_Amb,W ;Temp Ambiante Now movwf val1 movf TN_Amb+1,W movwf val1+1 call bcd_temp_r bank0 btfss Drapeaux,1 goto aff_fin ;---------------------------------------- ;filtrage arithmetique termine ? aff_TAF bank0 MOVLW LINE2 + 6 ; Position CALL LCD_Cde ; Set cursor movlw 'F' call LCD_Putchar MOVLW LINE2 + 8 ; Position CALL LCD_Cde bsf Drapeaux,3 bank1 movf TF_Amb,W ;Temp Ambiante Filtree movwf val1 movf TF_Amb+1,W movwf val1+1 call bcd_temp_r bank0 bcf Drapeaux,1 bcf Drapeaux,3 goto aff_fin ;---------------------------------------- aff_TE call LCD_Clear2 movlw 2 movwf Pointer_Msg Call AffNumMsg16car_Eeprom call LCD_Home movlw 0x01 ; drapeau pour affichage negatif movwf Special_MAE MOVLW LINE2 + 8 CALL LCD_Cde bank1 movf TN_Ext,W ;Temp exter Now movwf val1 movf TN_Ext+1,W movwf val1+1 ; movlw LOW .400 ; movwf val2 ; lsb ; movlw HIGH .400 ; movwf val2+1 ; msb ; call sub16 ; applique offset de -40.0øC btfss val1+1,7 goto UpperZero comf val1+1,f comf val1,f incf val1,f ; complement a 2 bank0 movlw 0x03 movwf Special_MAE UpperZero call bcd_temp_r bank0 btfss Drapeaux,2 goto aff_fin ; ;filtrage termine ? aff_TEF bank0 movlw 0x01 movwf Special_MAE MOVLW LINE2 + 6 ; Position 6 CALL LCD_Cde ; Set cursor movlw 'F' call LCD_Putchar MOVLW LINE2 + 8 ; Position 9 CALL LCD_Cde bsf Drapeaux,3 bank1 movf TF_Ext,W ;Temp Exter Filtree movwf val1 movf TF_Ext+1,W movwf val1+1 ; movlw LOW .4000 ; 0xA0 ; movwf val2 ; movlw HIGH .4000 ; 0x0F ; movwf val2+1 ; call sub16 ; applique offset de -40.00 btfss val1+1,7 goto UpperZeroF comf val1+1,f comf val1,f incf val1,f ; complement a 2 bank0 movlw 0x03 movwf Special_MAE UpperZeroF call bcd_temp_r bank0 bcf Drapeaux,2 bcf Drapeaux,3 goto aff_fin aff_TT call LCD_Clear2 movlw 3 movwf Pointer_Msg Call AffNumMsg16car_Eeprom MOVLW LINE2 + 6 Call LCD_Cde btfss Mode_NUIT ; affiche status JOUR/NUIT goto aff_Jour movlw 'N' ; 1=Mode NUIT call LCD_Putchar goto aff_Nuit aff_Jour movlw 'J' call LCD_Putchar aff_Nuit movlw 0x04 movwf Special_MAE MOVLW LINE2 + 8 ; Position CALL LCD_Cde bank1 movf Mn_En_Cours,W movwf val1 movf Mn_En_Cours+1,W movwf val1+1 call bcd_temp_r goto aff_fin ;---------------------------------------- Aff_ConsTAccuAdapt bank0 call LCD_Clear2 movlw .7 ;message #7 movwf Pointer_Msg Call AffNumMsg16car_Eeprom clrf Special_MAE MOVLW LINE2 + 8 ;Position 8 CALL LCD_Cde ;Set cursor bank1 movf ConsTAccuAdapt,W ;Temp Acccu Adaptee movwf val1 movf ConsTAccuAdapt+1,W movwf val1+1 call bcd_temp_r goto aff_fin ;------------------------- aff_fin bank0 BCF ELLIGIBLE clrf Special_MAE clrf COMND ; pour eviter de boucler! call delay_1s goto Main_Boucle ;------------------------------------------ cr_lf ;carriage return + line feed to rs232 port movlw 0x0D ;CR call Send_Char movlw 0x0A ;LF call Send_Char return ;----------------------------------------- ; MAJ RTC ; AMJHM ; + 97531 ; - 86420 ;---------------------------------- aff_MAJRTC bcf INTCON,GIE Actu1 call LCD_Line2 movlw .6 movwf Pointer_Msg Call AffNumMsg16car_Eeprom call aff_Heure Call Read_IR movlw .1 xorwf COMND,W btfss STATUS,Z goto NOT1 bsf PCLATH,3 call inc_minute_bcd bcf PCLATH,3 goto LoopActu NOT1 movlw .0 xorwf COMND,W btfss STATUS,Z goto NOT0 bsf PCLATH,3 call dec_minute_bcd bcf PCLATH,3 goto LoopActu NOT0 movlw .3 xorwf COMND,W btfss STATUS,Z goto NOT3 bsf PCLATH,3 call inc_hour_bcd bcf PCLATH,3 goto LoopActu NOT3 movlw .2 xorwf COMND,W btfss STATUS,Z goto NOT2 bsf PCLATH,3 call dec_hour_bcd bcf PCLATH,3 goto LoopActu NOT2 movlw .5 xorwf COMND,W btfss STATUS,Z goto NOT5 bsf PCLATH,3 call inc_date_bcd bcf PCLATH,3 goto LoopActu NOT5 movlw .4 xorwf COMND,W btfss STATUS,Z goto NOT4 bsf PCLATH,3 call dec_date_bcd bcf PCLATH,3 goto LoopActu NOT4 movlw .7 xorwf COMND,W btfss STATUS,Z goto NOT7 bsf PCLATH,3 call inc_month_bcd bcf PCLATH,3 goto LoopActu NOT7 movlw .6 xorwf COMND,W btfss STATUS,Z goto NOT6 bsf PCLATH,3 call dec_month_bcd bcf PCLATH,3 goto LoopActu NOT6 movlw .9 xorwf COMND,W btfss STATUS,Z goto NOT9 bsf PCLATH,3 call inc_year_bcd bcf PCLATH,3 goto LoopActu NOT9 movlw .8 xorwf COMND,W btfss STATUS,Z goto NOT8 bsf PCLATH,3 call dec_year_bcd bcf PCLATH,3 goto LoopActu NOT8 movlw OK_ ;87 xorwf COMND,W btfss STATUS,Z goto Actu1 bank0 clrf COMND clrf sequence Bsf INTCON,GIE goto Main_Boucle ; goto MAJ_Mn_En_Cours ; @06/01/2010 LoopActu call Write_Clock call aff_Heure clrf COMND goto Actu1 ; ;-------------------- UpConsigne movlw 1 xorwf TOGGLE,w btfss STATUS,Z goto aff_ConsX movlw 5 xorwf sequence,w btfss STATUS ,Z goto UpAccu bank1 movf ConsTamb,w movwf val1 movf ConsTamb+1,w movwf val1+1 movlw .10 goto Up_it UpAccu bank1 movf ConsTACC,w movwf val1 movf ConsTACC+1,w movwf val1+1 movlw .50 Up_it movwf val2 ;lsb clrf val2+1 ;msb call add16 bank0 movlw .5 xorwf sequence,w btfss STATUS ,Z goto StoreUpAccu bank1 movf val1,w movwf ConsTamb movf val1+1,w movwf ConsTamb+1 goto Up_end StoreUpAccu bank1 movf val1,w movwf ConsTACC movf val1+1,w movwf ConsTACC+1 Up_end bank0 clrf TOGGLE goto aff_ConsX ;-------- DownConsigne movlw 1 xorwf TOGGLE,w btfss STATUS,Z goto aff_ConsX movlw .5 xorwf sequence,w btfss STATUS ,Z goto DownAccu bank1 movf ConsTamb,w movwf val1 movf ConsTamb+1,w movwf val1+1 movlw .10 ; par pas de 1,0 C goto Down_it DownAccu bank1 movf ConsTACC,w movwf val1 movf ConsTACC+1,w movwf val1+1 movlw .50 ; par pas de 5,0 C Down_it movwf val2 ; lsb clrf val2+1 ; msb call sub16 bank0 movlw .5 xorwf sequence,w btfss STATUS ,Z goto StDownAccu bank1 movf val1,w movwf ConsTamb movf val1+1,w movwf ConsTamb+1 goto Down_end StDownAccu bank1 movf val1,w movwf ConsTACC movf val1+1,w movwf ConsTACC+1 Down_end bank0 clrf TOGGLE ;------------------------------ aff_ConsX bank0 call LCD_Clear2 bcf Drapeaux,3 movlw 5 xorwf sequence,w btfss STATUS ,Z goto aff_McAccu movlw 4 ; message Nø4 goto aff_McAmb aff_McAccu movlw 5 aff_McAmb movwf Pointer_Msg Call AffNumMsg16car_Eeprom movlw 0x01 movwf Special_MAE MOVLW LINE2 + 8 ; Position 8 CALL LCD_Cde ; Set cursor movlw 5 xorwf sequence,w btfss STATUS ,Z goto aff_VcAccu bsf Drapeaux,3 ; virgule au 1/100 de degre bank1 movf ConsTamb,W movwf val1 movf ConsTamb+1,W movwf val1+1 goto aff_Vce aff_VcAccu bank0 bcf Drapeaux,3 ; virgule au 1/10 de degre bank1 movf ConsTACC,W movwf val1 movf ConsTACC+1,W movwf val1+1 aff_Vce call bcd_temp_r bank0 bcf Drapeaux,3 call delay_250ms clrf Special_MAE bcf ELLIGIBLE clrf COMND goto Main_Boucle ;---------------------- aff_Heure call LCD_Clear1 movf year,W call packBCD_to_ascii movf month,W call packBCD_to_ascii movf date,W call packBCD_to_ascii movlw ' ' call LCD_Putchar movf hour,W call packBCD_to_ascii movlw ':' ; 0x3A call LCD_Putchar movf minute,W call packBCD_to_ascii movlw ':' ;0x3A call LCD_Putchar movf second,W call packBCD_to_ascii movlw ' ' call LCD_Putchar return ;================================== ; Affiche message en zone programme ;================================== TABLE_MSG MOVWF Cpt3 ; Point to the first char. we want LOOP_WR MOVF Cpt3,w ; Renew the pointer CALL TABLE_ST ; Initiate table lookup XORLW 0 ; Is this the terminating char? BTFSC STATUS,Z GOTO END_WR call LCD_Putchar INCF Cpt3,f ; Point to the next char GOTO LOOP_WR ; Do next character END_WR RETURN ;============================== ; affiche Nø Msg en eeprom, chaque Msg fait 16 caracteres ;============================== AffNumMsg16car_Eeprom movf Pointer_Msg,w movwf Cpt2 bcf STATUS,C rlf Cpt2,f rlf Cpt2,f rlf Cpt2,f rlf Cpt2,f ; pointeur = NøMsg * 16 clrf Cpt3 affMsg_ movf Cpt3,w addwf Cpt2,w ; W contient l'adresse = pointeur de message ; special 16F88 BANKSEL EEADR ; Select Bank 2 of EEADR ; MOVF ADDR, W ; W contient deja l'adresse! MOVWF EEADR ; Data Memory Address to read BANKSEL EECON1 ; Select Bank 3 of EECON1 BCF EECON1, EEPGD; Point to Data memory BSF EECON1, RD ; EE Read BANKSEL EEDATA ; Select Bank 2 of EEDATA MOVF EEDATA, W ; W = EEDATA bank0 call LCD_Putchar incf Cpt3,f btfss Cpt3,4 ; 16em car ? goto affMsg_ return ; ;============================= Send_Char bank0 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 ;byte envoy‚ Call delay_RS return ;----------------------------------- bcdRS bank1 movwf btmp ; affichage octet --> decimal 3 digits ( de 0 a 255 )-> RS232 movlw '0' movwf bcent movwf bdix bcdRS1 movlw 100 subwf btmp,w bnc bcdRS2 movwf btmp incf bcent,f goto bcdRS1 bcdRS2 movlw 10 subwf btmp,w bnc bcdRS3 movwf btmp incf bdix,f goto bcdRS2 bcdRS3 movlw '0' addwf btmp,w movwf bun movf bcent,w call Send_Char bank1 movf bdix,w call Send_Char bank1 movf bun,w call Send_Char return ;--------------------- bcd3 bank1 movwf btmp ; affichage octet --> decimal 3 digits ( de 0 a 255 ) movlw '0' movwf bcent movwf bdix bcd31 movlw 100 subwf btmp,w bnc bcd32 movwf btmp incf bcent,f goto bcd31 bcd32 movlw 10 subwf btmp,w bnc bcd33 movwf btmp incf bdix,f goto bcd32 bcd33 movlw '0' addwf btmp,w movwf bun movf bcent,w call LCD_Putchar bank1 movf bdix,w call LCD_Putchar bank1 movf bun,w call LCD_Putchar bank0 return ;=========================== ;#include "bcd_temp_2009.inc" ; use now val1=LSB then val+1=MSB on 16 bits values as MICROCHIP do it for registers ; 27 dec 2006 correction mesure Text Negative et bug test drapeau Special_MAE=3 ; conv mot 16bits -->mv ou øC ; gere l'affichage LCD BCD 5 digits -> vers Ascii suivant l'etat de ; Drapeaux,7 pour valeur negative ; Drapeaux,3 pour gerer la virgule 1/100 de degres ; Special_MAE,2 affiche en mV ou Degre ; 08 nov 2003 OK pour 628REGUL.pjt ; 5 mai 03 .. test sans multiplexeur avec seul T°amb connectee ; indique temperature negative (car prg poole T° exterieur 20° =2930mV 0mV= -x°C ) ; conv mot 16bits -->mv ou øC bcd_temp_r bank1 movf val1,W movwf valx movf val1+1,W movwf valx+1 swapf val1+1,W iorlw 0xf0 movwf mille addwf mille,F addlw 0xE2 ; 226 movwf cent addlw 0x32 ;50 movwf un movf valx+1,W andlw 0x0F addwf cent,F addwf cent,F addwf un,F addlw 0xE9 ;233 movwf dix addwf dix,F addwf dix,F swapf valx,W andlw 0x0F addwf dix,F addwf un,F rlf dix,F rlf un,F comf un,F rlf un,F movf valx,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 bank0 movlw '+' btfss Special_MAE,1 ; si Special_MAE=3 on traite le cas - goto Lb41 btfss Special_MAE,0 ; si Special_MAE=3 on traite le cas - goto Lb41 movlw '-' Lb41 call LCD_Putchar ; bank1 ; movf dixmil,W ; bank0 ; btfsc STATUS,Z ; goto Lb42 ; addlw '0' ; goto Lb43 Lb42 bank1 movf mille,w bank0 btfsc STATUS,Z goto Lb44 addlw '0' goto Lb45 Lb44 movlw ' ' Lb45 call LCD_Putchar bank1 movf cent,w bank0 addlw '0' call LCD_Putchar movlw ',' btfss Drapeaux,3 goto Lb51 btfss Special_MAE,2 ; bit 2 = 4 => affichage en mV call LCD_Putchar Lb51 bank1 movf dix,w bank0 addlw '0' call LCD_Putchar movlw ',' btfsc Drapeaux,3 goto Lb7 btfss Special_MAE,2 ; bit 2 = 4 => affichage en mV call LCD_Putchar Lb7 bank1 movf un,W bank0 addlw '0' call LCD_Putchar btfsc Special_MAE,2 ; bit 2 = 4 si TestJN goto En_mV movlw 'd' call LCD_Putchar movlw 'C' call LCD_Putchar return En_mV ; movlw 'm' movlw ' ' call LCD_Putchar ; movlw 'V' movlw ' ' call LCD_Putchar return ;*************************************************** ;#include "IR_RC5_2009.inc" ; rajout timeouts timer0 ;READ reads the incoming data stream and saves it into a 6-byte buffer ;RESTART_TMR0 Restart the timer with an 888 uSec delay ;PARSE Analyse : TOGGLE =repet touche, COMND= code touche ;DECODE Decodage trame IR RC5 PARSE_FLAGS<0> = valide,donnee 0 ou 1 ;Remember again that the IR pickup output is active low ;codage PHILIPS en retour: Carry =1 si ERREUR! sinon C=0 ;===================================================== Read_IR bank0 Rb0_One btfsc ELLIGIBLE ; eligibilite Mesures ,si oui on sort goto TestIR_end BTFSS IR_Sensor ; IR_Sensor TSOP 1738 (38Khz) sur RB0 GOTO Rb0_One Test_Rb0 btfsc ELLIGIBLE ; eligibilite Mesures ? goto TestIR_end ; si oui on sort BTFSC IR_Sensor ; IR_Sensor TSOP 1738 (38Khz) sur RB0 GOTO Test_Rb0 ; High is idle, low is active ; Traitement reception I.R suite interrupt sur Rb0 MOVLW D'147' ; Found data, load timer0 for 444 uS ; 444-11 o = 433 cycles 255-147=108 counts x 4 prescaler MOVWF TMR0 ; ce qui fait une attente de 1/4 bit BCF INTCON,T0IF ; Raz Timer0 bit overflow BCF STATUS,C ; C=0 CALL READ ; Read the data stream BTFSC STATUS,C ; si C=1 => erreur data GOTO Test_Rb0 ; recommence si erreur CALL PARSE ; Decode les donnees BTFSC STATUS,C ; C=1 => erreur GOTO Test_Rb0 ; recommence si erreur return TestIR_end return ;------------------------------------------------------- READ bank0 ; First, zero all storage MOVLW SERIAL_BUF ; Start of RAM buffer MOVWF FSR ; Load indirect register RD_LOOP1 CLRF INDF ; Zero out the buffer INCF FSR,f ; Increment to next byte MOVLW SERIAL_BUF+6 ; Test for 6 bytes done XORWF FSR,w BTFSS STATUS,Z GOTO RD_LOOP1 ; Loop till done CLRF BIT_COUNT CLRF BYTE_COUNT MOVLW SERIAL_BUF ; Reset the indirect pointer back MOVWF FSR ; to the start of the buffer space RD_LOOP2 BTFSS INTCON, T0IF ; Wait till timer goes 444 Usec GOTO RD_LOOP2 CALL RESTART_TMR0 ; Reset timer for 888 uSec BTFSC IR_Sensor ; Check RAx IR signal (i.e. debounce) GOTO BAD_DATA ; If it's high (logic 0), bail out RD_LOOP3 BTFSS INTCON, T0IF ; Wait till timer goes 888 uSec GOTO RD_LOOP3 CALL RESTART_TMR0 ; Restart 888 uSec timer INCF BIT_COUNT,f MOVLW D'43' ; See if we've done all 42 bits XORWF BIT_COUNT,w BTFSC STATUS,Z GOTO RD_FINISH ; Trame complete BSF STATUS,C ; Preset the carry bit BTFSC IR_Sensor ; Test IR input signal BCF STATUS,C ; Input bit is high (logic 0) so change carry ; Now the input bit is in the carry flag RLF INDF,f ; Rotate it into the buffer INCF BYTE_COUNT,f ; BTFSC BYTE_COUNT,3 ; See if all 8 bits are filled CALL NEXT_BYTE ; Yes, use next buffer byte GOTO RD_LOOP3 ; Loop back & do the rest of the bits RD_FINISH BCF STATUS,C ; RLF INDF,f ; The last buffer byte has only 2 RLF INDF,f ; bits loaded. RLF INDF,f ; So we shift them up to the top RLF INDF,f ; the hard way. RLF INDF,f RLF INDF,f BCF STATUS,C ; Clear carry to show a successful capture RETURN NEXT_BYTE INCF FSR,f ;Increment the FSR and clear the counter CLRF BYTE_COUNT RETURN ;------------------------------------------ ; Restart the timer with an 888 uSec delay ; and refresh the overflow flag. ; MPLAB stopwatch says there is a loop overhead of ; 14 cycles, thus we need it to run for 888-14=874 uSec ;------------------------------------------ RESTART_TMR0 bank0 BCF INTCON, T0IF ; Clear the overflow flag MOVLW D'37' ; 255 - 37 = 218 x 4 = 876 uSec MOVWF TMR0 RETURN ;------------------------------------------------ ; decodes the saved datastream into the various ; RC5 words and flags. ;------------------------------------------------ PARSE MOVLW SERIAL_BUF ; Put buffer start address into MOVWF FSR ; the FSR CLRF TEMP ; Initialize variables CLRF BYTE_COUNT ; CLRF MZ_FLAG ; CLRF FIELD ; CLRF TOGGLE ; CLRF SYSTEM ; CLRF COMND ; CLRF MZDATA ; ; First one is the field bit RLF INDF,f ; First bit into carry RLF TEMP,f ; Put it into TEMP for decoding RLF INDF,f ; Second bit RLF TEMP,f ; ditto INCF BYTE_COUNT,f ; Start keeping track of INDF bit position CALL DECODE BTFSC PARSE_FLAGS,2 ; Illegal pattern found GOTO BAD_DATA ; Must have found a good bit RRF PARSE_FLAGS,f ; Put field bit into Carry RLF FIELD,f ; Move it into FIELD CLRF TEMP ; Next one is the toggle bit RLF INDF,f ; First bit into carry RLF TEMP,f ; Put it into TEMP for decoding RLF INDF,f ; Second bit RLF TEMP,f ; ditto INCF BYTE_COUNT,f ; keep track of INDF bit position CALL DECODE BTFSC PARSE_FLAGS,2 ; Illegal pattern found GOTO BAD_DATA ; Must have found a good bit RRF PARSE_FLAGS,f ; Put toggle bit into Carry RLF TOGGLE,f ; Move it into TOGGLE ; MOVLW 0x05 ; Next one is the system byte, 5 bits MOVWF count0 SYS_1 CLRF TEMP RLF INDF,f ; First bit into carry RLF TEMP,f ; Put it into TEMP for decoding RLF INDF,f ; Second bit RLF TEMP,f ; ditto INCF BYTE_COUNT,f ; keep track of INDF bit position BTFSC BYTE_COUNT,2 ; (there are two rotates per count) CALL NEXT_BYTE ; Go to next buffer byte when count=4 CALL DECODE BTFSC PARSE_FLAGS,2 ; Illegal pattern found GOTO BAD_DATA ; Must have found a good bit RRF PARSE_FLAGS,f ; Put bit into Carry RLF SYSTEM,f ; Move it into SYSTEM DECFSZ count0,f ; Have we done all 5 bits? GOTO SYS_1 ; No, not yet ; Here we test for the two spaces, present in the extended data format. ; If they appear, we set a flag and skip over them to the command word. MOVLW B'11000000' ; Mask for 2nd buffer byte ANDWF SERIAL_2,w ; Are the 2 top bits zero? BTFSS STATUS,Z ; GOTO PHILIPS ; No space found CALL NEXT_BYTE ; Skip over first space RLF INDF,f ; Skip over second space RLF INDF,f INCF BYTE_COUNT,f MOVLW 0x01 MOVWF MZ_FLAG ; Set the flag ; PHILIPS MOVLW 0x06 ; Next one is the command byte, 6 bits MOVWF count0 CMD_1 CLRF TEMP RLF INDF,f ; First bit into carry RLF TEMP,f ; Put it into TEMP for decoding RLF INDF,f ; Second bit RLF TEMP,f ; ditto INCF BYTE_COUNT,f ; keep track of INDF bit position BTFSC BYTE_COUNT,2 ; (there are two rotates per count) CALL NEXT_BYTE ; Go to next buffer byte when count=4 CALL DECODE BTFSC PARSE_FLAGS,2 ; Illegal pattern found GOTO BAD_DATA ; Must have found a good bit RRF PARSE_FLAGS,f ; Put bit into Carry RLF COMND,f ; Move it into COMND DECFSZ count0,f ; Have we done all 6 bits? GOTO CMD_1 ; No, not yet BTFSS FIELD,0 ; If field bit=0 then comnd=comnd+64 BSF COMND,6 BTFSC MZ_FLAG,0 ; Test for extra data word GOTO MDAT_1 ; Parse extra data word RETURN ; Finish here if Philips format MDAT_1 MOVLW 0x06 ; Next one is the data byte, 6 bits MOVWF count0 MDAT_2 CLRF TEMP RLF INDF,f ; First bit into carry RLF TEMP,f ; Put it into TEMP for decoding RLF INDF,f ; Second bit RLF TEMP,f ; ditto INCF BYTE_COUNT,f ; keep track of INDF bit position BTFSC BYTE_COUNT,2 ; (there are two rotates per count) CALL NEXT_BYTE ; Go to next buffer byte when count=4 CALL DECODE BTFSC PARSE_FLAGS,2 ; Illegal pattern found GOTO BAD_DATA ; Must have found a good bit RRF PARSE_FLAGS,f ; Put bit into Carry RLF MZDATA,f ; Move it into MZDATA DECFSZ count0,f ; Have we done all 6 bits? GOTO MDAT_2 ; No, not yet PARSE_DONE RETURN ;------------------------------------------------------- ; DECODE .. enter with two-bit data in TEMP ; return with result code in PARSE_FLAGS, thus ; PARSE_FLAGS<0> = valid data, one or zero ; PARSE_FLAGS<1> = unused ; PARSE_FLAGS<2> = set if data is invalid ;------------------------------------------------------- DECODE CLRF PARSE_FLAGS MOVLW ONE XORWF TEMP,w ; Compare to bit pattern '01' BZ ONE_EXIT MOVLW ZERO XORWF TEMP,w ; compare to bit pattern '10' BZ ZERO_EXIT BAD_EXIT BSF PARSE_FLAGS,2 ; bit pattern neither 01 nor 10 RETURN ; ONE_EXIT BSF PARSE_FLAGS,0 ; Return with valid data in LSB ZERO_EXIT RETURN ; of the PARSE_FLAGS variable ; BAD_DATA .. Exit if Read or Parse doesn't like what it finds. ; The Carry flag is set as an error message. BAD_DATA BSF STATUS,C ; Set the carry flag to show error RETURN ;******************************************************************** ;#include "RTC1302.inc" ; last rev 10/10/03 ;Write_Clock specific RTC ds1302 subroutines per Mark K Sullivan 25.7.96 ;packBCD_to_ascii takes packed bcd byte in w -> ascii ->display ;Read_Clock ;wbyte ;rbyte ;================= Write_Clock bank0 bcf DS1302_SCLK ;negate clock line nop nop nop nop nop nop bcf DS1302_DATA nop nop bsf DS1302_RST ;negate RST DS1302_WR ; macro DS1302 data to write movlw 0x8E ;write control register call wbyte movlw 0x00 ;turn off Write Protect in rtc call wbyte movlw 7 ;nb de registres … parcourir movwf dummy3 movlw 0x80 ;rtc register address for `second' movwf count4 movlw second ; fsr pointe sur zone stockage donn‚es Clock movwf FSR wc1 bcf DS1302_RST ;assert RST nop nop bcf DS1302_SCLK ;negate clock nop 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=sens R/W incf count4,F decfsz dummy3,F ;decrement nb de registre … explorer goto wc1 bcf DS1302_RST ;assert RST clrf second ;@5/1/10 return ;------------------------------------------ ;takes packed bcd byte in w -> ascii ->display packBCD_to_ascii 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 LCD_Putchar ;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 LCD_Putchar ;char out LO nibble 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 nop bcf DS1302_RST ; bon depart avec RST=0 DS1302_WR ; macro DS1302 data to write nop nop nop nop bcf DS1302_DATA ;negate I/O nop bsf DS1302_RST ;negate RST movlw 0xBF ; burst read mode for clock registers call wbyte DS1302_RD ; DS1302 data to read 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 nop btfss Rdecal2,0 bcf DS1302_DATA nop btfsc Rdecal2,0 bsf DS1302_DATA nop nop nop bsf DS1302_SCLK nop 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 nop bsf DS1302_SCLK nop nop decfsz dummy1,F goto rbit incf FSR,F return ;******************************************************** ;#include "lcd4c.inc" ; rev 26 janv 2003 ; LCD subroutines, mode 4 bits 6 fils maxi = 4 datas portB + 2 cdes port A ; fichiers lies: delais.inc , lcd4c.h pour definitions des variables et EQUivalence ;routines en mode 4 Bits avec afficheur 2*16 a base de HD77480 ; 08 nov 2003 OK pour 628REGUL.pjt ; rev 26 janv 2003 lcd4c.inc ; fichiers lies: delais_b.inc lcd4c.h ; routines en mode 4 Bits avec afficheur 2*16 a base de HD77480 ; LCD_Init : initialisation de l'afficheur ; LCD_Putchar : envoi un caractere ( contenu dans w ) sur l'afficheur ; LCD_Cde : envoi une commande ( contenue dans w) a l'afficheur ; LCD_Cls : efface l'afficheur ; LCD_Clear1 : efface la premiere ligne de l'afficheur ; LCD_Clear2 : efface la deuxieme ligne de l'afficheur ; LCD_Home : renvoi le curseur en haut a gauche ; LCD_Line1 : renvoi le curseur au debut de la ligne 1 ; LCD_Line2 : renvoi le curseur au debut de la ligne 2 ; pour positionner le curseur sur la ligne 1 : movlw 0x80+offset call LCD_Cde ; pour positionner le curseur sur la ligne 2 : movlw 0xC0+offset call LCD_Cde ; ; variables a definir dans le programme principal: ; LCDtmp,LCDTmp1 ; LCD ; constantes a definir dans le programme principal: ; LCD_DATA EQU PORTB ; LCD: Port ou est branche le bus de donnee ( bits 4 a 7 ) ; LCD_DATA_TRIS EQU TRISB ; LCD: Port ou est branche le bus de donnee ( bits 4 a 7 ) ; LCD_CTRL EQU PORTA ; LCD: Port ou est branche le bus de commande ; LCD_CTRL_TRIS EQU TRISA ; LCD: Port ou est branche le bus de commande ; LCD_E EQU 1 ; LCD: Ligne de commande de controle de l'afficheur ;not used LCD_RW EQU 1 ; LCD: Ligne de Lecture/Ecriture de l'afficheur ; LCD_RS EQU 0 ; LCD: Ligne de selection de l'afficheur ; IMPORTANT : ce programme est optimise --> ne pas changer l'ordre des commandes ;---------------------- 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 LINE1 ; 0x80 call LCD_Cde call delay_2_5ms LCDc111 movlw ' ' call LCD_Putchar decfsz LCDtmp1,f goto LCDc111 LCD_Line1 movlw LINE1 call LCD_Cde goto delay_2_5ms ;-------------- LCD_Clear2 ; effacage de la deuxieme ligne movlw D'16' movwf LCDtmp1 movlw LINE2 ; 0xC0 call LCD_Cde call delay_2_5ms LCDcl21 movlw ' ' call LCD_Putchar decfsz LCDtmp1,f goto LCDcl21 LCD_Line2 movlw LINE2 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_1ms 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 nop bcf LCD_CTRL, LCD_RS nop ; 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 0x008 ; display off call LCD_Cde movlw 0x00C ; display on (0x00C sans curseur, 0x00E avec , 0x00F clign. ) call LCD_Cde movlw 0x006 LCD_Cde movwf LCDtmp call delay_100ms ; tempo 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 ;================================================= ; Mestemp_2009.inc ;================================================= ; rev 2009 ; 26 dec 06 correction bug temp exterieure negative! ; Inversion sens cde relais car usage transistor EC pour interface le relais ; PB hardware avec RA4 qui a une "sortance faible", la charge =Rb 2,7K sur transistor ; est trop faible, le niveau RA4 NE PEUT PAS PILOTER LE TRANSISTOR ; essai avec RB=4.7k mais 2N1613 non sature a fond => a modifier ; transistor a fort Beta et R attaque 10Kohms 2N2222 ; 13 avril 03 version mestemp5.inc ; remplacement sub16 par comp_signed16 pour activation relais ; 07 avril 2003 mestemp4.inc ; SP Selection de la voie, Acquisition via ADC MAx187 ; Mise a l'echelle,Stockage valeur, ; filtrage arithmetique sur 10 mesures ,prepare l'affichage ulterieur ; acquisition toutes les 3 secondes => mesure filtre sur 30 secondes ; MesTemper ;MesAccu ;---------------------------------------------------------------- ; PT100 50mV … 1650mV delta de 1600mV =>affiche 000.0 … 400.0øC ; Acquisition Pt100 via pont R -> AD820 Ampli Ana ; zero=100ohms= 50mV ; echelle=250 ohms=400øC -> 1650mV ; soit delta 1600mv *10 puis /4 => 0,0 … 400,0øC ;---------------------------------------------------------------- bank0 clrf Special_MAE bcf PORTB,4 nop bcf PORTB,5 nop call MemoMesure ;mise … l'echelle mesure Pt100 bank1 movlw .50 ; lo=50 decalage de zero movwf val2 ; lsb clrf val2+1 ; msb call sub16 movlw .10 movwf val2 ;val2 16 bits =10 clrf val2+1 call mult16 ; val1= val1*val2= val1*10 call Divise4 ; val1=val1 /4 ifdef DEBUGGING movlw LOW .2500 movwf val1 movlw HIGH .2500 movwf val1+1 endif movf val1,W movwf TN_Accu movf val1+1,W movwf TN_Accu+1 ;----------------- MesAmb bank0 movlw 0x01 movwf Special_MAE bsf PORTB,4 ; aiguillage mesure nop bcf PORTB,5 nop call MemoMesure ; bank1 ifdef DEBUGGING movlw LOW .160 ; 16,0øC movwf val1 movlw HIGH .160 movwf val1+1 endif movf val1,W movwf TN_Amb movf val1+1,W movwf TN_Amb+1 ; Sommation pour filtage arithmetique movf STF_Amb,W movwf val2 movf STF_Amb+1,W movwf val2+1 call add16 ; val1 contient la Temp Amb brute movf val1,W movwf STF_Amb movf val1+1,W movwf STF_Amb+1 ;------------------------------- MesExter ; avec conversion 12bits 1mV => 0,1øC bank0 movlw 0x01 ;@ modif 27/12/06 movwf Special_MAE bcf PORTB,4 nop bsf PORTB,5 nop call MemoMesure ; mesure en øK dans val1 bank1 ifdef DEBUGGING movlw LOW .2830 ; pour +10øC en øKelvin movwf val1 movlw HIGH .2830 movwf val1+1 endif ;mise a l'echelle mesure Ext base ZERO KELVIN 273 movlw LOW .2730 ; was 2330mV pour 2730-400 => -40°C movwf val2 ; movlw HIGH .2730 movwf val2+1 ; call sub16 ; val1=val1-val2 movf val1,W ; 2830-2730=100 => 10,0øC movwf TN_Ext ; mesure en øC movf val1+1,W movwf TN_Ext+1 ;Filtrage Arithmetique sur 10 valeurs (was 60 version 2006) movf STF_Ext,W ; val1 contient la Temp Exter. brute movwf val2 movf STF_Ext+1,W movwf val2+1 call add16 movf val1,W movwf STF_Ext movf val1+1,W movwf STF_Ext+1 incf SommeTxX,f movlw .10 xorwf SommeTxX,w btfss STATUS,Z goto Not_Enough ;Filtrage Arithmetique Atteint pour T Ext movf val1,W ; val1 contient encore la somme ! movwf TF_Ext ; 10,00øC movf val1+1,W movwf TF_Ext+1 clrf STF_Ext clrf STF_Ext+1 ;Filtrage Arithmetique Atteint aussi pour Tamb apres 10 passages! movf STF_Amb,w movwf TF_Amb movf STF_Amb+1,W movwf TF_Amb+1 clrf STF_Amb clrf STF_Amb+1 clrf SommeTxX bank0 bsf Drapeaux,2 bsf Drapeaux,1 ;----- regulation Tamb -------- ; avec mesure filtree au 1/100e de øC ; et consigne au 1/100em de degre ; BCF INTCON,GIE movlw .20 ; 0,20øC btfss Relais_Ventilo ; deja coll‚ movlw -.20 ; 0,20øC bank1 movwf val1 clrf val1+1 movf ConsTamb,w movwf val2 movf ConsTamb+1,w movwf val2+1 call add16 movf TF_Amb ,W ; val1 contient la mesure filtree movwf val1 ; soit 1600 pour 16,00øC movf TF_Amb+1,W movwf val1+1 call comp_signed16 ;@13/04/03 btfss STATUS,C ;c=0 si mesure < consigne goto VentiloUp bank0 BCF Relais_Ventilo ;inactive Relais Ventilos call delay_100ms goto VentiloDown VentiloUp bank0 BSF Relais_Ventilo ; active call delay_100ms VentiloDown nop ;---------------------------------------------------------- ;--- regulation Tø ACCU ----- ; basee sur mesures filtrees : Tøamb et mesure filtree TøExt ;----------------------------------------------------------- ; adaptation Consigne ACCU ; Demande fonction de la temperature Exterieure (en 1/100em de øC) ; (15.00øc - Temp Exter)*2 donc => delta de 20.0øC sur consigne Accu bank1 movf TF_Ext,w ;ex TøExt= 10,00øC soit 1000 = 0x03E8 movwf val2 movf TF_Ext+1,w movwf val2+1 movlw LOW .1500 ; valeur arbitraire de basculement movwf val1 ; autour de la valeur Tø Exterieure movlw HIGH .1500 ; 15øC => 15,00 1500 movwf val1+1 ; call sub16 ; 1500-1000= 500 bcf STATUS,C call Mul_x_2 ; val1*2 movf val1,w ; 500 *2 -> soit + 100,0øC sur la consigne Accu movwf val3 movf val1+1,w movwf val3+1 ; demande fonction de la temperature INTERIEURE ; ( ecart M-C Temp ambiante)*4 delta de 1øC => 40.0øC ; attention Temp Accu au 1/10em de degre et non pas au 1/100e movf ConsTamb,w movwf val1 movf ConsTamb+1,w ; ex 20øC 2000 0x07D0 movwf val1+1 movf TF_Amb,w ; ex: 16øC soit 1600 soit 0x0640 movwf val2 movf TF_Amb+1,w movwf val2+1 call sub16 ; (2000-1600)= 400 , soit 40.0 øC; bcf STATUS,C call Mul_x_2 ; val1*2 400*2=800 soit 80.0øc; movf val3,w ; 100,0øC movwf val2 movf val3+1,w movwf val2+1 call add16 ; 100.0 øC+ 80.0øC ; val1= 100.0+80.0 soit 180.0øC; movf ConsTACC,W ; consigne ACCU init … 100øC au demarrage movwf val2 ; soit 1000 -> 0x03E8 movf ConsTACC+1,W movwf val2+1 ; si val1 contient [100.0 + (15.0 degC-TExt)*2*10 + (M-C) TAmb * 4*10]; call add16 movf val1,w movwf val3 ; sauve consigne adaptee movf val1+1,w movwf val3+1 ; val3 contient ; valeur consigneAccu + influence delta Tø externe + influence TøAmb ; 100 + 100 + 80 => 280,0øC movlw LOW (.4200) movwf val2 movlw HIGH (.4200) movwf val2+1 call sub16 ; < 420 ? btfss STATUS,C goto Consigne_Less_420 ; limite maxi … 420 movlw LOW (.4200) movwf val1 movlw HIGH (.4200) movwf val1+1 goto Cons_Accu_420 ; nota : test si ConsAdap < ConsAccu soit 100øC non teste Consigne_Less_420 ; @debug movf val3,W ; recupere consigne "adaptee" movwf val1 movwf ConsTAccuAdapt movf val3+1,W movwf val1+1 movwf ConsTAccuAdapt+1 Cons_Accu_420 bank0 movlw .20 btfss Relais_Accu ; relais deja colle ? movlw -.20 bank1 ; rajoute Hystereris de 2øC addwf val1,f btfss STATUS,C incf val1+1,f ;la consigne ADAPTEE + hysteresis est dans val1 ; adaptation de consigne suivant JOUR NUIT ; de jour consigne Chauffage sur le Minima de consigneTemp Accu ex: 100øC ; de NUIT consigne chauffage suivant les conditions Tø Externe et Tø ambiante bank0 BTFSC Mode_NUIT goto Consigne_de_Nuit bank1 movf ConsTACC,W ; consigne ACCU de base mini init … 100øC au demarrage movwf val1 ; soit 1000 -> 0x03E8 movf ConsTACC+1,W movwf val1+1 Consigne_de_Nuit bank1 movf TN_Accu,W ; avoir un test fiable movwf val2 ; ex:398øC 3980 soit 0F8Ch movf TN_Accu+1,W ; val1 contient la consigne ADAPTEE movwf val2+1 ; val2 contient la mesure call comp_signed16 ; ecart Mesure_consigne btfss STATUS,C ; c=0 si val2>val1 c=1 si val1>val2 goto Chauffage_OFF Chauffage_ON bank0 BSF Relais_Accu ; Active Relais chauffage ACCU goto TAccuTraitee Chauffage_OFF bank0 BCF Relais_Accu ; desactive Relais chauffage ACCU TAccuTraitee NOP Not_Enough ; filtrages insuffisant bank0 bcf ELLIGIBLE ;FIN de Mesures donc RAZ bsf INTCON,GIE ; autorise IT return ;-------------------------------- MemoMesure bank0 ifdef DEBUGGING movlw LOW .1200 movwf Lo_Temp movlw HIGH .1200 movwf Hi_Temp else Call Max187 endif movf Hi_Temp,W bank1 movwf val1+1 bank0 movf Lo_Temp,W bank1 movwf val1 bank0 return ;---------------------------------- Max187 bcf INTCON,GIE bsf Max_CS ; CS=1 call delay_2_5ms ; delai de stabilisation aiguillage voie bcf Max_CLOCK clrf Lo_Temp clrf Hi_Temp bcf Max_CS ; CS=0 nop Max0 btfss Max_DATA ; test fin de conversion goto Max0 nop call M_clk ;13em clock ;-- MSB movlw 4 ; 4 clock (bits) movwf Cpt2 Max1 rlf Hi_Temp,F btfss Max_DATA bcf Hi_Temp,0 btfsc Max_DATA bsf Hi_Temp,0 call M_clk Decfsz Cpt2,F goto Max1 ;-- LSB movlw 8 ;8 clocks (bits) movwf Cpt2 Max2 rlf Lo_Temp,F btfss Max_DATA bcf Lo_Temp,0 btfsc Max_DATA bsf Lo_Temp,0 call M_clk Decfsz Cpt2,F goto Max2 bsf Max_CS BSF INTCON,GIE return M_clk nop bsf Max_CLOCK nop nop bcf Max_CLOCK nop return ; ;============================ ;#include "Math16F_2009.inc " ; inversion MSB et LSB dec 2009 ; val1= LSB val1+1 = MSB idem que pour l'ordre des registre Microchip ; last update 7 avril 03 ; ** Attention ** toutes les variables sont en bank1 avec PIC16F628* ; val1 MSB ; val1+1 LSB ;Divise4 mot val1= mot val1 / 4 ;Divise2 division par 2 mot de 16 bits val1=val1 / 2 ;add16 val1 = val1 + val2 ;sub16 val1 = val1 - val2 ;mult16 val1 = val1 * val2 ;div16 val1 = val1 / val2 (+ reste ) ;== math16_1.inc === ; rev 14 avril remplacement sub16 par comp_signed16 ; rev 11 avril 2003 PB avec new sp Sub16 ; last update 7 avril 03 ; ** Attention ** ; toutes les variables sont en bank1 avec PIC16F628 Divise4 bank1 ; mot val1= mot val1/4 bcf STATUS,C ; carry=0 rrf val1+1,F rrf val1,F ; division par 2 mot de 16bits Divise2 bank1 bcf STATUS,C rrf val1+1,F rrf val1,F ; division par 2 mot de 16bits return ;----------------------- add16 bank1 movf val2+1,w ; addition 16 bits addwf val1+1,f ; val1 = val1 + val2 movf val2,w addwf val1,f btfsc STATUS, C incf val1+1,f return ;----------------------- ;16 bit subtraction with borrow Rudy Wieser sub16 bank1 movf val2,W ; source lsb subwf val1,F ; dest lsb movf val2+1,W ; msb btfss STATUS,C incfsz val2+1,W ;msb subwf val1+1,F ;dest = dest - source, WITH VALID CARRY return ;---------------- mult16 bank1 clrf result ; multiplication 16 bits clrf result+1 ; val1 = val1 * val2 movlw 16 movwf Mcount mult161 rrf val1+1,F rrf val1,F btfss STATUS,C goto mult162 movf val2+1,W addwf result+1,F movf val2,W addwf result,F btfsc STATUS,C incf result+1,F mult162 bcf STATUS,C rlf val2,F rlf val2+1,F decfsz Mcount,F goto mult161 movf result,W movwf val1 movf result+1,W movwf val1+1 return ;---------------------- div16 bank1 clrf reste ; division 16 bits clrf reste+1 ; val1 = val1 / val2 ( reste ) movlw 16 movwf Mcount div161 rlf val1,f rlf val1+1,f rlf reste,f rlf reste+1,f movf val2+1,w subwf reste+1,W btfss STATUS,Z goto div162 movf val2,W subwf reste,W div162 btfss STATUS,C goto div163 movf val2,W subwf reste,f movf val2+1,W btfss STATUS,C incfsz val2+1,f subwf reste+1,f div163 rlf result,f rlf result+1,f DECFSZ Mcount,f goto div161 fin16 movf result+1,w movwf val1+1 movf result,w movwf val1 return ;----------------- ;USES val1 Mul_x_32 rlf val1,1 ;lsb rlf val1+1,1 ;msb Mul_x_16 rlf val1,1 rlf val1+1,1 Mul_x_8 rlf val1,1 rlf val1+1,1 Mul_x_4 rlf val1,1 rlf val1+1,1 Mul_x_2 rlf val1,1 rlf val1+1,1 return ; ;=================== ; comparaison 16 bits ; USES val1,val2,valx , W, status ....affect‚s comp_signed16: bank1 movf val1+1,w xorlw 0x80 movwf valx+1 movf val2+1,w xorlw 0x80 subwf valx+1,w ; subtract val1-val2 movwf valx+1 ; sauve ecart goto Are_they_equal comp_unsigned_16: movf val2+1,w subwf val1+1,w ; subtract Y-X Are_they_equal: ; Are they equal ? skpz goto result_comp ; yes, they are equal -- compare lo movf val2,w subwf val1,w ; subtract Y-X movwf valx ; sauve ecart result_comp: ; if val2=val1 then now Z=1. ; if val1= 0x7FF ) ERROR "Attention debordement PAGE 1 programme" ENDIF org 0x0800 ;**************************************************************** ;#include "bcd32toT.inc" ;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. ;bin2bcd: ;adj_bcd: ;2940 cycles including call and return. bin2bcd_used?: bcf STATUS,C movlw 32 movwf count5 clrf temp_a clrf temp_b clrf temp_c clrf temp_d clrf temp_e bin2bcd_loop: rlf buff_1, F rlf buff_2, F rlf buff_3, F rlf buff_4, F rlf temp_e, F rlf temp_d, F rlf temp_c, F rlf temp_b, F rlf temp_a, F decfsz count5, F goto adj_dec goto done adj_dec: movlw temp_e movwf FSR call adj_bcd movlw temp_d movwf FSR call adj_bcd movlw temp_c movwf FSR call adj_bcd movlw temp_b movwf FSR call adj_bcd movlw temp_a movwf FSR call adj_bcd goto bin2bcd_loop adj_bcd: movlw h'3' addwf INDF, W movwf temp_f btfsc temp_f, 3 movwf INDF movlw h'30' addwf INDF, W movwf temp_f btfsc temp_f, 7 movwf INDF return done: return ;************************************************************** ;#include "UpdateRTC.inc" ;incw_bcd ;increment a packed bcd 8bit freg., enter with data in w ;decw_bcd ;decrement a packed bcd freg., enter sub with data in w ;inc_minute_bcd ;incr minutes reg by 1, check for not overflow 60s ;dec_minute_bcd ;decrement minute reg, check for zero underflow ;inc_hour_bcd ;incr hours, packed bcd representation ;dec_hour_bcd ;decrement hour reg, check for zero underflow ;inc_date_bcd ;incr date of month,packed bcd,cheat & assume all months <= 28days ;dec_date_bcd ;decrement date reg, check for zero underflow ;inc_month_bcd ;incr month,packed bcd ;dec_month_bcd ;decrement date reg, check for zero underflow ;inc_year_bcd ;incr year, packed bcd ;dec_year_bcd ;decrement date reg, check for zero underflow ; last update 7 avril 03 ; incremente ou decrement registres RTC 1302 au format BCD ;------------ incw_bcd ;increment a packed bcd 8bit freg., enter with data in w ;ex T Scott Dattalo, 20/4/98 movwf dummy movlw 11111110b ; 126 addlw 0x9A+1 ; 9B -> 155 subwf dummy,W rlf dummy,F btfss STATUS,DC addlw -0x06 btfss dummy,0 addlw -0x60 rrf dummy,F ;result in w goto fin_Update 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 goto fin_Update 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 goto fin_Update ;z got set if minutes=59,so don't incr movf minute,W call incw_bcd movwf minute goto fin_Update dec_minute_bcd ;decrement minute reg, check for zero underflow movf minute,W btfsc STATUS,Z goto fin_Update ;underflow danger, don't decr call decw_bcd movwf minute goto fin_Update inc_hour_bcd ;incr hours, packed bcd representation movf hour,W sublw 0x24 btfsc STATUS,Z goto fin_Update movf hour,W call incw_bcd movwf hour goto fin_Update dec_hour_bcd ;decrement hour reg, check for zero underflow movf hour,W btfsc STATUS,Z ;underflow => don't decr goto fin_Update call decw_bcd movwf hour goto fin_Update inc_date_bcd ;incr date of month,packed bcd,cheat & assume all months <= 28days movf date,W sublw 0x28 btfsc STATUS,Z goto fin_Update movf date,W call incw_bcd movwf date goto fin_Update dec_date_bcd ;decrement date reg, check for zero underflow movf date,W btfsc STATUS,Z goto fin_Update ;underflow danger, don't decr call decw_bcd movwf date goto fin_Update inc_month_bcd ;incr month,packed bcd movf month,W sublw 0x12 btfsc STATUS,Z goto fin_Update movf month,W call incw_bcd movwf month goto fin_Update dec_month_bcd ;decrement date reg, check for zero underflow movf month,W btfsc STATUS,Z goto fin_Update call decw_bcd movwf month goto fin_Update inc_year_bcd ;incr year, packed bcd movf year,W sublw 0x99 btfsc STATUS,Z goto fin_Update movf year,W call incw_bcd movwf year goto fin_Update dec_year_bcd ;decrement date reg, check for zero underflow movf year,W btfsc STATUS,Z goto fin_Update call decw_bcd movwf year fin_Update bcf PCLATH,3 return ;******************************************************************************** ; 000--JOUR---90--NUIT---420---JOUR---------720---NUIT----840-----JOUR-----1439 ; 00H00 01H30 07H30 12H00 14H30 23H59 ;********************************************************************************* Is_itJN ; test mode JN EDF 1H30 .. 7H00 et 12H00..14H30 ; Minute 0000 … Minuit 00H00M00S ; 1440 Mn => par jour 000 ...1439 ; 1ere partie 90=0x005A ..420=0x01A4 ; 2em partie 720=0x02D0 ..870=0x0366 bank0 bsf ISmidnight ; si Minuit =1 movf hour,f btfss STATUS,Z bcf ISmidnight ; si heure <>0 Raz drapeau ISmidnight movf minute,f btfss STATUS,Z bcf ISmidnight ; si minute <>0 Raz drapeau ISmidnight ;donc si Minuit 00H 00Mn ISmidnight reste a 1 btfss ISmidnight goto Not_Midnight bank1 clrf Mn_En_Cours clrf Mn_En_Cours+1 bank0 return Not_Midnight bank1 ; Test 1ere Tranche : debut … la 90eme Mn movf Mn_En_Cours,w movwf val1 movf Mn_En_Cours+1,w movwf val1+1 movlw LOW(.90) movwf val2 movlw HIGH (.90) movwf val2+1 bcf PCLATH,3 call sub16 ; val1 - val2 -> val2 bsf PCLATH,3 nop BTFSS STATUS,C ; superieur … 90 ? goto Set_Jour movf Mn_En_Cours,w movwf val1 movf Mn_En_Cours+1,w movwf val1+1 movlw LOW (.420) movwf val2 movlw HIGH(.420) movwf val2+1 bcf PCLATH,3 call sub16 bsf PCLATH,3 nop BTFSC STATUS,C ; Test 1ere Tranche ..avant la fin de 420em Mn goto Tranche_2 bank0 BSF Mode_NUIT ; tarif NUIT return Tranche_2 movf Mn_En_Cours,w movwf val1 movf Mn_En_Cours+1,w movwf val1+1 movlw LOW (.720); superieur … la 720em Mn (13H30) movwf val2 movlw HIGH(.720) movwf val2+1 bcf PCLATH,3 call sub16 bsf PCLATH,3 nop BTFSS STATUS,C ; si < … 720 goto Set_Jour movf Mn_En_Cours,w movwf val1 movf Mn_En_Cours+1,w movwf val1+1 movlw LOW (.870) movwf val2 movlw HIGH(.870) movwf val2+1 bcf PCLATH,3 call sub16 bsf PCLATH,3 nop BTFSS STATUS,C ; inferieur … 870 goto Set_Nuit ; si >420 ET < 820 => TARIF NUIT Set_Jour bank0 BCF Mode_NUIT ; sinon Tarif JOUR return Set_Nuit bank0 BSF Mode_NUIT ; tarif NUIT return ZoneLibre equ 0xFFF - $ ;******************************* ; EEPROM DATA ;******************************* ORG 0x2100 ; "1234567890123456" ; ATTENTION il faut que les messages soient de taille modulo 16 EE0 DT "T.Acc = " EE1 DT "T.Amb = " EE2 DT "T.Ext = " EE3 DT "Tarif " EE4 DT "ConsTAmb " EE5 DT "ConsTAcc " EE6 DT "RTC AMJHM +97531" EE7 DT "ConsAdap " EE8 DT "(C)PFreyer 07/01/2010" DT " Regul_16F88_L.asm " DT " RELEASE version ",0 finEprom EQU $ IF ( finEprom > 0x21FF ) ERROR "Attention debordement zone EEPROM" ENDIF END ; End of program