Hello, and welcome to the forum.
Firstly, it is unclear to me whether you wish to encode the NEC IR protocol, or to decode the protocol. Secondly, this forum does not address any atmega coding issues - it is specifically for Freescale 8-bit MCUs, and their peripheral hardware. IR protocols, either sending or receiving, involve extensive timer hardware use.
The following recent thread on this forum addressed the encoding of the NEC protocol, without the 38kHz sub-carrier.
https://community.freescale.com/thread/103280
Regards,
Mac
I really like the 68xx family for decoding IR. I find it really easy to set the uC to interrup on both rising and falling edges and on each edge the ISR Stop the counter, stores the capture count, reset the counter to 0, and restart the counter. Check the timer value for the expected pulse ranges and determine if start sequence, 0 bit, 1 bit and store, exit the ISR. When the code is complete, set a flag for the Main routine.
There should be a state machine for the code sequence you are looking for like the NEC in the previous message links.
If you set the timier dividers properly, you can measure bits, start sequences, and repeat messages. When the timer overflows, you can also determine the message is not repeated.
Good Luck,
Peter
Try starting with these links:
http://lmgtfy.com/?q=make+tv+remote+control
http://www.ladyada.net/learn/sensors/ir.html
http://altiumwiki.onconfluence.com/display/ADOH/NEC+Infrared+Transmission+Protocol
Good Luck,
Peter