在菜单式MP3点播器的设计中,需要KL25Z驱动相应的显示器件来显示中文菜单,原打算使用只有4个引脚OLED来实现,因为这样可以节省GPIO的占用。然而尽管在多种MCU上成功地实现了移植,但在KL25Z、M451上却止住了脚步。无奈,只好先放下来另寻其他的显示器件。这次是选取LCD5110为显示器件,该器件共有8个引脚,各引脚的用途和连接情况如表1所示。 表1 LCD5110引脚作用及连接 这次移植到是一帆风顺,很快就见到了效果。恰逢中秋,就以“海上升明月,天涯共此时”为内容来表示节日的祝福吧,效果如图1所示。 图1 中秋佳句 由于显示的中文不是很多,因此就没劳烦板上FLASH 来作硬字库,而是将提前的字模放置到数组中来组成小字库。提取字模所用的软件为
, 它生成的字模共有2种规格,一种是12点阵,另一种是16点阵。图1采用的是16点阵,在歌曲菜单的显示上,是采用12点阵,这样能在有限的屏幕上输出更多的内容,其效果如图2所示。 图2 MP3点播器界面 KL25Z驱动LCD5110液晶屏的程序如下: - #include "includes.h"
- #define sce_1 GPIO_SET(MKL_PORTC,2)
- #define sce_0 GPIO_CLR(MKL_PORTC,2)
- #define dc_1 GPIO_SET(MKL_PORTC,1)
- #define dc_0 GPIO_CLR(MKL_PORTC,1)
- #define RST_1 GPIO_SET(MKL_PORTC,0);
- #define RST_0 GPIO_CLR(MKL_PORTC,0)
- #define LCD_SCLK_1 GPIO_SET(MKL_PORTE,0);
- #define LCD_SCLK_0 GPIO_CLR(MKL_PORTE,0)
- #define LCD_SDIN_1 GPIO_SET(MKL_PORTE,1)
- #define LCD_SDIN_0 GPIO_CLR(MKL_PORTE,1)
- unsigned char font6x8[][6] =
- {
- { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
- { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
- { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
- { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
- { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
- { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %
- { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
- { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
- { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
- { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
- { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
- { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
- { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,
- { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
- { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
- { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
- { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
- { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
- { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
- { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
- { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
- { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
- { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
- { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
- { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
- { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
- { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
- { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
- { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
- { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
- { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
- { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
- { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
- { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A
- { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
- { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
- { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
- { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
- { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
- { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
- { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
- { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
- { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
- { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
- { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
- { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
- { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
- { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
- ...
- };
- unsigned char font16x16[][32]={
- {0x10,0x60,0x02,0x0C,0xC0,0x10,0x08,0xF7,0x14,0x54,0x94,0x14,0xF4,0x04,0x00,0x00,0x04,0x04,0x7C,0x03,0x00,0x01,0x1D,0x13,0x11,0x55,0x99,0x51,0x3F,0x11,0x01,0x00},
- {0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00},
- {0x80,0x80,0x84,0x84,0x84,0xFE,0x82,0x83,0x82,0x80,0xFF,0x80,0x80,0x80,0x80,0x00,0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00},
- {0x00,0xFC,0x44,0x44,0x44,0xFC,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,0x0F,0x04,0x04,0x04,0x8F,0x40,0x30,0x0F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00},
- {0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00},
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
- {0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00,0x80,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x80,0x00},
- {0x10,0x60,0x02,0x8C,0x00,0xFE,0x82,0x92,0x92,0x92,0xFE,0x92,0x92,0x92,0x82,0x00,0x04,0x04,0x7E,0x81,0x60,0x1F,0x40,0x48,0x48,0x48,0x7E,0x48,0x48,0x48,0x40,0x00},
- {0x00,0x00,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,0x00,0x00,0x04,0x84,0x44,0x24,0x17,0x04,0x04,0x04,0x04,0x17,0x24,0x44,0x84,0x04,0x00},
- {0x00,0x00,0xF8,0x00,0x00,0xFF,0x20,0x20,0x00,0xFF,0x40,0x20,0x10,0x08,0x00,0x00,0x20,0x60,0x3F,0x20,0x10,0x1F,0x10,0x10,0x00,0x3F,0x40,0x40,0x40,0x40,0x78,0x00},
- {0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00},
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
- };
- const unsigned char chinese_character[][24]=
- {
- //菜0
- {0x12,0x32,0x52,0x17,0x32,0xD2,0x12,0x4F,0x2A,0x0A,0x02,0x00,0x09,0x09,0x05,0x03,0x01,0x0F,0x01,0x03,0x05,0x09,0x09,0x00},
- //单1
- {0x00,0x7C,0x55,0x56,0x54,0xFC,0x54,0x56,0x55,0x7C,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x0F,0x01,0x01,0x01,0x01,0x01,0x00},
- //式2
- {0x08,0x48,0x48,0xC8,0x48,0x48,0x08,0xFF,0x08,0x09,0x0A,0x00,0x08,0x08,0x08,0x07,0x04,0x04,0x04,0x00,0x03,0x04,0x0E,0x00},
- //点3
- {0x00,0xF0,0x10,0x10,0x10,0x1F,0x12,0x12,0x12,0xF2,0x02,0x00,0x08,0x05,0x01,0x05,0x09,0x01,0x05,0x09,0x01,0x05,0x08,0x00},
- //播4
- {0x88,0xFF,0x48,0xD6,0xBA,0x92,0xBE,0x91,0xB9,0xD5,0x90,0x00,0x08,0x0F,0x00,0x0F,0x0A,0x0A,0x0F,0x0A,0x0A,0x0F,0x00,0x00},
- //器5
- {0x20,0x27,0xA5,0xA5,0x67,0x38,0x67,0xA5,0xAD,0x37,0x20,0x00,0x01,0x0F,0x0A,0x0A,0x0E,0x00,0x0E,0x0A,0x0A,0x0F,0x01,0x00},
- //莫6
- {0x02,0xFA,0xAA,0xAF,0xAA,0xAA,0xAA,0xAF,0xAA,0xFA,0x02,0x00,0x0A,0x0A,0x0A,0x06,0x03,0x02,0x02,0x06,0x0A,0x0A,0x0A,0x00},
- //斯7
- {0x04,0xFF,0x54,0x54,0xFF,0x04,0xFE,0x12,0x12,0xF1,0x10,0x00,0x09,0x05,0x01,0x01,0x05,0x09,0x07,0x00,0x00,0x0F,0x00,0x00},
- //科8
- {0x12,0xD2,0xFE,0x51,0x90,0x12,0x24,0x00,0xFF,0x80,0x80,0x00,0x01,0x00,0x0F,0x00,0x00,0x01,0x01,0x01,0x0F,0x00,0x00,0x00},
- //郊9
- {0x44,0x34,0x85,0x06,0x94,0x24,0x00,0xFE,0x02,0x32,0xCE,0x00,0x08,0x04,0x02,0x01,0x02,0x04,0x00,0x0F,0x02,0x02,0x01,0x00},
- //外10
- {0x40,0x30,0x4F,0x88,0x78,0x00,0x00,0xFF,0x10,0x20,0xC0,0x00,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x00},
- //的11
- {0xFC,0x46,0x45,0x44,0xFC,0x10,0x08,0x27,0xC4,0x04,0xFC,0x00,0x0F,0x04,0x04,0x04,0x0F,0x00,0x00,0x00,0x08,0x08,0x07,0x00},
- //晚12
- {0xFE,0x22,0xFE,0x00,0xF8,0x94,0x93,0xF2,0x9A,0x96,0xF0,0x00,0x07,0x02,0x07,0x00,0x08,0x04,0x03,0x00,0x07,0x08,0x0C,0x00},
- //上13
- {0x00,0x00,0x00,0x00,0xFF,0x10,0x10,0x10,0x10,0x10,0x00,0x00,0x08,0x08,0x08,0x08,0x0F,0x08,0x08,0x08,0x08,0x08,0x08,0x00},
- //等14
- {0x44,0x53,0x52,0x56,0x52,0x7C,0x53,0xD2,0x56,0x52,0x42,0x00,0x01,0x01,0x03,0x05,0x01,0x09,0x09,0x0F,0x01,0x01,0x01,0x00},
- //待15
- {0x48,0x24,0xF2,0x09,0x50,0x54,0x54,0x5F,0xF4,0x54,0x50,0x00,0x00,0x00,0x0F,0x00,0x00,0x01,0x0A,0x08,0x0F,0x00,0x00,0x00},
- //鸿16
- {0x22,0x44,0x02,0xFE,0x02,0x00,0xFE,0x8B,0xA2,0xBE,0x80,0x00,0x04,0x02,0x04,0x07,0x02,0x00,0x02,0x02,0x0A,0x08,0x07,0x00},
- //雁17
- {0x00,0xFF,0x11,0xF9,0x27,0xF9,0x4F,0x49,0xFB,0x4D,0x49,0x00,0x08,0x07,0x00,0x0F,0x00,0x0F,0x09,0x09,0x0F,0x09,0x09,0x00},
- ...
- };
- void delay(uint16_t i)
- {
- while(i)
- {
- i--;
- }
- }
- void SPI_CONFIG()
- {
- PORT_ENABLE_CLK(MKL_PORTC);
- PORT_ENABLE_CLK(MKL_PORTE);
- IO_FUN_SEL(MKL_PORTC,0,1);
- IO_FUN_SEL(MKL_PORTC,1,1);
- IO_FUN_SEL(MKL_PORTC,2,1);
- IO_FUN_SEL(MKL_PORTE,0,1);
- IO_FUN_SEL(MKL_PORTE,1,1);
- GPIO_DDR_OUTPUT(MKL_PORTC,0);
- GPIO_DDR_OUTPUT(MKL_PORTC,1);
- GPIO_DDR_OUTPUT(MKL_PORTC,2);
- GPIO_DDR_OUTPUT(MKL_PORTE,1);
- GPIO_DDR_OUTPUT(MKL_PORTE,0);
- GPIO_SET(MKL_PORTC,0);
- GPIO_SET(MKL_PORTC,1);
- GPIO_SET(MKL_PORTC,2);
- GPIO_SET(MKL_PORTE,0);
- GPIO_SET(MKL_PORTE,1);
- RST_0;
- delay(100);
- RST_1;
- delay(100);
- RST_0;
- delay(100);
- RST_1;
- delay(100);
- }
- void LCD_write_byte(uint8_t dt, uint8_t command)
- {
- uint16_t i;
- if(command)
- {
- dc_1;
- }
- else
- {
- dc_0;
- }
- sce_0;
- for(i=0;i<8;i++)
- {
- if(dt & 0x80)
- LCD_SDIN_1;
- else
- LCD_SDIN_0;
- LCD_SCLK_1;
- LCD_SCLK_0;
- dt<<=1;
- }
- sce_1;
- }
- void LCD_set_XY(uint8_t X, uint8_t Y)
- {
- LCD_write_byte(0x40 | Y, 0);// column
- LCD_write_byte(0x80 | X, 0);// row
- }
- void LCD_clear(void)
- {
- uint8_t t;
- uint8_t k;
- LCD_set_XY(0,0);
- for(t=0;t<6;t++)
- {
- for(k=0;k<84;k++)
- {
- LCD_write_byte(0x00,1);
-
- }
- }
- }
- void LCD_init(void)
- {
- LCD_write_byte(0x21,0);//???Lcd,??????????
- LCD_write_byte(0xc3,0);//????????
- LCD_write_byte(0x10, 0); // 1:48
- LCD_write_byte(0x20,0);//??????
- LCD_write_byte(0x0C,0);//??????,????
- LCD_clear();
- }
- void LCD_write_char(unsigned char c,char dis)
- {
- unsigned char line;
- c -= 32;
- for (line=0; line<6; line++)
- if(dis)
- {
- LCD_write_byte(~font6x8[c][line], 1);
- }
- else
- {
- LCD_write_byte(font6x8[c][line], 1);
- }
- }
- void LCD_write_dangehanzi(unsigned char X,unsigned char Y,char s)
- {
- do
- {
- char line;
- LCD_set_XY(X,Y);
- for (line=0; line<16; line++)
- {
- LCD_write_byte(font16x16[s][line],1);
- }
- LCD_set_XY(X,Y+1);
- for (line=16; line<32; line++)
- {
- LCD_write_byte(font16x16[s][line],1);
- }
- }while(0);
- }
- void LCD_write_hanzi(unsigned char X,unsigned char Y,char s)
- {
- do
- {
- char line;
- LCD_set_XY(X,Y);
- for (line=0; line<12; line++)
- {
- LCD_write_byte(chinese_character[s][line], 1);
- }
- LCD_set_XY(X,Y+1);
- for (line=12; line<24; line++)
- {
- LCD_write_byte(chinese_character[s][line], 1);
- }
- }while(0);
- }
- void jm2(void)
- {
- LCD_write_english_string(0,0," MP3",0);
- LCD_write_hanzi(38,0,3);
- LCD_write_hanzi(50,0,4);
- LCD_write_hanzi(62,0,5);
- LCD_write_hanzi(2,2,6);
- LCD_write_hanzi(14,2,7);
- LCD_write_hanzi(26,2,8);
- LCD_write_hanzi(38,2,9);
- LCD_write_hanzi(50,2,10);
- LCD_write_hanzi(62,2,11);
- LCD_write_hanzi(2,4,12);
- LCD_write_hanzi(14,4,13);
- LCD_write_hanzi(26,4,23);
- LCD_write_hanzi(38,4,24);
- LCD_write_hanzi(50,4,21);
- LCD_write_hanzi(62,4,22);
- }
- void jm1(void)
- {
- LCD_clear();
- LCD_write_dangehanzi(0,0,0);
- LCD_write_dangehanzi(16,0,1);
- LCD_write_dangehanzi(32,0,2);
- LCD_write_dangehanzi(48,0,3);
- LCD_write_dangehanzi(64,0,4);
- LCD_write_dangehanzi(0,3,6);
- LCD_write_dangehanzi(16,3,7);
- LCD_write_dangehanzi(32,3,8);
- LCD_write_dangehanzi(48,3,9);
- LCD_write_dangehanzi(64,3,10);
- }
- int main (void)
- {
- SystemCoreClockUpdate();
- SIM_SCGC5 |= (SIM_SCGC5_PORTA_MASK
- | SIM_SCGC5_PORTB_MASK
- | SIM_SCGC5_PORTC_MASK
- | SIM_SCGC5_PORTD_MASK
- | SIM_SCGC5_PORTE_MASK );
- SPI_CONFIG();
- LCD_init();
- Jm1();
- myDelay(10000);
- Jm2();
- while(1);
- }
复制代码
|