C51 队列 方式 中断接收 查询发送
来源:互联网 发布:mac怎么打开xlsx 编辑:程序博客网 时间:2024/05/29 06:47
Keil C51没有 《stdbool.h》头文件,自己做一个
stdbool.h
#ifndef __STDBOOL_H__#define __STDBOOL_H__typedef enum{ false = 0, true = 1,}bool;#endif
最简单的数组模拟循环队列
Queue.h
#ifndef __QUEUE__#define __QUEUE__#include <REGX52.H>#include "stdbool.h"#define u8 unsigned char#define Maxsize 10typedef struct{u8 element[Maxsize];u8 front;u8 rear;}SeqCycleQueue;void Init_Cycle_Queue(SeqCycleQueue *Q);bool Entry_Queue(SeqCycleQueue *Q,u8 x);bool Delete_Queue(SeqCycleQueue *Q,u8 *x);bool Get_front_value(SeqCycleQueue *Q,u8 *x);bool Is_Queue_Full(SeqCycleQueue *Q);bool Is_Queue_Empty(SeqCycleQueue *Q);#endif
Queue.c
#include "Queue.h"SeqCycleQueue Q;void Init_Cycle_Queue(SeqCycleQueue *Q){Q->front = 0;Q->rear = 0;}bool Entry_Queue(SeqCycleQueue *Q,u8 x){if((Q->rear+1) % Maxsize == Q->front) {return false; }Q->element[Q->rear] = x;Q->rear = (Q->rear+1) % Maxsize;return true;}bool Delete_Queue(SeqCycleQueue *Q,u8 *x){if(Q->front == Q->rear)return false;*x = Q->element[Q->front];Q->front = (Q->front+1) % Maxsize;return true;}bool Get_front_value(SeqCycleQueue *Q,u8 *x){if(Q->front == Q->rear) { return false; } else { *x = Q->element[Q->front]; return true; }}bool Is_Queue_Full(SeqCycleQueue *Q){ if((Q->rear+1) % Maxsize == Q->front){ return true; } else { return false; }}bool Is_Queue_Empty(SeqCycleQueue *Q){if(Q->front == Q->rear) {return true; } else { return false; }}
main.c
#include "Queue.h"volatile unsigned char rx_data;extern SeqCycleQueue Q;void Send_Char(u8 ch){ SBUF = ch; while(TI == 0); TI = 0;}//----------------------------------------------void main (void){ volatile unsigned char tmp = 0; TMOD = 0x20; //T1方式2 TH1 = 0xFD; //Baud:9600bps@11.0592MHz TL1 = 0xFD; TR1 = 1; //启动定时器1 SCON = 0x50; //串口方式1, 8-n-1, 允许接收 REN = 1; //使能串口接收 EA = 1; //打开总中断 ES = 1; //打开串口中断开关 Init_Cycle_Queue(&Q); while(1) { if(!Is_Queue_Empty(&Q)) { Delete_Queue(&Q, &tmp); Send_Char(tmp); } }}//----------------------------------------------void serial(void) interrupt 4{ if(RI) { rx_data = SBUF; //P1 = rx_data; Entry_Queue(&Q, rx_data); RI = 0; }} //----------------------------------------------
阅读 51 手册,发送缓冲与接收缓冲是独立的两个SBUF(虽然都对应 名字一样的SUBF 特殊功能寄存器)
很遗憾,但就是没实现中断接收与中断发送的实验。
0 0
- C51 队列 方式 中断接收 查询发送
- C51 中断接收 查询发送
- C51:串口接收和发送,查询与中断方法
- C51:串口接收和发送,查询与中断方法
- C51串口中断接收和发送程序
- C51--矩阵键盘--查询--中断--方式
- C51串口中断接收和发送测试例程
- 20140624-STM8L101F3P6查询发送中断接收
- nRF24L01 C51 发送接收驱动程序
- C51---串口通信---接收---发送
- 单片机C51串口中断接收和发送测试例程(含通信协议的实现)
- 单片机C51串口中断接收和发送测试例程(含通信协议的实现)
- 单片机C51串口中断接收和发送测试例程(含通信协议的实现)
- 这是一个单片机C51串口接收(中断)和发送例程
- STM32串行通讯采用中断方式发送,接收
- C51 单片机 串口通讯总结——查询方式与中断方式
- C51:串口通信接收与发送
- STM32串口中断接收和中断发送
- 平衡二叉树
- 在线生产系统执行 alter table add column type default x ;的分析
- LeetCode Everyday --226
- cuDNN: efficient Primitives for Deep Learning 论文阅读笔记
- 程序员必读的六本书
- C51 队列 方式 中断接收 查询发送
- 组成:对象作为类的成员 应注意的问题
- 莫比乌斯反演
- Tomcat服务器在Mac平台和windows平台上的搭建
- mysql 存储过程时间月份减法
- xcode常用插件及工具
- 内存管理
- Integer Inquiry
- Objective-C中打僵尸问题解析