Advertisement  

Saturday, 07 December 2024
     
 
Main Menu
Home Home
Shop Shop
News News
BASCOM-AVR BASCOM-AVR
BASCOM-8051 BASCOM-8051
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-AVR Help BASCOM-AVR Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login
Username

Password

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

RSS News
 
     
 

 
   
     
 
AN #157 - Implementation of IR NEC protocol Print
Implementation of IR NEC protocol
By Rubashka Vasiliy , Ukraine

NEC Protocol

To my knowledge the protocol I describe here was developed by NEC. I've seen very similar protocol descriptions on the internet, and there the protocol is called Japanese Format.
I do admit that I don't know exactly who developed it. What I do know is that it is used in my late VCR produced by Sanyo and was marketed under the name of Fisher. NEC manufactured the remote control IC.
This description was taken from the VCR's service manual. Those were the days, when service manuals were fulled with useful information!

Features
  • 8 bit address and 8 bit command length
  • Address and command are transmitted twice for reliability
  • Pulse distance modulation
  • Carrier frequency of 38kHz
  • Bit time of 1.12ms or 2.25ms
Modulation

The NEC protocol uses pulse distance encoding of the bits. Each pulse is a 560µs long 38kHz carrier burst (about 21 cycles). A logical "1" takes 2.25ms to transmit, while a logical "0" is only 1.12ms. The recommended carrier duty-cycle is 1/4 or 1/3.

Protocol

NEC Pulse Train

The picture above shows a typical pulse train of the NEC protocol. With this protocol the LSB is transmitted first. In this case Address $59 and Command $16 is transmitted. A message is started by a 9ms AGC burst, which was used to set the gain of the earlier IR receivers. This AGC burst is then followed by a 4.5ms space, which is then followed by the Address and Command. Address and Command are transmitted twice. The second time all bits are inverted and can be used for verification of the received message. The total transmission time is constant because every bit is repeated with its inverted length. If you're not interested in this reliability you can ignore the inverted values, or you can expand the Address and Command to 16 bits each!

NEC Repeat

A command is transmitted only once, even when the key on the remote control remains pressed. Every 110ms a repeat code is transmitted for as long as the key remains down. This repeat code is simply a 9ms AGC pulse followed by a 2.25ms space and a 560µs burst.

NEC Sequence

Example Commands

The table below lists the messages sent by the remote control of my late Fisher 530 VCR (it served us well during its 20 years long life).

NEC Message Key Function
$68-$00 Play
$68-$01 Rec
$68-$02 Audio Dub
$68-$03 Frame Adv
$68-$04 Slow
$68-$05 Quick
$68-$06 Cue
$68-$07 Review
$68-$08 FF
$68-$09 Rew
$68-$0A Stop
$68-$0B Pause/Still
$68-$0C Up key
$68-$1E Down key

Source code:


'****************************************************************************
'* Filename    : IR NEC by http://www.sbprojects.com/knowledge/ir/ir.htm    *
'* Revision    : 1.0                                                        *
'* Controller  : ATMEGA8                                                    *
'* Compiler    : BASCOM-AVR 1.11.8.3 DEMO                                   *
'* Author      : Rubashka Vasiliy , Ukraine , 2007                          *
'* WWW         : http://ledeffects.net                                      *
'* Mail        : info@ledeffects.net                                        *
'****************************************************************************
'*                                                                          *
'*       IR  36kHz         ATMEGA  8                                         *
'*         .-O-.           .--_/--.                                        *
'*         |___|   /-[10k]-|Res    |                                        *
'*          |||    |       |       |                                        *
'*       /--/||    ---   |       |                                        *
'*       |   |*--------+---|Pd2 Pc2|----[510]-----|>|----  LED             *
'*       |   ||        |   |       |                     |                  *
'*       |   |-[47k]--*   |       |                     |                  *
'*       |   *--[100]--*---|Vcc GND|---------           |                  *
'*       *---+---------+---|GND    |         |           |                  *
'*       |   |     /---+---|Pb6 Vcc|------- |           |                  *
'*       |   |     | /-+---|Pb7 Pb5|----- | |           |                  *
'*       |   |     | | |   |    Pb4|--- | | |           |                  *
'*       |   |     | | |   |       |   | | | |           |                  *
'*       |   |     | | |   |    Pb2|- | | | |           |                  *
'*       |   |     | | | /-|Pb0    | | | | | |           |                  *
'*       |   |     | | | | '-------' | | | | |           |                  *
'*       |   |     | | | --------- | | | | |           |                  *
'*       |   |     | | -----------+-+-+-+-*-+-----*-----+-----*-------    *
'*       |  +|10,0 | ----------- | | | | | |     |0,1  |    +|100,0  |    *
'*       |  ---    ----------- | | | | | | |    ---    |    ---      |    *
'*       |  ---                | | | | | | | |    ---    |    ---      |    *
'*       |   |                 | | | | | | | |     |     |     |       |    *
'*       ---*-----------------+-+-+-+-+-+-+-*-*-*-*-----*-----*----- |    *
'*                             | | | | | | | | | |       |           | |    *
'*                            .-------------------.     ---          V V    *
'*                            |D D R E D D V V R V|                         *
'*                            |6 7 s   4 5 c s w 0|                  - +    *
'*                            '-------------------'                  5 5    *
'*                            ":::::::::::::::::::"                  V V    *
'*                            ":::::LCD::16*2:::::"                         *
'*                            ":::::::::::::::::::"                         *
'*                            """""""""""""""""""""                         *
'*                                                                          *
'*                                                                          *
'****************************************************************************
$regfile = "m8def.dat"
$crystal = 8000000                                          'Internal RC oscillator 8 MHz
$lib "lcd4.lbx"
Config Lcdpin = Pin , Rs = Portb., E = Portb., Db4 = Portb., Db5 = Portb., Db6 = Portb., Db7 = Portb.7
Config Lcd = 16 * 2
Config Pind.= Input
Config Portc.= Output
Config Timer0 = Timer , Prescale = 256                      '8000000/256=31250 Hz
Config Int0 = Falling                                       'Interruption on Falling
Stop Timer0
Enable Timer0
Enable Int0
Enable Interrupts
On Timer0 Tikers                                            'work on timer
On Int0 Infrared                                            'work on interruption

