Now functional, has issue with power loss events and desyncing from uc

This commit is contained in:
Jake Goodwin 2023-01-07 21:02:48 -08:00
parent 2c207d9c17
commit 56b6b0ffc9
1 changed files with 169 additions and 45 deletions

View File

@ -96,26 +96,57 @@ 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;
//SETUP HERE.
led_blink();
led_blink();
init_lcd();
_delay_ms(500);
//setup for single line mode.
//cmd_lcd(0x20);
//_delay_ms(1000);
//cmd_lcd(0x28);
return_home_lcd();
while(1) {
led_blink();
_delay_ms(1000);
cmd_lcd(0x20);
_delay_ms(1000);
cmd_lcd(0x28);
_delay_ms(2);
set_entry_mode_increment_lcd();
for(uint8_t i = 0; i < 15; i++) {
//shift_right_lcd();
write_lcd_address(0x7e);
_delay_ms(100);
}
set_entry_mode_decrement_lcd();
for(uint8_t i = 0; i < 15; i++) {
//shift_left_lcd();
write_lcd_address(0x7f);
_delay_ms(100);
}
//set_cgram_lcd_address(0x00);
//set_entry_mode_increment_lcd();
//bbs();
_delay_ms(1000);
clear_lcd();
PORTD = 0x00;
led_blink();
led_blink();
led_blink();
_delay_ms(1000);
_delay_ms(1000);
_delay_ms(1000);
_delay_ms(1000);
_delay_ms(1000);
}
return 0;
@ -127,21 +158,39 @@ int main() {
//FUNCTIONS
//#############################
void init_lcd(void) {
//allow us to read pin7
DDRD = 0x00;
setbit(DDRD, BIT7_DDR);
while(PORTD & (1<<BIT7_PIN)){
led_blink();
}
DDRD = 0xff; //All output
_delay_ms(20);
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
* Description: setsup the lcd for two line display and sets start posistion.
*/
void init_lcd(void) {
_delay_ms(500);
clear_buf_lcd();
clear_buf_lcd();
_delay_ms(10);
turn_on_lcd();
_delay_ms(10);
set_lcd_two_line();
return_home_lcd();
clear_lcd();
_delay_ms(10);
//clear_lcd();
_delay_ms(5);
//return_home_lcd();
_delay_ms(5);
}
@ -154,40 +203,127 @@ void set_lcd_two_line(void) {
cmd_lcd(0x28);
}
/*
* Input: None
* Outupt: None
* Description: Sets the LCD into 4bit one line display mode.
*/
void set_lcd_one_line(void) {
cmd_lcd(0x20);
}
/*
* Input: None
* Outupt: None
* Description: Sends the clear screen command to the LCD
*/
void clear_lcd(void) {
cmd_lcd(0x01);
}
/*
* Input: None
* Outupt: None
* Description: Returns the LCD cursor to home position.
*/
void return_home_lcd(void) {
cmd_lcd(0x02);
}
/*
* Input: None
* Output: None
* Description: Shifts cusor to the right one char.
*/
void shift_right_lcd(void) {
cmd_lcd(0x14);
}
/*
* Input: None
* Output: None
* Description: Shifts cusor to the left one char.
*/
void shift_left_lcd(void) {
cmd_lcd(0x10);
}
/*
* Input: None
* Outupt: None
* Description: Toggles the LCD power state.
*/
void turn_off_lcd(void) {
cmd_lcd(0x08);
}
/*
* Input: None
* Outupt: None
* Description: Toggles the LCD power state.
*/
void turn_on_lcd(void) {
cmd_lcd(0x08);
cmd_lcd(0x0f);
}
/*
* Input: None
* Outupt: None
* Description:
*/
void set_cgram_lcd_address(uint8_t addr) {
;
uint8_t cmd = 0x40;
cmd |= addr;
cmd_lcd(cmd);
}
/*
* Input: None
* Outupt: None
* Description:
*/
void set_ddram_lcd_address(uint8_t addr) {
;
uint8_t cmd = 0x80;
cmd |= addr;
cmd_lcd(cmd);
}
/*
* Input: None
* Outupt: None
* Description:
*/
void write_lcd_address(uint8_t addr) {
;
setbit(PORTD, RS_PIN);
cmd_lcd(addr);
clearbit(PORTD, RS_PIN);
_delay_ms(10);
}
void set_entry_mode_increment_lcd(void) {
cmd_lcd(0x06);
}
void set_entry_mode_decrement_lcd(void) {
cmd_lcd(0x04);
}
void clear_buf_lcd() {
DDRD = 0xff;
PORTD &=0x0f;
setbit(PORTD, ENA_PIN);
_delay_ms(5);
clearbit(PORTD, ENA_PIN);
_delay_ms(2);
setbit(PORTD, ENA_PIN);
_delay_ms(5);
clearbit(PORTD, ENA_PIN);
}
@ -207,7 +343,7 @@ void cmd_lcd(uint8_t cmd) {
PORTD |= (cmd & 0xf0);
_delay_ms(1);
clearbit(PORTD, ENA_PIN);
_delay_ms(2);
_delay_ms(3);
//Send the second nibble and shift cmd by four.
PORTD &= 0x0f;
@ -215,21 +351,9 @@ void cmd_lcd(uint8_t cmd) {
PORTD |= (cmd<<4);
_delay_ms(1);
clearbit(PORTD, ENA_PIN);
_delay_ms(2);
_delay_ms(3);
}
void cmd_nibble_lcd(uint8_t cmd) {
DDRD = 0xff;
PORTD &= 0x0f;
setbit(PORTD, ENA_PIN);
PORTD |= cmd;
_delay_ms(1);
clearbit(PORTD, ENA_PIN);
_delay_ms(1);
}
/*
* Input: None