LCD C
LCD C
//------
// Partially based on the example initialization found in the product specification pdf located at:
//
http://www.newhavendisplay.com/index.php?main_page=product_info&cPath=2_78&products_id=244
//
#include <avr/pgmspace.h>
#include "nlcd.h"
#include "delay.h"
//Internal functions
static int next_pos; //Address counter of the next display position to be written to
static int db_next_pos; //Counter of the next buffer position (modulo 16) to be written to.
static unsigned char scrolling_enabled; //Flag for determining when scrolling has been enabled
//Functions
//---------
DATA_DDRX |= (0x0f << DATA_PORTX0); //Set pin driver directions for data
nlcd_command(WAKE_UP);
delay_ms(5);
nlcd_command(WAKE_UP);
delay_us(100);
nlcd_command(WAKE_UP);
nlcd_command(FUNCTION_SET);
nlcd_command(INIT_CURSOR);
nlcd_command(INIT_DISPLAY);
nlcd_command(ENTRY_MODE);
scrolling_enabled = 0;
nlcd_string(PSTR("Comaidsystem 1.0"));
delay_ms(1500);
nlcd_wipe(); //Must call this at end to clear screen and initialize position trackers
return 0;
if (c == BACKSPACE)
nlcd_backspace();
else {
disp_buffer[(db_next_pos++) % DISP_BUFFER_SIZE] = c;
if (scrolling_enabled)
nlcd_bstring();
else {
nlcd_set_data();
nlcd_put_data(c);
nlcd_inc_pos();
//Send a constant string for the LCD to print, erasing the current display.
nlcd_wipe();
while(pgm_read_byte(str) != EOL)
nlcd_char(pgm_read_byte(str++));
//Send a non-constant (variable) string for the LCD to print, erasing the current display.
nlcd_wipe();
while(*strptr != EOL)
nlcd_char(*strptr++);
//Reset position trackers, wiping the buffer, and clears the screen
next_pos = FIRST_POS;
db_next_pos = FIRST_POS;
nlcd_clear();
}
//Flash text on screen for 'sec' seconds at FPS
int i = 0;
nlcd_command(DISP_OFF);
delay_ms(FPS_DELAY);
nlcd_command(DISP_ON);
delay_ms(FPS_DELAY);
scrolling_enabled = 1;
nlcd_bstring(); // Needed in case we enable scrolling after text hits end of screen
{
scrolling_enabled = 0;
//Internal functions
//------------------
nlcd_set_command();
nlcd_put_data(c);
}
//Send 8 bits of information (command or character)
next_pos++;
if (next_pos == HALF_POS)
next_pos--;
//Print the string currently residing in the buffer: used for pseudo-scrolling
{
int i = FIRST_POS;
nlcd_command(CLR_DISPLAY);
delay_ms(4);
nlcd_command(RETURN_HOME);
delay_ms(4);
if (next_pos == FIRST_POS)
else {
if (next_pos == HALF_POS) //Currently right after DDRAM split: need to jump back over it
nlcd_command(DDRAM_PRIOR_HALF_ADDRESS);
else
nlcd_set_data();
nlcd_put_data(BLANK);
nlcd_dec_pos();