Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Nec ir

Status
Not open for further replies.

AtomSoft

Well-Known Member
Hey guys, i can read a NEC IR signal no problem... i was wondering since i want to make a NEC IR remote... is the below math correct ?

38KHz = 0.00002631 = 26.31uS
1/3 DUTY = 0.00000877 = 8.77uS
2/3 DUTY = 0.00001754 = 17.54uS

1 Pulse = 1/3 HIGH and 2/3 LOW
 
Hey guys, i can read a NEC IR signal no problem... i was wondering since i want to make a NEC IR remote... is the below math correct ?

38KHz = 0.00002631 = 26.31uS
1/3 DUTY = 0.00000877 = 8.77uS
2/3 DUTY = 0.00001754 = 17.54uS

1 Pulse = 1/3 HIGH and 2/3 LOW
Numbers look good to me.

If I was pedantic, i would say that 38KHz = 26.32uS if rounded correctly, but luckily I am not that sad :)

EDIT: I believe (could be wrong) that some manufacturers use 1/4 duty cycle, but 1/3 duty cycle is a much safer choice.
 
Last edited:
We seem to agree on everything. Makes for a dull thread.....

What are you building? maybe that is interesting?
 
heh yeah. well im making a simple side remote for my tv. Its a 32" LG LCD TV. I use it as a gaming tv and PC monitor. Now i dont have my remote anymore.. lost it...

So im making a new remote but just to adjust volume and inputs. the INPUT option is the best. I will have 2 different buttons 1 for PC and 1 for TV. so when i press TV it sends 2 INPUT signals... and with PC button it sends just 1.
 
Did something similar, but with a different approach...

Built a small gadget that sits near the TV, which receives NEC protocol from spare buttons on existing PVR remote, and after a small delay, transmits TV codes.

This solves the difficulties of building my own remote, but allows control of two devices from one existing remote.

Not perfect of course..... but might give you alternative (possibly simpler) ideas.

EDIT: not great for volume control, however, due to the delays involved.
 
Last edited:
So maybe you can help me out...

How do you build remote control with a reasonable battery life?

In particular ... how do you detect button press whilst the processor is in ultra low-power mode?

It is these two questions that prevent me building my own remote control.
 
First... i plan on using ADC for buttons.
Second... I plan on using USB for power.

but you can simply put your PIC in SLEEP MODE and then use a interrupt to wake it up... I dont know how your buttons are set up or what pic you are using ... im using a OLD PIC18F248 for mines since its a old part. But it does have interrupt on ENTIRE PORTB ...
 
but you can simply put your PIC in SLEEP MODE and then use a interrupt to wake it up
That should work. Thanks.

As for what PIC I use.... well I never tried making my own battery remote, but I work with many PICs. I guess I would choose an ultra-low-power one.

Must give it a try one day soon, now you have inspired me. :)
 
ok im going nuts here... im using timer 0 as i have done in the past... im using a 18f2525 now...

Im using a 8mhz internal clock... so thats 1/2mhz = 0.0000005 = 500ns for 1 cycle
Code:
		T0CON = 0x88; //Timer0 ON , No PRESCALER
		//.........
		IRPIN = 1;
		while(TMR0() < 18); // 18 cycles is supposed to be 9uS
		CLRTIME(); // clears TMR0L and TMR0H
		IRPIN = 0;
		while(TMR0() < 35); //35 cycles is supposed to be 17.5uS
		CLRTIME(); // clears TMR0L and TMR0H

Now what i see in my logic analyzer is :
Code:
		T0CON = 0x88; //Timer0 ON , No PRESCALER
		//.........
		IRPIN = 1;
[B]		while(TMR0() < 18); // 44uS which is more like 88 Cycles[/B]
		CLRTIME(); // clears TMR0L and TMR0H
		IRPIN = 0;
[B]		while(TMR0() < 35); //88uS which is more like 176 Cycles[/B]
		CLRTIME(); // clears TMR0L and TMR0H

why am i having this issue?
 
