;******************************************************************* ;*-----------------------------------------------------------------* ;* Thermostaat * ;*-----------------------------------------------------------------* ;******************************************************************* LIST P=PIC16F877A #INCLUDE P16F877A.INC __CONFIG _CP_OFF & _DEBUG_OFF & _LVP_OFF & _PWRTE_ON & _WDT_OFF & _BODEN_OFF & _XT_OSC ;De Perfecte Versie ;---------------------------------------------------------------- ;Definieren van de registers en geheugenplaatsen ;---------------------------------------------------------------- KnoppenTemp EQU PORTA ;Knoppen voor temperatuurregeling LCDControl EQU PORTB ;Poort voor stuurFlag_Signbitalen LCD (= outputs) ResSel EQU H'0004' ;Register Select Signal= pin4 LCD ;(0 = characters als kommando's aan LCD gegeven ) ReadWrite EQU H'0003' ;Read Write Signal LCD = pin5 LCD (0 = schrijven) Enable EQU H'0002' ;Enable signal LCD = pin6 LCD (initiatie communicatie tss LCD en PIC) KnopUur EQU H'0000' KnopMin EQU H'0001' Sensor EQU PORTC ; TC_SCK EQU H'0006' ;1=binnenhalen van bits, 0=niet TC_CS EQU H'0000' ;aan/uit Maak dit controleerbaar. Moet dit wel, aangezien we toch op de klok zijn aangesloten van de PIC TC_SI EQU H'0004' ;data (temperatuur) LCDData EQU PORTD ;Poort voor het doorsturen van characters (= outputs) TIMER1 EQU H'20' TIMER2 EQU H'21' TIMER3 EQU H'22' TIMER4 EQU H'23' msec EQU H'24' ;counter die gelijk moet worden aan MSD zodat de 4Mhz getransformeerd is naar 1Hz sec EQU H'25' ;seconden min EQU H'26' ;minuten tensmin EQU H'27' ; uur EQU H'28' ;uren tensuur EQU H'29' ; finaluur EQU H'2A' ; WREG_TEMP EQU H'2B' STATUS_TEMP EQU H'2C' PCLATH_TEMP EQU H'2D' FSR_TEMP EQU H'2E' MSD EQU H'2F' ;millisecond divider (=255) Temp_Lo EQU H'30' ;Denk eraan => elke geheugenplaats is = 1 byte, dus 8 bits (temp verdeelt over 2 bits) Temp_Hi EQU H'31' Counter EQU H'32' ; teller voor het aantal ingelezen bits van de temperatuur Sign EQU H'33' Flag_Signbit EQU H'0000' Tmax EQU H'34' ;Temperatuursinterval Tmin EQU H'35' ModeFlag EQU H'36' ;++++++++++++++++++++++++++Begin+++++++++++++++++++++++++++++++++ ORG 0 goto Init ;**************************************************************** ; De Real-time klok - Start ;**************************************************************** ;---------------------------------------------------------------- ;Interrupt ;---------------------------------------------------------------- ORG 0x04 ;begin van de interrupt, standaard commando call Int incf msec,F ;msec+1 movf msec,W ;msec in W sublw MSD ;aftrekking => msec - MSD btfss STATUS,Z ;Is de aftrekking = 0?, zo ja begin dan met de seconden goto EndInt clrf msec ;Beginnen met de seconden, eerst msec = 0 maken dan idem msec incf sec,F movf sec,W sublw 0x3C ;aftrekking => sec - 60 btfss STATUS,Z goto EndInt clrf sec ;Beginnen met de minuten, eerst sec = 0 maken dan idem msec incf min,F movf min,W sublw 0x3C ;aftrekking => min - 60 btfss STATUS,Z goto EndInt clrf min incf uur,F movf uur,W sublw 0x18 ;aftrekking=> uur - 24 btfss STATUS,Z retfie clrf uur goto EndInt Int movwf WREG_TEMP ;save WREG movf STATUS,W ;store STATUS in WREG clrf STATUS ;select file register bank0 movwf STATUS_TEMP ;save STATUS value movf PCLATH,W ;store PCLATH in WREG movwf PCLATH_TEMP ;save PCLATH value clrf PCLATH ;select program memory page0 movf FSR,W ;store FSR in WREG movwf FSR_TEMP ;save FSR value Bank0 ;select bank0 btfsc INTCON,2 ;Is Timer0 in overflow, deze bit dus = 1 bcf INTCON,2 ;overflow clearen return EndInt Bank0 ;select bank 0 movf FSR_TEMP,W ;get saved FSR value movwf FSR ;restore FSR movf PCLATH_TEMP,W ;get saved PCLATH value movwf PCLATH ;restore PCLATH movf STATUS_TEMP,W ;get saved STATUS value movwf STATUS ;restore STATUS swapf WREG_TEMP,F ;prepare WREG to be restored swapf WREG_TEMP,W ;restore WREG without affecting STATUS retfie ;return from interrupt ;---------------------------------------------------------------- ;Initialisatie klok ;---------------------------------------------------------------- InitClock bsf STATUS,RP0 ; bank 1 movlw B'10000101' ; RBPU=off, INTEDG=off, T0CS=osc, PSA=TMR0 ; PSD = b'101' [64] movwf OPTION_REG bcf STATUS,RP0 ; bank 0 movlw B'10100000' ; enable global + TMR0 interrupt movwf INTCON bcf STATUS,RP0 ; reg. Bank 0 clrf msec ; msec = 0; clrf sec ; sec = 0; clrf min ; min = 0; clrf uur ; uur = 0; movlw 0xFF ;MSD = ;Verklaring van deze waarden: het is de bedoeling om een klok te maken met een frequentie van 1Hz, movwf MSD ;wat overeenkomt met een tijd van 1 seconde. Dit kunnen we bereiken door rekening te houden met de volgende ;betrekking => Fpic = Fosc/(4*256*PSD*MSD), met Fosc = 4.1943 Mhz, ;1/4 inherent aan de PIC en 256 omdat de timer gaat van 0 tot 255 (timer tikt dus 256 keer). ;We willen nu dat Fpic = 1Hz. Om dit te bereiken stellen we de prescaler PSD in op 1/16 (=B'011'). ;MSD wordt dan vervolgens berekend en = 255. Als msec nu = MSD => 1Hz, dus is er 1 seconde verstreken. return ;**************************************************************** ; De Real-time klok - Einde ;**************************************************************** ;**************************************************************** ; Initialisatie van de PIC - Start ;**************************************************************** RESET bsf STATUS,RP0 ; reg. Bank 1 ;PORTA bcf ADCON1,3 ;Alles van PORTA digitaal zijn bsf ADCON1,2 bsf ADCON1,1 bsf ADCON1,0 movlw B'001111' movwf TRISA ; PortA = input (de niet gebruikte pinnen als output gedefinieerd) ;PORTB movlw B'11000011' ; in-/uitgang definities movwf TRISB ;PORTC movlw B'00010000' ; in-/uitgang definities movwf TRISC ; ;PORTD movlw B'00000000' movwf TRISD ; PortD = output bcf STATUS,RP0 ; reg. Bank 0 ;Alles op 0 zeten ;PORTA movlw B'000000' movwf PORTA ; RA ports clear (=initiatie, uitgangen op 0 zetten) !!!!!!!!!!!!!!!!!!!!!! ;PORTB movlw B'00000000' movwf PORTB ; RB ports clear (=initiatie, uitgangen op 0 zetten) !!!!!!!!!!!!!!!!!!!!!! ;PORTC movlw B'00000000' movwf PORTC ; RC ports clear (=initiatie, uitgangen op 0 zetten) !!!!!!!!!!!!!!!!!!!!!! ;PORTD movlw B'00000000' movwf PORTD ; RD ports clear (=initiatie, uitgangen op 0 zetten) !!!!!!!!!!!!!!!!!!!!!! ;call InitDisplay ;bsf Sensor,TC_CS ;chip afzetten return ;**************************************************************** ; Initialisatie van de PIC - Einde ;**************************************************************** ;**************************************************************** ; Basis display procedures - Start ;**************************************************************** ;--------------------------------------------------------------- ;Procedure die een bepaald character naar de diplay stuurt ;--------------------------------------------------------------- SendData ;Dit is een zeer algemene procedur om data te versturen, zowel voor LCDControl als LCDData movwf LCDData ;De juiste waarde van LCDControl,ResSel hangt dus af van wat je wilt doen, verander deze waarde dus enkel in de hulpprocedures e niet in SendData bcf LCDControl,Enable bsf LCDControl,Enable ;E = 1, we kunnen schrijven naar de display (als R/W = 0, dit betekent schrijven en niet lezen) movlw D'255' ;* movwf TIMER1 ;* ; DELAY2 movlw D'2' ; x msec movwf TIMER2 decfsz TIMER2,F ;* goto $-1 ;* decfsz TIMER1,F goto DELAY2 retlw 0 ;-------------------------------------------------------------------------- ;Procedure om alle characters naar de display te sturen (1 procedure per char) ;-------------------------------------------------------------------------- Send_A movlw A'A' goto SendData Send_B movlw A'B' goto SendData Send_C movlw A'C' goto SendData Send_D movlw A'D' goto SendData Send_E movlw A'E' goto SendData Send_F movlw A'F' goto SendData Send_G movlw A'G' goto SendData Send_H movlw A'H' goto SendData Send_I movlw A'I' goto SendData Send_J movlw A'J' goto SendData Send_K movlw A'K' goto SendData Send_L movlw A'L' goto SendData Send_M movlw A'M' goto SendData Send_N movlw A'N' goto SendData Send_O movlw A'O' goto SendData Send_P movlw A'P' goto SendData Send_Q movlw A'Q' goto SendData Send_R movlw A'R' goto SendData Send_S movlw A'S' goto SendData Send_T movlw A'T' goto SendData Send_U movlw A'U' goto SendData Send_V movlw A'V' goto SendData Send_W movlw A'W' goto SendData Send_X movlw A'X' goto SendData Send_Y movlw A'Y' goto SendData Send_Z movlw A'Z' goto SendData Send_a movlw A'a' goto SendData Send_b movlw A'b' goto SendData Send_c movlw A'c' goto SendData Send_d movlw A'd' goto SendData Send_e movlw A'e' goto SendData Send_f movlw A'f' goto SendData Send_g movlw A'g' goto SendData Send_h movlw A'h' goto SendData Send_i movlw A'i' goto SendData Send_j movlw A'j' goto SendData Send_k movlw A'k' goto SendData Send_l movlw A'l' goto SendData Send_m movlw A'm' goto SendData Send_n movlw A'n' goto SendData Send_o movlw A'o' goto SendData Send_p movlw A'p' goto SendData Send_q movlw A'q' goto SendData Send_r movlw A'r' goto SendData Send_s movlw A's' goto SendData Send_t movlw A't' goto SendData Send_u movlw A'u' goto SendData Send_v movlw A'v' goto SendData Send_w movlw A'w' goto SendData Send_x movlw A'x' goto SendData Send_y movlw A'y' goto SendData Send_z movlw A'z' goto SendData Send_0 movlw A'0' goto SendData Send_1 movlw A'1' goto SendData Send_2 movlw A'2' goto SendData Send_3 movlw A'3' goto SendData Send_4 movlw A'4' goto SendData Send_5 movlw A'5' goto SendData Send_6 movlw A'6' goto SendData Send_7 movlw A'7' goto SendData Send_8 movlw A'8' goto SendData Send_9 movlw A'9' goto SendData Send_Space movlw A' ' goto SendData Send_Question movlw A'?' goto SendData Send_Point movlw A'.' goto SendData Send_ArrowUp movlw B'00000010' goto SendData Send_ArrowDown movlw B'00000001' goto SendData Send_ArrowKies movlw B'00000000' goto SendData Send_ArrowRight movlw B'01111110' goto SendData Send_ArrowLeft movlw B'01111111' goto SendData Send_Dubbel movlw A':' goto SendData Send_Minus movlw A'-' goto SendData Send_Plus movlw A'+' goto SendData Send_Exclamation movlw A'!' goto SendData Send_Degrees movlw B'11011111' goto SendData Send_En movlw A'&' goto SendData Send_Equal movlw A'=' goto SendData Send_GoHome bcf LCDControl,ResSel movlw B'00000010' ; Go to Home call SendData bsf LCDControl,ResSel return Send_ClearScreen bcf LCDControl,ResSel ;RS = 0, byte aan PORTD zijn nu commando's movlw B'00000001' ; Clear Display call SendData movlw B'00000010' ; Go to Home call SendData bsf LCDControl,ResSel call Delay9 return Send_NextLine bcf LCDControl,ResSel movlw B'11000000' call SendData bsf LCDControl,ResSel return Delay3 CLRWDT MOVLW D'100' MOVWF TIMER1 Delay4 MOVLW D'100' MOVWF TIMER2 DECFSZ TIMER2,F GOTO $-1 DECFSZ TIMER1,F GOTO Delay4 RETLW 0 ;--------------------------------------------------------------- ;Initialisatie van de display ;--------------------------------------------------------------- InitDisplay call Delay3 bcf LCDControl,ReadWrite ;schrijven naar de display bcf LCDControl,ResSel ;RS = 0, we sturen dus commando's naar de display call Delay3 movlw B'00110000' ;Deze datatransfers met delays zijn essentieel voor de goede werking van het scherm (kunnen eventueel nog wat kleiner worden gemaakt call SendData call Delay3 movlw B'00110000' call SendData call Delay3 movlw B'00110000' call SendData call Delay3 movlw B'00111000' ;Function set call SendData ;2 maal een 8bit line, volgens de datasheet call Delay3 movlw B'00001110' ;Display on/off Control call SendData call Delay3 movlw B'00000110' ;Entry Mode Set call SendData bsf LCDControl,ResSel ;RS = 1, we sturen dus terug characters naar de display call Delay3 return ;**************************************************************** ; Basis display procedures - Einde ;**************************************************************** ;**************************************************************** ; Delay - Start ;**************************************************************** Delay7 CLRWDT MOVLW D'255' MOVWF TIMER1 Delay8 MOVLW D'255' MOVWF TIMER2 DECFSZ TIMER2,F GOTO $-1 DECFSZ TIMER1,F GOTO Delay8 RETLW 0 Delay9 CLRWDT MOVLW D'20' MOVWF TIMER3 Delay10 MOVLW D'20' MOVWF TIMER4 DECFSZ TIMER4,F GOTO $-1 DECFSZ TIMER3,F GOTO Delay10 RETLW 0 ;**************************************************************** ; Delay - Einde ;**************************************************************** ;**************************************************************** ; Lezen van de temperatuur - Start ;**************************************************************** ;--------------------------------------------------------------- ;Loop waarin de temp bit per bit wordt gelezen ;--------------------------------------------------------------- TempRead movlw D'16' movwf Counter bcf Sensor,TC_SCK ;Klok op nul zetten. Er wordt geen data ontvangen van de sensor bcf Sensor,TC_CS ;Sensor opzetten call Delay7 call Delay9 call TempLoop return TempLoop ;Er wordt in deze loop geen data ontvangen van de sensor bsf Sensor,TC_SCK ;Zet de klok naar de sensor toe op 1. Er wordt een nieuwe databit gelezen ;Blijkbaar beslis je zelf wanneer de input TC_SI verandert btfsc Sensor,TC_SI ;Als TC_SI = 1 bsf STATUS,C ;wordt de Carry = 1 btfss Sensor,TC_SI ;Als TC_SI = 0 bcf STATUS,C ;wordt de Carry = 0 ;TC_SI is initieel = MSB, om dan bij elke doorgang van de loop te veranderen in de waarde rechts van de vorige call Delay7 bcf Sensor,TC_SCK ;De klok SCK is nu = 0 en wordt dus geen data meer gelezen rlf Temp_Lo ;De data wordt bit per bit in het register in gelezen met een rotate left through Carry = zie code hierboven rlf Temp_Hi ;De rotate left hier gebruikt de waarde die C heeft verkregen door de vorige rlf ;Zo schrijven we dus bit per bit het 16 bit getal in 2 registers decfsz Counter,F ;Counter - 1, als deze uitkomst = 0 goto TempLoop ;niet meer opnieuw TempLoop uitvoeren call Delay3 bsf Sensor,TC_CS ;uitschakelen van sensor call Delay9 call Delay7 return ;**************************************************************** ; Lezen van de temperatuur - Einde ;**************************************************************** ;**************************************************************** ; Temperatuursregeling - Start ;**************************************************************** ;---------------------------------------------------------------- ;Initialisatie van de Tmax en Tmin ;---------------------------------------------------------------- Init_AllTemps movlw B'00001111' ;Dit is de gereduceerde vorm van 15°C movwf Tmin movlw B'00011001' ;Dit is de gereduceerde vorm van 25°C movwf Tmax movlw D'0' movwf ModeFlag return ;---------------------------------------------------------------- ;Algemene Regeling ;---------------------------------------------------------------- ControleMax movf Tmax,w ;Tmax inschrijven in w subwf Temp_Lo,0 ;verschil (Temp_Lo - Tmax) maken en in w opslaan btfss STATUS,C ;de PIC gebruikt de 2's complement methode om verschillen te berekenen. ;verschil > 0 => carry = 1 ;verschil < 0 => carry = 0 goto ControleMin goto Send_Cooling ControleMin movf Tmin,w ;Tmin inschrijven in w subwf Temp_Lo,0 ;verschil (Temp_Lo - Tmin) maken en in w opslaan btfsc STATUS,C ;de pic gebruikt de 2's complement methode om verschillen te berekenen. ;verschil > 0 => carry = 1 ;verschil < 0 => carry = 0 goto Interval_ok goto Send_Heating Interval_ok goto Send_Off ControleMinVac movlw B'00000101' ;Dit is 15°C subwf Temp_Lo,0 ;verschil (Temp_Lo - 5°C) maken en in w opslaan btfsc STATUS,C ;de pic gebruikt de 2's complement methode om verschillen te berekenen. ;verschil > 0 => carry = 1 ;verschil < 0 => carry = 0 goto Interval_okVac goto Send_Heating Interval_okVac goto Send_Off ;---------------------------------------------------------------- ;Regeling Workday ;---------------------------------------------------------------- ;Eerste tempinterval van 7u tot 9u Workday1Start movf uur,W sublw D'6' ;Aftrekking = 6 - uur btfss STATUS,C ;verschil moet < 0, dus C = 0 goto Workday1End ;dan moeten we naar Workday1End goto TempWorkday ;anders, als C = 1, moeten we terug naar het begin van de loop Workday1End movf uur,W sublw D'9' ;9 - uur btfsc STATUS,C ;verschil moet > 0, dus C = 1, dan moet de thermostaat werken goto ControleMax ;Elke keer komt ControleMax terug in Thermostat goto Workday2Start ;Tweede tempinterval van 17u tot 23u Workday2Start movf uur,W sublw D'16' ;Aftrekking = 16 - uur btfss STATUS,C ;verschil moet < 0, dus C = 0 goto Workday2End ;dan moeten we naar Workday2End goto TempWorkday ;anders, als C = 1, moeten we terug naar het begin van de loop Workday2End movf uur,W sublw D'23' ;23 - uur btfsc STATUS,C ;verschil moet > 0, dus C = 1, dan moet de thermostaat werken goto ControleMax goto TempWorkday ;---------------------------------------------------------------- ;Regeling Weekend ;---------------------------------------------------------------- ;Eerste tempinterval van 8u tot 13u Weekend1Start movf uur,W sublw D'7' ;Aftrekking = 7 - uur btfss STATUS,C ;verschil moet < 0, dus C = 0 goto Weekend1End ;dan moeten we naar Weekend1End goto TempWeekend ;anders, als C = 1, moeten we terug naar het begin van de loop Weekend1End movf uur,W sublw D'13' ;13 - uur btfsc STATUS,C ;verschil moet > 0, dus C = 1, dan moet de thermostaat werken goto ControleMax ;Elke keer komt ControleMax terug in Thermostat goto Weekend2Start ;Tweede tempinterval van 17u tot 23u Weekend2Start movf uur,W sublw D'16' ;Aftrekking = 16 - uur btfss STATUS,C ;verschil moet < 0, dus C = 0 goto Weekend2End ;dan moeten we naar Weekend2End goto TempWeekend ;anders, als C = 1, moeten we terug naar het begin van de loop Weekend2End movf uur,W sublw D'23' ;23 - uur btfsc STATUS,C ;verschil moet > 0, dus C = 1, dan moet de thermostaat werken goto ControleMax goto TempWeekend ;---------------------------------------------------------------- ;Regeling Vacation ;---------------------------------------------------------------- Vacation1Start movlw B'00001010' ;Dit is 10°C subwf Temp_Lo,W ;10 - Temp_Lo btfsc STATUS,C ;verschil moet < 0, dus C = 0, dus actie ondernemen als C = 1 goto ControleMinVac ;dan moeten we naar ControleMinVac, aparte regeling voor Vacation goto TempVacation ;---------------------------------------------------------------- ;Wat na de complete temperatuursconversie ;---------------------------------------------------------------- TempAfterConv ;Is de temp conversie compleet? Als bit 2 van Temp_Lo = 1 is de conversie compleet btfss Temp_Lo,2 ;waarom skip if set? Om ervoor te zorgen dat er ook rekening wordt gehouden met het geval dat bit 2 goto ChoseThermoMode ;Laat de 3 LSB wegvallen (bit 0, 1 en 2), aangezien die niet mee de waarde van de temp bepalen bcf STATUS,C ;Carry = 0 rrf Temp_Hi rrf Temp_Lo bcf STATUS,C ;Carry = 0 rrf Temp_Hi rrf Temp_Lo bcf STATUS,C ;Carry = 0 rrf Temp_Hi rrf Temp_Lo return ;---------------------------------------------------------------- ;Berekeningen in het geval van een negatieve temperatuur ;---------------------------------------------------------------- NegativeComp btfsc Temp_Hi,4 ;als bit 4 = 1 bsf Sign,Flag_Signbit ;dan wordt Flag_Signbit = 1 => de temperatuur is negatief btfss Temp_Hi,4 ;als bit 4 = 0 bcf Sign,Flag_Signbit ;dan wordt Flag_Signbit = 0 => de temperatuur is positief btfss Sign,Flag_Signbit ;Als Flag_Signbit = 1 => temp is negatief en extra berekeningen zijn nodig in NegativeComp return ;anders deze procedure verlaten bsf Temp_Hi,7 ;Dit is omdat we werken met de 2's complement methode om binair een negatief getal weer te geven bsf Temp_Hi,6 bsf Temp_Hi,5 comf Temp_Hi,F ;complement nemen comf Temp_Lo,F ;complement nemen incf Temp_Lo,F ;2 optellen, binair gezien btfsc STATUS,C ;als Carry = 1, betekent dit dat de MSB van Temp_Lo + 1 buiten Temp_Lo valt incf Temp_Hi,F ;moet bij het 2de register ook 1 bijgeteld worden return ;---------------------------------------------------------------- ;Temperatuur afronden tot op 1°C ;---------------------------------------------------------------- TempRound bcf STATUS,C ;Carry = 0 rrf Temp_Hi rrf Temp_Lo bcf STATUS,C ;Carry = 0 rrf Temp_Hi rrf Temp_Lo bcf STATUS,C ;Carry = 0 rrf Temp_Hi rrf Temp_Lo bcf STATUS,C ;Carry = 0 rrf Temp_Hi rrf Temp_Lo return ;Hier verwaarlozen we dus de twee laatste bits van Temp_Lo. Voor de regeling beschouwen we nu enkel Temp_Lo. De temperatuursrange die we ;nu nog kunnen beschouwen loopt van +/- 1°C tot +/- 255°C wat ruim voldoende is voor een thermostaat. ;---------------------------------------------------------------- ;Extra display procedures ;---------------------------------------------------------------- Send_Cooling call Send_ClearScreen call Send_Space call Send_Space ;2 call Send_Space ;3 call Send_Space ;4 call Send_C ;5 call Send_o ;6 call Send_o ;7 call Send_l ;8 call Send_NextLine call Send_i call Send_n call Send_g goto Thermostatloop ;Terug begin van het programma Send_Heating call Send_ClearScreen call Send_Space call Send_Space ;2 call Send_Space ;3 call Send_Space ;4 call Send_H ;5 call Send_e ;6 call Send_a ;7 call Send_t ;8 call Send_NextLine call Send_i call Send_n call Send_g goto Thermostatloop ;Terug begin van het programma Send_Off call Send_ClearScreen call Send_Space call Send_Space ;2 call Send_Space ;3 call Send_Space ;4 call Send_Space ;4 call Send_Space ;4 call Send_O ;5 call Send_f ;6 call Send_NextLine call Send_f goto Thermostatloop ;Terug begin van het programma Send_Workday bsf ModeFlag,7 call Send_ClearScreen call Send_Space call Send_Space call Send_W call Send_o call Send_r call Send_k call Send_d call Send_a call Send_NextLine call Send_y call Send_Space call Send_M call Send_o call Send_d call Send_e return Send_Weekend bsf ModeFlag,6 call Send_ClearScreen call Send_Space call Send_Space call Send_W call Send_e call Send_e call Send_k call Send_e call Send_n call Send_NextLine call Send_d call Send_Space call Send_M call Send_o call Send_d call Send_e return Send_Vacation bsf ModeFlag,5 call Send_ClearScreen call Send_Space call Send_Space call Send_V call Send_a call Send_c call Send_a call Send_t call Send_i call Send_NextLine call Send_o call Send_n call Send_Space call Send_M call Send_o call Send_d call Send_e return Send_10Degrees call Send_Space call Send_1 call Send_0 call Send_Degrees call Send_C return Send_11Degrees call Send_Space call Send_1 call Send_1 call Send_Degrees call Send_C return Send_12Degrees call Send_Space call Send_1 call Send_2 call Send_Degrees call Send_C return Send_13Degrees call Send_Space call Send_1 call Send_3 call Send_Degrees call Send_C return Send_14Degrees call Send_Space call Send_1 call Send_4 call Send_Degrees call Send_C return Send_15Degrees call Send_Space call Send_1 call Send_5 call Send_Degrees call Send_C return Send_16Degrees call Send_Space call Send_1 call Send_6 call Send_Degrees call Send_C return Send_17Degrees call Send_Space call Send_1 call Send_7 call Send_Degrees call Send_C return Send_18Degrees call Send_Space call Send_1 call Send_8 call Send_Degrees call Send_C return Send_19Degrees call Send_Space call Send_1 call Send_9 call Send_Degrees call Send_C return Send_20Degrees call Send_Space call Send_2 call Send_0 call Send_Degrees call Send_C return Send_21Degrees call Send_Space call Send_2 call Send_1 call Send_Degrees call Send_C return Send_22Degrees call Send_Space call Send_2 call Send_2 call Send_Degrees call Send_C return Send_23Degrees call Send_Space call Send_2 call Send_3 call Send_Degrees call Send_C return Send_24Degrees call Send_Space call Send_2 call Send_4 call Send_Degrees call Send_C return Send_25Degrees call Send_Space call Send_2 call Send_5 call Send_Degrees call Send_C return Send_26Degrees call Send_Space call Send_2 call Send_6 call Send_Degrees call Send_C return Send_27Degrees call Send_Space call Send_2 call Send_7 call Send_Degrees call Send_C return Send_28Degrees call Send_Space call Send_2 call Send_8 call Send_Degrees call Send_C return Send_29Degrees call Send_Space call Send_2 call Send_9 call Send_Degrees call Send_C return Send_30Degrees call Send_Space call Send_3 call Send_0 call Send_Degrees call Send_C return ;---------------------------------------------------------------- ;Knoppen voor temperatuursmanipulatie ;---------------------------------------------------------------- ;We kiezen ervoor om de ingestelde temperaturen telkens met 1°C te laten toe- of afnemen telkens er op een knop wordt gedrukt ;Ik denk dat deze procedures best helemaal in het begin van het programma komen. Of Misschien regelmatig laten terugkomen???????????? ;ER MOETEN OOK ABSOLUTE MIN EN MAX ZIJN VOOR ZOWEL Tmax als Tmin => Finito TempMax2 btfss KnoppenTemp,0 ;Als er nog eens op de knop wordt gedrukt => Tmax + 1 return movlw B'00000001' ;Dit is = 1°C in gereduceerde vorm addwf Tmax,F ;Temperatuur laten toenemen met 1°C en dan Tmax overschrijven met de nieuwe waarde movlw B'00011111' ;Het absolute max van Tmax is dus = 30°C subwf Tmax,W btfsc STATUS,Z movlw B'00010100' ;Dit is 20°C btfsc STATUS,Z movwf Tmax call Send_Tmax call Delay7 call Delay7 call Delay7 return TempMin2 btfss KnoppenTemp,1 ;Als er nog eens op de knop wordt gedrukt => Tmax + 1 return movlw B'00000001' ;Dit is = 1°C in gereduceerde vorm addwf Tmin,F ;Temperatuur laten toenemen met 1°C en dan Tmax overschrijven met de nieuwe waarde movlw B'00010100' ;Het absolute max van Tmin is dus = 19°C subwf Tmin,W btfsc STATUS,Z movlw B'00001010' ;Dit is 10°C btfsc STATUS,Z movwf Tmin call Send_Tmin call Delay7 call Delay7 call Delay7 return TempButtons call TempMax2 call TempMin2 return ;---------------------------------------------------------------- ;Mode kiezen: voorstel om 2 knoppen tegelijkertijd in te drukken ;---------------------------------------------------------------- ChoseThermoMode ;Er moeten telkens 2 knoppen tegelijkertijd ingedrukt worden movf KnoppenTemp,W andlw B'00001100' ;Deze AND om zeker te zijn dat er geen invloed van de andere knoppen is sublw B'00001100' btfsc STATUS,Z ;Aftrekking = 0 => Z=1 call Send_Vacation btfsc STATUS,Z ;Aftrekking = 0 => Z=1 goto TempVacation ;Bijbehorende Flag = 0010000 btfsc KnoppenTemp,2 ;Wordt er op de knop gedrukt? Ja call Send_Workday ;Ga naar Workday Mode btfsc KnoppenTemp,2 ; goto TempWorkday ;en vervolgens naar de thermostaat regeling, bijbehorende flag = 1000000 btfsc KnoppenTemp,3 call Send_Weekend btfsc KnoppenTemp,3 goto TempWeekend ;Bijbehorende Flag = 0100000 return WhichMode movfw ModeFlag sublw B'10000000' btfsc STATUS,Z ;Als Z = 1 goto TempWorkday ;Dan zitten we in Workday Mode movfw ModeFlag sublw B'01000000' btfsc STATUS,Z ;Als Z = 1 goto TempWeekend ;Dan zitten we in Weekend Mode movfw ModeFlag sublw B'00100000' btfsc STATUS,Z ;Als Z = 1 goto TempVacation ;Dan zitten we in Vacation Mode return ;We zitten in geen Mode, er is nog nooit op de knoppen gedrukt. ModeScreen call Send_ClearScreen call Send_Space call Send_M call Send_o call Send_d call Send_e call Send_Space call Send_S call Send_e call Send_NextLine call Send_t call Send_t call Send_i call Send_n call Send_g call Send_s return ;---------------------------------------------------------------- ;Temperatuur naar de display sturen ;---------------------------------------------------------------- Send_Tmax call Send_ClearScreen call Send_Space call Send_Space call Send_T call Send_m call Send_a call Send_x call Send_Space call Send_Equal call Send_NextLine movlw B'00010100' subwf Tmax,W btfsc STATUS,Z call Send_20Degrees movlw B'00010101' subwf Tmax,W btfsc STATUS,Z call Send_21Degrees movlw B'00010110' subwf Tmax,W btfsc STATUS,Z call Send_22Degrees movlw B'00010111' subwf Tmax,W btfsc STATUS,Z call Send_23Degrees movlw B'00011000' subwf Tmax,W btfsc STATUS,Z call Send_24Degrees movlw B'00011001' subwf Tmax,W btfsc STATUS,Z call Send_25Degrees movlw B'00011010' subwf Tmax,W btfsc STATUS,Z call Send_26Degrees movlw B'00011011' subwf Tmax,W btfsc STATUS,Z call Send_27Degrees movlw B'00011100' subwf Tmax,W btfsc STATUS,Z call Send_28Degrees movlw B'00011101' subwf Tmax,W btfsc STATUS,Z call Send_29Degrees movlw B'00011110' subwf Tmax,W btfsc STATUS,Z call Send_30Degrees return Send_Tmin call Send_ClearScreen call Send_Space call Send_Space call Send_T call Send_m call Send_i call Send_n call Send_Space call Send_Equal call Send_NextLine movlw B'00001010' subwf Tmin,W btfsc STATUS,Z ;Als de aftrekking = 0 (Z = 1) is, call Send_10Degrees ;Stuur de juiste temp naar de display movlw B'00001011' subwf Tmin,W btfsc STATUS,Z call Send_11Degrees movlw B'00001100' subwf Tmin,W btfsc STATUS,Z call Send_12Degrees movlw B'00001101' subwf Tmin,W btfsc STATUS,Z call Send_13Degrees movlw B'00001110' subwf Tmin,W btfsc STATUS,Z call Send_14Degrees movlw B'00001111' subwf Tmin,W btfsc STATUS,Z call Send_15Degrees movlw B'00010000' subwf Tmin,W btfsc STATUS,Z call Send_16Degrees movlw B'00010001' subwf Tmin,W btfsc STATUS,Z call Send_17Degrees movlw B'00010010' subwf Tmin,W btfsc STATUS,Z call Send_18Degrees movlw B'00010011' subwf Tmin,W btfsc STATUS,Z call Send_19Degrees return ;**************************************************************** ; Temperatuursregeling - Einde ;**************************************************************** ;**************************************************************** ;Display procedures voor de klok ;**************************************************************** Send_00 call Send_0 call Send_0 return Send_01 call Send_0 call Send_1 return Send_02 call Send_0 call Send_2 return Send_03 call Send_0 call Send_3 return Send_04 call Send_0 call Send_4 return Send_05 call Send_0 call Send_5 return Send_06 call Send_0 call Send_6 return Send_07 call Send_0 call Send_7 return Send_08 call Send_0 call Send_8 return Send_09 call Send_0 call Send_9 return Send_10 call Send_1 call Send_0 return Send_11 call Send_1 call Send_1 return Send_12 call Send_1 call Send_2 return Send_13 call Send_1 call Send_3 return Send_14 call Send_1 call Send_4 return Send_15 call Send_1 call Send_5 return Send_16 call Send_1 call Send_6 return Send_17 call Send_1 call Send_7 return Send_18 call Send_1 call Send_8 return Send_19 call Send_1 call Send_9 return Send_20 call Send_2 call Send_0 return Send_21 call Send_2 call Send_1 return Send_22 call Send_2 call Send_2 return Send_23 call Send_2 call Send_3 return Send_24 call Send_2 call Send_4 return Send_25 call Send_2 call Send_5 return Send_26 call Send_2 call Send_6 return Send_27 call Send_2 call Send_7 return Send_28 call Send_2 call Send_8 return Send_29 call Send_2 call Send_9 return Send_30 call Send_3 call Send_0 return Send_31 call Send_3 call Send_1 return Send_32 call Send_3 call Send_2 return Send_33 call Send_3 call Send_3 return Send_34 call Send_3 call Send_4 return Send_35 call Send_3 call Send_5 return Send_36 call Send_3 call Send_6 return Send_37 call Send_3 call Send_7 return Send_38 call Send_3 call Send_8 return Send_39 call Send_3 call Send_9 return Send_40 call Send_4 call Send_0 return Send_41 call Send_4 call Send_1 return Send_42 call Send_4 call Send_2 return Send_43 call Send_4 call Send_3 return Send_44 call Send_4 call Send_4 return Send_45 call Send_4 call Send_5 return Send_46 call Send_4 call Send_6 return Send_47 call Send_4 call Send_7 return Send_48 call Send_4 call Send_8 return Send_49 call Send_4 call Send_9 return Send_50 call Send_5 call Send_0 return Send_51 call Send_5 call Send_1 return Send_52 call Send_5 call Send_2 return Send_53 call Send_5 call Send_3 return Send_54 call Send_5 call Send_4 return Send_55 call Send_5 call Send_5 return Send_56 call Send_5 call Send_6 return Send_57 call Send_5 call Send_7 return Send_58 call Send_5 call Send_8 return Send_59 call Send_5 call Send_9 return ;---------------------------------------------------------------- ;Knoppen voor de klokinstelling ;---------------------------------------------------------------- uurUp btfss LCDControl,0 ;Als er nog eens op de knop wordt gedrukt => uur + 1 return incf uur,F call Delay9 movlw D'24' subwf uur,W btfsc STATUS,Z ;Als uur - 24 = 0 (Z=1), dan moet het uur terug op nul springen, als we hier zijn in het programma is er op een knop gedrukt movlw D'0' btfsc STATUS,Z movwf uur call Send_uur return minUp btfss LCDControl,1 return incf min,F call Delay9 movlw D'60' subwf min,W btfsc STATUS,Z movlw D'0' btfsc STATUS,Z movwf min call Send_min return FinalTime call Delay7 movf LCDControl,W andlw B'00000011' sublw B'00000011' btfsc STATUS,Z ;Aftrekking = 0 => Z=1 goto Thermostat ;Begin met de temperatuurstoestanden (Dus Thermostat) btfss STATUS,Z ;Aftrekking = 1 => Z=0 goto KlokButtons ;Ga terug naar de knoppentoestanden TimeScreen call Send_ClearScreen call Send_Space call Send_T call Send_i call Send_m call Send_e call Send_Space call Send_S call Send_e call Send_NextLine call Send_t call Send_t call Send_i call Send_n call Send_g call Send_s return KlokButtons call uurUp call minUp call FinalTime return ;---------------------------------------------------------------- ;Klok naar de display sturen ;---------------------------------------------------------------- Send_uur call Send_ClearScreen call Send_Space call Send_Space call Send_Space call Send_Space call Send_Space movlw D'0' subwf uur,w btfsc STATUS,Z ;Als de aftrekking = 0 (Z = 1) is, call Send_Space ;Stuur het juiste uur naar de display btfsc STATUS,Z call Send_0 movlw D'1' subwf uur,w btfsc STATUS,Z call Send_Space btfsc STATUS,Z call Send_1 movlw D'2' subwf uur,w btfsc STATUS,Z call Send_Space btfsc STATUS,Z call Send_2 movlw D'3' subwf uur,w btfsc STATUS,Z call Send_Space btfsc STATUS,Z call Send_3 movlw D'4' subwf uur,w btfsc STATUS,Z call Send_Space btfsc STATUS,Z call Send_4 movlw D'5' subwf uur,w btfsc STATUS,Z call Send_Space btfsc STATUS,Z call Send_5 movlw D'6' subwf uur,w btfsc STATUS,Z call Send_Space btfsc STATUS,Z call Send_6 movlw D'7' subwf uur,w btfsc STATUS,Z call Send_Space btfsc STATUS,Z call Send_7 movlw D'8' subwf uur,w btfsc STATUS,Z call Send_Space btfsc STATUS,Z call Send_8 movlw D'9' subwf uur,w btfsc STATUS,Z call Send_Space btfsc STATUS,Z call Send_9 movlw D'10' subwf uur,w btfsc STATUS,Z call Send_10 movlw D'11' subwf uur,w btfsc STATUS,Z call Send_11 movlw D'12' subwf uur,w btfsc STATUS,Z call Send_12 movlw D'13' subwf uur,w btfsc STATUS,Z call Send_13 movlw D'14' subwf uur,w btfsc STATUS,Z call Send_14 movlw D'15' subwf uur,w btfsc STATUS,Z call Send_15 movlw D'16' subwf uur,w btfsc STATUS,Z call Send_16 movlw D'17' subwf uur,w btfsc STATUS,Z call Send_17 movlw D'18' subwf uur,w btfsc STATUS,Z call Send_18 movlw D'19' subwf uur,w btfsc STATUS,Z call Send_19 movlw D'20' subwf uur,w btfsc STATUS,Z call Send_20 movlw D'21' subwf uur,w btfsc STATUS,Z call Send_21 movlw D'22' subwf uur,w btfsc STATUS,Z call Send_22 movlw D'23' subwf uur,w btfsc STATUS,Z call Send_23 call Send_Dubbel return Send_min call Send_NextLine movlw D'0' subwf min,w btfsc STATUS,Z call Send_00 movlw D'1' subwf min,w btfsc STATUS,Z call Send_01 movlw D'2' subwf min,w btfsc STATUS,Z call Send_02 movlw D'3' subwf min,w btfsc STATUS,Z call Send_03 movlw D'4' subwf min,w btfsc STATUS,Z call Send_04 movlw D'5' subwf min,w btfsc STATUS,Z call Send_05 movlw D'6' subwf min,w btfsc STATUS,Z call Send_06 movlw D'7' subwf min,w btfsc STATUS,Z call Send_07 movlw D'8' subwf min,w btfsc STATUS,Z call Send_08 movlw D'9' subwf min,w btfsc STATUS,Z call Send_09 movlw D'10' subwf min,w btfsc STATUS,Z call Send_10 movlw D'11' subwf min,w btfsc STATUS,Z call Send_11 movlw D'12' subwf min,w btfsc STATUS,Z call Send_12 movlw D'13' subwf min,w btfsc STATUS,Z call Send_13 movlw D'14' subwf min,w btfsc STATUS,Z call Send_14 movlw D'15' subwf min,w btfsc STATUS,Z call Send_15 movlw D'16' subwf min,w btfsc STATUS,Z call Send_16 movlw D'17' subwf min,w btfsc STATUS,Z call Send_17 movlw D'18' subwf min,w btfsc STATUS,Z call Send_18 movlw D'19' subwf min,w btfsc STATUS,Z call Send_19 movlw D'20' subwf min,w btfsc STATUS,Z call Send_20 movlw D'21' subwf min,w btfsc STATUS,Z call Send_21 movlw D'22' subwf min,w btfsc STATUS,Z call Send_22 movlw D'23' subwf min,w btfsc STATUS,Z call Send_23 movlw D'24' subwf min,w btfsc STATUS,Z call Send_24 movlw D'25' subwf min,w btfsc STATUS,Z call Send_25 movlw D'26' subwf min,w btfsc STATUS,Z call Send_26 movlw D'27' subwf min,w btfsc STATUS,Z call Send_27 movlw D'28' subwf min,w btfsc STATUS,Z call Send_28 movlw D'29' subwf min,w btfsc STATUS,Z call Send_29 movlw D'30' subwf min,w btfsc STATUS,Z call Send_30 movlw D'31' subwf min,w btfsc STATUS,Z call Send_31 movlw D'32' subwf min,w btfsc STATUS,Z call Send_32 movlw D'33' subwf min,w btfsc STATUS,Z call Send_33 movlw D'34' subwf min,w btfsc STATUS,Z call Send_34 movlw D'35' subwf min,w btfsc STATUS,Z call Send_35 movlw D'36' subwf min,w btfsc STATUS,Z call Send_36 movlw D'37' subwf min,w btfsc STATUS,Z call Send_37 movlw D'38' subwf min,w btfsc STATUS,Z call Send_38 movlw D'39' subwf min,w btfsc STATUS,Z call Send_39 movlw D'40' subwf min,w btfsc STATUS,Z call Send_40 movlw D'41' subwf min,w btfsc STATUS,Z call Send_41 movlw D'42' subwf min,w btfsc STATUS,Z call Send_42 movlw D'43' subwf min,w btfsc STATUS,Z call Send_43 movlw D'44' subwf min,w btfsc STATUS,Z call Send_4 movlw D'45' subwf min,w btfsc STATUS,Z call Send_45 movlw D'46' subwf min,w btfsc STATUS,Z call Send_46 movlw D'47' subwf min,w btfsc STATUS,Z call Send_47 movlw D'48' subwf min,w btfsc STATUS,Z call Send_48 movlw D'49' subwf min,w btfsc STATUS,Z call Send_49 movlw D'50' subwf min,w btfsc STATUS,Z call Send_50 movlw D'51' subwf min,w btfsc STATUS,Z call Send_51 movlw D'52' subwf min,w btfsc STATUS,Z call Send_52 movlw D'53' subwf min,w btfsc STATUS,Z call Send_53 movlw D'54' subwf min,w btfsc STATUS,Z call Send_54 movlw D'55' subwf min,w btfsc STATUS,Z call Send_55 movlw D'56' subwf min,w btfsc STATUS,Z call Send_56 movlw D'57' subwf min,w btfsc STATUS,Z call Send_57 movlw D'58' subwf min,w btfsc STATUS,Z call Send_58 movlw D'59' subwf min,w return ;**************************************************************** ; Tijd instellen met de knoppen - Einde ;**************************************************************** ;--------------------------------------------------------------- ;--------------------------------------------------------------- ;Hoofdprogramma ;--------------------------------------------------------------- ;--------------------------------------------------------------- Init call InitDisplay ;Initialisatie Display call Init_AllTemps ;Initialisatie Regeltemperaturen call InitClock ;Initialisatie van de klok call RESET goto Time Time call TimeScreen Timeloop call KlokButtons goto Timeloop Thermostat call ModeScreen Thermostatloop call ChoseThermoMode ;Als er dus niet op een knop wordt gedrukt komen we in WhichMode waar met behulp van de ModeFlag de juiste regeling wordt gekozen call WhichMode ;Het is noodzakelijk dat ChoseThermoMode altijd overlopen wordt omdat hier de knoppen voor de bepaling van de mode worden gecontroleerd goto Thermostatloop TempWorkday ;Temp lezen ;bcf INTCON,GIE ;geen globale interrupts ;Gevolgde logica: geen interrupt in het midden van een tempconversie <=> Is dit nodig?????????? call TempRead ;Sensor initialiseren ;bsf INTCON,GIE ;enable globale interrupts. ;Zorgen dat er enkel databits over zijn call TempAfterConv ;Negatieve temperatuur call NegativeComp ;Bewerkingen conform met de two's complement methode voor binaire weergave van binaire getallen ;Extra manipulatie van de temperatuur zodat de regeling maar 1 byte nodig heeft om de thermostaat correct aan te sturen call TempRound ;Controleren of er op de knoppen wordt gedrukt call TempButtons ;Aangepaste regeling ;Denk eraan, waarde van uur blijft ook een heel uur dezelfde goto Workday1Start TempWeekend ;Temp lezen ;bcf INTCON,GIE ;geen globale interrupts ;Gevolgde logica: geen interrupt in het midden van een tempconversie <=> Is dit nodig?????????? call TempRead ;Sensor initialiseren ;bsf INTCON,GIE ;enable globale interrupts. ;Zorgen dat er enkel databits over zijn call TempAfterConv ;Negatieve temperatuur call NegativeComp ;Bewerkingen conform met de two's complement methode voor binaire weergave van binaire getallen ;Extra manipulatie van de temperatuur zodat de regeling maar 1 byte nodig heeft om de thermostaat correct aan te sturen call TempRound ;Controleren of er op de knoppen wordt gedrukt call TempButtons ;Aangepaste regeling ;Denk eraan, waarde van uur blijft ook een heel uur dezelfde goto Weekend1Start TempVacation ;Temp lezen ;bcf INTCON,GIE ;geen globale interrupts ;Gevolgde logica: geen interrupt in het midden van een tempconversie <=> Is dit nodig?????????? call TempRead ;Sensor initialiseren ;bsf INTCON,GIE ;enable globale interrupts. ;Zorgen dat er enkel databits over zijn call TempAfterConv ;Negatieve temperatuur call NegativeComp ;Bewerkingen conform met de two's complement methode voor binaire weergave van binaire getallen ;Extra manipulatie van de temperatuur zodat de regeling maar 1 byte nodig heeft om de thermostaat correct aan te sturen call TempRound ;Controleren of er op de knoppen wordt gedrukt call TempButtons ;Aangepaste regeling ;Denk eraan, waarde van uur blijft ook een heel uur dezelfde goto Vacation1Start ;Uit deze loop komen om te controleren in welke mode we zitten zit nu in feite vervat in de procedure WhichMode ;++++++++++++++++++++++++++Einde+++++++++++++++++++++++++++++++++ end