From 441f13c9a280835b39389a8da92ed2737491ab34 Mon Sep 17 00:00:00 2001 From: jakegoodwin Date: Fri, 6 Jan 2023 16:32:08 -0800 Subject: [PATCH] Build rough functions for 4bit parrallel use. --- 1602LCD_char_display.c | 208 +++++++++++++++++++++++++++++++---------- 1602LCD_char_display.o | Bin 7420 -> 0 bytes 2 files changed, 160 insertions(+), 48 deletions(-) delete mode 100644 1602LCD_char_display.o diff --git a/1602LCD_char_display.c b/1602LCD_char_display.c index 9202306..53f089d 100644 --- a/1602LCD_char_display.c +++ b/1602LCD_char_display.c @@ -15,73 +15,197 @@ #define RS_DDR DDD0 -#define RW_PORT PORTD -#define RW_PIN PIND1 -#define RW_DDR DDD1 +//#define RW_PORT PORTD +//#define RW_PIN PIND1 +//#define RW_DDR DDD1 #define ENA_PORT PORTD -#define ENA_PIN PIND2 -#define ENA_DDR DDD2 +#define ENA_PIN PIND1 +#define ENA_DDR DDD1 #define BIT4_PORT PORTD -#define BIT4_PIN PIND3 -#define BIT4_DDR DDD3 +#define BIT4_PIN PIND4 +#define BIT4_DDR DDD4 #define BIT5_PORT PORTD -#define BIT5_PIN PIND4 -#define BIT5_DDR DDD4 +#define BIT5_PIN PIND5 +#define BIT5_DDR DDD5 #define BIT6_PORT PORTD -#define BIT6_PIN PIND5 -#define BIT6_DDR DDD5 +#define BIT6_PIN PIND6 +#define BIT6_DDR DDD6 #define BIT7_PORT PORTD -#define BIT7_PIN PIND6 -#define BIT7_DDR DDD6 +#define BIT7_PIN PIND7 +#define BIT7_DDR DDD7 #define LED_PIN PINC0 #define LED_PORT PORTC #define LED_DDR DDC0 -//LCD CONNECTIONS -//PIND0 RS, H: data input L: Instruction input -//PIND1 RW, H: read L: write -//PIND2 ENABLE, Enable signal -//PIND3 BIT4 -//PIND4 BIT5 -//PIND5 BIT6 -//PIND6 BIT7 +//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); + + + +int main() { + //SETUP HERE. + _delay_ms(500); + while(1) { + led_blink(); + _delay_ms(1000); + set_lcd_one_line(); + _delay_ms(1000); + set_lcd_two_line(); + } + + return 0; +} + + //############################# //FUNCTIONS //############################# void init_lcd(void) { - DDRD |= (1<{L*Lk7*{jqOLrJ^42@|K44c*FR@;8u znA?oG9rm(WA+4WPTm|1FR$~s}zF_&Z;vXx1OYtBASU{a+hvHu-UW*|YL}AQ~;^!6r zPVtI`x1zs>;mfj`duLvI!epL7g;RWIE3V&7joUk|YCE=rDzbt%A_#NS= zgje6fvAElf85aJI@K)h7!Uf?Mguf{KBjIld|5W%T;hzcrR``PORpE=mw|szOy(T;) z{72y}!fyyaBz#49zwlMzlfr)&enI#h;a7#d7sF-YwRrlB`Iqn=!mK~XAGY}X;Z=<1 zGh*E!%r}Eqd<|WA+tHqL<2G=uk3kque_OFf&OTh=Dfjn zF>i+KTg@7)%bV@;ZeulXCQXEJYuL|vnAeBwyNn;x5ZaUMi?YkRnT^m7nccQ#0xb=B zWoO?NR^|8owDh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