AVR_ATMEGA_1602LCD/1602LCD_char_display.c

114 lines
1.9 KiB
C

/*
* Author: Jake Goodwin
* Date: 2022
* Description: Interfacing with a 1602LCD only with the uc no perifs
*/
#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 PIND2
#define ENA_DDR DDD2
#define BIT4_PORT PORTD
#define BIT4_PIN PIND3
#define BIT4_DDR DDD3
#define BIT5_PORT PORTD
#define BIT5_PIN PIND4
#define BIT5_DDR DDD4
#define BIT6_PORT PORTD
#define BIT6_PIN PIND5
#define BIT6_DDR DDD5
#define BIT7_PORT PORTD
#define BIT7_PIN PIND6
#define BIT7_DDR DDD6
#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
//#############################
//FUNCTIONS
//#############################
void init_lcd(void) {
DDRD |= (1<<RS_DDR)|(1<<RW_DDR)|(1<<ENA_DDR)|
(1<<BIT4_PIN)|(1<<BIT5_PIN)|(1<<BIT6_PIN)|(1<<BIT7_PIN);
_delay_ms(40);
PORTD = (0<<RS_PIN)|(0<<RW_PIN)|(0<<ENA_PIN)|
(1<<BIT4_PIN)|(1<<BIT5_PIN)|(0<<BIT6_PIN)|(1<<BIT7_PIN);
_delay_ms_(5);
PORTD = (0<<RS_PIN)|(0<<RW_PIN)|(0<<ENA_PIN)|
(1<<BIT4_PIN)|(1<<BIT5_PIN)|(0<<BIT6_PIN)|(1<<BIT7_PIN);
_delay_ms(1);
}
void cmd_lcd() {
;
}
/*
* Input: None
* Output: None
* Description: Toggles the pin for the LED indicator.
*/
static void led_blink(void) {
//Set the DDR for output.
DDRC |= (1<<LED_PIN);
PORTC ^= (1<<LED_PIN);
_delay_ms(250);
PORTC ^= (1<<LED_PIN);
_delay_ms(250);
}
int main() {
//SETUP HERE.
init_lcd();
while(1) {
led_blink();
test_lcd();
_delay_ms(1000);
off_lcd();
}
return 0;
}