Rev Author Line No. Line
615 kaklik 1 #include <avr/pgmspace.h>
2 #include <avr/interrupt.h>
3 #include <avr/signal.h>
4  
5 #include "common.h"
6 #include "usart.h"
7  
8  
9 void USART0::SendData(uint8_t aData) {
10 while(!TESTBIT(UCSR0A,(1 << UDRE0)));
11 UDR0 = aData;
12 }
13  
14 uint8_t USART0::ReceiveData() {
15 while(!TESTBIT(UCSR0A,(1 << RXC0)));
16 return UDR0;
17 }
18  
19 // a non-exported helper function
20 static char MakeHexDigit(uint8_t aDigit) {
21 if (aDigit > 9) return 'a'+aDigit-10; else return '0'+aDigit;
22 }
23  
24 void USART0::SendHexData(uint8_t aData) {
25 SendData(MakeHexDigit(aData >> 4));
26 SendData(MakeHexDigit(aData & 0x0f));
27 }
28  
29 void USART0::SendHexData(uint16_t aData) {
30 SendHexData((uint8_t)(aData >> 8));
31 SendHexData((uint8_t)(aData & 0xff));
32 }
33  
34 void USART0::SendHexData(uint32_t aData) {
35 SendHexData((uint16_t)(aData >> 16));
36 SendHexData((uint16_t)(aData & 0xffff));
37 }
38  
39 void USART0::SendHexData(int16_t aData) {
40 if (aData < 0) {
41 SendData('-');
42 aData = -aData;
43 } else {
44 SendData(' ');
45 }
46 SendHexData((uint16_t)aData);
47 }
48  
49 void USART0::SendHexData(int32_t aData) {
50 if (aData < 0) {
51 SendData('-');
52 aData = -aData;
53 } else {
54 SendData(' ');
55 }
56 SendHexData((uint32_t)aData);
57 }
58  
59 void USART0::SendString(const char *aString) {
60 while(aString != 0) SendData(*(aString++));
61 }
62  
63 void USART0::SendPGString(const char *aString) {
64 while(aString != 0) SendData(pgm_read_byte(aString++));
65 }