//Connect P1.2 of MSP430 to the IR LED
#include <msp430g2211.h>
#define DELAY_IR 13 // IR delay for protocol
// tej inc.
void one (void);
void zero (void);
void start (void);
void main()
{
WDTCTL = WDTPW + WDTHOLD;
// Stop WDT
BCSCTL1 = CALBC1_1MHZ;
// Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
TACTL = TASSEL_2 + MC_1;
// SMCLK, upmode
P1DIR |= 0x05;
// set P1.2 as output
P1REN = 0x08;
// enable Pull up/ pull down res;
P1OUT = 0x08;
// make it pull up resister
P1IE |= 0x08;
//enable interrupt
P1IES |= 0x08;
// hi-lo interrupt
_BIS_SR(LPM4_bits + GIE);
// Enter LPM4 + w/ interrupt
// check if loop is req for lpm4
}
// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
// ymax =no of bits of data to be transmitted
for(int y=0;y<=5;++y){
P1OUT |=0x01;
//give confirmation to the user by flashing led
__delay_cycles(100000);
P1OUT&=~0x01;
int k;
//burst length
int row =y; // row or coloumn
switch(row)
{
case 0 : k=3 ;break;
case 1 : k=30 ;break;
case 2 : k=110 ;break;
case 3 : k=180 ; break;
case 4 : k=200 ; break;
case 5 : k=600;
// remember to put break while adding tx bits;
}
//loop to transmit respective bits
for( ;k>0 ;--k){
zero();
}
__delay_cycles(2000000);
// delay 2 sec b/w transmittions
}
P1IFG=0;//clear the interrupt flag;
}
//function to transmit a 0 .
void zero()
{
for(int no_pulses=1;no_pulses>0;--no_pulses)
{
P1OUT|=0x04;
__delay_cycles(DELAY_IR);
P1OUT&=~0x04;
__delay_cycles(DELAY_IR);
}
return;
}
No comments:
Post a Comment