首页资源分类嵌入式处理器MSP430 > MSP430F6638 红外遥控驱动

MSP430F6638 红外遥控驱动

已有 445005个资源

下载专区

文档信息举报收藏

标    签:红外MSP430遥控

分    享:

文档简介

MSP430F6638自带的红外遥控键盘的驱动。

文档预览

/* * Resoured Used: * TA0.1 * */ #include "ir_keyboard.h" #include "lcd_12864.h" //static unsigned long g_ulIrValue; static unsigned long g_ulIrValueCache; static int g_iIRStatus = IR_WAITING; static unsigned char g_ucIRCnt; static int g_iIRAddr; static int g_iIRValue; void IrInit(void) { //TA0时钟源为ACLK-32kHz,工作在连续模式,清零,中断使能 TA0CTL = TASSEL__ACLK + MC__CONTINOUS + TACLR; //捕获下降沿,捕获CCI1_B,捕获模式,中断使能 TA0CCTL1 = CM_2 +CCIS_1+CAP+CCIE; P1SEL |= BIT6; P1DIR &= ~BIT6; } void JudgeAndDisplayKeys(char key) { disp_str(5, 1, " "); disp_str(5, 1, "Pressed: "); switch(key){ case KEY_0: disp_word(5, 10, 48); break; case KEY_1: disp_word(5, 10, 49); break; case KEY_2: disp_word(5, 10, 50); break; case KEY_3: disp_word(5, 10, 51); break; case KEY_4: disp_word(5, 10, 52); break; case KEY_5: disp_word(5, 10, 53); break; case KEY_6: disp_word(5, 10, 54); break; case KEY_7: disp_word(5, 10, 55); break; case KEY_8: disp_word(5, 10, 56); break; case KEY_9: disp_word(5, 10, 57); break; default: disp_word(5, 10, '-'); break; } } #pragma vector=TIMER0_A1_VECTOR __interrupt void TIMER0_A1_ISR(void) { static unsigned int cap_pre,cap_cur; unsigned int cap_dif; switch (__even_in_range(TA0IV, TA0IV_TAIFG)){ case TA0IV_TACCR1: cap_pre = cap_cur; cap_cur = TA0CCR1; if(cap_cur > cap_pre){ cap_dif = cap_cur - cap_pre; } else{ cap_dif = 65536 - (cap_pre - cap_cur); } if(IR_WAITING == g_iIRStatus){ if(IrJudge(cap_dif, IR_PREAMBLE)){ //前导码,准备接收数据 g_iIRStatus = IR_RECIEVING; g_ucIRCnt = 0; } else if(IrJudge(cap_dif, IR_CONTINUE)){ //连续码,收到和前面一致的数据 //g_ulIrValue = g_ulIrValueCache; g_ucIRCnt = 0; } } else if(IR_RECIEVING == g_iIRStatus){ //判断是0还是1 ++g_ucIRCnt; if(IrJudge(cap_dif, IR_H)){ //收到 1 g_ulIrValueCache = (g_ulIrValueCache << 1) + 1; } else if(IrJudge(cap_dif, IR_L)){ //收到 0 g_ulIrValueCache <<= 1; } else{ g_iIRStatus = IR_WAITING; g_ucIRCnt = 0; } //Recieved 32 bits if(32 == g_ucIRCnt){ g_iIRValue = (int)(g_ulIrValueCache & 0x0000ffff); g_iIRAddr = (int)((g_ulIrValueCache >> 16) & 0x0000ffff); g_iIRStatus = IR_WAITING; JudgeAndDisplayKeys((char)(g_iIRValue >> 8)); //DisplayIntInHex(g_iIRValue, 5, 1); //DisplayIntInHex(g_iIRAddr, 5, 8); } } } }

Top_arrow
回到顶部
EEWORLD下载中心所有资源均来自网友分享,如有侵权,请发送举报邮件到客服邮箱bbs_service@eeworld.com.cn 或通过站内短信息或QQ:273568022联系管理员 高员外,我们会尽快处理。