Created
July 7, 2019 13:17
-
-
Save surinoel/c810dd524a2b9da7e622d979bc659393 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); | |
} |
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
#ifndef LCD_H_ | |
#define LCD_H_ | |
#define LCD_DATABUS PORTC | |
#define LCD_CONTROL PORTA | |
#define LCD_DATABUS_DDR DDRC | |
#define LCD_CONTROL_DDR DDRA | |
#define RS 5 | |
#define RW 6 | |
#define EN 7 | |
void LCD_command(unsigned char command); | |
void LCD_data(unsigned char data); | |
void LCD_string(unsigned char command, char* string); | |
void LCD_init(); | |
#endif /* LCD_H_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment