博客
关于我
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/

你可能感兴趣的文章
mapping文件目录生成修改
查看>>
MapReduce程序依赖的jar包
查看>>
mariadb multi-source replication(mariadb多主复制)
查看>>
MaterialForm对tab页进行隐藏
查看>>
Member var and Static var.
查看>>
memcached高速缓存学习笔记001---memcached介绍和安装以及基本使用
查看>>
memcached高速缓存学习笔记003---利用JAVA程序操作memcached crud操作
查看>>
Memcached:Node.js 高性能缓存解决方案
查看>>
memcache、redis原理对比
查看>>
memset初始化高维数组为-1/0
查看>>
Metasploit CGI网关接口渗透测试实战
查看>>
Metasploit Web服务器渗透测试实战
查看>>
Moment.js常见用法总结
查看>>
MongoDB出现Error parsing command line: unrecognised option ‘--fork‘ 的解决方法
查看>>
MongoDB学习笔记(8)--索引及优化索引
查看>>
ms sql server 2008 sp2更新异常
查看>>
MS UC 2013-0-Prepare Tool
查看>>
msbuild发布web应用程序
查看>>
MSCRM调用外部JS文件
查看>>
MSEdgeDriver (Chromium) 不适用于版本 >= 79.0.313 (Canary)
查看>>