Last edited:
ERR here is a screen shot of logic...

err-jpg.54023


Here is my full source... also.. didnt want to release it until it was complete but im sure it can help fix my issue:

Code:
#include <p18Cxxx.h>
#include <delays.h>
#include <stdio.h>

#pragma config WDT = OFF, OSC = INTIO67, MCLRE = ON

void Delay_mS(int x);
void Delay_uS(int x);

#define IRTRIS TRISAbits.TRISA1
#define IRPIN LATAbits.LATA1
void SendNEC(unsigned char add, unsigned char cmd);
void PulseStart(void);
void Pulse0 (void);
void Pulse1 (void);
void Pulse560 (void);


#define ADDRESS 0x20
#define VOLUP 0x40
#define VOLDN 0xC0
#define INPUT 0xD0

void CLRTIME (void)
{
	INTCONbits.TMR0IF = 0;
	TMR0L = 0;
	TMR0H = 0;
}
unsigned int TMR0(void)
{
	unsigned int TIME = 0;
	unsigned int TIMEL = TMR0L;
	unsigned int TIMEH = TMR0H;

	TIME = (TIMEL | (TIMEH<<8));
	//CLRTIME();
	return TIME;
}
void main(void)
{
	OSCCON = 0x72;
	while(!OSCCONbits.IOFS);

	CMCON = 0x07;
	ADCON0 = 0x00;	
	ADCON1 = 0x0F;
	TRISA = 0;
	TRISB = 0;
	TRISC = 0;

	T0CON = 0x88;

	SendNEC(ADDRESS, VOLUP);
	while(1)
	{
		
		
	}
}

void SendNEC(unsigned char add, unsigned char cmd)
{
	unsigned char x;
	unsigned char addI = ~add;
	unsigned char cmdI = ~cmd;

	PulseStart();	//Delay 9ms HIGH then Delay 4.5ms LOW

	for(x=0;x<8;x++)	//Send add Byte
	{
		Pulse560();
		
		if(1 & add)
			Pulse1();
		else
			Pulse0();
			
		add >>= 1;
	}
	for(x=0;x<8;x++)//Send add Byte inverted
	{
		Pulse560();
		
		if(1 & addI)
			Pulse1();
		else
			Pulse0();
			
		addI >>= 1;
	}
	for(x=0;x<8;x++)//Send cmd Byte
	{
		Pulse560();
		
		if(1 & cmd)
			Pulse1();
		else
			Pulse0();
			
		cmd >>= 1;
	}
	for(x=0;x<8;x++)//Send cmd Byte inverted
	{
		Pulse560();
		
		if(1 & cmdI)
			Pulse1();
		else
			Pulse0();
			
		cmdI >>= 1;
	}
	IRPIN = 0;	//END LOW
}
void PulseStart(void)
{
	unsigned char x,y = 0;
	for(y=0;y<16;y++){
		CLRTIME();
		Pulse560();
	}

	IRPIN = 0;
	for(y=0;y<8;y++){
		for(x=0;x<21;x++){
			CLRTIME();
			IRPIN = 0;
			while(TMR0() < 47);
		}
	}
	CLRTIME();
}
void Pulse0 (void)
{
	unsigned char x = 0;
	for(x=0;x<21;x++){
		IRPIN = 0;
		while(TMR0() < 47);
		CLRTIME();
	}
	CLRTIME();
}
void Pulse1 (void)
{
	// Pulsed 2.25mS of 38KHz data
	unsigned char x = 0;
	for(x=0;x<63;x++){
		IRPIN = 0;
		while(TMR0() < 47);
		CLRTIME();
	}
	CLRTIME();
}
void Pulse560 (void)
{
	// Pulsed 560uS 
	unsigned char x = 0;

	for(x=0;x<21;x++){
		IRPIN = 1;
		while(TMR0() < 12);
		CLRTIME();
		IRPIN = 0;
		while(TMR0() < 35);
		CLRTIME();
	}

	CLRTIME();
}
 

Attachments

  • err.jpg
    err.jpg
    18.3 KB · Views: 507
Last edited:
Ok SO FAR SO GOOD!
Code:
#include <p18Cxxx.h>
#include <delays.h>
#include <stdio.h>

#pragma config WDT = OFF, OSC = HSPLL, MCLRE = ON

void Delay_mS(int x);
void Delay_uS(int x);

#define IRTRIS TRISAbits.TRISA1
#define IRPIN LATAbits.LATA1
void SendNEC(unsigned char add, unsigned char cmd);
void PulseStart(void);
void Pulse0 (void);
void Pulse1 (void);
void Pulse560 (void);


#define ADDRESS 0x20
#define VOLUP 0x40
#define VOLDN 0xC0
#define INPUT 0xD0

void CLRTIME (void)
{
	INTCONbits.TMR0IF = 0;
	TMR0L = 0;
	TMR0H = 0;
}
unsigned int TMR0(void)
{
	unsigned int TIME = 0;
	unsigned int TIMEL = 0;
	unsigned int TIMEH = 0;

	TIMEL = TMR0L;
	TIMEH = TMR0H;
	TIMEH <<=8;

	TIME = (TIMEL | TIMEH);
	//CLRTIME();
	return TIME;
}
void main(void)
{
	//OSCCON = 0x72;
	//while(!OSCCONbits.IOFS);

	CMCON = 0x07;
	ADCON0 = 0x00;	
	ADCON1 = 0x0F;
	TRISA = 0;
	TRISB = 0;
	TRISC = 0;

	T0CON = 0x88;

	
	while(1)
	{
		SendNEC(ADDRESS, VOLUP);	
		Delay_mS(1000);
	}
}
void Delay_mS(int x)
{
  while(x)
	{
		Delay1KTCYx(2);
		x--;
	}
}
void Delay_uS(int x)
{
  while(x)
	{
		Nop();
		x--;
	}
}
void SendNEC(unsigned char add, unsigned char cmd)
{
	unsigned char x;
	unsigned char addI = ~add;
	unsigned char cmdI = ~cmd;

	PulseStart();	//Delay 9ms HIGH then Delay 4.5ms LOW

	for(x=0;x<8;x++)	//Send add Byte
	{
		Pulse560();
		
		if(1 & add)
			Pulse1();
		else
			Pulse0();
			
		add >>= 1;
	}
	for(x=0;x<8;x++)//Send add Byte inverted
	{
		Pulse560();
		
		if(1 & addI)
			Pulse1();
		else
			Pulse0();
			
		addI >>= 1;
	}
	for(x=0;x<8;x++)//Send cmd Byte
	{
		Pulse560();
		
		if(1 & cmd)
			Pulse1();
		else
			Pulse0();
			
		cmd >>= 1;
	}
	for(x=0;x<8;x++)//Send cmd Byte inverted
	{
		Pulse560();
		
		if(1 & cmdI)
			Pulse1();
		else
			Pulse0();
			
		cmdI >>= 1;
	}
	IRPIN = 0;	//END LOW
}
void PulseStart(void)
{
	unsigned char x,y,z = 0;
	for(y=0;y<16;y++){
		Pulse560();
	}

	IRPIN = 0;
	for(y=0;y<8;y++){
		for(x=0;x<21;x++){
			TMR0L = 0;
			IRPIN = 0;
			while(TMR0L < 80);
			IRPIN = 0;
			TMR0L = 0;
			while(TMR0L < 154);					
		}
	}
}
void Pulse0 (void)
{
	unsigned char x,y = 0;
	for(x=0;x<21;x++){
		TMR0L = 0;
		IRPIN = 0;
		while(TMR0L < 80);
		IRPIN = 0;
		TMR0L = 0;
		while(TMR0L < 154);					
	}
}
void Pulse1 (void)
{
	// Pulsed 2.25mS of 38KHz data
	unsigned char x,y = 0;
	for(x=0;x<63;x++){
		TMR0L = 0;
		IRPIN = 0;
		while(TMR0L < 80);
		IRPIN = 0;
		TMR0L = 0;
		while(TMR0L < 154);		
	}
}
void Pulse560 (void)
{
	// Pulsed 560uS 
	unsigned char x = 0;
	for(x=0;x<21;x++){
		IRPIN = 1;
		TMR0L = 0;
		while(TMR0L < 80);
		IRPIN = 0;
		TMR0L = 0;
		while(TMR0L < 154);
	}

	TMR0L = 0;
}
Timing is like 99.2% correct.
 
Last edited:
OMG im using my NEC reader and it reads the signal fine.. but my tv volume doesnt change
Code:
#include <p18Cxxx.h>
#include <delays.h>
#include <stdio.h>

#pragma config WDT = OFF, OSC = HSPLL//, MCLRE = ON

void Delay_mS(int x);
void Delay_uS(int x);

#define IRTRIS TRISAbits.TRISA1
#define IRPIN LATAbits.LATA1
void SendNEC(unsigned char add, unsigned char cmd);
void PulseStart(void);
void Pulse0 (void);
void Pulse1 (void);
void Pulse560 (void);

#define WaitA 77
#define WaitB 146

#define ADDRESS 0x20
#define VOLUP 0x40
#define VOLDN 0xC0
#define INPUT 0xD0

void CLRTIME (void)
{
	INTCONbits.TMR0IF = 0;
	TMR0L = 0;
	TMR0H = 0;
}
unsigned int TMR0(void)
{
	unsigned int TIME = 0;
	unsigned int TIMEL = 0;
	unsigned int TIMEH = 0;

	TIMEL = TMR0L;
	TIMEH = TMR0H;
	TIMEH <<=8;

	TIME = (TIMEL | TIMEH);
	//CLRTIME();
	return TIME;
}
void main(void)
{
	//OSCCON = 0x72;
	//while(!OSCCONbits.IOFS);

//	CMCON = 0x07;
	ADCON0 = 0x00;	
	ADCON1 = 0x0F;
	TRISA = 0;
	TRISB = 0;
	TRISC = 0;

	T0CON = 0x88;

	
	while(1)
	{
		SendNEC(ADDRESS, VOLUP);	
		Delay_mS(3000);
	}
}
void Delay_mS(int x)
{
  while(x)
	{
		Delay1KTCYx(2);
		x--;
	}
}
void Delay_uS(int x)
{
  while(x)
	{
		Nop();
		x--;
	}
}
void SendNEC(unsigned char add, unsigned char cmd)
{
	unsigned char x;
	unsigned char addI = ~add;
	unsigned char cmdI = ~cmd;

	PulseStart();	//Delay 9ms HIGH then Delay 4.5ms LOW

	for(x=0;x<8;x++)	//Send add Byte
	{
		Pulse560();
		
		if(0x80 & add)
			Pulse1();
		else
			Pulse0();
			
		add <<= 1;
	}
	for(x=0;x<8;x++)//Send add Byte inverted
	{
		Pulse560();
		
		if(0x80 & addI)
			Pulse1();
		else
			Pulse0();
			
		addI <<= 1;
	}
	for(x=0;x<8;x++)//Send cmd Byte
	{
		Pulse560();
		
		if(0x80 & cmd)
			Pulse1();
		else
			Pulse0();
			
		cmd <<= 1;
	}
	for(x=0;x<8;x++)//Send cmd Byte inverted
	{
		Pulse560();
		
		if(0x80 & cmdI)
			Pulse1();
		else
			Pulse0();
			
		cmdI <<= 1;
	}
	IRPIN = 0;	//END LOW
}
////////////////////////////////////
// START
////////////////////////////////////
void PulseStart(void)
{
	unsigned char x,y,z = 0;
	for(y=0;y<16;y++){
		Pulse560();
	}

	for(y=0;y<8;y++){
		for(x=0;x<21;x++){
			TMR0L = 0;
			IRPIN = 0;
			while(TMR0L < 223);						
		}
	}
}
void Pulse0 (void)
{
	unsigned char x,y = 0;
	for(x=0;x<21;x++){
		TMR0L = 0;
		IRPIN = 0;
		while(TMR0L < 223);					
	}
}
void Pulse1 (void)
{
	// Pulsed 2.25mS of 38KHz data
	unsigned char x,y = 0;
	for(x=0;x<64;x++){
		TMR0L = 0;
		IRPIN = 0;
		while(TMR0L < 223);
	}
}
void Pulse560 (void)
{
	// Pulsed 560uS 
	unsigned char x = 0;
	for(x=0;x<22;x++){
		IRPIN = 1;
		TMR0L = 0;
		while(TMR0L < WaitA);
		IRPIN = 0;
		TMR0L = 0;
		while(TMR0L < WaitB);
	}

	TMR0L = 0;
}

If you have the logic softwae (FREE)
https://www.saleae.com/downloads/

You can check my output...
 

Attachments

  • NEC.zip
    13.6 KB · Views: 93
Looks sort of reasonable at a quick glance. I will check more carefully when I get back from work.

Don't suppose you have a working signal (from your universal remote) to compare it to?

How do you know what device address and button code to use anyway?
 
I actually do have a remote thats how i made my nec receiver... It can decode the remote and give me address byte and command byte and displays it on lcd. Ill make a video in a little then upload my remote ir captue from logic and the universal remote capture also so anyone can compare the. The differeNce isnt big. Im following the exact protocol from sbprojects ir pages
 
I read your logic analyser trace as (hex) 20-df-40-bf and the timings look correct to me.

Does your NEC reader read all 4 bytes? I presume that it does, but if it did happen to only read bytes 1 and 3, and assume bytes 2 and 4 to always be the complement of bytes 1 and 3, then the problem might lie there.

Many remotes treat bytes 1 and 2 as a 16 bit address, rather than 8 bit address with complement byte.

But then....... you probably know all of this already.

Can't see any obvious reason that your remote is not working.

Will be interested to see the logic analyser trace for the working universal remote.
 
Last edited:
hah i got it working! had to send 1 extra end pulse

Code:
#include <p18Cxxx.h>
#include <delays.h>
#include <stdio.h>

#pragma config WDT = OFF, OSC = HSPLL//, MCLRE = ON

void Delay_mS(int x);
void Delay_uS(int x);

#define IRTRIS TRISAbits.TRISA1
#define IRPIN LATAbits.LATA1
void SendNEC(unsigned char add, unsigned char cmd);
void PulseStart(void);
void Pulse0 (void);
void Pulse1 (void);
void Pulse560 (void);

#define WaitA 80
#define WaitB 150

#define ADDRESS 0x20
#define VOLUP 0x40
#define VOLDN 0xC0
#define INPUT 0xD0

void CLRTIME (void)
{
	INTCONbits.TMR0IF = 0;
	TMR0L = 0;
	TMR0H = 0;
}
unsigned int TMR0(void)
{
	unsigned int TIME = 0;
	unsigned int TIMEL = 0;
	unsigned int TIMEH = 0;

	TIMEL = TMR0L;
	TIMEH = TMR0H;
	TIMEH <<=8;

	TIME = (TIMEL | TIMEH);
	//CLRTIME();
	return TIME;
}
void main(void)
{
	//OSCCON = 0x72;
	//while(!OSCCONbits.IOFS);

//	CMCON = 0x07;
	ADCON0 = 0x00;	
	ADCON1 = 0x0F;
	TRISA = 0;
	TRISB = 0;
	TRISC = 0;

	T0CON = 0x88;

	
	while(1)
	{
		SendNEC(ADDRESS, VOLUP);	
		Delay_mS(3000);
	}
}
void Delay_mS(int x)
{
  while(x)
	{
		Delay1KTCYx(2);
		x--;
	}
}
void Delay_uS(int x)
{
  while(x)
	{
		Nop();
		x--;
	}
}
void SendNEC(unsigned char add, unsigned char cmd)
{
	unsigned char x;
	unsigned char addI = ~add;
	unsigned char cmdI = ~cmd;

	PulseStart();	//Delay 9ms HIGH then Delay 4.5ms LOW

	for(x=0;x<8;x++)	//Send add Byte
	{
		Pulse560();
		
		if(0x80 & add)
			Pulse1();
		else
			Pulse0();
			
		add <<= 1;
	}
	for(x=0;x<8;x++)//Send add Byte inverted
	{
		Pulse560();
		
		if(0x80 & addI)
			Pulse1();
		else
			Pulse0();
			
		addI <<= 1;
	}
	for(x=0;x<8;x++)//Send cmd Byte
	{
		Pulse560();
		
		if(0x80 & cmd)
			Pulse1();
		else
			Pulse0();
			
		cmd <<= 1;
	}
	[B]for(x=0;x<9;x++)//Send cmd Byte inverted[/B]
	{
		Pulse560();
		
		if(0x80 & cmdI)
			Pulse1();
		else
			Pulse0();
			
		cmdI <<= 1;
	}
	//IRPIN = 0;	//END LOW
}
////////////////////////////////////
// START
////////////////////////////////////
void PulseStart(void)
{
	unsigned char x,y,z = 0;
	for(y=0;y<16;y++){
		Pulse560();
	}

	for(y=0;y<8;y++){
		for(x=0;x<22;x++){
			TMR0L = 0;
			IRPIN = 0;
			while(TMR0L < 223);						
		}
	}
}
void Pulse0 (void)
{
	unsigned char x,y = 0;
	for(x=0;x<22;x++){
		TMR0L = 0;
		IRPIN = 0;
		while(TMR0L < 223);					
	}
}
void Pulse1 (void)
{
	// Pulsed 2.25mS of 38KHz data
	unsigned char x,y = 0;
	for(x=0;x<66;x++){
		TMR0L = 0;
		IRPIN = 0;
		while(TMR0L < 223);
	}
}
void Pulse560 (void)
{
	// Pulsed 560uS 
	unsigned char x = 0;
	for(x=0;x<21;x++){
		IRPIN = 1;
		TMR0L = 0;
		while(TMR0L < WaitA);
		IRPIN = 0;
		TMR0L = 0;
		while(TMR0L < WaitB);
	}

	TMR0L = 0;
}

Notice the 9 instead of the 8 in the last byte sent... (cmdI)
 
Last edited:
Ok full code so far.. might need adjusting but works 100% so far
Code:
#include <p18Cxxx.h>
#include <delays.h>
#include <stdio.h>

#pragma config WDT = OFF, OSC = HSPLL//, MCLRE = ON

void Delay_mS(int x);
void Delay_uS(int x);

#define IRTRIS TRISAbits.TRISA1
#define IRPIN LATAbits.LATA1
void SendNEC(unsigned char add, unsigned char cmd);
void PulseStart(void);
void Pulse0 (void);
void Pulse1 (void);
void Pulse560 (void);
unsigned int GetAN0(void);

#define WaitA 80
#define WaitB 150

#define ADDRESS 0x20
#define VOLUP 0x40
#define VOLDN 0xC0
#define INPUT 0xD0

//KEYS
#define UP 0x8000
#define DWN 0x3000
#define PC 0x1F00
#define TV 0x3FC0

