[SOLVED] NEC protocol generation using ATMEGA 8

Status
Not open for further replies.

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Visit site
Activity points
4,554
Can anybody guide me on how to generate NEC protocol for a Mp3 modue to play mp3 files using ATMEGA8 and codevision avr.
 

Here is my code for NEC protocol generation. I have used timer 1 with clock source of 8Mhz, with prescale of 8, with 1us time cycle duration.So i loaded timer with different values each time for calling interrupt. I am using a software called IR protocol analyzer to test the signals from microcontroller. Though It is showing right time duration for all the data it is not accepting it. I send address 32640, command 18 and its inverse 237, still no result.
Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V2.03.4 Standard
Automatic Program Generator
© Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 4/2/2014
Author  : 
Company : 
Comments: 


Chip type           : ATmega8
Program type        : Application
Clock frequency     : 8.000000 MHz
Memory model        : Small
External RAM size   : 0
Data Stack size     : 256
*****************************************************/

#include <mega8.h>
#include <delay.h>

bit i=0;
int j=0;
//unsigned char mp3_addr[15]={1,1,1,1,1,1,1,1,0,0,0,0,0,0,0};
unsigned char mp3_addr[15]={0,0,0,0,0,0,0,1,1,1,1,1,1,1,1};
//unsigned char mp3_cmd[8]={0,0,0,1,0,0,1,0};      //18
unsigned char mp3_cmd[8]={0,1,0,0,1,0,0,0};
//unsigned char mp3_cmd_inv[8]={1,1,1,0,1,1,0,1};  //237
unsigned char mp3_cmd_inv[8]={1,0,1,1,0,1,1,1};

// Timer 1 overflow interrupt service routine
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer 1 value
TCNT1H=0xDC;
TCNT1L=0xD8;
// Place your code here
    i=1;

}

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port B initialization
// Func7=In Func6=In Func5=In Func4=Out Func3=Out Func2=Out Func1=In Func0=Out 
// State7=T State6=T State5=T State4=0 State3=0 State2=0 State1=T State0=0 
PORTB=0x00;
DDRB=0x1D;

// Port C initialization
// Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 1000.000 kHz
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x02;
TCNT1H=0xdc;
TCNT1L=0xd8;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x04;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// Global enable interrupts
//#asm("sei")
delay_ms(100);
//while (1)
//      {
      //i=0;
      TCNT1H=0xdc; //dc
      TCNT1L=0xd8; //d8
      #asm("sei")
      while(i==0){
      PORTB.0=1;
      }
      #asm("cli")
      i=0;
      PORTB.0=0;
      TCNT1H=0xee;
      TCNT1L=0x76;
      #asm("sei")
      while(i==0){
      PORTB.0=1;
      }
      #asm("cli")      
      i=0;
            for(j=0;j<15;j++){
//            if(mp3_addr[j]==0){
//                PORTB.0=1;
//                TCNT1H=0xfd;
//                TCNT1H=0xe2;
//                #asm("sei")
//                while(i==0){
//                    PORTB.0=1;
//                }
//                #asm("cli")
//                i=0;     
//             }
//            if(mp3_addr[j]==1){
                
                TCNT1H=0xfd;
                TCNT1L=0xce;
                #asm("sei")
                while(i==0){
                    PORTB.0=1;
                }
                #asm("cli")
                i=0; 
            // }               
                    if(mp3_addr[j]==0){
                    TCNT1H=0xfd;
                    TCNT1L=0xce;
                    #asm("sei")
                    while(i==0){
                        PORTB.0=0;
                    }
                    #asm("cli")
                    i=0;
                    }
                    
                    if(mp3_addr[j]==1){
                    TCNT1H=0xf9;
                    TCNT1L=0x75;
                    #asm("sei")
                    while(i==0){
                        PORTB.0=0;
                    }
                    #asm("cli")
                    i=0;
                    }
                    
                                 
            }
            
      
            for(j=0;j<8;j++){
//            if(mp3_cmd[j]==0){
//                
//                TCNT1H=0xfd;
//                TCNT1H=0xe2;
//                #asm("sei")
//                while(i==0){
//                    PORTB.0=1;
//                }
//                #asm("cli")
//                i=0;     
//             }
//             if(mp3_cmd[j]==1){
                
                TCNT1H=0xfd;
                TCNT1L=0xce;
                #asm("sei")
                while(i==0){
                    PORTB.0=1;
                }
                #asm("cli")
                i=0; 
           //  }               
                    if(mp3_cmd[j]==0){
                    TCNT1H=0xfd;
                    TCNT1L=0xce;
                    #asm("sei")
                    while(i==0){
                        PORTB.0=0;
                    }
                    #asm("cli")
                    i=0;
                    }
                    
                    if(mp3_cmd[j]==1){
                    TCNT1H=0xf9;
                    TCNT1L=0x75;
                    #asm("sei")
                    while(i==0){
                        PORTB.0=0;
                    }
                    #asm("cli")
                    i=0;
                    }
                    
                    //#asm("cli")
      
            }
            
            for(j=0;j<8;j++){
//             if(mp3_cmd_inv[j]==0){
//                PORTB.0=1;
//                TCNT1H=0xfd;
//                TCNT1H=0xe2;
//                #asm("sei")
//                while(i==0){
//                    PORTB.0=1;
//                }
//                #asm("cli")
//                i=0;     
//             }
//             if(mp3_cmd_inv[j]==1){
                //PORTB.0=1;   
                TCNT1H=0xfd;
                TCNT1L=0xce;
                #asm("sei")
                while(i==0){
                    PORTB.0=1;
                }
                #asm("cli")
                i=0;
            // }                
                    if(mp3_cmd_inv[j]==0){
                    TCNT1H=0xfd;
                    TCNT1L=0xce;
                    #asm("sei")
                    while(i==0){
                        PORTB.0=0;
                    }
                    #asm("cli")
                    i=0;
                    }
                    
                    if(mp3_cmd_inv[j]==1){
                    TCNT1H=0xf9;
                    TCNT1L=0x75;
                    #asm("sei")
                    while(i==0){
                        PORTB.0=0;
                    }
                    #asm("cli")
                    i=0;
                    }
                    
//                    #asm("cli")
            }
                       
           
//      };
}

What must be the issue?
 

What is meant by that? address is correct, no issues with that. What else do i have to look for?
here are the screen shots
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…