#include <reg52.h> sbit P0_1 = P0^1; // Define P0.1 as sbit type void main() { P0_1 = 0; // Activate P0.1 and set its value to low // Output "123456" via serial port printf("123456"); while(1) { // Do nothing, wait for input signal } }
sbit P0_1 = P0^1; // Define P0.1 as sbit type
char input[7];
void main()
{
while(1)
{
scanf("%s", input);
if (strcmp(input, "123456") == 0)
{
P0_1 = 1; // Activate P0.1 and set its value to high
}
}
}
注意:需要包含"stdio.h"頭文件并初始化串口。