comparison uart_addon.c @ 9:7da9a3f23592

Import ds18x20 code
author Matt Johnston <matt@ucc.asn.au>
date Fri, 18 May 2012 23:57:08 +0800
parents
children
comparison
equal deleted inserted replaced
8:c55321727d02 9:7da9a3f23592
1 /*************************************************************************
2 Title: UART addon-library
3 Author: Martin Thomas <[email protected]>
4 http://www.siwawi.arubi.uni-kl.de/avr_projects
5 Software: AVR-GCC 3.3/3.4, Peter Fleury's UART-Library
6
7 DESCRIPTION:
8
9 USAGE:
10 Refere to the header file uart_addon.h for a description of the routines.
11
12 *************************************************************************/
13
14 #include <stdlib.h>
15
16 #include <avr/io.h>
17 #include "uart.h"
18
19
20 /*************************************************************************
21 Function: uart_put_int()
22 Purpose: transmit integer as ASCII to UART
23 Input: integer value
24 Returns: none
25 **************************************************************************/
26 void uart_put_int( const int val )
27 {
28 char buffer[10];
29 uart_puts( itoa( val, buffer, 10 ) );
30 } /* uart_puti */
31
32 /*************************************************************************
33 Function: uart_put_longint()
34 Purpose: transmit long integer as ASCII to UART
35 Input: integer value
36 Returns: none
37 **************************************************************************/
38 void uart_put_longint( const long int val )
39 {
40 char buffer[15];
41 uart_puts( ltoa( val, buffer, 10 ) );
42 } /* uart_puti */
43
44 /*************************************************************************
45 Function: uart_put_ulongint()
46 Purpose: transmit long integer as ASCII to UART
47 Input: integer value
48 Returns: none
49 **************************************************************************/
50 void uart_put_ulongint( const unsigned long int val )
51 {
52 char buffer[15];
53 uart_puts( utoa( val, buffer, 10 ) );
54 } /* uart_puti */
55
56 /*************************************************************************
57 Function: uart_puthex_nibble()
58 Purpose: transmit lower nibble as ASCII-hex to UART
59 Input: byte value
60 Returns: none
61 **************************************************************************/
62 void uart_puthex_nibble(const unsigned char b)
63 {
64 unsigned char c = b & 0x0f;
65 if ( c > 9 ) {
66 c += 'A'-10;
67 }
68 else {
69 c += '0';
70 }
71 uart_putc(c);
72 } /* uart_puthex_nibble */
73
74 /*************************************************************************
75 Function: uart_puthex_byte()
76 Purpose: transmit upper and lower nibble as ASCII-hex to UART
77 Input: byte value
78 Returns: none
79 **************************************************************************/
80 void uart_puthex_byte( const unsigned char b )
81 {
82 uart_puthex_nibble( b >> 4 );
83 uart_puthex_nibble( b );
84 } /* uart_puthex_byte */
85
86 /*************************************************************************
87 Function: uart_puthex_long()
88 Purpose: transmit unsigned long as ASCII-hex to UART
89 Input: uint32_t value
90 Returns: none
91 **************************************************************************/
92 void uart_puthex_long( const unsigned long l )
93 {
94 uart_puthex_byte( (unsigned char)( l >> 24 ) );
95 uart_puthex_byte( (unsigned char)( l >> 16 ) );
96 uart_puthex_byte( (unsigned char)( l >> 8 ) );
97 uart_puthex_byte( (unsigned char)( l ) );
98 } /* uart_puthex_byte */
99
100
101 /*************************************************************************
102 Function: uart_putbin_byte()
103 Purpose: transmit byte as ASCII-bin to UART
104 Input: byte value
105 Returns: none
106 **************************************************************************/
107 void uart_putbin_byte( const unsigned char b )
108 {
109 signed char i;
110 for ( i= 7;i >= 0;i-- ) {
111 if ( b & ( 1 << i ) ) {
112 uart_putc( '1' );
113 }
114 else {
115 uart_putc( '0' );
116 }
117 }
118 } /* uart_putbin_byte */