打印
[Kinetis]

YL-KL26Z实验-3

[复制链接]
909|12
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
奥德赛|  楼主 | 2015-12-25 17:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
由于寄存器方式需要学习的太多,只好采用现成的函数编写程序。
首先实验128x64.dot的黑白LCD,这款用的焦躁,其中的初始化LCD程序已能在多款类似芯片下成功显示。
此次驱显得是类0108芯片的LCD。采用两款:大屏幕的和小屏幕的,尽管芯片不同,但采用0108 驱动都正常,仅仅是在控制电压上改改而已。
按照原GPIO程序中的口定义函数,将PORTD0~D3定义为输出方式,以控制4线制的LCD。
定义如下:
选择I/O口:
IO_FUN_SEL(MKL_PORTD,0,1);//LCD Clock
IO_FUN_SEL(MKL_PORTD,1,1);//LCD Data
IO_FUN_SEL(MKL_PORTD,2,1);//Cmd:1=Data & 0=Command
IO_FUN_SEL(MKL_PORTD,3,1);//Reset LCD


相关帖子

沙发
奥德赛|  楼主 | 2015-12-25 17:56 | 只看该作者
定义为输出I/O口:
GPIO_DDR_OUTPUT(MKL_PORTD,0);//LCD Clock
GPIO_DDR_OUTPUT(MKL_PORTD,1);//LCD Data
GPIO_DDR_OUTPUT(MKL_PORTD,2);//Cmd:1=Data & 0=Command
GPIO_DDR_OUTPUT(MKL_PORTD,3);//Reset LCD:- Enable

其中
LCD Clock为LCD写时钟,下沿有效
LCD Data为LCD数据,保持后由Clock锁存
Cmd:1=Data & 0=Command为命令数据描述,1写入LCD的是数据,0写入的是控制命令
Reset LCD为LCD复原信号,0有效,1还原。

使用特权

评论回复
板凳
奥德赛|  楼主 | 2015-12-25 17:57 | 只看该作者
说明:经过测试,LCD Select chip set——cs信号用处不大,只有这个LCD,省略了。
将以前在M051上成功运行显示符号的程序改吧改吧直接移过来,就Ok了。
//I/O Initial
void ioInit(void){
IO_FUN_SEL(MKL_PORTB,18,1);//Test led1
IO_FUN_SEL(MKL_PORTB,19,1);//Test led2
IO_FUN_SEL(MKL_PORTD,0,1);//LCD Clock
IO_FUN_SEL(MKL_PORTD,1,1);//LCD Data
IO_FUN_SEL(MKL_PORTD,2,1);//Cmd:1=Data & 0=Command
IO_FUN_SEL(MKL_PORTD,3,1);//Reset LCD
GPIO_DDR_OUTPUT(MKL_PORTB,18);
GPIO_DDR_OUTPUT(MKL_PORTB,19);
GPIO_DDR_OUTPUT(MKL_PORTD,0);//LCD Clock
GPIO_DDR_OUTPUT(MKL_PORTD,1);//LCD Data
GPIO_DDR_OUTPUT(MKL_PORTD,2);//Cmd:1=Data & 0=Command
GPIO_DDR_OUTPUT(MKL_PORTD,3);//Reset LCD:- Enable
}

使用特权

