#include "LCD_44780.h"
#include <util/delay.h>
namespace lcd{
static void ena(word);
#ifdef __AVR_ATmega32U4__
inline void RS(bool x) {if (x) PORTB|=0x04; else PORTB&=~0x04;}
inline void E(bool x) {if (x) PORTB|=0x02; else PORTB&=~0x02;}
static void send(char c,word x=US2CY(200)) {
PORTF=c;
ena(US2CY(200));
PORTF=c<<4|c>>4;
ena(x);
}
#else
inline void RS(bool x) {if (!x) PORTA&=~0x20;}
inline void E(bool x) {if (x) PORTA|=0x10; else PORTA&=~0x10;}
static void send(char c,word x=US2CY(200)) {
DDRA = 0x3F; // zu Ausgängen machen (Bus anfordern)
// DDRB |= 0x80;
byte h= PORTA;
swap(c);
PORTA = h&0xF0|c&0x0F;
swap(c);
ena(US2CY(200));
PORTA = h&0xF0|c&0x0F;
ena(x);
// DDRB &=~0x80;
DDRA = 0x10; // zu Eingängen machen (Bus freigeben)
PORTA = h|0x20;// 5 Pullups aktivieren: ..hLhhhh
}
#endif
void send0(char c, word x) {RS(0);send(c,x);}
void write(char c) {
RS(1);
send(c);
}
static void ena(word x) {
E(1);
_delay_us(1.0);
E(0);
for (byte n=CLKPR;n;n--) asm( // aufrundend rechtsschieben
" lsr %B0 \n"
" ror %A0 \n"
" adc %A0,__zero_reg__ \n"
" adc %B0,__zero_reg__ \n"
:"=r"(x):"0"(x));
_delay_loop_2(x);
}
void init() {
_delay_ms(15.0/8); // >15ms
// E(0);
send0(0x03,US2CY(10000)); // initiate
ena(US2CY(2000)); // 15us +impuls
send0(0x02); // 4-Bit-Bus
send0(0x28); // 2 Zeilen
off();
clear();
send0(0x06); // Entry Mode Set
send0(0x80); // Set DD-RAM Address
on();
}
void write(const char*s) {
while (char a=*s++) write(a);
}
void write_rom(const char*s) {
while (char a=pgm_read_byte(s++)) write(a);
}
void userchars(const char*s) {
send0(0x40);
for (char i=0;i<8*8;i++) write(pgm_read_byte(s++));
}
}//namespace
| Detected encoding: UTF-8 | 0
|