void CLRTIME (void)
{
	INTCONbits.TMR0IF = 0;
	TMR0L = 0;
	TMR0H = 0;
}
unsigned int TMR0(void)
{
	unsigned int TIME = 0;
	unsigned int TIMEL = 0;
	unsigned int TIMEH = 0;

	TIMEL = TMR0L;
	TIMEH = TMR0H;
	TIMEH <<=8;

	TIME = (TIMEL | TIMEH);
	//CLRTIME();
	return TIME;
}
void main(void)
{
	unsigned int KEY;
	//OSCCON = 0x72;
	//while(!OSCCONbits.IOFS);

//	CMCON = 0x07;
	ADCON0 = 0x01;	//AN0 is ANALOG //Fastest
	ADCON1 = 0x0E;	

	TRISA = 1;//AN0 = INPUT
	TRISB = 0;
	TRISC = 0;

	T0CON = 0x88;

	
	while(1)
	{
		KEY=GetAN0();

		switch(KEY)
		{
			case UP:
				SendNEC(ADDRESS, VOLUP);
				break;
			case DWN:
				SendNEC(ADDRESS, VOLDN);
				break;
			case PC:
				SendNEC(ADDRESS, INPUT);
				Delay_mS(500);
				SendNEC(ADDRESS, INPUT);
				break;
			case TV:
				SendNEC(ADDRESS, INPUT);
				Delay_mS(500);
				break;
		}
		//SendNEC(ADDRESS, VOLUP);	
		Delay_mS(100);
	}
}
unsigned int GetAN0(void)
{
	volatile unsigned int temp = 0;
	volatile unsigned int temp2 = 0;

	ADCON0bits.GO = 1;
	Delay10TCYx(2);
	while(ADCON0bits.DONE != 0);

	temp2 = ADRESL;
	temp = ADRESH;
	temp = temp << 8;
	temp |= temp2;

	return temp;
}
void Delay_mS(int x)
{
  while(x)
	{
		Delay1KTCYx(2);
		x--;
	}
}
void Delay_uS(int x)
{
  while(x)
	{
		Nop();
		x--;
	}
}
void SendNEC(unsigned char add, unsigned char cmd)
{
	unsigned char x;
	unsigned char addI = ~add;
	unsigned char cmdI = ~cmd;

	PulseStart();	//Delay 9ms HIGH then Delay 4.5ms LOW

	for(x=0;x<8;x++)	//Send add Byte
	{
		Pulse560();
		
		if(0x80 & add)
			Pulse1();
		else
			Pulse0();
			
		add <<= 1;
	}
	for(x=0;x<8;x++)//Send add Byte inverted
	{
		Pulse560();
		
		if(0x80 & addI)
			Pulse1();
		else
			Pulse0();
			
		addI <<= 1;
	}
	for(x=0;x<8;x++)//Send cmd Byte
	{
		Pulse560();
		
		if(0x80 & cmd)
			Pulse1();
		else
			Pulse0();
			
		cmd <<= 1;
	}
	for(x=0;x<9;x++)//Send cmd Byte inverted
	{
		Pulse560();
		
		if(0x80 & cmdI)
			Pulse1();
		else
			Pulse0();
			
		cmdI <<= 1;
	}
	//IRPIN = 0;	//END LOW
}
////////////////////////////////////
// START
////////////////////////////////////
void PulseStart(void)
{
	unsigned char x,y,z = 0;
	for(y=0;y<16;y++){
		Pulse560();
	}

	for(y=0;y<8;y++){
		for(x=0;x<22;x++){
			TMR0L = 0;
			IRPIN = 0;
			while(TMR0L < 223);						
		}
	}
}
void Pulse0 (void)
{
	unsigned char x,y = 0;
	for(x=0;x<22;x++){
		TMR0L = 0;
		IRPIN = 0;
		while(TMR0L < 223);					
	}
}
void Pulse1 (void)
{
	// Pulsed 2.25mS of 38KHz data
	unsigned char x,y = 0;
	for(x=0;x<66;x++){
		TMR0L = 0;
		IRPIN = 0;
		while(TMR0L < 223);
	}
}
void Pulse560 (void)
{
	// Pulsed 560uS 
	unsigned char x = 0;
	for(x=0;x<21;x++){
		IRPIN = 1;
		TMR0L = 0;
		while(TMR0L < WaitA);
		IRPIN = 0;
		TMR0L = 0;
		while(TMR0L < WaitB);
	}

	TMR0L = 0;
}

Going to make a new video...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top