74 #if defined( DOXYGEN )
75 static const seg_map[];
76 static const LCD_character_table[];
77 static const seg_inf[];
78 static const lcd_symbol_chart[LCD_SYMBOL_COUNT];
82 static const unsigned char seg_map[] PROGMEM = {
83 NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F ,
84 NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C ,
85 NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B| NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E| NUM_LCD_SYMBOL_G,
86 NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D| NUM_LCD_SYMBOL_G,
87 NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C| NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G,
88 NUM_LCD_SYMBOL_A| NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D| NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G,
89 NUM_LCD_SYMBOL_A| NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G,
90 NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C ,
91 NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G,
92 NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D| NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G,
93 NUM_LCD_SYMBOL_A|NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C| NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G,
94 NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G,
95 NUM_LCD_SYMBOL_A| NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F ,
96 NUM_LCD_SYMBOL_B|NUM_LCD_SYMBOL_C|NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E| NUM_LCD_SYMBOL_G,
97 NUM_LCD_SYMBOL_A| NUM_LCD_SYMBOL_D|NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G,
98 NUM_LCD_SYMBOL_A| NUM_LCD_SYMBOL_E|NUM_LCD_SYMBOL_F|NUM_LCD_SYMBOL_G,
105 static const unsigned int LCD_character_table[] PROGMEM =
181 static const unsigned char seg_inf[] PROGMEM = {
192 static const lcd_symbol_t lcd_symbol_chart[LCD_SYMBOL_COUNT] PROGMEM= {
250 static unsigned char lcd_text[20];
253 static int lcd_text_rd_ptr = 0;
256 static int lcd_text_wr_ptr = 0;
258 static bool lcd_scroll_enable;
259 static int lcd_scroll_prescale;
260 static int lcd_scroll_prescale_value;
261 static int lcd_num_print(uint16_t numb,
bool negative, lcd_padding_t padding);
262 static void lcd_nmb_print_dig(uint8_t val,
int dig);
263 static int lcd_text_sl(
void);
264 static int lcd_text_put(
const char* s,
int pos);
265 static int lcd_char_put(
unsigned char c,
int pos);
286 lcd_config_t lcd_config ;
287 lcd_config.blanking = LCD_BLANKING_OFF;
288 lcd_config.buffer = LCD_BUFFER_ON;
289 lcd_config.wave = LCD_WAVE_LOW_POWER;
290 lcd_config.clock = LCD_CLOCK_EXTERN;
291 lcd_config.bias = LCD_BIAS_HALF;
292 lcd_config.prescl = LCD_PRESCL_16;
293 lcd_config.div = LCD_DIV_8;
294 lcd_config.drive = LCD_DRIVE_450;
295 lcd_config.contrast = LCD_CONTRAST_3_30;
298 PRR &= ~(1 << PRLCD);
301 LCDCRB = lcd_config.lcdcrb|(LCD_PM_0_39<<LCDPM0)|(LCD_DUTY_QUART<<LCDMUX0);
302 LCDFRR = lcd_config.lcdfrr;
303 LCDCCR = lcd_config.lcdccr;
304 LCDCRA = lcd_config.lcdcra|(1<<LCDEN)|(1<<LCDIE);
307 lcd_symbol_clr_all();
310 lcd_scroll_prescale_value = LCD_CLCK_FRQ/128;
311 lcd_scroll_prescale_value >>= (lcd_config.prescl == 0) ? 4 : (5+lcd_config.prescl);
312 lcd_scroll_prescale_value /= (lcd_config.div+1);
313 lcd_scroll_prescale_value = (lcd_scroll_prescale_value==0) ? 1 : lcd_scroll_prescale_value;
314 lcd_scroll_prescale = lcd_scroll_prescale_value;
327 while (!(LCDCRA & (1<<LCDIF)))
334 LCDCRA = (1<<LCDEN)|(1<<LCDIF)|(1<<LCDBL);
336 while ( !(LCDCRA & (1<<LCDIF)) )
340 LCDCRA = (0<<LCDEN) | (0<<LCDIE);
362 while (inNumber >= 10){
367 newByte = newByte << 4;
368 newByte = (newByte | inNumber);
387 return lcd_num_print(numb,
false, padding);
409 }
else if (numb < -9999) {
417 return lcd_num_print(bcd, (
bool)(numb<0), padding);
430 volatile unsigned char* lcd_data = (
volatile unsigned char*)0xEC;
435 lcd_data[pgm_read_byte(&seg_inf[j])&0x1F] &= ~((pgm_read_byte(&seg_inf[j])>>5)<<(i*2));
453 strcpy((
char*)lcd_text, s);
454 lcd_text_wr_ptr = strlen(s);
457 lcd_text_put((
char*)&lcd_text[lcd_text_rd_ptr], 1);
459 lcd_scroll_enable = (lcd_text_wr_ptr > 7) ?
true :
false;
477 memcpy((
void*)lcd_text, (
void const*)s, length);
478 lcd_text_wr_ptr = length;
481 lcd_text_put((
char*)&lcd_text[lcd_text_rd_ptr], 1);
483 lcd_scroll_enable = (lcd_text_wr_ptr > 7) ?
true :
false;
500 strcpy_P((
char*)lcd_text, s);
501 lcd_text_wr_ptr = strlen_P(s);
504 lcd_text_put((
char*)&lcd_text[lcd_text_rd_ptr], 1);
506 lcd_scroll_enable = (lcd_text_wr_ptr > 7) ?
true :
false;
523 lcd_text[lcd_text_wr_ptr++] = c;
524 lcd_text[lcd_text_wr_ptr] = 0;
526 lcd_text_put((
char*)&lcd_text[lcd_text_rd_ptr], 1);
528 lcd_scroll_enable = (lcd_text_wr_ptr > 7) ?
true :
false;
543 unsigned char mem_offset;
544 unsigned char bit_offset;
545 volatile unsigned char* lcd_data = (
volatile unsigned char*)0xEC;
548 bit_offset = (symbol >> 5);
549 mem_offset = (symbol & 0x1F);
550 if ( mem_offset >= 20 ){
553 lcd_data = lcd_data + mem_offset;
555 *lcd_data = *lcd_data | ( 1 << bit_offset);
568 unsigned char offset;
569 unsigned char setbit;
570 volatile unsigned char* lcd_data = (
volatile unsigned char*)0xEC;
573 setbit = (symbol >> 5);
574 offset = (symbol & 0x1F);
579 lcd_data = lcd_data + offset;
581 *lcd_data = *lcd_data & ~( 1 << setbit);
595 count = (start + count)>LCD_SYMBOL_COUNT ?
596 LCD_SYMBOL_COUNT - start :
600 for(i=start; i<start+count; ++i){
616 count = (start + count)>LCD_SYMBOL_COUNT ?
617 LCD_SYMBOL_COUNT - start :
621 for(i=start; i<count; ++i){
638 lcd_num_print(uint16_t numb,
bool negative, lcd_padding_t padding)
643 lcd_nmb_print_dig(pgm_read_byte(&seg_map[(numb&(0xF<<4*i))>>4*i]), i);
647 if (numb >> 4*i == 0) {
648 if (negative ==
true) {
649 lcd_nmb_print_dig(pgm_read_byte(&seg_map[(padding == LCD_NUM_PADDING_ZERO) ? LCD_SEV_SEG_INDEX_0 : LCD_SEV_SEG_INDEX_MINUS]), i++);
650 if (padding == LCD_NUM_PADDING_ZERO) {
657 lcd_nmb_print_dig(pgm_read_byte(&seg_map[(padding == LCD_NUM_PADDING_ZERO) ? LCD_SEV_SEG_INDEX_0 : LCD_SEV_SEG_INDEX_SPACE]), i++);
661 if (negative ==
true) {
680 lcd_nmb_print_dig(uint8_t val,
int dig)
682 volatile unsigned char* lcd_data = (
volatile unsigned char*)0xEC;
687 lcd_data[pgm_read_byte(&seg_inf[j])&0x1F] |= (pgm_read_byte(&seg_inf[j])>>5)<<(dig*2);
690 lcd_data[pgm_read_byte(&seg_inf[j])&0x1F] &= ~((pgm_read_byte(&seg_inf[j])>>5)<<(dig*2));
706 if (lcd_text[lcd_text_rd_ptr] == 0) {
719 lcd_text_put((
char*)&lcd_text[lcd_text_rd_ptr], pos);
735 lcd_text_put(
const char* s,
int pos)
740 for (i=1; i<pos; i++) {
741 lcd_char_put(
' ', i);
745 for ( i=pos; i<=7; ++i) {
747 lcd_char_put(
' ', i);
750 lcd_char_put( (
unsigned char)*s++, i);
768 lcd_char_put(
unsigned char c,
int pos)
770 unsigned int seg, segMask;
772 unsigned char mask, nibble, nibbleMask;
774 volatile unsigned char* lcd_data = (
volatile unsigned char*)0xEC;
775 unsigned char lcd_reg;
782 if (((c >=
'*') && (c <=
'z')) || (c ==
' ')){
796 seg = pgm_read_dword(&LCD_character_table[c]);
813 nibble = seg & 0x000F;
814 nibbleMask = segMask & 0x000F;
820 mask = 0xF0 | nibbleMask;
824 mask = 0x0F | ( nibbleMask <<4 );
827 *lcd_data |= (lcd_reg & mask) | nibble;
830 *lcd_data &= (lcd_reg & mask) | nibble;
848 if (lcd_scroll_enable) {
849 if (--lcd_scroll_prescale == 0) {
851 lcd_scroll_prescale = lcd_scroll_prescale_value;
892 lcd_nmb_print_dig(pgm_read_byte(&seg_map[numb]), pos);