Timer1 Compare Match  ver.1.0
Nguyen 2016
_debug.h
Go to the documentation of this file.
1 /*
2 * Debugging lib based on liquid crystal kner 2015
3 *
4 * uses http://www.dfrobot.com/wiki/index.php/Arduino_LCD_KeyPad_Shield_%28SKU:_DFR0009%29
5 * for debugging
6 */
7 
8 
9 #ifndef _DEBUG_H
10 #define _DEBUG_H
11 
12 #ifdef DEBUG_LCD
13 // this section is not compiled in debug mode
14 
15 #include <Arduino.h>
16 #include "LiquidCrystal.h"
17 
18 #define NCHARS 16
19 #define LINE1 0
20 #define LINE2 1
21 
22 #define L(x) debug.setCursor(0,0);debug.print(x);
23 #define L2(x,y) debug.setCursor(0,0);debug.print(x,y);
24 #define R(x) debug.setCursor(12,0);debug.print(x);
25 #define R2(x,y) debug.rightToLeft();debug.setCursor(12,0);debug.print(x,y);
26 #define M(x) debug.setCursor(8,0);debug.print(x);
27 #define M2(x,y) debug.setCursor(8,0);debug.print(x,y);
28 #define T(x) debug.trace(x);
29 #define THEX(x) debug.tracehex(x);
30 #define TDEC(x) debug.tracedec(x);
31 #define WAIT_MS(x) debug.wait_ms(x);
32 
33 
34 class Debug: public LiquidCrystal{
35  private:
36 
37  char buffer[NCHARS];
38 
39  public: Debug(): LiquidCrystal(8, 9, 4, 5, 6, 7){
40  LiquidCrystal::begin(NCHARS,LINE2+1);
41  }
42 
43  /*
44  trace adds new strings at the beginning and rotates the string to the right
45  */
46  void trace(const char* s){
47  uint8_t len=strlen(s);
48  //rotate right by len positions
49  for (uint8_t pos=NCHARS-1;pos>0; pos--) buffer[pos]=buffer[pos-len-1];
50  //copy s to start of buffer
51  for (uint8_t i=0; i<len;i++) buffer[i]=s[i];
52  //separator
53  buffer[len]='|';
54  LiquidCrystal::setCursor(0,1);
55  LiquidCrystal::print(buffer);
56  }
57  void tracehex(uint16_t u){
58  char buf[6];
59  itoa(u,buf,16);
60  trace(buf);
61  }
62  void tracedec(uint16_t u){
63  char buf[8];
64  itoa(u,buf,10);
65  trace(buf);
66  }
67 
68  void wait_ms(uint16_t time){
69  for (volatile long int i=0; i<(time*150L); i++); //just wait
70  }
71 
72 };
73 
74 Debug debug;
75 #else
76 // no flash memory used if undef DEBUG_LCD
77 
78  #define L(x) ((void) 0);
79  #define L2(x,y) ((void) 0);
80  #define R(x) ((void) 0);
81  #define R2(x,y) ((void) 0);
82  #define M(x) ((void) 0);
83  #define M2(x,y) ((void) 0);
84  #define M2(x,y) ((void) 0);
85  #define T(x) ((void) 0);
86  #define THEX(x) ((void) 0);
87  #define TDEC(x) ((void) 0);
88  #define WAIT_MS(x) ((void) 0);
89 
90 #endif /* DEBUG_LCD */
91 #endif /* _DEBUG_H */
#define L(x)
Definition: _debug.h:78