Interact with the display
Enable the SPI bus to configure the display and program its ram. For that the fastest available SPI clock is used. To configure the display a minimal config is used which is not identical but similar to the displays datasheet. The display can only be filled columnwise so far.
This commit is contained in:
parent
0065fb630f
commit
7f7d7b628a
2 changed files with 66 additions and 1 deletions
|
@ -24,7 +24,7 @@ $(BIN): $(OBJ)
|
|||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -Os -c $< -o $@
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
.PHONY: flash clean check size
|
||||
|
||||
|
|
|
@ -4,6 +4,67 @@
|
|||
#include <util/delay.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define SPI_PORT PORTB
|
||||
#define SPI_DDR DDRB
|
||||
#define SPI_SCK PB5
|
||||
#define SPI_MOSI PB3
|
||||
#define SPI_SS PB2
|
||||
|
||||
#define LCD_CD PB6
|
||||
#define LCD_RST PB1
|
||||
|
||||
void spi_init(void) {
|
||||
SPI_DDR |= (1 << SPI_SCK) | (1 << SPI_MOSI) | (1 << SPI_SS);
|
||||
SPI_PORT |= (1 << SPI_SS);
|
||||
SPCR = (1 << SPE) | (1 << MSTR);
|
||||
SPSR = (1 << SPI2X);
|
||||
}
|
||||
|
||||
uint8_t spi_byte(uint8_t data) {
|
||||
SPDR = data;
|
||||
while(!(SPSR & (1 << SPIF)));
|
||||
return SPDR;
|
||||
}
|
||||
|
||||
void lcd_write(uint8_t data) {
|
||||
SPI_PORT &= ~(1 << SPI_SS);
|
||||
spi_byte(data);
|
||||
SPI_PORT |= (1 << SPI_SS);
|
||||
}
|
||||
|
||||
void lcd_init(void) {
|
||||
SPI_DDR |= (1 << LCD_CD) | (1 << LCD_RST);
|
||||
_delay_ms(1);
|
||||
SPI_PORT |= (1 << LCD_RST);
|
||||
_delay_ms(5);
|
||||
|
||||
lcd_write(0x40); // (6) Set Scroll Line: Display start line 0
|
||||
lcd_write(0xA1); // (13) Set SEG direction: SEG reverse
|
||||
lcd_write(0xC0); // (14) Set COM direction: Normal COM0 - COM63
|
||||
lcd_write(0xA6); // (11) Set Inverse Display: Display inverse off
|
||||
lcd_write(0xA2); // (17) Set LCD Bias Ratio: Set Bias 1/9 (Duty 1/65)
|
||||
lcd_write(0x2F); // (5) Set Power Control: Booster, Regulator and Follower on
|
||||
lcd_write(0x27); // (8) Set VLCD Resistor Ratio: Set Contrast
|
||||
lcd_write(0x81); // (9) Set Electronic Volume: Set Contrast
|
||||
lcd_write(0x10); // (9) Set Electronic Volume: Set Contrast
|
||||
lcd_write(0xAF); // (12) Set Display Enable: Display on
|
||||
}
|
||||
|
||||
void lcd_fill(uint8_t data) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
SPI_PORT &= ~(1 << LCD_CD);
|
||||
lcd_write(0x00);
|
||||
lcd_write(0x10);
|
||||
lcd_write(0xB0 + i); // page address 0 + i
|
||||
|
||||
SPI_PORT |= (1 << LCD_CD);
|
||||
|
||||
for (uint8_t j = 0; j < 102; j++) {
|
||||
lcd_write(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
// FastPWM: 1.25kHz
|
||||
TCCR0A = (1 << WGM01) | (1 << WGM00) | (1 << COM0B1);
|
||||
|
@ -14,6 +75,10 @@ int main(void) {
|
|||
|
||||
bool reverse = 0;
|
||||
|
||||
spi_init();
|
||||
lcd_init();
|
||||
lcd_fill(0xFF);
|
||||
|
||||
while (1) {
|
||||
_delay_ms(1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue