vscode51单片机c语言常用子函数代码块
时间: 2023-07-26 19:30:51 浏览: 123
51单片机C语言延时函数STM32单片机学习笔记
你可以在 VSCode 中自定义 51 单片机 C 语言常用子函数代码块,步骤如下:
1. 打开 VSCode,进入命令面板(快捷键为 Ctrl + Shift + P);
2. 输入“snippet”并选择“配置语言特定用户代码片段”;
3. 在弹出的列表中选择“C”;
4. 在打开的 JSON 文件中输入以下代码:
```json
"printf": {
"prefix": "printf",
"body": [
"serial_printf(\"${1:%s}\", ${2:arg});",
],
"description": "51 Serial printf"
},
"delay_ms": {
"prefix": "delay_ms",
"body": [
"delay(${1:ms});",
],
"description": "51 Delay in milliseconds"
},
"delay_us": {
"prefix": "delay_us",
"body": [
"delay_us(${1:us});",
],
"description": "51 Delay in microseconds"
},
"uart_init": {
"prefix": "uart_init",
"body": [
"uart_init(${1:baud_rate});",
],
"description": "51 UART initialization"
},
"adc_read": {
"prefix": "adc_read",
"body": [
"adc_read(${1:channel});",
],
"description": "51 ADC read"
},
"pwm_set": {
"prefix": "pwm_set",
"body": [
"pwm_set(${1:value});",
],
"description": "51 PWM set"
},
"timer0_init": {
"prefix": "timer0_init",
"body": [
"timer0_init(${1:ms});",
],
"description": "51 Timer0 initialization"
},
"timer1_init": {
"prefix": "timer1_init",
"body": [
"timer1_init(${1:ms});",
],
"description": "51 Timer1 initialization"
},
"timer2_init": {
"prefix": "timer2_init",
"body": [
"timer2_init(${1:ms});",
],
"description": "51 Timer2 initialization"
}
```
5. 保存文件并关闭。
现在,当你在 51 单片机 C 语言文件中输入上述代码块的前缀并按下 Tab 键,就会自动生成相应的代码。你只需要填写相应的参数即可。需要注意的是,这些代码块是针对常用的 51 单片机函数和库函数的快捷方式,需要先在代码中引入相应的头文件和函数库。
阅读全文