Dim Tik As Word 'counter of teaks of timer
Dim Byt As Byte 'counter accepted bit
Dim Repeat_flag As Bit 'flag of repetition
Dim Start_flag As Bit 'flag of start condition
Dim Address As Byte 'byte of address
Dim Command As Byte 'byte of command
Dim Address_1 As Byte 'direct byte of address
Dim Command_1 As Byte 'direct byte of command
Dim Address_0 As Byte 'indirect byte of address
Dim Command_0 As Byte 'indirect byte of command
Dim Summa As Word

Cursor Off 'Switch Off cursor
'################################################################################################################

Do 'Main cycle
Cls 'Clean LCD
Lcd Address ; " " ; Command                                 'Lcd ADDRESS and COMMAND
If Command = 8 Then Portc.= 1                             'If pressed key "P+" - to include LED
If Command = 240 Then Portc.= 0                           'If pressed key "P-" - to switch off LED
Waitms 10                                                   'Delay 10 ěń
Loop
End 'End of main cycle

'################################################################################################################

 Tikers: 'work on timer
 Timer0 = 253                                               '31250/(256-253)=10416,66 Hz (96 ěęń)
 Incr Tik
 If Tik >= 1200 Then 'if 1200 teaks, have thrown all in source condition
 Tik = 0
 Repeat_flag = 0
 Start_flag = 0
 Address_1 = 0
 Command_1 = 0
 Address_0 = 0
 Command_0 = 0
 Address = 0
 Command = 0
 Stop Timer0
 End If
 Return
'################################################################################################################

 Infrared: 'work on interruption
 Start Timer0

 If Tik >= 139 And Tik < 150 Then 'if has happenned from 139 before 150 teaks - "START"
  Address = 1
  Repeat_flag = 0
  Start_flag = 1
  Address_1 = 0
  Command_1 = 0
  Address_0 = 0
  Command_0 = 0
 End If

 If Tik >= 116 And Tik < 139 Then 'if has happenned from 116 before 138 teaks - "REPETITION"
  Address = 2
  Repeat_flag = 1
  Start_flag = 0
 End If

 If Tik >= 22 And Tik < 116 And Start_flag = 1 Then 'if has happenned from 22 before 115 teaks - have taken "1"
 Incr Byt

 If Byt < 9 Then
 Shift Address_1 , Left
     Address_1 = Address_1 + 1
 End If

 If Byt >= 9 And Byt < 17 Then
 Shift Address_0 , Left
     Address_0 = Address_0 + 1
 End If

 If Byt >= 17 And Byt < 25 Then
 Shift Command_1 , Left
     Command_1 = Command_1 + 1
 End If

 If Byt >= 25 Then
 Shift Command_0 , Left
     Command_0 = Command_0 + 1
 End If
 End If

 If Tik >= 10 And Tik < 22 And Start_flag = 1 Then 'if has happenned from 10 before 21 teaks - have taken "0"
 Incr Byt

 If Byt < 9 Then
 Shift Address_1 , Left
 End If

 If Byt >= 9 And Byt < 17 Then
 Shift Address_0 , Left
 End If

 If Byt >= 17 And Byt < 25 Then
 Shift Command_1 , Left
 End If

 If Byt >= 25 Then
 Shift Command_0 , Left
 End If
 End If

 Tik = 0

 If Byt = 32 Then 'if have taken 4 bytes, check correctness a receiving a command
 'if address or command 16-bit, check does not pass
 'Summa = Address_0 + Address_1
 'If Summa = 255 Then
    Address = Address_1
 'Else
 'Address = 0
 'End If

 'Summa = Command_0 + Command_1
 'If Summa = 255 Then
    Command = Command_1
 'Else
 'Command = 0
 'End If
  Byt = 0
  Repeat_flag = 0
  Start_flag = 0
 Stop Timer0
 End If

 Return

'################################################################################################################