久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2063|回復: 0
打印 上一主題 下一主題
收起左側

STC89xx系列單片機串行口的測試程序(C程序)

[復制鏈接]
跳轉到指定樓層
樓主
ID:402219 發表于 2018-9-29 08:42 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
串行口的測試程序(C程序及匯編程序)
1. C程序:
/*------------------------------------------------------------------------------------*/
/* --- STC MCU International Limited ---------------------------------------*/
/* --- 演示STC89xx系列單片機串行口功能 (8-bit/9-bit) ----------------*/
/*-------------------------------------------------------------------------------------*/
#include "reg51.h"
#include "intrins.h"
typedef unsigned char BYTE;
typedef unsigned int WORD;
#define FOSC 18432000L //System frequency
#define BAUD 9600 //UART baudrate
/*Define UART parity mode*/
#define NONE_PARITY 0 //None parity
#define ODD_PARITY 1 //Odd parity
#define EVEN_PARITY 2 //Even parity
#define MARK_PARITY 3 //Mark parity
#define SPACE_PARITY 4 //Space parity
#define PARITYBIT EVEN_PARITY //Testing even parity
sbit bit9 = P2^2; //P2.2 show UART data bit9
bit busy;
void SendData(BYTE dat);
void SendString(char *s);
void main()
{
#if (PARITYBIT == NONE_PARITY)
SCON = 0x50; //8-bit variable UART
135
#elif (PARITYBIT == ODD_PARITY) || (PARITYBIT == EVEN_PARITY) || (PARITYBIT == MARK_PARITY)
SCON = 0xda; //9-bit variable UART, parity bit initial to 1
#elif (PARITYBIT == SPACE_PARITY)
SCON = 0xd2; //9-bit variable UART, parity bit initial to 0
#endif
TMOD = 0x20; //Set Timer1 as 8-bit auto reload mode
TH1 = TL1 = -(FOSC/12/32/BAUD); //Set auto-reload vaule
TR1 = 1; //Timer1 start run
ES = 1; //Enable UART interrupt
EA = 1; //Open master interrupt switch
SendString("STC89-90xx\r\nUart Test !\r\n");
while(1);
}
/*----------------------------
UART interrupt service routine
----------------------------*/
void Uart_Isr() interrupt 4 using 1
{
if (RI)
{
RI = 0; //Clear receive interrupt flag
P0 = SBUF; //P0 show UART data
bit9 = RB8; //P2.2 show parity bit
}
if (TI)
{
TI = 0; //Clear transmit interrupt flag
busy = 0; //Clear transmit busy flag
}
}
/*----------------------------
Send a byte data to UART
Input: dat (data to be sent)
Output:None
----------------------------*/
void SendData(BYTE dat)
{
while (busy); //Wait for the completion of the previous data is sent
ACC = dat; //Calculate the even parity bit P (PSW.0)
if (P) //Set the parity bit according to P
{
#if (PARITYBIT == ODD_PARITY)
136
TB8 = 0; //Set parity bit to 0
#elif (PARITYBIT == EVEN_PARITY)
TB8 = 1; //Set parity bit to 1
#endif
}
else
{
#if (PARITYBIT == ODD_PARITY)
TB8 = 1; //Set parity bit to 1
#elif (PARITYBIT == EVEN_PARITY)
TB8 = 0; //Set parity bit to 0
#endif
}
busy = 1;
SBUF = ACC; //Send data to UART buffer
}
/*----------------------------
Send a string to UART
Input: s (address of string)
Output:None
----------------------------*/
void SendString(char *s)
{
while (*s) //Check the end of the string
{
SendData(*s++); //Send current char and increment string ptr
}
}
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 91久久精品国产 | 中文字幕精品一区 | 久久久久久久久久久高潮一区二区 | 亚洲天堂av在线 | 国产1页 | 欧美国产一区二区 | av手机在线看 | 精品国产鲁一鲁一区二区张丽 | 亚洲视频欧美视频 | 狠狠色综合网站久久久久久久 | 黄色一级网| 亚洲精品在线视频 | 日日操视频 | 欧美日韩在线综合 | 97国产精品| 色毛片 | 婷婷综合色 | 中文字幕一区二区三区不卡 | 日本福利视频免费观看 | a级片在线观看 | 国产成人精品免费 | 国产精品免费一区二区三区四区 | 日韩欧美高清dvd碟片 | 狠狠躁躁夜夜躁波多野结依 | 天天干.com| 国产 日韩 欧美 在线 | 欧美日韩中文字幕在线 | 全免费a级毛片免费看视频免费下 | 午夜免费看视频 | 免费黄色片在线观看 | 欧美一区2区三区4区公司 | 亚洲精品一区二区在线观看 | 精品国产乱码久久久久久蜜柚 | 一级毛片免费 | aaaaa毛片| 国产精品一区二区不卡 | av中文天堂 | a毛片| 亚洲日韩中文字幕一区 | 日韩色在线 | 国产精品区一区二区三区 |