?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik //*****************************************************************************
2 // File Name : rprintftest.c
3 //
4 // Title : example usage of rprintf library functions
5 // Revision : 1.0
6 // Notes :
7 // Target MCU : Atmel AVR series
8 // Editor Tabs : 4
9 //
10 // Revision History:
11 // When Who Description of change
12 // ----------- ----------- -----------------------
13 // 10-Sep-2002 pstang Created the program
14 //*****************************************************************************
15  
16  
17 //----- Include Files ---------------------------------------------------------
18 #include <avr/io.h> // include I/O definitions (port names, pin names, etc)
19 #include <avr/interrupt.h> // include interrupt support
20  
21 #include "global.h" // include our global settings
22 #include "uart.h" // include uart function library
23 #include "rprintf.h" // include printf function library
24 #include "timer.h" // include timer function library (timing, PWM, etc)
25 #include "vt100.h" // include VT100 terminal support
26  
27 void rprintfTest(void);
28  
29 //----- Begin Code ------------------------------------------------------------
30 int main(void)
31 {
32 // initialize our libraries
33 // initialize the UART (serial port)
34 uartInit();
35 // set the baud rate of the UART for our debug/reporting output
36 uartSetBaudRate(9600);
37 // initialize the timer system
38 timerInit();
39  
40 // initialize rprintf system
41 // - use uartSendByte as the output for all rprintf statements
42 // this will cause all rprintf library functions to direct their
43 // output to the uart
44 // - rprintf can be made to output to any device which takes characters.
45 // You must write a function which takes an unsigned char as an argument
46 // and then pass this to rprintfInit like this: rprintfInit(YOUR_FUNCTION);
47 rprintfInit(uartSendByte);
48  
49 // initialize vt100 library
50 vt100Init();
51  
52 // clear the terminal screen
53 vt100ClearScreen();
54  
55 // run the test
56 rprintfTest();
57  
58 return 0;
59 }
60  
61 void rprintfTest(void)
62 {
63 u16 val;
64 u08 mydata;
65 u08 mystring[10];
66 float b;
67 u08 small;
68 u16 medium;
69 u32 big;
70  
71 // print a little intro message so we know things are working
72 rprintf("\r\nThis is my cool program!\r\n");
73  
74  
75 rprintf("\r\nWelcome to rprintf Test!\r\n");
76  
77 // print single characters
78 rprintfChar('H');
79 rprintfChar('e');
80 rprintfChar('l');
81 rprintfChar('l');
82 rprintfChar('o');
83 // print a constant string stored in FLASH
84 rprintfProgStrM(" World!");
85 // print a carriage return, line feed combination
86 rprintfCRLF();
87 // note that using rprintfCRLF() is more memory-efficient than
88 // using rprintf("\r\n"), especially if you do it repeatedly
89  
90 mystring[0] = 'A';
91 mystring[1] = ' ';
92 mystring[2] = 'S';
93 mystring[3] = 't';
94 mystring[4] = 'r';
95 mystring[5] = 'i';
96 mystring[6] = 'n';
97 mystring[7] = 'g';
98 mystring[8] = '!';
99 mystring[9] = 0; // null termination
100  
101 // print a null-terminated string from RAM
102 rprintfStr(mystring);
103 rprintfCRLF();
104  
105 // print a section of a string from RAM
106 // - start at index 2
107 // - print 6 characters
108 rprintfStrLen(mystring, 2, 6);
109 rprintfCRLF();
110  
111  
112 val = 24060;
113 mydata = 'L';
114  
115 // print a decimal number
116 rprintf("This is a decimal number: %d\r\n", val);
117  
118 // print a hex number
119 rprintf("This is a hex number: %x\r\n", mydata);
120  
121 // print a character
122 rprintf("This is a character: %c\r\n", mydata);
123  
124 // print hex numbers
125 small = 0x12; // a char
126 medium = 0x1234; // a short
127 big = 0x12345678; // a long
128  
129 rprintf("This is a 2-digit hex number (char) : ");
130 rprintfu08(small);
131 rprintfCRLF();
132  
133 rprintf("This is a 4-digit hex number (short): ");
134 rprintfu16(medium);
135 rprintfCRLF();
136  
137 rprintf("This is a 8-digit hex number (long) : ");
138 rprintfu32(big);
139 rprintfCRLF();
140  
141 // print a formatted decimal number
142 // - use base 10
143 // - use 8 characters
144 // - the number is signed [TRUE]
145 // - pad with '.' periods
146 rprintf("This is a formatted decimal number: ");
147 rprintfNum(10, 8, TRUE, '.', val);
148 rprintfCRLF();
149  
150 b = 1.23456;
151  
152 // print a floating point number
153 // use 10-digit precision
154  
155 // NOTE: TO USE rprintfFloat() YOU MUST ENABLE SUPPORT IN global.h
156 // use the following in your global.h: #define RPRINTF_FLOAT
157  
158 //rprintf("This is a floating point number: ");
159 //rprintfFloat(8, b);
160 //rprintfCRLF();
161 }
162  
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3