MSP430(F149)學(xué)習(xí)筆記——紅外接收
- #include<msp430x14x.h>
- #include"delay.h"
- staticunsignedshortaddr=0x00;
- staticunsignedcharir_rx_buf[256];
- staticunsignedcharir_rx_w_offset=0;
- staticunsignedcharir_rx_r_offset=0;
- voidir_tx_open(){
- P2DIR|=BIT2|BIT3;//P2.2,P2.3輸出
- P2SEL|=BIT3;//P2.2:IOP2.3:TA0
- P2SEL&=~BIT2;//
- P2OUT&=~(BIT2|BIT3);
- //38K->P2.3
- CCR0=(int)(26.3*8+0.5);
- CCTL1=OUTMOD_6;
- CCR1=(int)(13.15*8+0.5);
- TACTL=TASSEL_2+MC_1;
- }
- voidir_set_addr(unsignedcharaddr){
- addr=(unsignedchar)(0xff&addr);
- }
- staticvoidir_start(){
- P2OUT|=BIT2;
- delay_us(9000);
- P2OUT&=~BIT2;
- delay_us(4500);
- }
- staticvoidir_next(){
- P2OUT|=BIT2;
- delay_us(9000);
- P2OUT&=~BIT2;
- delay_us(2250);
- }
- staticvoidir_send_byte(unsignedcharc){
- unsignedchari;
- for(i=0;i!=8;++i){
- P2OUT|=BIT2;
- delay_us(560);
- P2OUT&=~BIT2;
- if(c&0x01){
- delay_us(1685);
- }
- else{
- delay_us(565);
- }
- c>>=1;
- }
- }
- staticvoidir_end(){
- P2OUT|=BIT2;
- delay_us(300);
- P2OUT&=~BIT2;
- }
- voidir_put_char(unsignedcharc){
- ir_start();
- ir_send_byte(addr);
- ir_send_byte(~addr);
- ir_send_byte(c);
- ir_send_byte(~c);
- ir_end();
- }
- voidir_put_string(char*str){
- if(*str!=