Some cleanup
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
This commit is contained in:
parent
bfb78be425
commit
1acda4a55a
16
lcdLib.c
16
lcdLib.c
|
@ -90,6 +90,18 @@ void writeCharToLCD(char c) {
|
||||||
writeCharToLCD_(c);
|
writeCharToLCD_(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeStringToLCD(const char* str) {
|
||||||
|
while (*str != '\0') {
|
||||||
|
writeCharToLCD(*str);
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearScreen(void) {
|
||||||
|
writeLCDInstr(CMD_CLEAR_SCREEN);
|
||||||
|
_delay_us(LCD_CLEAR_SCREEN_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
char readCharFromLCD(void) {
|
char readCharFromLCD(void) {
|
||||||
loop_until_LCD_BF_clear(); // Wait until LCD is ready for new instructions
|
loop_until_LCD_BF_clear(); // Wait until LCD is ready for new instructions
|
||||||
|
|
||||||
|
@ -165,11 +177,13 @@ void initLCD (void) {
|
||||||
flashLED(5); // DEBUG
|
flashLED(5); // DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
void quickInitLCD(void) {
|
void initLCDByInternalReset(void) {
|
||||||
enableLCDOutput();
|
enableLCDOutput();
|
||||||
writeLCDInstr_(0x38);
|
writeLCDInstr_(0x38);
|
||||||
writeLCDInstr_(0x0F);
|
writeLCDInstr_(0x0F);
|
||||||
writeLCDInstr_(0x06);
|
writeLCDInstr_(0x06);
|
||||||
|
writeLCDInstr_(0x01);
|
||||||
|
_delay_ms(16);
|
||||||
|
|
||||||
/* writeLCDInstr_(0x01); // Clear display */
|
/* writeLCDInstr_(0x01); // Clear display */
|
||||||
/* writeLCDInstr_(0x30); // RS=RW=0, 0b00110000 */
|
/* writeLCDInstr_(0x30); // RS=RW=0, 0b00110000 */
|
||||||
|
|
39
lcdLib.h
39
lcdLib.h
|
@ -24,7 +24,7 @@
|
||||||
// Includes
|
// Includes
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
|
|
||||||
// Constants
|
// LCD data bus PORT, PIN and DDR
|
||||||
#define LCD_DBUS_PORT PORTB
|
#define LCD_DBUS_PORT PORTB
|
||||||
#define LCD_DBUS_DDR DDRB
|
#define LCD_DBUS_DDR DDRB
|
||||||
#define LCD_DBUS_PIN PINB
|
#define LCD_DBUS_PIN PINB
|
||||||
|
@ -32,20 +32,35 @@
|
||||||
#define LCD_CTRL_PORT PORTD
|
#define LCD_CTRL_PORT PORTD
|
||||||
#define LCD_CTRL_DDR DDRD
|
#define LCD_CTRL_DDR DDRD
|
||||||
|
|
||||||
#define LCD_RS PD2
|
#define LCD_RS PD2
|
||||||
#define LCD_RW PD3
|
#define LCD_RW PD3
|
||||||
#define LCD_ENABLE PD4
|
#define LCD_ENABLE PD4
|
||||||
|
|
||||||
#define LCD_BF PB7
|
#define LCD_DBUS0 PB0
|
||||||
|
#define LCD_DBUS1 PB1
|
||||||
|
#define LCD_DBUS2 PB2
|
||||||
|
#define LCD_DBUS3 PB3
|
||||||
|
#define LCD_DBUS4 PB4
|
||||||
|
#define LCD_DBUS5 PB5
|
||||||
|
#define LCD_DBUS6 PB6
|
||||||
|
#define LCD_DBUS7 PB7
|
||||||
|
#define LCD_BF PB7
|
||||||
|
|
||||||
#define LCD_DELAY 50
|
// LCD delays (in microseconds)
|
||||||
|
#define LCD_DELAY 50
|
||||||
|
#define LCD_CLEAR_SCREEN_DELAY 16000
|
||||||
|
#define LCD_SEND_DELAY 40 // unused
|
||||||
|
|
||||||
|
// LCD Commands
|
||||||
|
#define CMD_CLEAR_SCREEN 0x01
|
||||||
|
#define CMD_RETURN_HOME 0x02
|
||||||
|
|
||||||
|
//------------------------------------
|
||||||
|
|
||||||
#define STATUS_LED_PORT PORTC
|
#define STATUS_LED_PORT PORTC
|
||||||
#define STATUS_LED_DDR DDRC
|
#define STATUS_LED_DDR DDRC
|
||||||
#define STATUS_LED PC5
|
#define STATUS_LED PC5
|
||||||
|
|
||||||
//------------------------------------
|
|
||||||
|
|
||||||
// Function definitions
|
// Function definitions
|
||||||
void flashLED(uint8_t times);
|
void flashLED(uint8_t times);
|
||||||
|
|
||||||
|
@ -63,12 +78,16 @@ void writeCharToLCD_(char c);
|
||||||
|
|
||||||
void writeCharToLCD(char c);
|
void writeCharToLCD(char c);
|
||||||
|
|
||||||
|
void writeStringToLCD(const char* str);
|
||||||
|
|
||||||
|
void clearScreen(void);
|
||||||
|
|
||||||
char readCharFromLCD(void);
|
char readCharFromLCD(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Do software initialization as specified by the datasheet
|
Do software initialization as specified by the datasheet
|
||||||
*/
|
*/
|
||||||
void initLCD (void);
|
void initLCD(void);
|
||||||
|
|
||||||
void quickInitLCD(void);
|
void initLCDByInternalReset(void);
|
||||||
|
|
||||||
|
|
34
lcdOutput.c
34
lcdOutput.c
|
@ -37,32 +37,24 @@ int main(void) {
|
||||||
|
|
||||||
STATUS_LED_DDR |= 1 << STATUS_LED; // DEBUG
|
STATUS_LED_DDR |= 1 << STATUS_LED; // DEBUG
|
||||||
|
|
||||||
|
const char* data[4] = { "Hello there friend!!",
|
||||||
|
"Anyways, I must go..",
|
||||||
|
"Isn't it a nice day.",
|
||||||
|
"To a midnight show;)" };
|
||||||
|
|
||||||
initLCD();
|
initLCD();
|
||||||
//quickInitLCD();
|
//initLCDByInternalReset();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
writeCharToLCD('H');
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
writeCharToLCD('e');
|
writeStringToLCD(data[i]);
|
||||||
writeCharToLCD('l');
|
}
|
||||||
writeCharToLCD('l');
|
_delay_ms(5000);
|
||||||
writeCharToLCD('o');
|
clearScreen();
|
||||||
writeCharToLCD(' ');
|
|
||||||
writeCharToLCD('t');
|
|
||||||
writeCharToLCD('h');
|
|
||||||
writeCharToLCD('e');
|
|
||||||
writeCharToLCD('r');
|
|
||||||
writeCharToLCD('e');
|
|
||||||
writeCharToLCD(' ');
|
|
||||||
writeCharToLCD('f');
|
|
||||||
writeCharToLCD('r');
|
|
||||||
writeCharToLCD('i');
|
|
||||||
writeCharToLCD('e');
|
|
||||||
writeCharToLCD('n');
|
|
||||||
writeCharToLCD('d');
|
|
||||||
writeCharToLCD('!');
|
|
||||||
|
|
||||||
//flashLED(5); // DEBUG
|
//flashLED(5); // DEBUG
|
||||||
_delay_ms(5000);
|
_delay_ms(3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue