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!= 主站蜘蛛池模板: 新竹市| 达尔| 亳州市| 昌都县| 三门峡市| 五莲县| 甘南县| 醴陵市| 定日县| 红安县| 湄潭县| 福安市| 衡南县| 绥阳县| 阿坝县| 东乡族自治县| 中山市| 甘洛县| 河池市| 泌阳县| 建宁县| 大同县| 汾阳市| 三原县| 资源县| 西乌珠穆沁旗| 平邑县| 遂昌县| 刚察县| 洛宁县| 迭部县| 公安县| 镇巴县| 如东县| 永靖县| 长乐市| 淮滨县| 横山县| 福贡县| 永年县| 突泉县|