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  

miercuri, 15 ianuarie 2014

Afișarea codurilor telecomenzii NEC

      Despre protocolul NEC se pot găsi o mulțime de informații pe internet, iar pentru decodarea codului am găsit pe forumul picbasic ceva ce se poate folosi la realizarea unui montaj care afișează pe un LCD 2x16 adresa și comanda butonului apăsat. Eu am folosit 16F886, dar se poate adapta ușor la orice PIC.


 '****************************************************************  
 '* Name  : Decode NEC3.BAS                   
 '* Author : Nica Florin                     
 '* Notice : Decodare semnale telecomanda de modulator FM     
 '*     :                           
 '* Date  : 19.12.2013                      
 '* Version : 1.0                         
 '* Notes  : 16F886                        
 '*     :                           
 '****************************************************************  
   
 @ __config _CONFIG1,_WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF  
 @ __config _CONFIG2, _WRT_OFF  
      ;oscilator intern 4 MHz  
     
   ANSEL=0             ;porturile A si B sunt digitale  
   ANSELH=0  
   ADCON0.0=0  
   SSPCON.5=0            ;dezactiveaza portC serial  
   RCSTA.7=0  
 ;******** legaturi display 2x16 caractere *******  
  DEFINE LCD_DREG  PORTC       ;PortC folosit pentru date  
      DEFINE LCD_DBIT  4     ;pinul RC4 este primul pin de date conectat  
      DEFINE LCD_RSREG  PORTC   ;portC folosit pt. pinul RS  
      DEFINE LCD_RSBIT  2         ;RC2 - Register select pin  
      DEFINE LCD_EREG  PORTC   ;foloseste PortC pentru pinul E  
      DEFINE LCD_EBIT  3         ;RC3 - Enable pin  
      DEFINE LCD_BITS  4         ;bus pe 4 biti  
      DEFINE LCD_LINES  2         ;LCD cu doua randuri de caractere  
      Pause 500  
 ;******* variabile si constante ***********  
   Leader VAR WORD      ' will be up to 900 for a 9mS leader pulse  
   BtnVal VAR BYTE[32]    ' holds 32 pulse results  
   DByte1 VAR BYTE      ' address byte  
   DByte2 VAR BYTE      ' inverse of address byte  
   DByte3 VAR BYTE      ' command byte  
   DByte4 VAR BYTE      ' inverse of command byte  
   X   VAR BYTE      ' loop count  
   
     
   buzzer    var PortC.1    ; pin 12 - conexiune buzzer  
   IR_Receiver var PORTB.0    ; pin 21 - conexiune TSOP1736  
   
     
 ;******* intrari/iesiri **********    
   TrisB.0=1                           ;RB0 input                       
   TrisC.1=0               ;RC1 output       
    
  Main:   
    PULSIN IR_Receiver,0,Leader    ' leader pulse is ~9mS low-going  
    IF Leader < 850 THEN Main  
      
    FOR X = 0 TO 31          ' grab 32 incoming pulses  
      PULSIN IR_Receiver,1,BtnVal(X) ' now measuring high-going pulse widths  
    NEXT X  
      
    ' now we'll decode 4 bytes from 32 pulses  
    FOR X = 0 TO 7           ' sort 1st 8 pulses  
      IF BtnVal[X] > 150 THEN    ' > 150 x 10uS = > 1.5mS pulse period  
        DByte1.0[X]=1  
      ELSE  
        DByte1.0[X]=0  
      ENDIF  
    NEXT X  
      
    FOR X = 8 TO 15          ' sort 2nd 8 pulses, etc....  
      IF BtnVal[X] > 150 THEN  
        DByte2.0[X-8]=1  
      ELSE  
        DByte2.0[X-8]=0  
      ENDIF  
    NEXT X  
      
    FOR X = 16 TO 23  
      IF BtnVal[X] > 150 THEN  
        DByte3.0[X-16]=1  
      ELSE  
        DByte3.0[X-16]=0  
      ENDIF  
    NEXT X  
      
    FOR X = 24 TO 31  
      IF BtnVal[X] > 150 THEN  
        DByte4.0[X-24]=1  
      ELSE  
        DByte4.0[X-24]=0  
      ENDIF  
    NEXT X  
      Sound buzzer,[85,10]  
        
    Lcdout "Adress  ", dec DByte1  
    Lcdout $FE,$C0  
    Lcdout "Command ", dec DByte3  
    pause 3000  
    Lcdout $FE,1        ;clear display  
    Lcdout $FE,2        ;return home  
      
    GOTO Main  
                        
   

vineri, 10 ianuarie 2014

Reglare iluminare LED-uri din telecomandă

   Astăzi am pus în sfârșit la treabă modulul PWM inclus în 16F886, am adăugat senzorul IR și a ieșit ... un  dimmer. Lanterna este alimentată prin BD 901. Trebuie să mai studiez modul cum se poate adapta un triac pentru reglarea intensității luminoase a unui bec, ceva în felul acesta.

joi, 9 ianuarie 2014

Termometru cu 18B20

   Simplu și eficient, termometru cu senzorul de temperatură digital 18B20. Firele de conexiune, din câte se pare, pot fi prelungite mai mulți metri, și deci se poate monta și în afara locuinței pentru măsurarea temperaturii exterioare.

luni, 6 ianuarie 2014

Cod de securitate I

    Inspirat de aici m-am apucat să construiesc și eu ceva asemănător și am făcut mai multe variante. Am folosit 16F690, o tastatură, un LCD 2x16, câteva rezistențe. A ieșit ce se vede mai jos...
     Pentru acționare se formează cod#. Codul este format din 5 cifre, se poate schimba în orice moment de la tastatură (codvechi*codnou#). Față de cel de pe jap.hu, are avantajul că nu necesită încă un circuit integrat pentru comanda LCD-ului.
     Am realizat și o variantă cu telecomandă RC5.
                                    
  Pentru decodarea codului RC5 m-am inspirat de aici.

Motor pas cu pas unipolar controlat din telecomandă

    Când am realizat prima dată circuitul, nu a funcționat chiar cum trebuia din pricina sursei de alimentare. După aceea am alimentat montajul cu PIC din calculator, prin intermediul programatorului, iar circuitul de comandă al motorului dintr-o sursă veche de PC. Schema este inspirată din cea de mai jos, la care am făcut niște modificări.
Am folosit 16F886, am eliminat buffer-ul 4050 și am pus rezistențe de 3k în loc. De asemenea, am eliminat push-butoanele și am folosit un senzor infraroșu TSOP 1736. Ca tranzistoare am folosit BD 901. Pe forumul PicBasic am găsit pe undeva o rutină de decodare a protocolului NEC și am integrat-o în program. Telecomanda este de modulator FM .

duminică, 5 ianuarie 2014

Ceas cu 16F628A

   Ceasul lui Bogdi. Toți cei care l-au făcut îl laudă. Și eu de asemenea. După aproape două luni de funcționare neîntreruptă, are 5 secunde abatere. În acest timp au fost perioade de câteva ore când a funcționat pe baterii (i-am pus 3 baterii din acelea cum sunt la brichetele cu LED). Ca alimentare, am desfăcut un încărcător mai vechi de telefon Sony Ericsson și am luat plăcuța de acolo. A ieșit un ceas foarte compact și care consumă foarte puțin, în jur de 50 mA.