Chào mừng bạn đến với Điện Tử Viễn Thông SV! =>>Chúc Bạn Một Ngày Vui Vẻ....!

Thứ Ba, 18 tháng 7, 2017

Giao tiếp at89c52 với modum bluetooth điều khiển thiết bị


I.Giới thiệu
1.Sơ đồ nguyên lý

2.Chuẩn bị



3.Mô phỏng protues




II.Code
Mã:Gi
//Code giao tiep Vdk 89c52 với modum bluetooth 5 ngo ra
#include <REGX52.H>

#include"main.h"

#include<stdio.h>

 char c;

 char flag=0;  //bien phu luu gia tri



//ham delay

void delay(int time)

{

 unsigned int i,j;

 for(i=0;i<time;i++)

 for(j=0;j<1275;j++);

}

void batdau()

{

   TMOD=0x20;

   SCON=0x50;

   TH1=0xfd;

   TR1=1;

   TI = 1; 

}

void main()

{

  batdau();

  delay(50);

  while(1)

  {

    while(!RI);

    flag=SBUF;

    c=flag;

    RI=0;

    if(c=='A'){P2_4=0;}
   else if(c=='a'){P2_4=1;}
   else if(c=='B'){P2_3=0;}
   else if(c=='b'){P2_3=1;}
   else if(c=='C'){P2_2=0;}
   else if(c=='c'){P2_2=1;}
   else if(c=='D'){P2_1=0;}
   else if(c=='d'){P2_1=1;}
   else if(c=='E'){P2_0=0;}
   else if(c=='e'){P2_0=1;}
   else if(c=='F'){P2=0x00;}
   else if(c=='f'){P2=0xFF;}
   c=0;

   c=0;

  delay(50);

  }

}

//-------=================----/
================>>Chúc bạn thành công<<==============