设计要求:
实现与Proteus中的8051单片机进行串行通信。先回顾一下串行通信。在串行通信中有两个引脚分别称为TX和RX。TX引脚用于发送数据,而RX引脚用于接收数据。
原理图和代码就直接放一下好了

#include #define Baud_rate 0xFD void SerialInitialize(void); void SendByteSerially(unsigned char); void cct_init(void); sbit Appliance1 = P1^0; sbit Appliance2 = P1^1; sbit Appliance3 = P1^2; sbit Appliance4 = P1^3; sbit Appliance5 = P1^4; sbit Appliance6 = P1^5; sbit Appliance7 = P1^6; sbit Appliance8 = P1^7; void main() { cct_init(); SerialInitialize(); EA = 1; ES = 1; while(1) {;} } void cct_init(void) { P0 = 0x00; P1 = 0x00; P2 = 0x00; P3 = 0x03; } void SerialInitialize(void) { TMOD = 0x20; SCON = 0x50; TH1 = Baud_rate; TR1 = 1; } void SendByteSerially(unsigned char serialdata) { SBUF = serialdata; while(TI == 0); TI = 0; } void serial_ISR (void) interrupt 4 { char chr; if(RI==1) { chr = SBUF; RI = 0; } P0 = ~P0; switch(chr) { case '1': Appliance1 = 1; SendByteSerially('k'); break; case '2': Appliance2 = 1; SendByteSerially('k'); break; case '3': Appliance3 = 1; SendByteSerially('k'); break; case '4': Appliance4 = 1; SendByteSerially('k'); break; case '5': Appliance5 = 1; SendByteSerially('k'); break; case '6': Appliance6 = 1; SendByteSerially('k'); break; case '7': Appliance7 = 1; SendByteSerially('k'); break; case '8': Appliance8 = 1; SendByteSerially('k'); break; case 'a': Appliance1 = 0; SendByteSerially('k'); break; case 'b': Appliance2 = 0; SendByteSerially('k'); break; case 'c': Appliance3 = 0; SendByteSerially('k'); break; case 'd': Appliance4 = 0; SendByteSerially('k'); break; case 'e': Appliance5 = 0; SendByteSerially('k'); break; case 'f': Appliance6 = 0; SendByteSerially('k'); break; case 'g': Appliance7 = 0; SendByteSerially('k'); break; case 'h': Appliance8 = 0; SendByteSerially('k'); break; default: ; break; } RI = 0; } 好像没什么特别需要注意的
上一篇:机器周期,指令周期,时钟周期,节拍与晶振
下一篇:用PROTEUS仿真点亮LED项目
推荐阅读最新更新时间:2026-03-21 04:21
- LM2904DMR2G 函数发生器运算放大器的典型应用
- DEMO9RS08KA2: DEMO9RS08KA2 Demonstration Board
- MCP73871EV,MCP73871 锂离子电池充电器评估板
- STEVAL-IHM039V1,采用 STM32F415 微控制器的双电机控制演示板
- LTC1606CG 演示板、16 位、250ksps ADC
- RT8086B 3.5A、1.2MHz、同步降压转换器的典型应用
- TS4999EIJT 典型应用 免滤波器立体声 2.8 W D 类音频功率放大器,可选择 3D 音效
- LTM4615,采用 15mm-15mm 封装的完整双路和三路输出负载点模块稳压器
- LTC2415-1IGN 24 位 ADC 的典型应用电路使用电阻器阵列在励磁放大器中提供精确匹配
- 使用 Analog Devices 的 LTC1450LIN 的参考设计

RC522射频卡
STC8H全系列单片机应用手册
Follow me第三季第4期任务
现代雷达系统的信号设计
BFR340T






京公网安备 11010802033920号