日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]#ifndef __DEBUGSERIAL_H_#define __DEBUGSERIAL_H_#include "sys.h"#include "stdio.h"extern u8 serialBuffer[256];extern u16 serialStatus;//?void Debug_Serial_Init(u32 baud);void Debug_Serial_Send_Byte(u8

#ifndef __DEBUGSERIAL_H_

#define __DEBUGSERIAL_H_

#include "sys.h"

#include "stdio.h"

extern u8 serialBuffer[256];

extern u16 serialStatus;

//?

void Debug_Serial_Init(u32 baud);

void Debug_Serial_Send_Byte(u8 dat);

void Debug_Serial_Send_Buffer(u8 length,u8*buffer);

#endif

#include "debugSerial.h"

//加入printf支持

#pragma import(__use_no_semihosting)

struct __FILE

{

int handle;

/* Whatever you require here. If the only file you are using is */

/* standard output using printf() for debugging, no file handling */

/* is required. */

};

FILE __stdout;

_sys_exit(int x)

{

x=x;

}

int fputc(int ch,FILE*f)

{

while(!((LPC_UART0->LSR)&0x20)); //等待判斷LSR[5](即THRE)是否是1,1時(shí)表示THR中為空

LPC_UART0->THR=(u8)ch; //發(fā)送數(shù)據(jù)

returnch;

}

//定義一個(gè)256字節(jié)的緩沖區(qū)用于存放接收到的串口數(shù)據(jù)信息

//定義一個(gè)16位數(shù)據(jù)同時(shí)保存接收數(shù)據(jù)長(zhǎng)度以及接收數(shù)據(jù)的狀態(tài)

u8 serialBuffer[256]={0};

u16 serialStatus=0;

//16字節(jié)的狀態(tài)

//低八位為當(dāng)前存儲(chǔ)的有效數(shù)據(jù)長(zhǎng)度

//15位為接收完成等待處理標(biāo)志

//8位表示當(dāng)前已經(jīng)接受到回車(chē)符r

//第9到十四位表示在等待處理期間系統(tǒng)冗余發(fā)送的數(shù)據(jù)量

//用于后期通訊系統(tǒng)的負(fù)載自適應(yīng)

void TransSerialsCommand(u8 res)

{

u8 lostCount;

u8 receiveCount;

//接收數(shù)據(jù)處理

if(serialStatus&(1<<15))//已經(jīng)接收完成,這個(gè)數(shù)據(jù)被拋棄

{

lostCount=((u8)(serialStatus>>9))&0x3f;//漏掉的數(shù)據(jù)計(jì)數(shù)

if(lostCount<0x3f)lostCount++;

serialStatus&=~(0x3f<<9);

serialStatus|=(lostCount<<9);

}

else//上一個(gè)命令沒(méi)有接收完

{

if(serialStatus&(1<<8))//接收到r

{

//等待接收N

if(res=='n')

{

//接收完成

serialStatus|=0x8000;

}

else//不是n,這一次命令作廢

{

serialStatus=0;

}

}

else//沒(méi)收到r

{

if(res=='r')

{

serialStatus|=0x0100;

}

else

{

receiveCount=(u8)(serialStatus&0xff);

if(receiveCount<255)

{

serialBuffer[receiveCount]=res;

receiveCount++;

serialStatus&=0xff00;

serialStatus|=receiveCount;

}

else

{

//數(shù)據(jù)溢出,清空

serialStatus=0;

}

}

}

}

}

void UART0_IRQHandler(void)

{

u8 status=0;

u8 res=0;

//清除串口中斷掛起

NVIC_ClearPendingIRQ(GPIO_IRQn);

//清除串口接收中斷

if(!(LPC_UART0->IIR&0x01))//確認(rèn)有中斷發(fā)生

{

status=LPC_UART0->IIR&0x0e;

if(status==0x04)//確認(rèn)是RDA中斷

{

//讀取串口接收值

res=(LPC_UART0->RBR&0xff);

//處理串口接收值

TransSerialsCommand(res);

}

}

}

void Debug_Serial_Init(u32 baud)

{

LPC_SC->PCONP|=(1<<3)|(1<<15); //打開(kāi)時(shí)鐘

//配置io口

LPC_IOCON->P0_2=0x00; //選擇TXD功能,禁止遲滯 不反向 正常推挽

LPC_IOCON->P0_2|=(1<<0)|(2<<3); //上拉

LPC_IOCON->P0_3=0x00; //選擇RXD功能,禁止遲滯 不反向 正常推挽

LPC_IOCON->P0_3|=(1<<0)|(2<<3); //上拉

LPC_UART0->LCR=0x83; //設(shè)置串口數(shù)據(jù)格式,8位字符長(zhǎng)度,1個(gè)停止位,無(wú)校驗(yàn),使能除數(shù)訪問(wèn)

LPC_UART0->DLM=((ApbClock/16)/baud)/256; //除數(shù)高八位 , 沒(méi)有小數(shù)情況

LPC_UART0->DLL=((ApbClock/16)/baud)%256; //除數(shù)第八位

LPC_UART0->LCR=0x03; //禁止訪問(wèn)除數(shù)鎖存器,鎖定波特率

LPC_UART0->FCR=0x00; //禁止FIFO

LPC_UART0->IER = 0x01; //使能接收中斷RDA

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