Name: A machine serial program
Description: A machine sends control command characters to machine B.
The machine also receives the number sent by the machine and displays it in
On the digital tube.
*/
#include
#define uchar unsigned char
#define uint unsigned int
Sbit LED1=P1^0;
Sbit LED2=P1^3;
Sbit K1=P1^7;
Uchar Operation_No=0; //Operation code
/ / Digital tube code
Uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//delay
Void DelayMS(uint ms)
{
Uchar i;
While(ms--) for(i=0;i<120;i++);
}
/ / Send characters to the serial port
Void Putc_to_SerialPort(uchar c)
{
SBUF=c;
While(TI==0);
TI=0;
}
/ / Main program
Void main()
{
LED1=LED2=1;
P0=0x00;
SCON=0x50; serial mode 1, allow reception
TMOD=0x20; //T1 working mode 2
PCON=0x00; the baud rate is not multiplied
TH1=0xfd;
TL1=0xfd;
TI=RI=0;
TR1=1;
IE=0x90; //Allow serial port interrupt
While(1)
{
DelayMS(100);
If(K1==0) //Select the operation code 0,1,2,3 when K1 is pressed
{
While(K1==0);
Operation_No=(Operation_No+1)%4;
Switch(Operation_No) sends A/B/C or stops sending according to the operation code
{
Case 0: Putc_to_SerialPort('X');
LED1=LED2=1;
Break;
Case 1:Putc_to_SerialPort('A');
LED1=~LED1; LED2=1;
Break;
Case 2: Putc_to_SerialPort('B');
LED2=~LED2; LED1=1;
Break;
Case 3: Putc_to_SerialPort('C');
LED1=~LED1; LED2=LED1;
Break; }
}
}
}
//A machine serial port receives interrupt function
Void Serial_INT() interrupt 4
{
If(RI)
{
RI=0;
If(SBUF>=0&&SBUF<=9) P0=DSY_CODE[SBUF];
Else P0=0x00;
}
}
/* Name: The machine of the machine B receives the characters sent by the machine and completes the corresponding action.
Note: After receiving the signal sent by the machine, the machine B controls the LED to complete different blinking actions according to the corresponding signal.
*/
#include
#define uchar unsigned char
#define uint unsigned int
Sbit LED1=P1^0;
Sbit LED2=P1^3;
Sbit K2=P1^7;
Uchar NumX=-1;
//delay
Void DelayMS(uint ms)
{
Uchar i;
While(ms--) for(i=0;i<120;i++);
}
/ / Main program
Void main()
{
LED1=LED2=1;
SCON=0x50; serial mode 1, allow reception
TMOD=0x20; //T1 working mode 2
TH1=0xfd;
TL1=0xfd; //baud rate 9600
PCON=0x00; the baud rate is not multiplied
RI=TI=0;
TR1=1;
IE=0x90;
While(1)
{
DelayMS(100);
If(K2==0)
{
While(K2==0);
NumX=++NumX%11; //Generate a number in the range 0~10, where 10 means close
SBUF=NumX;
While(TI==0);
TI=0;
}
}
}
Void Serial_INT() interrupt 4
{
If(RI)//If received, the LED will act
{
RI=0;
Switch (SBUF) / / according to the different command characters received to complete different actions
{
Case 'X': LED1=LED2=1; break; //destroy
Case 'A': LED1=0; LED2=1; break;//LED1 bright
Case 'B': LED2=0; LED1=1; break;//LED2 bright
Case 'C': LED1=LED2=0;//Full bright
}
}
}
Tr90 Glasses,Tr90 Perspective Glasses,Tr90 Sunglasses,Tr90 Material Glasses
Danyang Hengshi Optical Glasses Co., Ltd. , https://www.hengshi-optical.com