评论回复
地板
奥德赛|  楼主 | 2015-12-25 17:57 | 只看该作者
//Delayer Longer Time:32768X32767 Clock
void delay(INT16U count){
INT16U i,j;              
for(i=0;i<count;i++){for(j=0;j<i;j++);}            
}
//Write Plus
void wri(){
GPIO_CLR(MKL_PORTD,0);
GPIO_SET(MKL_PORTD,0);
}
//不同大小的图形符号,圆,WYD
const unsigned char hanzi[]={
//16X16
0X03,0X08,0X20,0X00,0X40,0X00,0X80,0X81,0X81,0X80,0X00,0X40,0X00,0X20,0X08,0X03,
0XC0,0X10,0X04,0X00,0X02,0X00,0X01,0X81,0X81,0X01,0X00,0X02,0X00,0X04,0X10,0XC0,

使用特权

评论回复
5
奥德赛|  楼主 | 2015-12-25 17:58 | 只看该作者
//32X32
0X00,0X00,0X01,0X03,0X04,0X08,0X18,0X38,0X20,0X40,0X40,0X40,0X80,0X80,0X80,0XE0,
0XE0,0X80,0X80,0X80,0X40,0X40,0X40,0X30,0X30,0X10,0X08,0X04,0X03,0X01,0X00,0X00,
0X0F,0X71,0X81,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,
0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X80,0X81,0X71,0X0F,
0XF0,0X8E,0X81,0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X80,
0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X81,0X8E,0XF0,
0X00,0X00,0X80,0XC0,0X20,0X10,0X18,0X1C,0X04,0X02,0X02,0X02,0X01,0X01,0X01,0X07,
0X07,0X01,0X01,0X01,0X02,0X02,0X02,0X04,0X1C,0X18,0X10,0X20,0XC0,0X80,0X00,0X00,

使用特权

评论回复
6
奥德赛|  楼主 | 2015-12-25 17:59 | 只看该作者
//32X32-DOT
0X00,0X00,0X01,0X03,0X04,0X08,0X18,0X38,0X20,0X40,0X43,0X43,0X80,0X80,0X80,0XE6,
0XE6,0X80,0X80,0X80,0X40,0X43,0X43,0X30,0X30,0X10,0X08,0X04,0X03,0X01,0X00,0X00,
0X0F,0X71,0X81,0X80,0X00,0X01,0X31,0X30,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,
0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X30,0X31,0X01,0X00,0X80,0X81,0X71,0X0F,
0XF0,0X8E,0X81,0X01,0X00,0X80,0X8C,0X0C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X80,
0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X0C,0X8C,0X80,0X00,0X01,0X81,0X8E,0XF0,
0X00,0X00,0X80,0XC0,0X20,0X10,0X18,0X1C,0X04,0X02,0XC2,0XC2,0X01,0X01,0X01,0X67,
0X67,0X01,0X01,0X01,0XC2,0XC2,0X02,0X04,0X1C,0X18,0X10,0X20,0XC0,0X80,0X00,0X00,

使用特权

评论回复
7
奥德赛|  楼主 | 2015-12-25 18:00 | 只看该作者
//16X16-Nothing
0X03,0X08,0X20,0X00,0X40,0X00,0X80,0X81,0X81,0X80,0X00,0X40,0X00,0X20,0X08,0X03,
0XC0,0X10,0X04,0X00,0X02,0X00,0X01,0X81,0X81,0X01,0X00,0X02,0X00,0X04,0X10,0XC0,
//64X64
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0X03,0X03,0X07,0X0F,
0X0F,0X1C,0X18,0X38,0X30,0X70,0X60,0X60,0X60,0X60,0X60,0XE0,0XC0,0XC0,0XF8,0XF8,
0XF8,0XF8,0XC0,0XC0,0XE0,0X60,0X60,0X60,0X60,0X60,0X70,0X30,0X38,0X18,0X1C,0X0F,
0X07,0X07,0X03,0X03,0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X03,0X0F,0X1E,0X38,0X70,0XE0,0XC0,0X80,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X80,0XC0,0XE0,0X70,0X38,0X1E,0X0F,0X03,0X01,0X00,0X00,0X00,0X00,
0X00,0X07,0X1F,0X7C,0XF0,0XE0,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0XC0,0XF0,0X7C,0X1F,0X07,0X00,
0X3F,0XFF,0XE3,0X03,0X03,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0X03,
0X03,0X03,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0X03,0XE3,0XFF,0X3F,
0XFC,0XFF,0XC7,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0XC0,
0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0XC0,0XC7,0XFF,0XFC,
0X00,0XE0,0XF8,0X3E,0X0F,0X03,0X01,0X01,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X07,0X07,0X0F,0X3E,0XF8,0XE0,0X00,
0X00,0X00,0X00,0X00,0X80,0XC0,0XF0,0XF8,0X1C,0X0E,0X07,0X03,0X01,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X01,0X03,0X07,0X0E,0X1C,0X78,0XF0,0XC0,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X80,0XC0,0XC0,0XE0,0X60,
0X70,0X78,0X78,0X1C,0X0C,0X0E,0X06,0X06,0X06,0X06,0X06,0X07,0X03,0X03,0X1F,0X1F,
0X1F,0X1F,0X03,0X03,0X07,0X06,0X06,0X06,0X06,0X06,0X0E,0X0C,0X1C,0X18,0X38,0XF0,
0XF0,0XE0,0XC0,0XC0,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,

使用特权

评论回复
8
奥德赛|  楼主 | 2015-12-25 18:01 | 只看该作者
//wyd
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0X03,0X03,0X03,0X03,0X03,0X03,0X03,0X03,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X03,0X03,0X03,0X03,0X03,0X03,0X03,0X03,0X03,0X03,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0X03,0X03,0X03,0X07,0X07,0X0F,0X0F,
0X0F,0X0F,0X1F,0X1F,0X1F,0X1F,0X0F,0X0F,0X07,0X07,0XFD,0XFF,0XFF,0XFF,0XFF,0XFF,
0XC0,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X7F,0X7F,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X0F,0X0F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X1F,0X1F,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X7F,0X7F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF8,
0XF8,0XC0,0X80,0X80,0X80,0X80,0XC0,0XE0,0XF8,0XF8,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0X00,0X00,0X7C,0XFE,0X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C1,0XC1,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFC,0XFC,0XC0,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X3F,0X3F,0X3F,0X1F,0X1F,0X1F,0X3F,0XBF,0XFF,0XFE,
0XFE,0XFC,0XF8,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
};

