51单片机-4G模块

51单片机-4G模块

4G控制LED

c 复制代码
#include "reg52.h"
#include "intrins.h"
#include <string.h>


#define SIZE 12
sfr AUXR = 0x8E;
sbit D5 = P3^7;
char cmd[SIZE];

void UartInit(void)		//9600bps@11.0592MHz
{
	AUXR = 0x01;
	SCON = 0x50; //配置串口工作方式1,REN使能接收
	TMOD &= 0x0F;
	TMOD |= 0x20;//定时器1工作方式位8位自动重装
	
	TH1 = 0xFD;
	TL1 = 0xFD;//9600波特率的初值
	TR1 = 1;//启动定时器
	
	EA = 1;//开启总中断
	ES = 1;//开启串口中断
}

void Delay1000ms()		//@11.0592MHz
{
	unsigned char i, j, k;

	_nop_();
	i = 8;
	j = 1;
	k = 243;
	do
	{
		do
		{
			while (--k);
		} while (--j);
	} while (--i);
}

void sendByte(char data_msg)
{
	SBUF = data_msg;
	while(!TI);
	TI = 0;
}

void sendString(char* str)
{
	while( *str != '\0'){
		sendByte(*str);
		str++;
	}
}

void main()
{

	D5 = 1;
	//配置C51串口的通信方式
	UartInit();
	
	while(1){
		Delay1000ms();
		//往发送缓冲区写入数据,就完成数据的发送
		//sendString("chenlichen shuai\r\n");
	}
}

void Uart_Handler() interrupt 4
{
	static int i = 0;//静态变量,被初始化一次
	char tmp;
	
	if(RI)//中断处理函数中,对于接收中断的响应
	{
			RI = 0;//清除接收中断标志位
			tmp = SBUF;
			if(tmp == ':'){
				i = 0;
			}
			cmd[i++] = tmp;
			
			if(cmd[0]== ':' && cmd[1] == 'o' && cmd[2]=='p'){
				D5 = 0;//点亮D5
				i = 0;
				memset(cmd,'\0',SIZE);
			}
			if(cmd[0]== ':' && cmd[1] == 'c' && cmd[2]=='l'){
				D5 = 1;//熄灭D5
				i = 0;
				memset(cmd,'\0',SIZE);
			}
			
			if(i == 12) i = 0;
	}
		
	if(TI);
}
相关推荐
程序员 _孜然8 小时前
Ubuntu/Debian修改网卡名字enP3p49s0为eth0
linux·运维·驱动开发·嵌入式硬件·ubuntu·debian
hahaha60168 小时前
pcie实现虚拟串口
stm32·单片机·fpga开发
Hard_August10 小时前
STM32窗口看门狗(WWDG)深度解析:精准守护嵌入式系统的实时性
stm32·单片机·嵌入式硬件·物联网
李永奉11 小时前
51单片机-实现外部中断模块教程
单片机·嵌入式硬件·51单片机
木木灬.14 小时前
单片机---------WIFI模块
单片机·嵌入式硬件
你怎么知道我是队长18 小时前
STM32CubeIDE V1.9.0下载资源链接
stm32·单片机·嵌入式硬件
曾哥嵌入式19 小时前
Stm32通过ESP8266 WiFi连接阿里云平台
stm32·嵌入式硬件·阿里云
顾念`19 小时前
单片机常用通信协议(二)
单片机·嵌入式硬件
Ronin-Lotus1 天前
嵌入式硬件篇---手柄
嵌入式硬件·手柄
芯岭技术1 天前
普冉PY32F002A单片机用LPTIM唤醒stop模式
单片机·嵌入式硬件