joi, 16 ianuarie 2014

Afișarea codurilor telecomenzii RC5

     Precum scriam în altă postare, am reușit să decodific codurile telecomenzii RC, inspirându-mă de aici. Schema folosită este cea de acolo, la care am făcut modificări, deoarece am folosit 16F690.


 '****************************************************************  
 '* Name  : Show IR code.BAS                   
 '* Author :                            
 '* Notice :                            
 '*     :                           
 '* Date  : 07.12.2013                      
 '* Version : 1.0                         
 '* Notes  : 16F690                        
 '* inspirat dupa http://www.picbasic.nl/frameload_uk.htm?http://www.picbasic.nl/rc5_display_uk.htm   
 '****************************************************************  
   ANSEL=0   'toate porturile sunt digitale  
   ANSELH=0               
 ;******** legaturi display 2x16 caractere *******  
      DEFINE LCD_DREG  PORTC    ;PortC folosit pentru date  
      DEFINE LCD_DBIT  0        ;pinul RC0 este primul pin de date conectat  
      DEFINE LCD_RSREG  PORTC   ;portC folosit pt. pinul RS  
      DEFINE LCD_RSBIT  5       ;RC5 - Register select pin  
      DEFINE LCD_EREG  PORTC    ;foloseste PortB pentru pinul E  
      DEFINE LCD_EBIT  4        ;RC4 - Enable pin  
      DEFINE LCD_BITS  4        ;bus pe 4 biti  
      DEFINE LCD_LINES  2       ;LCD cu doua randuri de caractere  
      ;Pause 400  
      DEFINE OSC 4  
 ;Attention: The TSOP1736 (= 36kHz IR-receiver) must connected via a 470 Ohm resistor to   
 ;      +5V and over the + and - pin a tantalium C of minimal 0,1uF !          
 ;      Connection TSOP1736: || |                            
 ;                           -+ s                                      
   TRISA =000100  
   TriSC.6=0:TrisC.7=0  
 ;Normal aliases (constants)  
   Glitch    con 52     ;Max 255: Reduction glitches  
   LED_Time  con 500    ;mSec: Error LED's burning time  
   Ok        con 50     ;Max 255: Controltime of the RC5 code is received ok  
 ;Logic aliases (constants)   
   AAN     con 0    ;Reversed ON  
   FALSE   con 0  
   OFFF    con 0  
   ONN     con 1  
   TRUE    con 1  
   UIT     con 1    ;Reversed OFF  
 ;Port aliases  
   LED_Yellow  var PORTA.1 ;glitch-uri        
   LED_Red     var PORTA.0 ;semnal slab sau nu e RC5/RC6  
   LED_Green   var PORTC.7 ;semnal infrarosu receptionat  
   LED_Toggle  var PORTC.6 ;bit-ul toggle  
   IR_Receiver var PORTA.2 ;TSOP1736  
 ;BYTE  
  Command      var BYTE  ;RC5/RC6 command byte  
  CommandOld   var BYTE  
  Systeem      var BYTE  ;RC5/RC6 system byte  
  SysteemOld   var BYTE  
  BD1          var BYTE  ;Byte Dummy  
 ;BIT  
  CodeRC5X    var BIT  ;TRUE when it's RC5X code else...  
  CodeRC6     var BIT  ;...TRUE if it's RC6 code (else RC5)  
  CodeRC6Old  var BIT  ;By switching between RC6 and RC5/RC5X must the LCD been updated  
  ToggBit     var BIT  ;RC5/RC6 toggle bit  
  Value       var BIT  ;Argument for subroutine "BitOphalen"  
  ID1         var BIT  ;bIt Dummy  
   CLEAR  
   pauseus 500         ;LC-Display stabilize  
   Lcdout $FE,1        ;clear display  
   Lcdout $FE,2        ;return home  
   Lcdout "Decoder UK V-1"  ;Program name and version  
   Lcdout $FE,$C0,"www.picbasic.nl"  
 GOTO Start          ;Jump over the subroutines  
 ;SUBROUTINES                                                        
 BitOphalen:  
  BD1 = 0  
  Value = IR_Receiver                       ;Make value 0 or 1 depending from received IR-code  
  WHILE IR_Receiver = Value AND BD1 < Ok ;Level must change within time 'Ok'  
   BD1=BD1+1  
  WEND  
  IF Ok = BD1 THEN ErrorReceiving  ;No level-change whitin the 'Ok' time  
  IF CodeRC6 = TRUE THEN  
   Value = 1 - Value     ;RC6 is inverted to RC5/RC5X  
   pauseus 625           ;525 - 725 ;(889us / 2 = 444) + half from this time to come in the middle of the next bit; 444+222 = 666, - a few usec's for the program itself = about 625  
  ELSE  
   pauseus 850       ;950 - 1600  1100  
  ENDIF  
  RETURN  
 ;MAINPROGRAM                                                        
 Start:  
  LED_Green =  OFFF  
  LED_Yellow = OFFF  
  LED_Red  =   OFFF  
  BD1 = 0  
  WHILE IR_Receiver = UIT: WEND        ;Wait for IR receive  
  WHILE IR_Receiver = AAN AND BD1 &lt ; Glitch  
   BD1=BD1+1  
  WEND  
  
  CommandOld = Command    ;Save old values for repair in case of a error  
  SysteemOld = Systeem  
  LED_Green = ONN         ;Received an IR-signal  
 ;Find out which protocol----------------  
  BD1 = 0  
  Command = 0         ;Eerst 0 maken omdat RC5/RC5X bits 6 & 7 niet overschrijft, als RC6 deze eerder hoog heeft gemaakt, blijven deze hoog (=fout)  
  Systeem = 0         ;Eerst 0 maken omdat RC5/RC5X bits 5,6,7 niet overschrijft, als RC6 deze eerder hoog heeft gemaakt, blijven deze hoog (=fout)  
  WHILE BD1 < 255 AND IR_Receiver = AAN   
   BD1=BD1+1  
  WEND  
  CodeRC5X = FALSE  
  CodeRC6 = FALSE  
   if BD1>25 and BD1<90 then     ;RC5X  
      CodeRC5X = TRUE  
      Command.6 = 1  
      pauseus 800                      ; 900 - 1700 (RC5X)   1280  
   endif  
   if BD1>90 then                   ;RC6  
     CodeRC6  = TRUE  
   endif  
   if BD1<25 or BD1>90 then   
     pauseus 1700                      ;1800 - 2600 (RC5)   2180   
   endif  
 ; --------------------------------------  
  IF CodeRC6 = TRUE THEN  
   WHILE IR_Receiver = UIT :WEND ;00  
   WHILE IR_Receiver = AAN :WEND ;1  
   WHILE IR_Receiver = UIT :WEND ;0  
   WHILE IR_Receiver = AAN :WEND ;1  
   WHILE IR_Receiver = UIT :WEND ;0  
   pauseus 2000      ;Wait till the last '1' from the header comes (1778us), by this it come in the middle of the first toggle bit  
   LED_Toggle  = IR_Receiver  
   ToggBit    = IR_Receiver  
   WHILE ToggBit = IR_Receiver :WEND               ;Wait till the inverted part from the togglebit comes  
   pauseus 1100              ;1000 - 1200         ; By this it comes in the middle of the first system bit  
   GOSUB BitOphalen  
   Systeem.7 = Value  
   GOSUB BitOphalen  
   Systeem.6 = Value  
   GOSUB BitOphalen  
   Systeem.5 = Value  
  ELSE  
   GOSUB BitOphalen  
   LED_Toggle = Value  
  ENDIF  
  GOSUB BitOphalen  
  Systeem.4 = Value  
  GOSUB BitOphalen  
  Systeem.3 = Value  
  GOSUB BitOphalen  
  Systeem.2 = Value  
  GOSUB BitOphalen  
  Systeem.1 = Value  
  GOSUB BitOphalen  
  Systeem.0 = Value  
  IF CodeRC6 = TRUE THEN   ;RC5/RC5X has no 6th and 7th bits  
   GOSUB BitOphalen  
   Command.7 = Value  
   GOSUB BitOphalen  
   Command.6 = Value  
  ENDIF  
  GOSUB BitOphalen  
  Command.5 = Value  
  GOSUB BitOphalen  
  Command.4 = Value  
  GOSUB BitOphalen  
  Command.3 = Value  
  GOSUB BitOphalen  
  Command.2 = Value  
  GOSUB BitOphalen  
  Command.1 = Value  
  GOSUB BitOphalen  
  Command.0 = Value  
  IF Systeem <> SysteemOld OR Command <> CommandOld OR CodeRC6 <> CodeRC6Old THEN ;Without this line the LCD blinks when receiving IR signal (because of CLS)  
   Lcdout $FE,1        ;clear display  
   IF CodeRC5X = TRUE THEN  
    Lcdout "RC5X"  
   ELSEIF CodeRC6 = TRUE THEN  
    Lcdout "RC6"  
   ELSE  
    Lcdout "RC5"  
   ENDIF  
   lcdout  " Protocol"  
   pause 1000         ;Time for indication RC5, RC5X or RC6 protocol  
   Lcdout $FE,1        ;clear display  
   Lcdout "Sys:", DEC Systeem," ",BIN Systeem  
   Lcdout $FE,$C0,"Com:", DEC Command," ",BIN Command  
  ENDIF  
 ;Don't put this line at the beginning near Start, else is would also reset when a glitch is received  
  CodeRC6Old = CodeRC6    ;By switching between RC6 and RC5/RC5X must the LCD been updated  
 GOTO Start  
 ErrorGlitch:  
  LED_Yellow = ONN       ;Receive error (No RC5 code or glitch)  
  pause LED_Time  
 GOTO Start  
 ErrorReceiving:  
  LED_Green = OFFF  
  LED_Red  = ONN       ;No RC5 code or no optimal receiving  
  pause LED_Time  
  Command = CommandOld    ;Repair Command and Systeem  
  Systeem = SysteemOld  
 GOTO Start  

Niciun comentariu:

Trimiteți un comentariu