![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
host/Source/App/console.c
- Committer:
- Kovalev_D
- Date:
- 2016-02-03
- Revision:
- 23:12e6183f04d4
File content as of revision 23:12e6183f04d4:
#include "console.h" #include "lpc17xx.h" #include "CyclesSync.h" #define FOSC 12000000 #define FCCLK (FOSC * 8) #define FCCO (FCCLK * 3) #define FPCLK (FCCLK / 4) #define UART0_BPS 38400 unsigned int BuffOut[1024]; unsigned int InputIndexBO; unsigned int OutputIndexBO; unsigned int BuffIn[1024]; unsigned int InputIndexBI; unsigned int OutputIndexBI; //unsigned int OLD_OutputIndex; void UART0_Init_m (void)///èíèéöèàëèçàöèÿ íóëåâîãî óàðòà { uint16_t usFdiv; /* UART0 */ LPC_PINCON->PINSEL0 |= (1 << 4); /* Pin P0.2 used as TXD0 (Com0) */ LPC_PINCON->PINSEL0 |= (1 << 6); /* Pin P0.3 used as RXD0 (Com0) */ LPC_UART0->LCR = 0x83; usFdiv = (FPCLK / 16) / UART0_BPS; LPC_UART0->DLM = usFdiv / 256; LPC_UART0->DLL = usFdiv % 256; LPC_UART0->LCR = 0x03; LPC_UART0->FCR = 0x06; } int UART0_SendByte_m (int ucData) { //while (!(LPC_UART0->LSR & 0x20)){}; return (LPC_UART0->THR = ucData); } void ClearBuffout(void) //î÷èñòêà áóôåðà íà âûäà÷ó(ñáðîñ óêàçàòåëåé) { InputIndexBO=0; OutputIndexBO=0; } void SendToBuffByte(unsigned int *input) // çàïèñü â áóôåð íà âûäà÷ó îäíîãî çíà÷åíèÿ èíò(áåççíàêîâîãî) { InputIndexBO++; InputIndexBO &= 0x3ff; BuffOut[InputIndexBO]=*input; } void SendToBuff(unsigned char *input, unsigned int size)//çàïèñü íåñêîëüêèõ çíà÷åíèé ñ óêàçàíèåì ðàçìåðíîñòè çàïèñè â áóôåð íà âûäà÷ó. { unsigned int i; for(i=0;i<size;i++) { InputIndexBO++; InputIndexBO &= 0x3ff; BuffOut[InputIndexBO]=*input++; } } void SendToBuffStr(char *s)//çàïèñü ñòðîêè (êîíåö îòñëåæèâàåòñÿ ïî íóëþ) â áóôåð íà âûäà÷ó. { while (*s != 0) { InputIndexBO++; InputIndexBO &= 0x3ff; BuffOut[InputIndexBO]=*s++; } } void TakeFromBuff(void)//ïåðåäà÷à èç áóôåðà íà âûäà÷ó. { if((OutputIndexBO != InputIndexBO) && (LPC_UART0 -> LSR & 0x20)) { OutputIndexBO++; OutputIndexBO &= 0x3ff; LPC_UART0->THR = BuffOut[OutputIndexBO]; } } /* void UART0_SendString (char *s) { while (*s != 0) { InputIndex++; InputIndex &= 0x3ff; BuffOut[InputIndex]=*s++; } } */ void ClearBuffIn(void) { InputIndexBI=0; OutputIndexBI=0; } void BuffDataReady(void) { if((OutputIndexBI != InputIndexBI) && (!(LPC_UART0 -> LSR & 0x01))) { } } void ReadDataInBuff(void) { while (LPC_UART0->LSR & 0x01) { BuffIn[InputIndexBI] = LPC_UART0->RBR; InputIndexBI++; } }