找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3390|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

基于430f5529的無線按鍵傳輸

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:214217 發(fā)表于 2017-7-22 09:32 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
前幾天做了一用433M的無線傳輸,用430單片機發(fā)送和就收數(shù)據(jù)。但是很有很多的不足之處,F(xiàn)在想繼續(xù)用兩對這樣的模塊來實現(xiàn)雙工通信。
發(fā)送程序


#include "msp430.h"
#include "HAL_UCS.h"
#include "system.h"

#define uchar unsigned char
#define uint unsigned int

#define SET_DATA_PORT P6OUT |= BIT5;
#define CLR_DATA_PORT P6OUT &= ~BIT5;

uchar table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar i=0,j=0,count=0;
void Port2_Init()
{
  P2DIR &= ~BIT1;
  P2OUT |= BIT1;
  P2REN |= BIT1;//設(shè)置上拉
  P2IES |= BIT1;//P2.1設(shè)置為下降沿觸發(fā)中斷方式
  P2IE |= BIT1;//使能P2.1中斷  
  __enable_interrupt();
}

void Send_Start_Code()//引導(dǎo)碼
{
  SET_DATA_PORT;
  __delay_cycles(24000);//delay 5ms
  CLR_DATA_PORT;
  __delay_cycles(16000);
}

void Send_Data_Code(uchar bit)//數(shù)據(jù)碼
{
  if(bit)
  {
    SET_DATA_PORT;
    __delay_cycles(12000);//3000us high  2000us low 1
    CLR_DATA_PORT;
    __delay_cycles(8000);
  }
  else
  {
    SET_DATA_PORT;
    __delay_cycles(8000);
    CLR_DATA_PORT;
    __delay_cycles(12000);//2000us high 3000us low 0
  }
}

void Send_One_Byte(uchar data)//發(fā)送一個字節(jié)的數(shù)據(jù)
{
  uchar bi;
  for(i=0;i<8;i++)
  {
    bi=data&0x80;
    data=data<<1;
    if(bi)
    {
      Send_Data_Code(1);
    }
    else
    {
      Send_Data_Code(0);
    }
  }
}

int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  System_Clock_Init();
  //Port2_Init();

  P4DIR |= BIT7;
  P4OUT |= BIT7;

  P6DIR |= BIT5;
  CLR_DATA_PORT;
  while(1)
  {
    Send_Start_Code();
    Send_One_Byte(0x3f);
    Send_One_Byte(0x06);
    Send_One_Byte(0x5b);
    Send_One_Byte(0x4f);
    Send_One_Byte(0x66);
    Send_One_Byte(0x6d);
    Send_One_Byte(0x7d);
    Send_One_Byte(0x07);
    Send_One_Byte(0x7f);
    Send_One_Byte(0x67);
    __delay_cycles(200000);
  }
}

接收程序

#include "msp430.h"
#include "HAL_UCS.h"
#include "system.h"

#define uchar unsigned char
#define uint unsigned int

#define DATA_INPUT P2IN&BIT0

uchar table[10];
uchar th,tl,i,j;

uchar Get_Start_Line()
{
  uchar i=0;
  while(DATA_INPUT&&i<50)//為1時循環(huán),但不能超過8ms
  {
    i++;
    __delay_cycles(400);
  }
  return i;
}

uchar Get_High_Line()
{
  uchar i=0;
  while(DATA_INPUT&&i<80)//為1時循環(huán),但不能超過8ms
  {
    i++;
    __delay_cycles(400);
  }
  return i;
}

uchar Get_Low_Line()
{
  uchar i=0;
  while(!DATA_INPUT&&i<60)
  {
    i++;
    __delay_cycles(400);
  }
  return i;
}

int main( void )
{
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  System_Clock_Init();
  P4DIR |= BIT7;
  P4OUT &= ~BIT7;
  P1DIR |= BIT0;
  P1OUT &= ~BIT0;
  P3DIR = 0xff;
  P3OUT = 0x3f;
  while(1)
  {
    restart:while(!DATA_INPUT) P1OUT &= ~BIT0;

    th=Get_High_Line();
    if(th<55||th>65) goto restart;
    tl=Get_Low_Line();
    if(tl<35||tl>45) goto restart;//<3.5ms||>4.5ms

    P1OUT |= BIT0;
    for(j=0;j<10;j++)
    {
      for(i=0;i<8;i++)
      {
        th=Get_High_Line();
        //if(th<15||th>35) goto restart;
        tl=Get_Low_Line();
        //if(tl<15||tl>35) goto restart;
        table[j]<<=1;
        if(th>22){table[j] |= 0x01;}
      }
    }

    P3OUT = table[0];
    __delay_cycles(2000000);
    P3OUT = table[1];
    __delay_cycles(2000000);
    P3OUT = table[2];
    __delay_cycles(2000000);
    P3OUT = table[3];
    __delay_cycles(2000000);
    P3OUT = table[4];
    __delay_cycles(2000000);
    P3OUT = table[5];
    __delay_cycles(2000000);
    P3OUT = table[6];
    __delay_cycles(2000000);
    P3OUT = table[7];
    __delay_cycles(2000000);
    P3OUT = table[8];
    __delay_cycles(2000000);
    P3OUT = table[9];
    __delay_cycles(2000000);
  }
}






評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表