serial.c

来自「MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis」· C语言 代码 · 共 66 行

C
66
字号
//  This file is part of MANTIS OS, Operating System//  See http://mantis.cs.colorado.edu/////  Copyright (C) 2003,2004,2005 University of Colorado, Boulder////  This program is free software; you can redistribute it and/or//  modify it under the terms of the mos license (see file LICENSE)/** @file serial.c * @brief Serial functions for the boot loader. */#include "mos.h"#include "uart.h"#define FORCEON 0x07#define FORCEOFF 0x06#define EN 0x05/** @brief Initialize for the boot-loader serial connection. */void init_serial(){   // Setup default baud rate   UBRR0H = (uint8_t)(DEFAULT_BAUD_RATE >> 8);   UBRR0L = (uint8_t)(DEFAULT_BAUD_RATE);   // enable transmitter and receiver#ifdef CLOCK_SPEED_4_0   UCSR0A = (1 << U2X);#endif   UCSR0B = (1 << RXEN0) | (1 << TXEN0);      // no parity, 8 bits   UCSR0C = (3 << UCSZ00);}/** @brief Send a byte over the UART. * @param c Byte to send */void send_byte(uint8_t c){   while (!(UCSR0A & (1 << UDRE0)));    // wait until reg clear   UDR0 = c;                    // prepare transmission}/** @brief Receive a byte from the UART. * @return Byte received */uint8_t recv_byte(void){   while(!(UCSR0A & (1 << RXC0)));  // wait for data   return UDR0;}/** @brief Check to see if data is available from the UART. * @return 1 if data is available */int8_t check_recv(void){   if(UCSR0A & (1 << RXC0))      return 1;   else      return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?