Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

36KHz Ir rc5 send ATTiny45

Status
Not open for further replies.

MicZ

New Member
hi
this sample is to send any rc5 code without Keyboard is adaptation of ATTiny2313 sample

Code:
'-------------------------------------------------------------------------------
'Name                     : 36KHzKey6.bas
'By Mic-Josi 2013/02 build 1.0
'Language BASCOM AVR build 2.0.7.5  Demo Version
'purpose                  : RC5 code 36KHz by Timer0 CTC mode
'micro                    : ATTINY45
'suited for demo          : yes
'sample adaptation of sample  RC5 ATTiny2313 "rc_tx1a.bas"who run with 12 keys' keyboard  
'this sample run without keyboard only set "Key" for command and Rc5_address for device
'in this sample the French TV channel is selectionned "Key = 6" 
'-----------------------------------------------------------------------------------------
'you must Setting a Divide clock by 8 FuseBit to OFF 


$regfile = "attiny45.dat"                                   ' microcontroler

$crystal = 8000000                                          '8 Mhz internal oscillateur 

'****** you can also use theses settings with an ATTiny13******* not tested
$hwstack = 16                                               '  use 16 for the hardware stack

$swstack = 16                                               '  use 16 for the SW stack

$framesize = 16                                             ' use 16 for the frame space
'*******************************************************************************
Dim Key As Byte Simule L                                    'simulate keyboard key pressed 
Dim Rc5_bit_nr As Byte                                      ' device adresse  "0 = TV"
Dim Toggle_bit As Boolean                                   ' repeating key
Dim Rc5_address As Byte                                     ' channel selection "6"
"Dim Rc5_command As Byte

Const Carrier_on = &B01000000                               'IR 36kHz carrier on
Const Carrier_off = &B11000000                              'IR 36 KHz carrier off


Declare Sub Logic_0                                         'bit 0
Declare Sub Logic_1                                         'bit 1

Config Timer0 = Timer , Prescale = 1 , Compare A = Toggle , Clear Timer = 1
Timer0 = 0


'110 = 36KHz   104 = 38 KHz
 Ocr0a = 110                                                '36KHz carrier

Tccr0a = Carrier_off
Toggle_bit = 1                                              ' ask for répétition
Rc5_address = 0                                             ' TV device
Do
  Key = 6                                                   ' channel 6
  Waitms 1

   Ddrb.0 = 1
                                             'set OC0 (Pb.1) = IR LED carrier out 
    Logic_1                                                 '1er start bit
    Logic_1                                                 'second start bit
    If Toggle_bit = 0 Then Logic_0 Else Logic_1
     Rc5_command = Lookup(key , Rc5_commands)               'reding data commande RC-5
     For Rc5_bit_nr = 4 To 0 Step -1                        '5 bit addresse, msb first
      If Rc5_address.rc5_bit_nr = 0 Then Logic_0 Else Logic_1
    Next

    For Rc5_bit_nr = 5 To 0 Step -1                         '6 bit commande, msb first
      If Rc5_command.rc5_bit_nr = 0 Then Logic_0 Else Logic_1
    Next

    Tccr0a = Carrier_off
    Waitms 87                                               'trame delay 


     Loop

End                                                         'end program

 Sub Logic_0
  Tccr0a = Carrier_on
  Waitus 883
  Tccr0a = Carrier_off
  Waitus 884
End Sub

Sub Logic_1
  Tccr0a = Carrier_off
  Waitus 883
  Tccr0a = Carrier_on
  Waitus 884
End Sub


Rc5_commands:
Data 1 , 2 , 3 , 0                                          'column 4 not used  (3x4 keypad)
Data 4 , 5 , 6 , 0
Data 7 , 8 , 9 , 0
Data 10 , 11 , 12 , 0
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top