' attiny13 remote control test
'
' find RC5 remote control
'
' PB0 output if RC5
' PB1 output if TV
' PB2 output switched
' PB4 output Com1
' PB3 input RC5
'
' GS 2014/4
'
'***************************************************************************
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License.
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY;
'***************************************************************************
'
' ATtiny45 dip
' (PCINT5/RESET/ADC0/dW) PB5 VCC
' (PCINT3/XTAL1/CLKI/OC1B/ADC3) PB3 PB2 (SCK/USCK/SCL/ADC1/T0/INT0/PCINT2)
' (PCINT4/XTAL2/CLKO/OC1B/ADC2) PB4 PB1 (MISO/DO/AIN1/OC0B/OC1A/PCINT1)
' GND PB0 (MOSI/DI/SDA/AIN0/OC0A/OC1A/AREF/PCINT0)
'
'***************************************************************************
'use byte library for smaller code
'$lib "mcsbyte.lbx"
$regfile = "attiny13.dat"
$crystal = 1200000
'$crystal = 8000000
$hwstack = 8
$swstack = 8
$framesize = 4
Led0 Alias Portb.0 'output if RC5
Led1 Alias Portb.1 'output if TV
Led2 Alias Portb.2 'output switched
Dim Address As Byte , Command As Byte , Tog As Byte
Dim Cnt As Byte
Portb = &B00001000
Ddrb = &B00010111
'CLKPR = &B10000000 'Clock Prescaler Change Enable
'CLKPR = &B00000000 'Clock Division Factor=0, 8 MHz
Config Rc5 = Pinb.3
Acsr.acd = 0 ' switch off analog comparator
Open "comb.4:9600,8,n,1,INVERTED" For Output As #1
Print #1 , "Wait for RC5"
Enable Interrupts
Do
Getrc5(address , Command)
If Address < 255 Then
Tog = Command And &B10000000
Command = Command And &B01111111 'clear the toggle bit
Led0 = 1 'RC5
If Address = 0 Then 'TV '
Led1 = 1
End If
If Command = 0 Then 'switch on if 0 '
Led2 = 1
Else
Led2 = 0
End If
Disable Interrupts 'debug print
Print #1 , " Adr:" ; Address ; " Cmd:" ; Command
Enable Interrupts
End If 'If Address < 255
Incr Cnt
If Cnt = 20 Then
Led0 = 0
Led1 = 0
Cnt = 0
End If
Loop
End