123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #include "HD44780.h"
- static void HD44780_WriteNibble(const uint8_t nib)
- {
-
- PORTD = (PORTD & ~(ENABLE | LO4_MASK)) | (nib & LO4_MASK);
-
- asm volatile("nop\n\t"
- "nop\n\t"
- :: );
-
- PORTD |= ENABLE;
- asm volatile("nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- :: );
-
- PORTD &= ~ENABLE;
- asm volatile("nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- "nop\n\t"
- :: );
- }
- static void HD44780_WriteByte(const uint8_t c)
- {
- HD44780_WriteNibble(HI4(c));
- HD44780_WriteNibble(LO4(c));
- }
- static void HD44780_PowerUp4Bit(void)
- {
-
- _delay_ms(40);
- HD44780_WriteNibble(0x03);
-
- _delay_ms(5);
- HD44780_WriteNibble(0x03);
-
- _delay_us(100);
- HD44780_WriteNibble(0x03);
-
- _delay_us(50);
- HD44780_WriteNibble(0x02);
-
- _delay_us(50);
- }
- void HD44780_Initialize(void)
- {
- PORTD &= ~ALL_BITS;
- DDRD |= ALL_BITS;
- HD44780_PowerUp4Bit();
- }
- void HD44780_WriteCommand(const uint8_t c)
- {
- PORTD &= ~RS;
- HD44780_WriteByte(c);
- _delay_us(50);
- }
- void HD44780_WriteData(const uint8_t c)
- {
- PORTD |= RS;
- HD44780_WriteByte(c);
- PORTD &= ~RS;
- _delay_us(50);
- }
|