📄 console.c
字号:
/*********************************************************************
*
* Console Routines
*
*********************************************************************
* FileName: Console.c
* Dependencies:
* Processor: PIC18
* Complier: MCC18 v1.00.50 or higher
* HITECH PICC-18 V8.10PL1 or higher
* Company: Microchip Technology, Inc.
*
* Software License Agreement
*
* The software supplied herewith by Microchip Technology Incorporated
* (the 揅ompany? for its PICmicro?Microcontroller is intended and
* supplied to you, the Company抯 customer, for use solely and
* exclusively on Microchip PICmicro Microcontroller products. The
* software is owned by the Company and/or its supplier, and is
* protected under applicable copyright laws. All rights are reserved.
* Any use in violation of the foregoing restrictions may subject the
* user to criminal sanctions under applicable laws, as well as to
* civil liability for the breach of the terms and conditions of this
* license.
*
* THIS SOFTWARE IS PROVIDED IN AN 揂S IS?CONDITION. NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
* TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
* IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*
*
* Author Date Comment
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Nilesh Rajbharti 10/15/04 Original
* Nilesh Rajbharti 11/1/04 Pre-release version
********************************************************************/
// Uncomment ENABLE_DEBUG line to enable debug mode for this file.
// Or you may also globally enable debug by defining this macro
// in zigbee.def file or from compiler command-line.
#ifndef ENABLE_DEBUG
//#define ENABLE_DEBUG
#endif
#include "Console.h"
#include "zigbee.h"
#include "Debug.h"
#define USART_USE_BRGH_HIGH
#if defined(USART_USE_BRGH_LOW)
#define SPBRG_VAL ( ((CLOCK_FREQ/BAUD_RATE)/64) - 1)
#else
#define SPBRG_VAL ( ((CLOCK_FREQ/BAUD_RATE)/16) - 1)
#endif
#if SPBRG_VAL > 255
#error "Calculated SPBRG value is out of range for currnet CLOCK_FREQ."
#endif
void ConsoleInit(void)
{
#if defined(USART_USE_BRGH_HIGH)
TXSTA = 0x24;
#else
TXSTA = 0x20;
#endif
RCSTA = 0x90; // 0b10010000;
SPBRG = SPBRG_VAL;
ConsoleBuf_init();
}
void ConsolePutROMString(ROM char* str)
{
BYTE c;
while( c = *str++ )
ConsolePut(c);
}
BYTE ConsoleGetString(char *buffer, BYTE bufferLen)
{
BYTE v;
BYTE count;
count = 0;
do
{
if ( bufferLen-- == 0 )
break;
while( !ConsoleIsGetReady() );
v = RCREG;
if ( v == '\r' || v == '\n' )
break;
count++;
*buffer++ = v;
*buffer = '\0';
} while(1);
return count;
}
void ConsolePut(BYTE c)
{
while( !ConsoleIsPutReady() );
TXREG = c;
}
void ConsolePutString(BYTE *s)
{
BYTE c;
while( (c = *s++) )
ConsolePut(c);
}
BYTE ConsoleGet(void)
{
// Clear overrun error if it has occured
// New bytes cannot be received if the error occurs and isn't cleared
if(OERR)
{
CREN = 0; // Disable UART receiver
CREN = 1; // Enable UART receiver
}
return RCREG;
}
// Buffer Output
unsigned char len,first,last;
BYTE data[0xF1];
void ConsoleBuf_init(void)
{
len = first = last = 0;
}
BYTE ConsoleBuf_Put(BYTE c)
{
if(len<0xF0)
{
data[first] = c;
first ++ ;
if ( first > 0xF0 ) first = 0;
len ++;
}
return c;
}
void ConsoleBuf_Flush(void)//send buffer data from rs-232
{
while(len>0)
{
//ConsolePut(data[last]);
while( !ConsoleIsPutReady() );
TXREG = data[last];
last++;
if ( last > 0xF0 ) last = 0;
len --;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -