欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
51單片機WIFI通信發射機源碼
[打印本頁]
作者:
green33
時間:
2018-6-11 14:26
標題:
51單片機WIFI通信發射機源碼
單片機源程序如下:
#include "reg51.h"
#include "intrins.h"
#include "timer0.h"
typedef unsigned char BYTE;
typedef unsigned int WORD;
#define FOSC 11059200L //System frequency 系統頻率
#define BAUD 9600 //UART baudrate UART波特率
/*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 校驗位始終為1
#define SPACE_PARITY 4 //Space parity 校驗位始終為0
#define PARITYBIT NONE_PARITY //Testing even parity 偶校驗測試
bit busy;
void SendData(BYTE dat);
void SendString(char *s);
void Delay500ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
i = 4;
j = 129;
k = 119;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void main()
{
#if (PARITYBIT == NONE_PARITY)
SCON = 0x50; //8-bit variable UART(8位變量的UART)
#elif (PARITYBIT == ODD_PARITY) || (PARITYBIT == EVEN_PARITY) || (PARITYBIT == MARK_PARITY)
SCON = 0xda; //9-bit variable UART, parity bit initial to 1(9位變量的UART,奇偶位初始值為1)
#elif (PARITYBIT == SPACE_PARITY)
SCON = 0xd2; //9-bit variable UART, parity bit initial to 0(9位變量的UART,奇偶位初始值為0)
#endif
TMOD = 0x20; //Set Timer1 as 8-bit auto reload mode(設置定時器18位自動重載模式)
TH1 = TL1 = -(FOSC/12/32/BAUD); //Set auto-reload vaule(設置自動加載值)
TR1 = 1; //Timer1 start run(打開定時器1)
ES = 1; //Enable UART interrupt(開UART中斷)
EA = 1; //Open master interrupt switch(開主中斷開關)
while(1)
{
Delay500ms();
SendString("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
}
if (TI)
{
TI = 0; //Clear transmit interrupt flag(清除傳輸中斷標志)
busy = 0; //Clear transmit busy flag(清除傳輸繁忙標志)
}
}
/*----------------------------
Send a byte data to UART 將字節數據發送到UATR
Input: dat (data to be sent) 輸入:dat(要發送的數據)
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) 計算奇偶校驗位P(PSW.0)
if (P) //Set the parity bit according to P 根據P設置奇偶校驗位
{
#if (PARITYBIT == ODD_PARITY)
TB8 = 0; //Set parity bit to 0 將奇偶校驗位設置為0
#elif (PARITYBIT == EVEN_PARITY)
TB8 = 1; //Set parity bit to 1 將奇偶校驗位設置為1
#endif
}
else
{
#if (PARITYBIT == ODD_PARITY)
TB8 = 1; //Set parity bit to 1 將奇偶校驗位設置為1
#elif (PARITYBIT == EVEN_PARITY)
TB8 = 0; //Set parity bit to 0 將奇偶校驗位設置為0
#endif
}
busy = 1;
SBUF = ACC; //Send data to UART buffer 發送數據到UART緩沖區
}
/*----------------------------
Send a string to UART 發送字符串到UART
Input: s (address of string) 輸入:s(字符串抵地址)
Output:None 輸出:無
----------------------------*/
void SendString(char *s)
{
while (*s) //Check the end of the string 檢查字符串結尾
{
SendData(*s++); //Send current char and increment string ptr 發送當前字符和字符串指針增量
}
}
復制代碼
所有資料51hei提供下載:
發射機.zip
(29.7 KB, 下載次數: 21)
2018-6-11 14:25 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1