#include <msp430g2553.h>
#define CPU_F ((double)1000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
void ir_open();
void ir_start();
void ir_send_byte(unsigned char c);
void ir_end();
void ir_put(unsigned char c);
void ir_open()
{
TACTL |=TASSEL_2+TACLR+MC_1;
TACCTL1 |= OUTMOD_7;
CCR0=26;
CCR1=13;
P1DIR |= BIT2;
P1SEL |= BIT2;
}
void ir_start()
{
P1SEL|=BIT2;
delay_us(9000);
P1SEL&=~BIT2;
delay_us(4500);
}
void ir_send_byte(unsigned char c){
unsigned char i;
for(i = 0; i != 8; ++i)
{
P1SEL|=BIT2;
delay_us(560);
P1SEL&=~BIT2;
if(c&0x01){
delay_us(1685);
}
else{
delay_us(565);
}
c >>= 1;
}
}
void ir_end()
{
P1SEL|=BIT2;
delay_us(650);
P1SEL&=~BIT2;
delay_ms(40);
}
void ir_put(unsigned char c)
{
ir_start();
ir_send_byte(0x00);
ir_send_byte(0xff);
ir_send_byte(c);
ir_send_byte(~c);
ir_end();
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
DCOCTL=CALDCO_1MHZ;
BCSCTL1=CALBC1_1MHZ;
ir_open();
while(1){
ir_put(0x04);
P1OUT|=BIT2;
delay_ms(1000);
}
}
|