標(biāo)題: 紅外遙控器發(fā)射程序編譯錯(cuò)誤 [打印本頁(yè)]

作者: wmq1517fc    時(shí)間: 2024-7-25 16:59
標(biāo)題: 紅外遙控器發(fā)射程序編譯錯(cuò)誤
各位老師,這里的誤法錯(cuò)誤需要怎么更改。
1.
#include <STC8G.H>
#include "IR.h"

//根據(jù)協(xié)議發(fā)送數(shù)據(jù),IO口模擬時(shí)序?qū)崿F(xiàn)
//延時(shí)8.77us,是一個(gè)周期的1/3 的時(shí)間  一個(gè)周期26.3us,38KHZ

sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^2;
sbit s4=P3^3;

void main()
{
  unsigned char anjian;
        P1M1 = 0x00;        //默認(rèn)00與STC89系列IO通用,標(biāo)準(zhǔn)雙向IO模式
  P1M0 = 0x00;        //如果是使用STC89系列單片機(jī),本段程序可以刪除
  P3M1 = 0x00;
  P3M0 = 0x00;
  P5M1 = 0x00;
  P5M0 = 0x00;
        while(1)   //無(wú)條件永遠(yuǎn)執(zhí)行大循環(huán)
        {
                if(!s1)                          //這些按鍵按下,就會(huì)使anjian變量賦以相應(yīng)的值。
                        anjian=1;
                if(!s2)
                        anjian=2;
                if(!s3)
                        anjian=3;
                if(!s4)
                        anjian=4;
                switch(anjian)
                {
                        case 1:Send_NEC_Message(User_Code,Key1_Code);break;
                        case 2:Send_NEC_Message(User_Code,Key2_Code);break;
                        case 3:Send_NEC_Message(User_Code,Key3_Code);break;
                        case 4:Send_NEC_Message(User_Code,Key4_Code);break;
                         default:break;
                }   
  }
}


2.
#ifndef __IR_H__
#define __IR_H__

#include<STC8G.H>

#define User_Code 0xff00
#define Key1_Code 0x41 //命令碼 按鍵1
#define Key2_Code 0x42 //命令碼 按鍵2
#define Key3_Code 0x43 //命令碼 按鍵3
#define Key4_Code 0x44 //命令碼 按鍵4
sbit IR_EN=P1^7;
void Send_NEC_Message(unsigned int User_Code,unsigned char data_Code);

#endif

3.
#include "IR.h"
#include "intrins.h"

void Delay8_77us(void)  //@11.0592MHz
{
  unsigned char data i;
  _nop_();
  i = 30;
  while (--i);
}

//載波發(fā)射
void Send_IR(unsigned int i)        
{
  while (--i);
  {
    IR_EN=1;
    Delay8_77us();
    IR_EN=0;
    Delay8_77us();
    Delay8_77us();
  }
}

//載波不發(fā)射
void No_Send_IR(unsigned int i)        
{
  while (--i);
  {
    IR_EN=0;
    Delay8_77us();
    Delay8_77us();
    Delay8_77us();
  }
}

//發(fā)射數(shù)據(jù) 0 ,符合NEC協(xié)議
void Send_NEC_0()        
{
  Send_IR(21);
  No_Send_IR(21);
}

//發(fā)射數(shù)據(jù) 1 ,符合NEC協(xié)議
void Send_NEC_1()        
{
  Send_IR(21);
  No_Send_IR(64);
}

//發(fā)射一幀完整的NEC信息 引導(dǎo)碼+用戶碼低八位+用戶碼高八位+8位數(shù)據(jù)碼+8位數(shù)據(jù)碼的反碼+結(jié)束碼“0”
void Send_NEC_Message(unsigned int User_Code,unsigned char data_Code)        
{
  unsigned int temp;
  unsigned char i;
  Send_IR(342);
  No_Send_IR(171);
  temp=User_Code;
  for(i=0;i<16;i++)
  {
    if(temp&0x0001)
      Send_NEC_1();
    else
      Send_NEC_0();
    temp>>=1;
  }
  temp=data_Code;
  for(i=0;i<8;i++)
  {
    if(temp&0x01)
      Send_NEC_1();
    else
      Send_NEC_0();
    temp>>=1;
  }
  temp=~data_Code;
  for(i=0;i<8;i++)
  {
    if(temp&0x01)
      Send_NEC_1();
    else
      Send_NEC_0();
    temp>>=1;
  }
  Send_NEC_0();
}


1.png (347.24 KB, 下載次數(shù): 24)

1.png

2.png (223.45 KB, 下載次數(shù): 19)

2.png

3.png (377.33 KB, 下載次數(shù): 18)

3.png

作者: lkc8210    時(shí)間: 2024-7-26 09:17
宏定義和函數(shù)傳參重名了
建議其中一個(gè)改為UserCode




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1