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

你可能感兴趣的文章
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>
Multicast1
查看>>
MySQL Cluster 7.0.36 发布
查看>>
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>
MySQL Cluster与MGR集群实战
查看>>
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>
mysql CONCAT()函数拼接有NULL
查看>>
multiprocessing.Manager 嵌套共享对象不适用于队列
查看>>
multiprocessing.pool.map 和带有两个参数的函数
查看>>
MYSQL CONCAT函数
查看>>
multiprocessing.Pool:map_async 和 imap 有什么区别?
查看>>
MySQL Connector/Net 句柄泄露
查看>>
multiprocessor(中)
查看>>
mysql CPU使用率过高的一次处理经历
查看>>
Multisim中555定时器使用技巧
查看>>
MySQL CRUD 数据表基础操作实战
查看>>