Created
July 7, 2019 13:16
-
-
Save surinoel/bd701c911ecdd07f5d57b4ca7ae01573 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define F_CPU 16000000UL | |
#include "LCD.h" | |
#include <avr/io.h> | |
#include <util/delay.h> | |
void LCD_command(unsigned char command) | |
{ | |
LCD_CONTROL &= ~((1<<EN) | (1<<RS) | (1<<RW)); | |
_delay_us(1); | |
LCD_DATABUS = command; | |
LCD_CONTROL |= (1<<EN); | |
_delay_us(1); | |
LCD_CONTROL &= ~(1<<EN); | |
_delay_us(40); | |
} | |
void LCD_data(unsigned char data) | |
{ | |
LCD_CONTROL &= ~((1<<EN) | (1<<RW)); | |
LCD_CONTROL |= (1<<RS); | |
_delay_us(1); | |
LCD_DATABUS = data; | |
LCD_CONTROL |= (1<<EN); | |
_delay_us(1); | |
LCD_CONTROL &= ~(1<<EN); | |
_delay_us(40); | |
} | |
void LCD_string(unsigned char command, char* string) | |
{ | |
LCD_command(command); | |
while(*string != '\0') | |
{ | |
LCD_data(*string); | |
string++; | |
} | |
} | |
void LCD_init() | |
{ | |
LCD_DATABUS_DDR = 0b11111111; | |
LCD_CONTROL_DDR |= ((1<<EN) | (1<<RS) | (1<<RW)); | |
_delay_us(50); | |
LCD_CONTROL |= ((1<<EN) | (1<<RS)); | |
_delay_us(50); | |
LCD_CONTROL &= ~(1<<EN); | |
_delay_us(50); | |
LCD_command(0x38); | |
LCD_command(0x0C); | |
LCD_command(0x06); | |
LCD_command(0x01); | |
_delay_ms(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment