Friday, 21 February 2020
Main Menu
Home Home
Shop Shop
News News
Products Products
Application Notes Application Notes
Publications Publications
Links Links
Support Center Support Center
Downloads Downloads
Forum Forum
Resellers Resellers
Contact Us Contact Us
Updates Updates
MCS Wiki MCS Wiki
Online Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login


If you have problem after log in with disappeared login data, please press F5 in your browser

RSS News

AN #120 - Sony IR receiver using the SIRCS protocol Print
Sony IR receiver using the SIRCS protocol

This application note was submitted by Alex Shepherd

This AN shows a good usage of the input capture function of the timer. You can use the AN to decode other formats as well.

Download source code

' AVR Sony SIRCS IR Remote Decoder
' Copyright (c) 2002 Alex Shepherd email:
' Here is a alternative to AN20 to decode the output of SONY IR Remote that uses
' the SIRCS Protocol and decodes 12, 15 and 20 bit codes

' It uses a 3 pin integrated demodulator/decoder IR Decoder device called
' an IS1U621 see
' but there are a number of similar devices.
' This program works by connecting the Data output from the IS1U621 to the ICP
' Pin of the AVR and then uses the Capture1 interrupt to measure the time
' between each bit to know if it is a 1 or a 0 and then uses Compare1a interrupt
' to detect that there has not been a bit toggle for several bit times to
' detect the end of the packet.
' I ran the code on a AT90S8535 @ 8MHz and also a ATMega8 @ 10MHz, however
' the timings below are for the AT90S8535 @ 8MHz
' If you need to change the XTAL frequency then look down at line: 126 and
' uncomment the Print line there so that it prints out the clock counts per data
' line toggle so you get an idea of the count distributions.
' Then alter the count thresholds on lines 47 and 48 so that you detect the
' initial start bit which is longer than the rest and then observe the time
' differences between the other bits and pick a number between the average of
' the 1 or 0 count averages.
' I got a startbit of about 450 counts, a 1 bit of about 55 counts and a 0 bit
' of about 37 counts so I chose 200 and 46 for the two thresholds
' Your mileage may vary...

Config Timer1 = Timer , Prescale = 256 , Capture Edge = Rising , Compare A No_output = Disconnect
Config Serialout = Buffered , Size = 150

On Capture1 Capture1_int
On Compare1a Compare1a_int

Dim Ready As Byte
Dim Address As Word
Dim Code As Word
Dim Startbitperiod As Byte
Dim Normalbitperiod As Byte

' If you change the XTAL frequency then you will need to alter these 3 values
= 200
= 45

' Set the Compare threshold to detect end of packet after 4 bit times of no activity
Compare1a = Normalbitperiod * 4

Enable Interrupts
Enable Capture1
Enable Compare1a

Lcd "Sony IR Receiver"

If Ready <> 0 Then
= 0

Lcd "Address: " ; Address ; " Code: " ; Code ; " "

End If


Dim Period As Word
Dim Command As Long
Dim Bitcount As Byte
Dim Shiftcount As Byte

' Uncomment the line below to see the bit patterns to debug new
' command sizes not allowed for in the code
' Print "B " ; Bitcount ; " C " ; Bin(command)

= 1

If Bitcount = 12 Or Bitcount = 15 Or Bitcount = 20 Then
= 31 - Bitcount
Shift Command , Right , Shiftcount
= 0

End If

= Command And &H0000007F

Shift Command , Right , 7

= Command

= 0


Timer1 = 0

= Capture1

If Period >= Startbitperiod Then
= 0
= 0

If Period > Normalbitperiod Then
= Command Or &H80000000
End If

Shift Command , Right

Incr Bitcount
End If

' Uncomment this line to print out the bit times see how to tweak the
' Period thresholds if you change the XTAL frequency
' Print "P " ; Period ; " B " ; Bitcount