Compare commits
No commits in common. "2c207d9c17715cbad39443de780190b988b6d4a7" and "8756d364109c466d9522ddf3051d0bdd9cc43a46" have entirely different histories.
2c207d9c17
...
8756d36410
2 changed files with 17 additions and 42 deletions
|
|
@ -66,7 +66,6 @@
|
|||
* DB4~DB7: high order three-state data lines.
|
||||
*/
|
||||
|
||||
|
||||
//#############################
|
||||
//MACROS
|
||||
//#############################
|
||||
|
|
@ -84,7 +83,7 @@
|
|||
|
||||
|
||||
void init_lcd(void);
|
||||
void cmd_lcd(uint8_t cmd);
|
||||
//void cmd_lcd(uint8_t cmd);
|
||||
void cmd_nibble_lcd(uint8_t cmd);
|
||||
void clear_lcd(void);
|
||||
static void led_blink(void);
|
||||
|
|
@ -102,20 +101,12 @@ void write_lcd_address(uint8_t addr);
|
|||
int main() {
|
||||
//SETUP HERE.
|
||||
_delay_ms(500);
|
||||
|
||||
//setup for single line mode.
|
||||
//cmd_lcd(0x20);
|
||||
//_delay_ms(1000);
|
||||
//cmd_lcd(0x28);
|
||||
|
||||
while(1) {
|
||||
led_blink();
|
||||
_delay_ms(1000);
|
||||
cmd_lcd(0x20);
|
||||
set_lcd_one_line();
|
||||
_delay_ms(1000);
|
||||
cmd_lcd(0x28);
|
||||
_delay_ms(2);
|
||||
|
||||
set_lcd_two_line();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -151,28 +142,34 @@ void init_lcd(void) {
|
|||
* Description: Sets the LCD into 4bit two line display mode.
|
||||
*/
|
||||
void set_lcd_two_line(void) {
|
||||
cmd_lcd(0x28);
|
||||
cmd_nibble_lcd(0x20);
|
||||
cmd_nibble_lcd(0x80);
|
||||
}
|
||||
|
||||
void set_lcd_one_line(void) {
|
||||
cmd_lcd(0x20);
|
||||
cmd_nibble_lcd(0x20);
|
||||
cmd_nibble_lcd(0x00);
|
||||
}
|
||||
|
||||
void clear_lcd(void) {
|
||||
cmd_lcd(0x01);
|
||||
cmd_nibble_lcd(0x00);
|
||||
cmd_nibble_lcd(0x10);
|
||||
}
|
||||
|
||||
void return_home_lcd(void) {
|
||||
cmd_lcd(0x02);
|
||||
cmd_nibble_lcd(0x00);
|
||||
cmd_nibble_lcd(0x20);
|
||||
}
|
||||
|
||||
void turn_off_lcd(void) {
|
||||
cmd_lcd(0x08);
|
||||
cmd_nibble_lcd(0x00);
|
||||
cmd_nibble_lcd(0x80);
|
||||
}
|
||||
|
||||
|
||||
void turn_on_lcd(void) {
|
||||
cmd_lcd(0x08);
|
||||
cmd_nibble_lcd(0x00);
|
||||
cmd_nibble_lcd(0x80);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -191,31 +188,9 @@ void write_lcd_address(uint8_t addr) {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* Input: uint8_t, a 8bit command code.
|
||||
* Output: none
|
||||
* Description: Takes a 8bit command code and sends it as two 4bit nibbles
|
||||
* to the 1602LCD. The timing of delays is very important to match the
|
||||
* datasheets timing diagrams.
|
||||
*/
|
||||
//A version that doesn't require multiple calls.
|
||||
void cmd_lcd(uint8_t cmd) {
|
||||
DDRD = 0xff;
|
||||
PORTD &=0x0f;
|
||||
|
||||
//Send first nibble
|
||||
setbit(PORTD, ENA_PIN);
|
||||
PORTD |= (cmd & 0xf0);
|
||||
_delay_ms(1);
|
||||
clearbit(PORTD, ENA_PIN);
|
||||
_delay_ms(2);
|
||||
|
||||
//Send the second nibble and shift cmd by four.
|
||||
PORTD &= 0x0f;
|
||||
setbit(PORTD, ENA_PIN);
|
||||
PORTD |= (cmd<<4);
|
||||
_delay_ms(1);
|
||||
clearbit(PORTD, ENA_PIN);
|
||||
_delay_ms(2);
|
||||
;
|
||||
}
|
||||
|
||||
void cmd_nibble_lcd(uint8_t cmd) {
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Reference in a new issue