Transistor Gijutsu, October 2014, Special Features Chapter 7,Software of the LCRmeter トランジスタ技術2014年10月号 特集第7章のソフトウェア,サバイバルLCRメータ
Dependencies: mbed
lcd_P4bit.cpp@0:b3e41ec91adf, 2014-08-28 (annotated)
- Committer:
- Dance
- Date:
- Thu Aug 28 07:09:42 2014 +0000
- Revision:
- 0:b3e41ec91adf
????????2014?10?????7????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Dance | 0:b3e41ec91adf | 1 | // |
Dance | 0:b3e41ec91adf | 2 | // HD44780 type 4bit parallel LCD control |
Dance | 0:b3e41ec91adf | 3 | // |
Dance | 0:b3e41ec91adf | 4 | #include "mbed.h" |
Dance | 0:b3e41ec91adf | 5 | |
Dance | 0:b3e41ec91adf | 6 | DigitalOut LCDRS(P0_3); // LCD module Register Select |
Dance | 0:b3e41ec91adf | 7 | DigitalOut LCDE(P0_1); // LCD module Enable |
Dance | 0:b3e41ec91adf | 8 | DigitalOut LCDD4(P1_19); // LCD data lines(4bit) |
Dance | 0:b3e41ec91adf | 9 | DigitalOut LCDD5(P0_5); |
Dance | 0:b3e41ec91adf | 10 | DigitalOut LCDD6(P0_4); |
Dance | 0:b3e41ec91adf | 11 | DigitalOut LCDD7(P1_15); |
Dance | 0:b3e41ec91adf | 12 | |
Dance | 0:b3e41ec91adf | 13 | void enable( void ) |
Dance | 0:b3e41ec91adf | 14 | { |
Dance | 0:b3e41ec91adf | 15 | wait_us( 1 ); |
Dance | 0:b3e41ec91adf | 16 | LCDE = 1; |
Dance | 0:b3e41ec91adf | 17 | wait_us( 1 ); |
Dance | 0:b3e41ec91adf | 18 | LCDE = 0; |
Dance | 0:b3e41ec91adf | 19 | wait_us( 1 ); |
Dance | 0:b3e41ec91adf | 20 | } |
Dance | 0:b3e41ec91adf | 21 | |
Dance | 0:b3e41ec91adf | 22 | void lcd_set4bit( unsigned char d ) |
Dance | 0:b3e41ec91adf | 23 | { |
Dance | 0:b3e41ec91adf | 24 | LCDD4 = d & 0x01; |
Dance | 0:b3e41ec91adf | 25 | LCDD5 = d & 0x02; |
Dance | 0:b3e41ec91adf | 26 | LCDD6 = d & 0x04; |
Dance | 0:b3e41ec91adf | 27 | LCDD7 = d & 0x08; |
Dance | 0:b3e41ec91adf | 28 | } |
Dance | 0:b3e41ec91adf | 29 | |
Dance | 0:b3e41ec91adf | 30 | void lcd_write4bit( unsigned char d ) |
Dance | 0:b3e41ec91adf | 31 | { |
Dance | 0:b3e41ec91adf | 32 | lcd_set4bit( d ); |
Dance | 0:b3e41ec91adf | 33 | enable(); |
Dance | 0:b3e41ec91adf | 34 | } |
Dance | 0:b3e41ec91adf | 35 | |
Dance | 0:b3e41ec91adf | 36 | void LCD_cmd( char c ) |
Dance | 0:b3e41ec91adf | 37 | { |
Dance | 0:b3e41ec91adf | 38 | LCDRS = 0; |
Dance | 0:b3e41ec91adf | 39 | lcd_write4bit( c / 16 ); |
Dance | 0:b3e41ec91adf | 40 | lcd_write4bit( c & 0x0f ); |
Dance | 0:b3e41ec91adf | 41 | wait_us( 30 ); |
Dance | 0:b3e41ec91adf | 42 | } |
Dance | 0:b3e41ec91adf | 43 | |
Dance | 0:b3e41ec91adf | 44 | void LCD_data( char d ) |
Dance | 0:b3e41ec91adf | 45 | { |
Dance | 0:b3e41ec91adf | 46 | LCDRS = 1; |
Dance | 0:b3e41ec91adf | 47 | lcd_write4bit( d / 16 ); |
Dance | 0:b3e41ec91adf | 48 | lcd_write4bit( d & 0x0f ); |
Dance | 0:b3e41ec91adf | 49 | wait_us( 30 ); |
Dance | 0:b3e41ec91adf | 50 | } |
Dance | 0:b3e41ec91adf | 51 | |
Dance | 0:b3e41ec91adf | 52 | void LCD_puts( char *s ) |
Dance | 0:b3e41ec91adf | 53 | { |
Dance | 0:b3e41ec91adf | 54 | while( *s ) LCD_data( *s++ ); |
Dance | 0:b3e41ec91adf | 55 | } |
Dance | 0:b3e41ec91adf | 56 | |
Dance | 0:b3e41ec91adf | 57 | void LCD_iniz( void ) |
Dance | 0:b3e41ec91adf | 58 | { |
Dance | 0:b3e41ec91adf | 59 | LCDE = 0; |
Dance | 0:b3e41ec91adf | 60 | LCDRS = 0; |
Dance | 0:b3e41ec91adf | 61 | wait_ms( 40 ); // wait 40mS |
Dance | 0:b3e41ec91adf | 62 | lcd_write4bit( 0x03 ); |
Dance | 0:b3e41ec91adf | 63 | wait_ms( 5 ); |
Dance | 0:b3e41ec91adf | 64 | lcd_write4bit( 0x03 ); |
Dance | 0:b3e41ec91adf | 65 | wait_ms( 2 ); |
Dance | 0:b3e41ec91adf | 66 | lcd_write4bit( 0x03 ); |
Dance | 0:b3e41ec91adf | 67 | wait_ms( 2 ); |
Dance | 0:b3e41ec91adf | 68 | lcd_write4bit( 0x02 ); // 4bit interface select |
Dance | 0:b3e41ec91adf | 69 | LCD_cmd( 0x28 ); // 2 lines 5x8 chr. |
Dance | 0:b3e41ec91adf | 70 | LCD_cmd( 0x08 ); // display off |
Dance | 0:b3e41ec91adf | 71 | LCD_cmd( 0x01 ); // display clear |
Dance | 0:b3e41ec91adf | 72 | wait_ms( 2 ); |
Dance | 0:b3e41ec91adf | 73 | LCD_cmd( 0x06 ); // entry mode |
Dance | 0:b3e41ec91adf | 74 | LCD_cmd( 0x0C ); // display on |
Dance | 0:b3e41ec91adf | 75 | } |
Dance | 0:b3e41ec91adf | 76 |