Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Firmware/Src/lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define DAT_LINE ((uint16_t)0x00F0)
#define E_LINE GPIO_PIN_3
#define RS_LINE GPIO_PIN_2
#define RESET_LINE GPIO_PIN_1

char digits[11];

Expand Down Expand Up @@ -38,6 +39,15 @@ void lcd_init()

void oled_init()
{
#ifdef OLED_EASTRISING
HAL_GPIO_WritePin( GPIOA, E_LINE, GPIO_PIN_RESET ); // E line startup state
HAL_GPIO_WritePin( GPIOA, RS_LINE, GPIO_PIN_RESET ); // command mode

HAL_GPIO_WritePin( GPIOB, RESET_LINE, GPIO_PIN_RESET );
lcd_delay( 100000 ); // awaiting for power supply stability
HAL_GPIO_WritePin( GPIOB, RESET_LINE, GPIO_PIN_SET );
lcd_delay( 100 );
#else
HAL_GPIO_WritePin( GPIOA, E_LINE, GPIO_PIN_SET ); // E line startup state
HAL_GPIO_WritePin( GPIOA, RS_LINE, GPIO_PIN_RESET ); // command mode

Expand All @@ -64,7 +74,8 @@ void oled_init()
GPIOA->ODR = GPIOA->ODR & ~DAT_LINE | 0x20; // 0010 0000b
lcd_pulse();
lcd_delay( 40 );

#endif

// function set
lcd_command( 0x28 ); // 0010 1000b; 4-bit, 2-line, 5x8
lcd_command( 0x0c ); // 0000 1100b; display=on, cursor=off, blinking=off
Expand Down Expand Up @@ -152,6 +163,12 @@ void lcd_printd4( int32_t n )

void lcd_position( uint8_t position )
{
#ifdef OLED_EASTRISING
// The datasheet lies. Second line
// is in a different position.
if (position & 0x40)
position -= 0x20;
#endif
lcd_command( position | 0x80 );
}

Expand Down
25 changes: 25 additions & 0 deletions Firmware/Src/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,28 @@ void lcd_position( uint8_t );
void lcd_clear();
void lcd_pulse();
extern void lcd_delay( uint32_t delay );

// Support for the ER-OLEDM1602-4Y OLED from Buydisplay.
// In lieu of the LED on PB1, PB1 must be connected to
// RESET. CS should be tied to ground.
// Jumper settings: BS2 HIGH BS1 LOW BS0 HIGH
//
// Pin mapping:
// VCC - 3.3V
// RD - E
// RW - R/W
// DC - RS
// RES - PB1
// CS - GND
// D7-D4 to D7-D4 straight.
//
// I placed an extra cap VCC-GND on the OLED board, this
// might not be necessary.
// Note that programming may fail if the display is connected
// (unsure why)
//
// 3.3V current draw ~65mA continuous. Suggest maybe
// substitute a different 3.3V regulator for more margin?

// Define for ER-OLEDM1602-4Y, undef for WEH001602AGPP5N00001
#define OLED_EASTRISING
2 changes: 2 additions & 0 deletions Firmware/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ int main(void)
if( hal_tick % IWDG_REFRESH_DELAY == 0 )
{
HAL_IWDG_Refresh( &hiwdg );
#ifndef OLED_EASTRISING // Pin used for reset line
HAL_GPIO_TogglePin( GPIOB, GPIO_PIN_1 ); //heartbeat just for fun
#endif
}

if( tip_delay > 0 )
Expand Down