12-2-1.c
来自「51单片机开发与应用技术详解(珍藏版)PPT及源码」· C语言 代码 · 共 24 行
C
24 行
#include<string.h> //头文件
#include<stdio.h>
#include <reg51.h>
void main(void) //主函数
{
static char str[20]="This is a test!";
void *c;
SCON=0x50; //串口模式1,允许接收
TMOD|=0x20; //初始化T1为定时功能,模式2
PCON|=0x80; //设置SMOD=1
TL1=0xF4; //波特率4800bit/s,初值
TH1=0xF4;
IE|=0x90; //中断
TR1=1; //启动定时器
c=memchr(str,'a',sizeof(str)); //调用函数
if(c==NULL) //未找到字符
printf("'a' was not found in the str\n");
else //找到字符
printf("found 'a' in the str\n");
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?