;******************************************************************************; ; ; ; SBP EcoModif: afstandsbediende stekkerblok ; ; ; ;Leden: - De Batselier Jonathan ; ; - De Ridder Bart ; ; - Roelants Dennis ; ; - Van Herck Tom ; ; ; ;Nota: V1.1 Enkel RC5 Eindwerk 2007-2008 ; ;******************************************************************************; DEVICE 16F630 CONFIG WDT_OFF, PWRTE_ON, BODEN_OFF;Geen kristal XTAL 8 ;Bij gebruik van een kristal een 8MHz type gebuiken (zijn tijden op gebaseerd) ALL_DIGITAL TRUE PORTC = %00000000 ;PIC opstarten met alle PORTA poorten laag TRISC = %00000001 ;uitgang=O ingang=1 aan poort A.0 komt de sensor ;----------------------------- tijden voor ontvangen van bits uigedrukt in µs ------------------ symbol tijd_RC5 = 870 symbol tijd_RC6_Correctie = 56 symbol tijd_RC6_LeaderSimbol = 889 symbol tijd_RC6_Bit = 444 symbol tijd_RC6_Trailer = 888 ;I/O symbol ingang = portC.5 symbol uitgang1 = PortC.4 ;TV symbol uitgang2 = portC.3 ;randaparaat symbol uitgang3 = portC.2 ;randaparaat symbol uitgang_PWM = portC.1 ;lamp Symbol LEDA = portC.0 ;led ;------------------------------- variabelen ----------------------------------------------------- dim type as bit ;RC5=0 RC6=1 dim fout as bit ;controle voor fouten dim devicestatus as bit ;status van de stembykiller dim adrescode as byte ;resultaat van het ophalen van de adrescode dim commandocode as byte ;resultaat van het ophalen van de commandocode dim mode as byte ;resultaat van het ophalen van de modebits + trailer en toogelebit dim straffe_lamp as byte dim controleadres as byte ;controle resultaat ophalen van de adresbits dim controlecommando as byte ;controle resultaat ophalen van de commandobits dim controlemode as byte ;controle van mode register devicestatus = 0 delayms 500 straffe_lamp = 0 while 1=1 ; start programma continu doorlopend ;------------------------------- onderschijd maken tussen RC5 en RC6 ----------------------------- if ingang = 1 then ;starten met het ophalen van de bits mode = 0 delayus tijd_RC5 ;we gebruiken de tijd voor RC5 voor het onderschijd te maken ;en maken bij RC6 gebruik van een corectie (zie exels) mode.2 = ingang ;most significant mode bit delayus tijd_RC5 mode.1 = ingang delayus tijd_RC5 mode.0 = ingang if mode = 5 then ;RC5 code 101 type=0 fout=0 elseif mode = 7 then ;als geen RC5 maar wel RC6: 111 type=1 fout=0 else fout=1 end if end if mode = 0 ;-------------------------------indien RC5--------------------------------------------------------- if type=0 and fout=0 then delayus tijd_RC5 mode.0= ingang ;ophalen MSB van de tooglebit delayus tijd_RC5 controlemode.0= 1 - ingang ;controle van de tooglebit delayus tijd_RC5 adrescode.4= ingang ;ophalen MSB van de adresbits delayus tijd_RC5 controleadres.4= 1 - ingang ;de controlebits zijn het complement van het het gene op de poort staat delayus tijd_RC5 adrescode.3= ingang delayus tijd_RC5 controleadres.3= 1 - ingang delayus tijd_RC5 adrescode.2= ingang delayus tijd_RC5 controleadres.2= 1 - ingang delayus tijd_RC5 adrescode.1= ingang delayus tijd_RC5 controleadres.1= 1 - ingang delayus tijd_RC5 adrescode.0= ingang delayus tijd_RC5 controleadres.0= 1 - ingang delayus tijd_RC5 commandocode.5 = ingang ;ophalen van de commandobits delayus tijd_RC5 controlecommando.5 = 1 - ingang ;ophalen van de controlebits deze zijn het complement van de commandoits delayus tijd_RC5 commandocode.4 = ingang ;ophalen van de commandobits delayus tijd_RC5 controlecommando.4 = 1 - ingang ;ophalen van de controlebits deze zijn het complement van de commandoits delayus tijd_RC5 commandocode.3 = ingang delayus tijd_RC5 controlecommando.3 = 1 - ingang delayus tijd_RC5 commandocode.2 = ingang delayus tijd_RC5 controlecommando.2 = 1 - ingang delayus tijd_RC5 commandocode.1 = ingang delayus tijd_RC5 controlecommando.1 = 1 - ingang delayus tijd_RC5 commandocode.0 = ingang delayus tijd_RC5 controlecommando.0 = 1 - ingang end if ;-------------------------------indien RC6--------------------------------------------------------- if mode = 1 and fout = 0 then delayus tijd_RC6_Correctie + tijd_RC6_LeaderSimbol ;tijd die het leader symbol in neemt mode.4 = ingang ;startbit delayus tijd_RC6_Bit controlemode.4 = 1 - ingang ;startbit controle delayus tijd_RC6_Bit mode.3 = ingang ;ophalen mode bit 2 delayus tijd_RC6_Bit controlemode.3 = 1 - ingang delayus tijd_RC6_Bit mode.2 = ingang ;ophalen mode bit 1 delayus tijd_RC6_Bit controlemode.2 = 1 - ingang delayus tijd_RC6_Bit mode.1 = ingang ;ophalen mode bit 0 delayus tijd_RC6_Bit controlemode.1 = 1 - ingang delayus tijd_RC6_Bit mode.0 = ingang ;ophalen trailer bit deze bit duurt langer delayus tijd_RC6_Trailer controlemode.0 = 1 - ingang ;ophalen controle van de trailerbit delayus tijd_RC6_Trailer ;tijd tot het begin van de adresbits adrescode.7 = 1 ;ophalen controlebits delayus tijd_RC6_Bit controleadres.7 = 1- ingang delayus tijd_RC6_Bit adrescode.6 = 1 delayus tijd_RC6_Bit controleadres.6 = 1- ingang delayus tijd_RC6_Bit adrescode.5 = 1 delayus tijd_RC6_Bit controleadres.5 = 1- ingang delayus tijd_RC6_Bit adrescode.4 = 1 delayus tijd_RC6_Bit controleadres.4 = 1- ingang delayus tijd_RC6_Bit adrescode.3 = 1 delayus tijd_RC6_Bit controleadres.3 = 1- ingang delayus tijd_RC6_Bit adrescode.2 = 1 delayus tijd_RC6_Bit controleadres.2 = 1- ingang delayus tijd_RC6_Bit adrescode.1 = 1 delayus tijd_RC6_Bit controleadres.1 = 1- ingang delayus tijd_RC6_Bit adrescode.0 = 1 delayus tijd_RC6_Bit controleadres.0 = 1- ingang delayus tijd_RC6_Bit ;tijd tot het starten van het ophalen van de comandocode commandocode.7 = 1 ;ophalen van de commandocode delayus tijd_RC6_Bit controlecommando.7 = 1- ingang delayus tijd_RC6_Bit commandocode.6 = 1 delayus tijd_RC6_Bit controlecommando.6 = 1- ingang delayus tijd_RC6_Bit commandocode.5 = 1 delayus tijd_RC6_Bit controlecommando.5 = 1- ingang delayus tijd_RC6_Bit commandocode.4 = 1 delayus tijd_RC6_Bit controlecommando.4 = 1- ingang delayus tijd_RC6_Bit commandocode.3 = 1 delayus tijd_RC6_Bit controlecommando.3 = 1- ingang delayus tijd_RC6_Bit commandocode.2 = 1 ;ophalen van de commandocode delayus tijd_RC6_Bit controlecommando.2 = 1- ingang delayus tijd_RC6_Bit commandocode.1 = 1 delayus tijd_RC6_Bit controlecommando.1 = 1- ingang delayus tijd_RC6_Bit commandocode.0 = 1 delayus tijd_RC6_Bit controlecommando.0 = 1- ingang end if ;-------------------------------controle van de opgehaalde resultaten------------------------------ if adrescode = controleadres and commandocode = controlecommando and mode = controlemode then fout=0 else fout=1 end if ;------------------------------- verwerking van de resultaten voor RC5---------------------------------------- if type = 0 and fout = 0 and commandocode = 12 and adrescode = 0 then ; in en uitschakelen van het toestel devicestatus = 1 - devicestatus elseif type = 0 and fout = 0 and devicestatus = 0 and commandocode = 16 and adrescode = 0 then ; volume + if not straffe_lamp != 250 then straffe_lamp= straffe_lamp + 10 end if elseif type = 0 and fout = 0 and devicestatus = 0 and commandocode = 17 and adrescode = 0 then ; Volume - if straffe_lamp != 0 then straffe_lamp= straffe_lamp - 10 end if end if ;---------------------------------verwerking van de resultaten vor RC6---------------------------------------- if type = 1 and fout = 0 and adrescode =0 and commandocode =12 then ;hier kan ingestelt worden wanneer devicestatus = 1 - devicestatus elseif type = 1 and fout = 0 and devicestatus = 0 and adrescode =0 and commandocode =50 then if not straffe_lamp != 250 then straffe_lamp= straffe_lamp + 10 end if elseif type = 1 and fout = 0 and devicestatus = 0 and adrescode =0 and commandocode =51 then if straffe_lamp != 0 then straffe_lamp= straffe_lamp - 10 end if end if ;-------------------------------aansturen van de uitgangen---------------------------------------------------- if devicestatus = 1 then uitgang1 = 1 uitgang2 = 1 uitgang3 = 1 LEDA = 1 else uitgang1 = 0 uitgang2 = 0 uitgang3 = 0 LEDA = 1 end if ;-----------------------------------delay en terugkeren naar het begin------------------------------------------ delayms 2000 ;tijd die minstens nodig is om er zeker van te zijn dat de drukknop los gelaten kan worden LEDA=0 adrescode = 0 mode = 0 commandocode = 0 controleadres = 0 controlecommando = 0 controlemode = 0 PWM PORTA.6, straffe_lamp, 5 wend