MCU communication program

Publisher:幸福如愿Latest update time:2016-08-06 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
       The transmitter sends key information, and the receiver displays the received information with a digital tube

 

Transmitter Program

 

#include
#define uchar unsigned char 
#define uint unsigned int
void delay(uint);
void SET_SYSTEM(void);
uchar KEY_scan(void);


void main() 
{
 uchar data i;
 delay(100);
 SET_SYSTEM();
 while(1)
 {
  i=KEY_scan();
  if(i)
  {
   TI=0;
   SBUF=i;
   while(!TI);
  }
 }

/*************************************************************************************/
void delay(uint t) /* Delay subroutine*/
{
 uchar i;
 while(t--)
 {
  for(i=0;i<125;i++) {}; /* 12 MHz crystal is about 1 ms */
 }
}
/*****************************************************************************************/   
uchar KEY_scan(void) /*Keyboard scanning program (stand-alone)*/
{
 uchar data key;
 
 P1=0xff;
 key=P1;
 if(key==0xff) return 0;
 else 
 {
  delay(10);
  key=P1;
  if(key==0xff) return 0;
  else
  {
   switch(key)
   {
    case 0xfe: return 1;break;
    case 0xfd: return 2;break;
    case 0xfb: return 3;break;
    case 0xf7: return 4;break;
    case 0xef: return 5;break;
    case 0xdf: return 6;break;
    case 0xbf: return 7;break;
    case 0x7f: return 8;break;
    default : return 9;
   }
  }
 }
}                    
/***********************************************************************************/
void SET_SYSTEM(void)
{
 TMOD=0x20; /* Timer 1 works in mode 2 */
 PCON=PCON&0x07;
 TH1=0xfe; /* Set the baud rate*/
 TL1=0xfe;
 SCON=0x50;
 IE=0x00; /* That is, EA=0; turn off all interrupts*/
 TI=0;
 RI=0;
 TR1=1;
}
/****************************************************************************************/

 

 

Receiver Program

 

#include
#define uchar unsigned char 
#define uint unsigned int
void delay(uint);
void SET_SYSTEM(void);
uchar KEY_scan(void);
void LED_display(uchar ,uchar);
uchar xdata IO_8155_order _at_ 0x2100;
uchar xdata IO_8155_PA _at_ 0x2101;
uchar xdata IO_8155_PB _at_ 0x2102;
uchar xdata IO_8155_PC _at_ 0x2103;
uchar data dt=0;
uchar code dig_num[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; /*Segment selection code of common cathode digital tube */
void main() 
{
 delay(200);
 SET_SYSTEM();
 IO_8155_order=0x0d; /* 8155 initialization*/
 while(1)
 {
  LED_display(0,dt);
  P1=dt;
 }

/***** ************************************************** ******************************/
void delay(uint t) /* Delay subroutine*/
{
 uchar i;
 while (t--)
 {
  for(i=0;i<125;i++) {}; /* 12 MHz crystal is about 1 ms */
 }
}
/****************************************** **************************************************/
void LED_display (uchar d_bit,uchar digit) /* LED digital tube display subroutine*/
{ /*d_bit represents the bit selection code, digit represents the number to be displayed */
 IO_8155_PC=d_bit; /* Bit selection code output */
 IO_8155_PA=dig_num[ digit]; /* Segment selection code output */
 delay(10);                      
}
/************************************ ************************************************** ***/
void SET_SYSTEM(void)
{
 TMOD=0x20; /* Timer 1 works in mode 2 */
 PCON=PCON&0x07;
 TH1=0xfe; /* Set baud rate */
 TL1=0xfe;
 SCON=0x50;
 IE=0x90; /* EA=1; ES=1; ET1=0; serial port interrupt is enabled, timer 1 interrupt is disabled*/
 TI=0;
 RI=0;
 TR1=1;
}
/** ************************************************** *********************************/
void RI_RI(void) interrupt 4 
{
 RI=0;
 dt=SBUF;
}

Keywords:MCU Reference address:MCU communication program

Previous article:LCD12864 Program
Next article:Traffic light program for 8051

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号