LCD displej EA-DOGM 163
Zo stránky SensorWiki
Dokumentácia
- Datasheet displeja EA-DOGM163
- Datasheet radiča displeja ST7036 s tabuľkou inštrukcií a mapou znakov
- Stránka výrobcu displejov Display Visions
- Simulátor displeja pre Win
/*
* lcd.h Library for MISA @ FEI STU
*
* Created: 21. 4. 2024 19:31:48
* Author: Richard Balogh based on gitHub code for EA*DOGM163
*/
#ifndef LCD_H_
#define LCD_H_
#include <stdlib.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#define CHARACTER_BUFFER_BASE_ADDRESS 0x80
#define CHARACTERS_PER_ROW 16
#define DISPLAY_RS_PORT PORTD
#define DISPLAY_RS_DDR DDRD
#define DISPLAY_RS_PIN 2
#define DISPLAY_CSB_PORT PORTD
#define DISPLAY_CSB_DDR DDRD
#define DISPLAY_CSB_PIN 4
#define DISPLAY_BKLT_PORT PORTD
#define DISPLAY_BKLT_DDR DDRD
#define DISPLAY_BKLT_PIN 6
#define DISPLAY_RS_low (DISPLAY_RS_PORT &= ~(1<<DISPLAY_RS_PIN))
#define DISPLAY_RS_high (DISPLAY_RS_PORT |= (1<<DISPLAY_RS_PIN))
#define DISPLAY_CSB_low (DISPLAY_CSB_PORT &= ~(1<<DISPLAY_CSB_PIN))
#define DISPLAY_CSB_high (DISPLAY_CSB_PORT |= (1<<DISPLAY_CSB_PIN))
#define DISPLAY_BKLT_low (DISPLAY_BKLT_PORT &= ~(1<<DISPLAY_BKLT_PIN))
#define DISPLAY_BKLT_high (DISPLAY_BKLT_PORT |= (1<<DISPLAY_BKLT_PIN))
//instructions (see the ST7036 instruction set for further information)
#define INSTRUCTION_CLEAR_DISPLAY 0b00000001
#define INSTRUCTION_FUNCTION_SET_INIT_0 0b00110011
#define INSTRUCTION_FUNCTION_SET_INIT_1 0b00110010
#define INSTRUCTION_FUNCTION_SET_INIT_2 0b00101001
#define INSTRUCTION_INSTRUCTION_SET_0 0b00101000
#define INSTRUCTION_INSTRUCTION_SET_1 0b00101001
#define INSTRUCTION_BIAS_SET 0b00010101
#define INSTRUCTION_POWER_CONTROL 0b01010011
#define INSTRUCTION_FOLLOWER_CONTROL 0b01101100
#define INSTRUCTION_CONTRAST_SET 0b01111111
#define INSTRUCTION_DISPLAY_ON 0b00001100
#define INSTRUCTION_ENTRY_MODE 0b00000110
void lcd_init(void);
void lcd_write( char data );
void lcd_data( char data );
void lcd_command( char instruction );
void lcd_putc( char znak );
void lcd_puts( char *string );
void lcd_clear( void );
void lcd_clearline( unsigned char zeile );
void lcd_setCursor(char row, char col);
void lcd_bklt( char OnOff);
#endif /* LCD_H_ */
#include "lcd.h"
#include "uart.h"
/* Primitivne funkcie, nepredpoklada sa ich vyuzitie uzivatelom */
/* Funkcia zapise jeden bajt po SPI zbernici do zariadenia */
void lcd_write( char data )
{
signed char index = 8;
char c_data;
clear_bit(DISPLAY_CSB_PORT,DISPLAY_CSB_PIN); // Chip-Select do log.0
c_data = data;
do
{
_delay_us(6);
if ( c_data & 0x80 ) // najyssi bit zamaskujeme
set_bit(PORTB,3); // a posleme ho na zbernicu
else
clear_bit(PORTB,3); // cez vodic MOSI (alebo len SI)
_delay_us(5); // a vygenerujeme jeden hodinovy pulz
clear_bit(PORTB,5); // na vyvod CLK
_delay_us(6);
set_bit(PORTB,5);
c_data = c_data << 1; // na najvyssie miesto posunieme dalsi bit
index--;
} while (index > 0); // a toto spravime dokola 8x
// a napokon zdvihneme /CS do log.1
_delay_ms( 2 );
set_bit(DISPLAY_CSB_PORT,DISPLAY_CSB_PIN);
}
/* Funkcia zapise jeden byte do riadiaceho (Control) registra */
void lcd_command( char instruction )
{
clear_bit(DISPLAY_RS_PORT,DISPLAY_RS_PIN);
_delay_us( 1 );
lcd_write( instruction );
}
/* Funkcia zapise jeden byte do datoveho (Data) registra */
void lcd_data( char data )
{
set_bit(DISPLAY_RS_PORT,DISPLAY_RS_PIN);
_delay_us( 7 );
lcd_write( data );
}
/* Uzivatelske funkcie, ktore ma pouzivat uzivatel */
/* Inicializacia displeja podla datasheetu pre radic ST7036 */
void lcd_init(void)
{
DDRB |= (1<<PB3) | (1<<PB5); // MOSI + SCK as OUTPUTs
DISPLAY_RS_DDR |= 1<<DISPLAY_RS_PIN; // All signals as OUTPUT
DISPLAY_CSB_DDR |= 1<<DISPLAY_CSB_PIN;
DISPLAY_BKLT_DDR |= 1<<DISPLAY_BKLT_PIN;
set_bit(PORTB,5); // set_bit( ST7036_CLK );
set_bit(DISPLAY_CSB_PORT,DISPLAY_CSB_PIN); // set_bit( ST7036_CSB );
clear_bit(DISPLAY_RS_PORT,DISPLAY_RS_PIN); // set_bit( ST7036_CSB );
_delay_ms(50); // pockame viac ako 40ms na ustalenie napajacieho napatia
lcd_command( 0x39 ); // Function set; 8-bit Datenlänge, 2 Zeilen, Instruction table 1
_delay_us(50); // mehr als 26,3µs warten
lcd_command( 0x1d ); // Bias Set; BS 1/5; 3 zeiliges Display /1d
_delay_us(50); // mehr als 26,3µs warten
lcd_command( 0x50 ); // Booster aus; Kontrast C5, C4 setzen /50
_delay_us(50); // mehr als 26,3µs warten
lcd_command( 0x6c ); // Spannungsfolger und Verstärkung setzen /6c
_delay_ms( 500 ); // mehr als 200ms warten !!!
lcd_command( 0x7c ); // Kontrast C3, C2, C1 setzen /7c
_delay_us(50); // mehr als 26,3µs warten
lcd_command( 0x38 ); // Display EIN, Cursor EIN, Cursor BLINKEN /0f
_delay_us(50); // mehr als 26,3µs warten
lcd_command( 0x0f ); // Display EIN, Cursor EIN, Cursor BLINKEN /0f
_delay_us(50); // mehr als 26,3µs warten
lcd_command( 0x01 ); // Display löschen, Cursor Home
_delay_ms(400); //
lcd_command( 0x06 ); // Cursor Auto-Increment
_delay_us(50); // mehr als 26,3µs warten
}
/* Funkcia zobrazi na pozicii kurzoru jeden znak */
/* Alias funkcia z dovodov kompatibility */
void lcd_putc( char znak )
{
lcd_data(znak);
}
/* Funkcia zobrazi na displeji nejaky text*/
void lcd_puts(char *string)
{
/* ToDo: toto je vasa uloha */
}
/* Funkcia nastavi kurzor na poziciu riadok, stlpec */
/* a text sa samozrejme vypise od kurzora dalej. */
void lcd_setCursor(char row, char col)
{
/* ToDo: aj toto je vasa uloha */
}
void lcd_clearline( unsigned char riadok )
{
unsigned char index;
lcd_setCursor( riadok, 0 );
for (index=1; index<20; index++) lcd_data( ' ' );
}
void lcd_clear( void )
{
lcd_clearline( 0 );
lcd_clearline( 1 );
lcd_clearline( 2 );
}
/* Funkcia zapne alebo vypne podsvietenie displeja */
void lcd_bklt( char OnOff)
{
if (OnOff)
DISPLAY_BKLT_high;
else
DISPLAY_BKLT_low;
}
/* Ukazkovy program pre LCD displej */
/*
* Blink.c Ver 0.1 (10. 3. 2024 9:47:21)
*
* Minimal working example for the FEI STU
* Function:
* a) setup serial interface and prepare stdio.h
* b) on-board LED blink
*
* Definitions:
* ATmega328P
* F_CPU 16000000UL
* BAUDRATE 9600
*
* Tato verzia nepodporuje printf s float aritmetikou!
* Ak ju pozadujete, treba pre float treba navyse:
* Toolchain -> AVR/GNU C -> Miscelanous -> Other Linker Flags: -Wl,-u,vfprintf -lprintf_flt
*
* Documentation: http://senzor.robotika.sk/mips/Blink
*
*/
#include <avr/io.h>
#include "uart.h"
#include "lcd.h"
#include <stdio.h>
FILE mystdout = FDEV_SETUP_STREAM(uart_putc, NULL, _FDEV_SETUP_WRITE);
int main(void)
{
hw_init();
uart_init();
lcd_init();
stdout = &mystdout; // printf() works from now
printf("Hello, world! \n");
lcd_puts("Hello, world!");
lcd_setCursor(1,12);
lcd_putc('X');
lcd_putc(':');
lcd_putc('1');
lcd_putc('2');
lcd_setCursor(2,0);
lcd_puts("Ahoj, svet!");
lcd_bklt(1);
while(1)
{
//TODO:: Please replace this code with your application code
}
return(0);
}
#include <Arduino.h>
#include <SPI.h>
#include <dogm_7036.h>
/*Available functions in dogm_7036 Libraray:
void initialize (byte p_cs, byte p_si, byte p_clk, byte p_rs, byte p_res, boolean sup_5V, byte lines);
void string (const char *str);
void ascii (char character);
void position (byte column, byte line);
void displ_onoff (boolean on);
void cursor_onoff (boolean on);
void define_char (byte mem_adress, byte *dat);
void clear_display (void);
void contrast (byte contr);
*/
#define LED_D1 16
#define SW_A 17
#define SW_B 7
#define SW_C 8
// LCD Displej:
#define CLK 13 //(aka PB5)
#define SI 11 //(aka PB3)
#define RS 2 // (aka PD2)
#define CS 4 // (aka PD4)
#define BKLT 6 // (aka PD6)
dogm_7036 LCD;
int BL_pin = 6; // BL je na pine D6
void init_backlight();
void mono_backlight(byte brightness);
void setup()
{
init_backlight(); //use mono backlight in this sample code. Please change it to your configuration
// CS, RS
LCD.initialize(CS,SI,CLK,RS,4,1,DOGM163); //SS = 10, 0,0= use Hardware SPI, 9 = RS, 4 = RESET, 1 = 5V, EA DOGM163-A (=3 lines)
LCD.displ_onoff(true); //turn Display on
LCD.cursor_onoff(true); //turn Curosor blinking on
LCD.clear_display(); //Clear the whole content
LCD.position(1,1); //set Position: first line, first character
LCD.string("UAMT FEI STU"); //show String
LCD.position(1,2); //set Position: second line, first character
LCD.string("5. aprila 2024");
LCD.position(1,3);
LCD.string("3 lines 16 char");
mono_backlight(255); //full
delay(2000);
}
int con=0;
int mode=0;
int pod=0xff;
char buffer[16];
void loop()
{
/* sem dame zmeny kontrastu a podsvietenia cez tlacitka */
if ( digitalRead(SW_A)==0)
if (mode)
LCD.contrast(con--);
else
mono_backlight(pod--);
if ( digitalRead(SW_B)==0)
if (mode)
LCD.contrast(con++);
else
mono_backlight(pod++);
if (con<=0) con =1;
if (con>=63) con = 63;
if (pod<=0) pod = 1;
if (pod>=255) pod = 255;
if ( digitalRead(SW_C)==0)
{ digitalWrite(LED_D1,HIGH);
mode = !mode;
}
else
digitalWrite(LED_D1,LOW);
sprintf(buffer, "Podsviet: %02X ", pod);
LCD.position(1,2);
// 0123456789012345
LCD.string(buffer);
sprintf(buffer, "Contrast: %02d ", con);
LCD.position(1,3);
// 0123456789012345
LCD.string(buffer);
delay(100);
}
void init_backlight()
{
pinMode(BL_pin, OUTPUT);
mono_backlight(255);
}
void mono_backlight(byte brightness)
{
analogWrite(BL_pin, brightness);
}