![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
n
Fork of LG by
console.c@21:bc8c1cec3da6, 2016-02-03 (annotated)
- Committer:
- igor_v
- Date:
- Wed Feb 03 07:19:30 2016 +0000
- Revision:
- 21:bc8c1cec3da6
- Parent:
- 12:74bd0ecf7f83
?????????? ??????? ??????????, ???????? ??? ?????? ?????????? ??????????? ?????????.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 12:74bd0ecf7f83 | 1 | |
igor_v | 1:f2adcae3d304 | 2 | #include "Global.h" |
igor_v | 1:f2adcae3d304 | 3 | |
igor_v | 21:bc8c1cec3da6 | 4 | #define FOSC 12000000 |
igor_v | 21:bc8c1cec3da6 | 5 | |
igor_v | 21:bc8c1cec3da6 | 6 | #define FCCLK (FOSC * 8) |
igor_v | 0:8ad47e2b6f00 | 7 | |
igor_v | 21:bc8c1cec3da6 | 8 | #define FCCO (FCCLK * 3) |
igor_v | 21:bc8c1cec3da6 | 9 | |
igor_v | 21:bc8c1cec3da6 | 10 | #define FPCLK (FCCLK / 4) |
igor_v | 0:8ad47e2b6f00 | 11 | |
igor_v | 0:8ad47e2b6f00 | 12 | #define UART0_BPS 38400 |
igor_v | 0:8ad47e2b6f00 | 13 | |
igor_v | 0:8ad47e2b6f00 | 14 | |
igor_v | 0:8ad47e2b6f00 | 15 | |
igor_v | 0:8ad47e2b6f00 | 16 | unsigned int BuffOut[1024]; |
igor_v | 0:8ad47e2b6f00 | 17 | |
igor_v | 0:8ad47e2b6f00 | 18 | unsigned int InputIndexBO; |
igor_v | 0:8ad47e2b6f00 | 19 | unsigned int OutputIndexBO; |
igor_v | 0:8ad47e2b6f00 | 20 | |
igor_v | 0:8ad47e2b6f00 | 21 | |
igor_v | 0:8ad47e2b6f00 | 22 | |
igor_v | 0:8ad47e2b6f00 | 23 | unsigned int BuffIn[1024]; |
igor_v | 0:8ad47e2b6f00 | 24 | |
igor_v | 0:8ad47e2b6f00 | 25 | unsigned int InputIndexBI; |
igor_v | 0:8ad47e2b6f00 | 26 | unsigned int OutputIndexBI; |
igor_v | 0:8ad47e2b6f00 | 27 | |
igor_v | 0:8ad47e2b6f00 | 28 | //unsigned int OLD_OutputIndex; |
igor_v | 0:8ad47e2b6f00 | 29 | |
igor_v | 21:bc8c1cec3da6 | 30 | void UART0_Init_m (void)///инийциализация нулевого уарта |
igor_v | 1:f2adcae3d304 | 31 | { |
igor_v | 21:bc8c1cec3da6 | 32 | uint16_t usFdiv; |
igor_v | 0:8ad47e2b6f00 | 33 | /* UART0 */ |
igor_v | 0:8ad47e2b6f00 | 34 | LPC_PINCON->PINSEL0 |= (1 << 4); /* Pin P0.2 used as TXD0 (Com0) */ |
igor_v | 0:8ad47e2b6f00 | 35 | LPC_PINCON->PINSEL0 |= (1 << 6); /* Pin P0.3 used as RXD0 (Com0) */ |
igor_v | 21:bc8c1cec3da6 | 36 | |
igor_v | 21:bc8c1cec3da6 | 37 | LPC_UART0->LCR = 0x83; |
igor_v | 21:bc8c1cec3da6 | 38 | usFdiv = (FPCLK / 16) / UART0_BPS; |
igor_v | 0:8ad47e2b6f00 | 39 | LPC_UART0->DLM = usFdiv / 256; |
igor_v | 21:bc8c1cec3da6 | 40 | LPC_UART0->DLL = usFdiv % 256; |
igor_v | 21:bc8c1cec3da6 | 41 | LPC_UART0->LCR = 0x03; |
igor_v | 21:bc8c1cec3da6 | 42 | LPC_UART0->FCR = 0x06; |
igor_v | 0:8ad47e2b6f00 | 43 | } |
igor_v | 0:8ad47e2b6f00 | 44 | |
igor_v | 0:8ad47e2b6f00 | 45 | int UART0_SendByte_m (int ucData) |
igor_v | 0:8ad47e2b6f00 | 46 | { |
igor_v | 21:bc8c1cec3da6 | 47 | //while (!(LPC_UART0->LSR & 0x20)){}; |
igor_v | 0:8ad47e2b6f00 | 48 | |
igor_v | 21:bc8c1cec3da6 | 49 | return (LPC_UART0->THR = ucData); |
igor_v | 0:8ad47e2b6f00 | 50 | } |
igor_v | 21:bc8c1cec3da6 | 51 | void ClearBuffout(void) //очистка буфера на выдачу(сброс указателей) |
igor_v | 0:8ad47e2b6f00 | 52 | { |
igor_v | 21:bc8c1cec3da6 | 53 | InputIndexBO=0; |
igor_v | 21:bc8c1cec3da6 | 54 | OutputIndexBO=0; |
igor_v | 0:8ad47e2b6f00 | 55 | } |
igor_v | 21:bc8c1cec3da6 | 56 | void SendToBuffByte(unsigned int *input) // запись в буфер на выдачу одного значения инт(беззнакового) |
igor_v | 0:8ad47e2b6f00 | 57 | { |
igor_v | 21:bc8c1cec3da6 | 58 | InputIndexBO++; |
igor_v | 21:bc8c1cec3da6 | 59 | InputIndexBO &= 0x3ff; |
igor_v | 21:bc8c1cec3da6 | 60 | BuffOut[InputIndexBO]=*input; |
igor_v | 0:8ad47e2b6f00 | 61 | } |
igor_v | 21:bc8c1cec3da6 | 62 | void SendToBuff(unsigned char *input, unsigned int size)//запись нескольких значений с указанием размерности записи в буфер на выдачу. |
igor_v | 0:8ad47e2b6f00 | 63 | { |
igor_v | 21:bc8c1cec3da6 | 64 | unsigned int i; |
igor_v | 21:bc8c1cec3da6 | 65 | for(i=0; i<size; i++) { |
igor_v | 21:bc8c1cec3da6 | 66 | InputIndexBO++; |
igor_v | 21:bc8c1cec3da6 | 67 | InputIndexBO &= 0x3ff; |
igor_v | 21:bc8c1cec3da6 | 68 | BuffOut[InputIndexBO]=*input++; |
igor_v | 21:bc8c1cec3da6 | 69 | } |
igor_v | 0:8ad47e2b6f00 | 70 | } |
igor_v | 0:8ad47e2b6f00 | 71 | |
igor_v | 0:8ad47e2b6f00 | 72 | |
igor_v | 21:bc8c1cec3da6 | 73 | void SendToBuffStr(char *s)//запись строки (конец отслеживается по нулю) в буфер на выдачу. |
igor_v | 0:8ad47e2b6f00 | 74 | { |
igor_v | 21:bc8c1cec3da6 | 75 | while (*s != 0) { |
igor_v | 21:bc8c1cec3da6 | 76 | InputIndexBO++; |
igor_v | 21:bc8c1cec3da6 | 77 | InputIndexBO &= 0x3ff; |
igor_v | 21:bc8c1cec3da6 | 78 | BuffOut[InputIndexBO]=*s++; |
igor_v | 21:bc8c1cec3da6 | 79 | } |
igor_v | 0:8ad47e2b6f00 | 80 | } |
igor_v | 0:8ad47e2b6f00 | 81 | |
igor_v | 0:8ad47e2b6f00 | 82 | |
igor_v | 21:bc8c1cec3da6 | 83 | void TakeFromBuff(void)//передача из буфера на выдачу. |
igor_v | 0:8ad47e2b6f00 | 84 | { |
igor_v | 21:bc8c1cec3da6 | 85 | if((OutputIndexBO != InputIndexBO) && (LPC_UART0 -> LSR & 0x20)) { |
igor_v | 21:bc8c1cec3da6 | 86 | OutputIndexBO++; |
igor_v | 21:bc8c1cec3da6 | 87 | OutputIndexBO &= 0x3ff; |
igor_v | 21:bc8c1cec3da6 | 88 | LPC_UART0->THR = BuffOut[OutputIndexBO]; |
igor_v | 21:bc8c1cec3da6 | 89 | } |
igor_v | 0:8ad47e2b6f00 | 90 | } |
igor_v | 0:8ad47e2b6f00 | 91 | |
igor_v | 21:bc8c1cec3da6 | 92 | |
igor_v | 21:bc8c1cec3da6 | 93 | |
igor_v | 0:8ad47e2b6f00 | 94 | /* |
igor_v | 21:bc8c1cec3da6 | 95 | void UART0_SendString (char *s) |
igor_v | 0:8ad47e2b6f00 | 96 | { |
igor_v | 21:bc8c1cec3da6 | 97 | while (*s != 0) |
igor_v | 0:8ad47e2b6f00 | 98 | { |
igor_v | 0:8ad47e2b6f00 | 99 | InputIndex++; |
igor_v | 0:8ad47e2b6f00 | 100 | InputIndex &= 0x3ff; |
igor_v | 0:8ad47e2b6f00 | 101 | BuffOut[InputIndex]=*s++; |
igor_v | 0:8ad47e2b6f00 | 102 | } |
igor_v | 0:8ad47e2b6f00 | 103 | } |
igor_v | 0:8ad47e2b6f00 | 104 | */ |
igor_v | 0:8ad47e2b6f00 | 105 | |
igor_v | 0:8ad47e2b6f00 | 106 | void ClearBuffIn(void) |
igor_v | 0:8ad47e2b6f00 | 107 | { |
igor_v | 21:bc8c1cec3da6 | 108 | InputIndexBI=0; |
igor_v | 21:bc8c1cec3da6 | 109 | OutputIndexBI=0; |
igor_v | 0:8ad47e2b6f00 | 110 | } |
igor_v | 0:8ad47e2b6f00 | 111 | |
igor_v | 0:8ad47e2b6f00 | 112 | void BuffDataReady(void) |
igor_v | 0:8ad47e2b6f00 | 113 | { |
igor_v | 21:bc8c1cec3da6 | 114 | if((OutputIndexBI != InputIndexBI) && (!(LPC_UART0 -> LSR & 0x01))) { |
igor_v | 21:bc8c1cec3da6 | 115 | |
igor_v | 21:bc8c1cec3da6 | 116 | } |
igor_v | 0:8ad47e2b6f00 | 117 | } |
igor_v | 0:8ad47e2b6f00 | 118 | void ReadDataInBuff(void) |
igor_v | 0:8ad47e2b6f00 | 119 | { |
igor_v | 21:bc8c1cec3da6 | 120 | while (LPC_UART0->LSR & 0x01) { |
igor_v | 21:bc8c1cec3da6 | 121 | BuffIn[InputIndexBI] = LPC_UART0->RBR; |
igor_v | 21:bc8c1cec3da6 | 122 | InputIndexBI++; |
igor_v | 21:bc8c1cec3da6 | 123 | } |
igor_v | 0:8ad47e2b6f00 | 124 | } |