Программа написана на codevision для LCD 16x2 и хочу переделать под графический дисплей.
- Код: Выделить всё • Развернуть
lcd_text_intern(5, 4 ,FONT_FIVE_DOT,"0",0);
//lcd_text_String("PRIVET");
//lcd_glyph( 10,10, 30, 30, &icon1_bmp,0);
lcd_update_all();// вывод на LCD
delay_ms(1000);// задержка
lcd_erase();// очистка LCD
- Код: Выделить всё • Развернуть
//--------------------------------------------------------------------------------------
void lcd_text_intern(unsigned int left, unsigned int top, unsigned int font, flash const char *str, unsigned int inprogmem)
{
unsigned int x;
unsigned int glyph;// ñïåöèàëüíûé íàáîðíûé çíàê õðàíÿùèéñÿ â ïàìÿòè,â öèôðîâîì âèäå
unsigned int width;// øèðèíà
unsigned int height, defaultheight;// âûñîòà, âûñîòà ïî óìîë÷àíèþ
unsigned int store_width;// õðàíèìàÿ øèðèíà
unsigned int *glyph_ptr;// óêàçàòåëü íà ñïåöèàëüíûé íàáîð
unsigned int *width_table_ptr;
unsigned int *glyph_table_ptr;
unsigned int glyph_beg, glyph_end;
unsigned int fixedwidth;
x = left;// êîîðäèíàòà ëåâîãî íà÷àëà ñðîêè
defaultheight = peekb ( &(unsigned int)(fonts[font].glyph_height) );// áåðåì çíà÷åíèÿ âûñîòû äîëæíî áûòü "8"
store_width = peekb ( &((unsigned int)fonts[font].store_width) );// áåðåì çíà÷åíèÿ øèðèíû "2"
width_table_ptr = (unsigned int*) pgm_read_word ( &(fonts[font].width_table) );//
glyph_table_ptr = (unsigned int*) pgm_read_word ( &(fonts[font].glyph_table) );
glyph_beg = peekb( &((unsigned int)fonts[font].glyph_beg) );// çíà÷åíèå " "
glyph_end = peekb( &((unsigned int)fonts[font].glyph_end) );// çíà÷åíèå "~ "
fixedwidth = peekb( &((unsigned int)fonts[font].fixed_width) );// çíà÷åíèå "0"
if (inprogmem)
{
glyph = pgm_read_byte((unsigned int )str);
}
else
{
glyph = (unsigned int)*str;
}
while(glyph != 0x00) // while(*str != 0x00)
{
if((glyph < glyph_beg) || (glyph > glyph_end))
{
glyph = peekb( &((unsigned int)fonts[font].glyph_def) );
}
glyph -= glyph_beg;
if(fixedwidth == 0)
// width=fonts[font].width_table[glyph];
{
width=peekb((unsigned int)width_table_ptr+glyph);
}
else
{
width = fixedwidth;
}
height = defaultheight;
//glyph_ptr = fonts[font].glyph_table + ((unsigned int)glyph * (unsigned int)store_width * (unsigned int)height);
glyph_ptr = glyph_table_ptr + ((unsigned int)glyph * (unsigned int)store_width * (unsigned int)height);
if(x > 121)
{x = 121;}
if((x + width) > 121+1)
{width = 121 - x + 1;}
if(top > 31)
{top = 31;}
if((top + height) > 31+1)
{ height = 31 - top + 1;}
lcd_glyph(x,top,width,height,glyph_ptr,store_width);
x += width;
str++;
if (inprogmem)
{glyph = pgm_read_byte((unsigned int)str);}
else
{
glyph = (unsigned int)*str;}
}
}
- Код: Выделить всё • Развернуть
#define PROGMEM __flash
#define PSTR(x) x
#define pgm_read_byte(x) (*((uint8_t __flash *)(x)))
#define pgm_read_word(x) (*((uint16_t __flash *)(x)))
- Код: Выделить всё • Развернуть
static PROGMEM unsigned char five_dot_glyph_table [] =
{
/* '0' charwidth: 5 */
0x11, /* [ ] */
0x60, /* [ ** ] */
0x90, /* [* * ] */
0x90, /* [* * ] */
0x90, /* [* * ] */
0x60, /* [ ** ] */
0x00, /* [ ] */
/* '1' charwidth: 3 */
0x22, /* [ ] */
0x40, /* [ * ] */
0xC0, /* [** ] */
0x40, /* [ * ] */
0x40, /* [ * ] */
0x40, /* [ * ] */
0x00 /* [ ] */
};
#endif
static PROGMEM unsigned char five_dot_width_table []=
{
5, /* '0' */
3 /* '1' */
};
- Код: Выделить всё • Развернуть
struct FONT_DEF
{
const unsigned char store_width; /* glyph storage width in bytes */
const unsigned char glyph_height; /* glyph height for storage */
const unsigned char PROGMEM *glyph_table; /* font table start address in memory */
const unsigned char fixed_width; /* fixed width of glyphs. If zero */
/* then use the width table. */
const unsigned char PROGMEM *width_table; /* variable width table start adress */
const unsigned char glyph_beg; /* start ascii offset in table */
const unsigned char glyph_end; /* end ascii offset in table */
const unsigned char glyph_def; /* code for undefined glyph code */
}fonts [FONT_COUNT]=
{
#ifdef EN_FIVE_DOT
{
1, 7, five_dot_glyph_table, 0, five_dot_width_table,' ','~','.'
},
#endif
#ifdef EN_SIX_DOT
{2, 8, six_dot_glyph_table, 0, six_dot_width_table,' ','~','.'}
#endif
};
- Код: Выделить всё • Развернуть
void lcd_glyph(unsigned int left, unsigned int top, unsigned int width, unsigned int height,unsigned int *glyph_ptr, unsigned int store_width)
{
unsigned int bit_pos;
unsigned int byte_offset;
unsigned int y_bits;
unsigned int remaining_bits;
unsigned int mask;
unsigned int char_mask;
unsigned int x;
unsigned int *glyph_scan;
unsigned int glyph_offset;
bit_pos = top & 0x07;
glyph_offset = 0;
char_mask = 0x80;
for (x = left; x < (left + width); x++)
{
byte_offset = top >> 3;
y_bits = height;
remaining_bits = 8 - bit_pos;
mask = l_mask_array[bit_pos];
glyph_scan = glyph_ptr + glyph_offset;
while((y_bits) && (byte_offset < 4))
{
if(pgm_read_byte((unsigned int)glyph_scan) & char_mask)
{
l_display_array[byte_offset][x] |= mask;
}
else
{
l_display_array[byte_offset][x] &= ~mask;
}
if(l_mask_array[0] & 0x80)
{
mask >>= 1;
}
else
{mask <<= 1;}
y_bits--;
remaining_bits--;
if(remaining_bits == 0)
{
remaining_bits = 8;
byte_offset++;
mask = l_mask_array[0];
}
glyph_scan += store_width;
}
char_mask >>= 1;
if(char_mask == 0)
{
char_mask = 0x80;
glyph_offset++;
}
}
}
вот вроде все данные,надеюсь что ничего не забыл.Выводит на экран какую то ерунду.Исполузую codevision 1.24.8d professional