NetBurner 3.1
hd44780.h
1 #ifndef __HD44780_H
2 #define __HD44780_H
3 /*NB_REVISION*/
4 
5 /*NB_COPYRIGHT*/
6 
7 #include <predef.h>
8 
9 class HD44780_LCD_Bus {
10  volatile uint8_t bus[2];
11  class reg {
12  uint8_t addr;
13  volatile uint8_t * lcd;
14 public:
15  reg(uint8_t addr, volatile uint8_t * lcd) : addr(addr), lcd(lcd) {}
16  operator uint8_t() { return read(); }
17  uint8_t operator=(uint8_t val) { write(val); return val; }
18 
19  uint8_t read() { return lcd[addr]; }
20  void write(uint8_t val)
21  {
22  while (lcd[0] & 0x80) { asm("dsb"); }
23  lcd[addr] = val;
24  }
25  };
26 public:
27  HD44780_LCD_Bus();
28 
29  void init(uint8_t cols, uint8_t rows);
30  void putchar(char c);
31  void putstr(const char *str);
32  void setCursor(int row, int col);
33  void clr();
34 
35  reg operator[] (int i) { return reg(i & 0x1, bus); }
36  friend class HD44780_LCD;
37 };
38 
39 class HD44780_LCD {
40 public:
41  enum cursorDisp_t {
42  CURSOR_OFF = 0,
43  CURSOR_ON = 2,
44  CURSOR_BLINK= 3
45  };
46 
47 private:
48  HD44780_LCD_Bus &bus;
49  uint8_t cols;
50  uint8_t rows;
51  cursorDisp_t cursorDisp;
52  bool dispState;
53 public:
54  HD44780_LCD(HD44780_LCD_Bus &bus, uint8_t cols, uint8_t rows);
55 
56  void init() { bus.init(cols, rows); }
57  void putchar(char c) { bus.putchar(c); }
58  void putstr(const char *str) { bus.putstr(str); }
59  void setCursor(int row, int col) { bus.setCursor(row, col); }
60  void enableCursor(cursorDisp_t disp);
61  void enableDisplay(bool enable);
62  void clr();
63 
64  HD44780_LCD_Bus::reg operator[] (int i) { return bus[i]; }
65 };
66 
67 
68 
69 #endif /* ----- #ifndef __HD44780_H ----- */
void init()
System initialization. Normally called at the beginning of all applications.
Definition: init.cpp:22
int write(int fd, const char *buf, int nbytes)
This function writes data to the stream associated with a file descriptor (fd).
Definition: fileio.cpp:152
int read(int fd, char *buf, int nbytes)
This function reads data from a file descriptor (fd), and will block forever until at least one byte ...
Definition: fileio.cpp:288