使用特权

评论回复
9
奥德赛|  楼主 | 2015-12-25 18:02 | 只看该作者
/Like 0108LCD Initial
void lcdInit(void){
delay(2000);
GPIO_CLR(MKL_PORTD,3);
delay(2000);
GPIO_SET(MKL_PORTD,3);
delay(2000);
btol(0xAE,0);//AE= Off/AF=On
btol(0xE2,0);//LCD Initial
delay(500);
btol(0xA0,0);//A0=1~132/A1=132~1
btol(0xC0,0);//C0=1~64/C8=64~1||A0+C8 col+4
btol(0xA3,0);//A2=1大/65=1/7_A3=1小/65=1/9
delay(500);
btol(0x2F,0);//Base Vol 28+VC+VR+VF
delay(1000);
btol(0x22,0);//20~27=1.9,2.19,2.55,3.02,3.61,4.35,5.29,6.48V/
delay(1000);
btol(0x81,0);//V0-Next Num//大20小2C
btol(0x2C,0);//000000~111111=0~63=8.83~11.17V/30=10V
delay(1000);

使用特权

评论回复
10
奥德赛|  楼主 | 2015-12-25 18:02 | 只看该作者
btol(0xA4,0);//A4-Off/A5-On[??]
btol(0x10,0);//Column40x10+0000~1111
btol(0x00,0);//Column40x10+0000~1111
btol(0xAF,0);//LCD On
btol(0xAD,0);//AC=Cursor on/AD= off
btol(0x02,0);//??00=OFF/01=1S/02=0.5S/03=AllOn
delay(2000);
}
按照LCD初始化,引线在下,左上角为坐标0,0;右下角为127,63
//MAIN
int main(void){
//uint32_t i;
SystemCoreClockUpdate();
SIM_SCGC5 |=(SIM_SCGC5_PORTA_MASK|SIM_SCGC5_PORTB_MASK|SIM_SCGC5_PORTC_MASK|SIM_SCGC5_PORTD_MASK|SIM_SCGC5_PORTE_MASK);
//for(i=20000;i>0;i--){;};
ioInit();
lcdInit();

使用特权

评论回复
11
奥德赛|  楼主 | 2015-12-25 18:04 | 只看该作者
//uart0Init(9600,0,0,8,1);
//printf("YL-KL25Z128 GPIO for ISP Test 2.4Inch TFT LCD\r\n");
GPIO_SET(MKL_PORTB,18);
GPIO_CLR(MKL_PORTB,19);
delay(1000);
GPIO_CLR(MKL_PORTB,18);
GPIO_SET(MKL_PORTB,19);
delay(2000);
while(1){
  GPIO_SET(MKL_PORTB,18);
  GPIO_CLR(MKL_PORTB,19);
  dispOut();
  delay(1000);
  GPIO_CLR(MKL_PORTB,18);
  GPIO_SET(MKL_PORTB,19);
  delay(2000);
}
}

使用特权

评论回复
12
奥德赛|  楼主 | 2015-12-25 18:07 | 只看该作者
主程序中的系统时钟等照旧,只是增加了LCD显示部分。dispOut(),以及将8位字符转成1bit写入LCD的相关程序先不给出,希望先自己尝试编程。上述LCD初始化之后,LCD屏幕应该能看到变化的,说明已能控制LCD了。过几天忙完后给出完整程序。再下来的实验大致为:
将ADC测试的数值显示在LCD上。以后有时间了再玩其他实验。

使用特权

评论回复
13
奥德赛|  楼主 | 2015-12-25 18:07 | 只看该作者


小屏幕128x64LCD




大屏幕128x64 LCD



                    

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

46

主题

397

帖子

3

粉丝