Hello,
I want to control a led with a remote control. So i have put a IR-Receiver on the pin 1.1 of a msp430f2013 and a led on the pin 1.0.
This is the signal receive on the pin 1.1 :
http://upload.wikimedia.org/wikipedia/c … etails.jpg
But i don’t know how to transform this signal into bits.
Thanks for your answer, and sorry for my english i’m french.
This is what i have make (don’t work) :
#include "msp430.h"
void wait(int nombre) {
unsigned int a;
a = nombre;
while (a != 0)
{
a--;
}
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x09; // Pin 1.1 en Input
unsigned char pin;
unsigned char nbrzero=0; // number of 0 since the last 1, if more than 16 zero followin, the "message" is end
unsigned char tableau[32];
unsigned char huit=0; // every 8 bits we increase i because their are 8 bits in a char so we write in the next char
unsigned char i=0; // number for the array
unsigned char capt = 0; // capture the signal (value = 0), don't capture the signal (value 1)
// "reset" the array
while(i!=32)
{
tableau[i] = 0x00;
i++;
}
i = 0;
for (;;)
{
// watch the state of pin 1.1
pin = P1IN;
pin &= 0x02;
if( i == 31 ){ i=0; } // security in order not to have tableau[544545]
if(pin == 0x02){
if (capt == 0) { capt = 1; }
if(huit == 8) { huit = 0; i++; }
tableau[i] = tableau[i] << 1; // Left shift of all the bits
tableau[i] = tableau[i] + 1; // add bits 1
nbrzero = 0;
huit++;
}
else
{
if(capt == 1)
{
if(huit == 8) { huit = 0; i++; }
tableau[i] = tableau[i] << 1; // Left shift of all the bits
nbrzero++;
huit++;
}
if(nbrzero > 16) {
capt = 0;
nbrzero = 0;
i=0;
huit=0;
tableau[31] = 0x00;
// => Normaly when we arrive at this state, the array contains the bits send by the remote control but it don't work, i don't receive alwais the same bits
while(i!=32)
{
tableau[i] = 0x00;
i++;
}
i = 0;
}
}
wait(1900); // little delay
}
}