博客
关于我
51单片机串口的使用
阅读量:335 次
发布时间:2019-03-04

本文共 2261 字,大约阅读时间需要 7 分钟。

#include
/********************非精确延时*********************/void delay(long d){ while(d--) ;}/***************************************** 串口单字节发送********************************************/void uar1tByte(char byte){ SBUF = byte ; while(!TI); TI = 0 ;}/***************************************** 串口字符串发送********************************************/void uart1String(char *s){ while(*s) { uar1tByte(*s++) ; }}/***************************************** 串口数字发送********************************************/void uart1Figure(long figure){ if(figure >= 100000000) uar1tByte('0'+figure/100000000%10); if(figure >= 10000000) uar1tByte('0'+figure/10000000%10); if(figure >= 1000000) uar1tByte('0'+figure/1000000%10); if(figure >= 100000) uar1tByte('0'+figure/100000%10); if(figure >= 10000) uar1tByte('0'+figure/10000%10); if(figure >= 1000) uar1tByte('0'+figure/1000%10); if(figure >= 100) uar1tByte('0'+figure/100%10); if(figure >= 10) uar1tByte('0'+figure/10%10); if(figure >= 0) uar1tByte('0'+figure/1%10);}/***************************************** 中断初始化函数 使用定时器1初始化*******************************************/// void uart1TiINIT()// { // unsigned int INITValue = 256-(11059200/12/32/9600) ; // EA = 1 ; //打开总中断 // ES = 1 ; //打开串口中断 // SCON = 0x50; //8位数据,可变波特率 // TMOD &= 0x0F; //清除定时器1模式位 // TMOD |= 0x20; //设定定时器1为8位自动重装方式 // TH1 = TL1 = INITValue; // ET1 = 0; //禁止定时器1中断 // TR1 = 1; //启动定时器1// }/***************************************** 中断初始化函数 使用定时器2初始化*******************************************/void uart1T2INIT() //串口初始化{ unsigned int INITValue = 65536 - (11059200/32/9600) ; EA=1; ES = 1; SCON = 0x50; T2CON = 0x34; TH2 = RCAP2H = INITValue/256; TL2 = RCAP2L = INITValue%256; TR2 = 1;}int i = 0 ;/*************************************** main函数 程序入口***************************************/void main(){ // uart1TiINIT(); //中断初始化 uart1T2INIT() ; while(1) { i++; uart1String("i = ") ; uart1Figure(i); uart1String("\r\n") ; delay(10000) ; }}//^^main函数^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^/*----------------------------UART interrupt service routine----------------------------*/void uart1Receive() interrupt 4{ if (RI) { RI = 0; //Clear receive interrupt flag }}

转载地址:http://fbrq.baihongyu.com/

你可能感兴趣的文章
mysql5.7命令总结
查看>>
mysql5.7安装
查看>>
mysql5.7性能调优my.ini
查看>>
MySQL5.7新增Performance Schema表
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>
Webpack 之 basic chunk graph
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>