Compare commits
2 commits
56b6b0ffc9
...
7e7cb73cd2
Author | SHA1 | Date | |
---|---|---|---|
7e7cb73cd2 | |||
02bde95d40 |
3 changed files with 125 additions and 109 deletions
|
@ -8,73 +8,7 @@
|
|||
#include <avr/interrupt.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
|
||||
#define RS_PORT PORTD
|
||||
#define RS_PIN PIND0
|
||||
#define RS_DDR DDD0
|
||||
|
||||
|
||||
//#define RW_PORT PORTD
|
||||
//#define RW_PIN PIND1
|
||||
//#define RW_DDR DDD1
|
||||
|
||||
|
||||
#define ENA_PORT PORTD
|
||||
#define ENA_PIN PIND1
|
||||
#define ENA_DDR DDD1
|
||||
|
||||
#define BIT4_PORT PORTD
|
||||
#define BIT4_PIN PIND4
|
||||
#define BIT4_DDR DDD4
|
||||
|
||||
|
||||
#define BIT5_PORT PORTD
|
||||
#define BIT5_PIN PIND5
|
||||
#define BIT5_DDR DDD5
|
||||
|
||||
#define BIT6_PORT PORTD
|
||||
#define BIT6_PIN PIND6
|
||||
#define BIT6_DDR DDD6
|
||||
|
||||
#define BIT7_PORT PORTD
|
||||
#define BIT7_PIN PIND7
|
||||
#define BIT7_DDR DDD7
|
||||
|
||||
#define LED_PIN PINC0
|
||||
#define LED_PORT PORTC
|
||||
#define LED_DDR DDC0
|
||||
|
||||
//LCD CONNECTIONS:
|
||||
/*
|
||||
* VSS --> GND
|
||||
* VDD --> VCC
|
||||
* V0 --> POT --> GND
|
||||
* RS --> PD0(AVR)
|
||||
* RW --> GND
|
||||
* E --> PD1(AVR)
|
||||
* D4 --> PD4(AVR)
|
||||
* D5 --> PD5(AVR)
|
||||
* D6 --> PD6(AVR)
|
||||
* D7 --> PD7(AVR)
|
||||
*
|
||||
* PURPOSE:
|
||||
* RS: register select,
|
||||
* RW: Read/Write select signal,
|
||||
* E: Operation(data read/write) enable signal.
|
||||
* DB0~DB3: not used for 4bit operations.
|
||||
* DB4~DB7: high order three-state data lines.
|
||||
*/
|
||||
|
||||
|
||||
//#############################
|
||||
//MACROS
|
||||
//#############################
|
||||
|
||||
//already defined
|
||||
//#define _BV(bit) (1 << bit)
|
||||
#define setbit(port, bit) (port) |= (1 << (bit))
|
||||
#define clearbit(port, bit) (port) &= ~(1 << (bit))
|
||||
#include "1602LCD_char_display.h"
|
||||
|
||||
|
||||
|
||||
|
@ -82,28 +16,6 @@
|
|||
//FUNCTION PROTOTYPES
|
||||
//#############################
|
||||
|
||||
|
||||
void init_lcd(void);
|
||||
void cmd_lcd(uint8_t cmd);
|
||||
void cmd_nibble_lcd(uint8_t cmd);
|
||||
void clear_lcd(void);
|
||||
static void led_blink(void);
|
||||
void set_lcd_one_line_(void);
|
||||
void set_lcd_two_line(void);
|
||||
void return_home_lcd(void);
|
||||
void turn_off_lcd(void);
|
||||
void turn_on_lcd(void);
|
||||
void set_cgram_lcd_address(uint8_t addr);
|
||||
void set_ddram_lcd_address(uint8_t addr);
|
||||
void write_lcd_address(uint8_t addr);
|
||||
void set_entry_mode_increment_lcd(void);
|
||||
void set_entry_mode_decrement_lcd(void);
|
||||
void shift_right_lcd(void);
|
||||
void shift_left_lcd(void);
|
||||
void bbs(void);
|
||||
void clear_buf_lcd();
|
||||
|
||||
|
||||
int main() {
|
||||
PORTD = 0x00;
|
||||
DDRD = 0xff;
|
||||
|
@ -158,18 +70,6 @@ int main() {
|
|||
//FUNCTIONS
|
||||
//#############################
|
||||
|
||||
|
||||
void bbs(void) {
|
||||
_delay_ms(500);
|
||||
write_lcd_address(0x42);
|
||||
write_lcd_address(0x4f);
|
||||
write_lcd_address(0x4f);
|
||||
write_lcd_address(0x42);
|
||||
write_lcd_address(0x49);
|
||||
write_lcd_address(0x45);
|
||||
write_lcd_address(0x53);
|
||||
}
|
||||
|
||||
/*
|
||||
* Input: none
|
||||
* Output: none
|
||||
|
|
97
1602LCD_char_display.h
Normal file
97
1602LCD_char_display.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/sleep.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
|
||||
#define RS_PORT PORTD
|
||||
#define RS_PIN PIND0
|
||||
#define RS_DDR DDD0
|
||||
|
||||
|
||||
//#define RW_PORT PORTD
|
||||
//#define RW_PIN PIND1
|
||||
//#define RW_DDR DDD1
|
||||
|
||||
|
||||
#define ENA_PORT PORTD
|
||||
#define ENA_PIN PIND1
|
||||
#define ENA_DDR DDD1
|
||||
|
||||
#define BIT4_PORT PORTD
|
||||
#define BIT4_PIN PIND4
|
||||
#define BIT4_DDR DDD4
|
||||
|
||||
|
||||
#define BIT5_PORT PORTD
|
||||
#define BIT5_PIN PIND5
|
||||
#define BIT5_DDR DDD5
|
||||
|
||||
#define BIT6_PORT PORTD
|
||||
#define BIT6_PIN PIND6
|
||||
#define BIT6_DDR DDD6
|
||||
|
||||
#define BIT7_PORT PORTD
|
||||
#define BIT7_PIN PIND7
|
||||
#define BIT7_DDR DDD7
|
||||
|
||||
#define LED_PIN PINC0
|
||||
#define LED_PORT PORTC
|
||||
#define LED_DDR DDC0
|
||||
|
||||
//LCD CONNECTIONS:
|
||||
/*
|
||||
* VSS --> GND
|
||||
* VDD --> VCC
|
||||
* V0 --> POT --> GND
|
||||
* RS --> PD0(AVR)
|
||||
* RW --> GND
|
||||
* E --> PD1(AVR)
|
||||
* D4 --> PD4(AVR)
|
||||
* D5 --> PD5(AVR)
|
||||
* D6 --> PD6(AVR)
|
||||
* D7 --> PD7(AVR)
|
||||
*
|
||||
* PURPOSE:
|
||||
* RS: register select,
|
||||
* RW: Read/Write select signal,
|
||||
* E: Operation(data read/write) enable signal.
|
||||
* DB0~DB3: not used for 4bit operations.
|
||||
* DB4~DB7: high order three-state data lines.
|
||||
*/
|
||||
|
||||
|
||||
//#############################
|
||||
//MACROS
|
||||
//#############################
|
||||
|
||||
//already defined
|
||||
//#define _BV(bit) (1 << bit)
|
||||
#define setbit(port, bit) (port) |= (1 << (bit))
|
||||
#define clearbit(port, bit) (port) &= ~(1 << (bit))
|
||||
|
||||
//#############################
|
||||
//FUNCTION PROTOTYPES
|
||||
//#############################
|
||||
|
||||
|
||||
void init_lcd(void);
|
||||
void cmd_lcd(uint8_t cmd);
|
||||
void cmd_nibble_lcd(uint8_t cmd);
|
||||
void clear_lcd(void);
|
||||
static void led_blink(void);
|
||||
void set_lcd_one_line_(void);
|
||||
void set_lcd_two_line(void);
|
||||
void return_home_lcd(void);
|
||||
void turn_off_lcd(void);
|
||||
void turn_on_lcd(void);
|
||||
void set_cgram_lcd_address(uint8_t addr);
|
||||
void set_ddram_lcd_address(uint8_t addr);
|
||||
void write_lcd_address(uint8_t addr);
|
||||
void set_entry_mode_increment_lcd(void);
|
||||
void set_entry_mode_decrement_lcd(void);
|
||||
void shift_right_lcd(void);
|
||||
void shift_left_lcd(void);
|
||||
void clear_buf_lcd();
|
||||
|
||||
|
35
README.md
35
README.md
|
@ -23,20 +23,30 @@ ___
|
|||
```C
|
||||
#include "AVR_ATMEGA_1602LCD.h"
|
||||
|
||||
void lcd_begin() {
|
||||
set_lcd_two_line();
|
||||
return_home_lcd();
|
||||
clear_lcd();
|
||||
void do_stuff() {
|
||||
PORTD = 0x00;
|
||||
DDRD = 0xff;
|
||||
init_lcd();
|
||||
|
||||
//Do stuff.
|
||||
return_home_lcd();
|
||||
set_entry_mode_increment_lcd();
|
||||
|
||||
//Refernce the datasheet for charecter codes.
|
||||
write_lcd_address(0x7f); //Right pointing arrow
|
||||
|
||||
//wait a bit.
|
||||
_delay_ms(1000);
|
||||
|
||||
//clear it up
|
||||
clear_lcd();
|
||||
return_home_lcd();
|
||||
|
||||
//Do more stuff...
|
||||
}
|
||||
```
|
||||
|
||||
## RoadMap:
|
||||
|
||||
1. define all functions for the data sheets instructions.
|
||||
2. Change cmd_lcd() function to only be called once instead of nibbles.
|
||||
3. Make functions port indapendant.
|
||||
4. ADD function to print strings
|
||||
5. ADD function to display bit images
|
||||
6. ADD function to act as a loading screen.
|
||||
|
@ -45,4 +55,13 @@ void lcd_begin() {
|
|||
9. ADD PWM control for backlight
|
||||
|
||||
|
||||
## ISSUES:
|
||||
|
||||
Currently during powerloss events and initialization, long wire runs or
|
||||
residual charge can cause the LCD to maintain memory for a shor duration.
|
||||
|
||||
In 4bit mode it's possible to end up with a invalid "nibble" in the LCD memory
|
||||
in this case the system should power cycle the LCD unit assuming it's
|
||||
controlled by the microcontroller.
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue