[Kinetis] YL-KL26Z实验-4

[复制链接]
968|13
 楼主| ccw1986 发表于 2015-12-25 17:39 | 显示全部楼层 |阅读模式
最近有个项目需操作,我将显示ASCII码和屏幕上显示JSQ:、AD0:~AD7:以及其他固定信息和计数器计数显示的完整程序放上,有时间了,会将ADC程序与此程序结合实现ADC分次测试和取n次平均后的显示。看看此板的ADC的精度如何。当然LCD显示有了,其他的实验数据都可以直接显示出来以便后来的操作。全代码如下[学习可以,转载不可!]:
  1. //2.4Inch TFT LCD Test I/O for SPI--Changge gpio & M051
  2. #include "includes.h"

  1. const unsigned char asc2[][8]={//8x6 Dots 32 to 127 + caratteri alfa_omega a seguire
  2. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},// space
  3. {0x00,0x1c,0x22,0x24,0x18,0x16,0x00,0x00},//!-1=32
  4. {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},//"
  5. {0x00,0x02,0x04,0x78,0x10,0x0c,0x02,0x00},//#
  6. {0x00,0x7e,0x15,0x15,0x15,0x0a,0x00,0x00},//$
  7. {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},//%
  8. {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},//&
  9. {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},//'
  10. {0x00,0x00,0x1C,0x22,0x41,0x00,0x00,0x00},//(
  11. {0x00,0x00,0x41,0x22,0x1C,0x00,0x00,0x00},//)
  12. {0x00,0x14,0x08,0x3E,0x08,0x14,0x00,0x00},//**/-10=42
  13. {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},//+
  14. {0x00,0x00,0x50,0x30,0x00,0x00,0x00,0x00},//;
  15. {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},//-
  16. {0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00},//.
  17. {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},///
  18. {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},//0


 楼主| ccw1986 发表于 2015-12-25 17:40 | 显示全部楼层
  1. {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},//1
  2. {0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00},//2
  3. {0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00},//3
  4. {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},//4-20
  5. {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},//5
  6. {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},//6
  7. {0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00},//7
  8. {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},//8
  9. {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},//9
  10. {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},//:
  11. {0x00,0x00,0x56,0x36,0x00,0x00,0x00,0x00},//;
  12. {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},//<
  13. {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},//=
  14. {0x00,0x00,0x41,0x22,0x14,0x08,0x00,0x00},//>-30
  15. {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},//?
  16. {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},//@
  17. {0x00,0x7E,0x11,0x11,0x11,0x7E,0x00,0x00},//A
  18. {0x00,0x41,0x7F,0x49,0x49,0x36,0x00,0x00},//B
  19. {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},//C
  20. {0x00,0x41,0x7F,0x41,0x41,0x3E,0x00,0x00},//D
  21. {0x00,0x7F,0x49,0x49,0x49,0x49,0x00,0x00},//E
  22. {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},//F
  23. {0x00,0x3E,0x41,0x41,0x49,0x7A,0x00,0x00},//G
  24. {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},//H
  25. {0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00},//I-40
 楼主| ccw1986 发表于 2015-12-25 17:42 | 显示全部楼层
  1. {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},//J
  2. {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},//K
  3. {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},//L
  4. {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},//M
  5. {0x00,0x7F,0x06,0x08,0x30,0x7F,0x00,0x00},//N
  6. {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},//O
  7. {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},//P
  8. {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},//Q
  9. {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},//R
  10. {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},//S
  11. {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},//T-50
  12. {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},//U
  13. {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},//V
  14. {0x00,0x7F,0x20,0x18,0x20,0x7F,0x00,0x00},//W
  15. {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},//X
  16. {0x00,0x07,0x08,0x70,0x08,0x07,0x00,0x00},//Y
  17. {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},//Z
  18. {0x00,0x00,0x7F,0x41,0x41,0x00,0x00,0x00},//[
  19. {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},//\//
  20. {0x00,0x00,0x41,0x41,0x7F,0x00,0x00,0x00},//]
 楼主| ccw1986 发表于 2015-12-25 17:43 | 显示全部楼层
  1. {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},//^-60
  2. {0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00},//_
  3. {0x00,0x00,0x00,0x07,0x05,0x07,0x00,0x00},//' Insty
  4. {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},//a
  5. {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},//b
  6. {0x00,0x38,0x44,0x44,0x44,0x28,0x00,0x00},//c
  7. {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},//d
  8. {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},//e
  9. {0x00,0x00,0x08,0x7E,0x09,0x02,0x00,0x00},//f
  10. {0x00,0x0C,0x52,0x52,0x4C,0x3E,0x00,0x00},//g
  11. {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},//h-70
  12. {0x00,0x00,0x44,0x7D,0x40,0x00,0x00,0x00},//i
  13. {0x00,0x20,0x40,0x44,0x3D,0x00,0x00,0x00},//j
  14. {0x00,0x00,0x7F,0x10,0x28,0x44,0x00,0x00},//k
  15. {0x00,0x00,0x41,0x7F,0x40,0x00,0x00,0x00},//l
  16. {0x00,0x7C,0x04,0x78,0x04,0x78,0x00,0x00},//m
  17. {0x00,0x7C,0x08,0x04,0x04,0x78,0x00,0x00},//n
  18. {0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00},//o
  19. {0x00,0x7E,0x0C,0x12,0x12,0x0C,0x00,0x00},//p
  20. {0x00,0x0C,0x12,0x12,0x0C,0x7E,0x00,0x00},//q
  21. {0x00,0x7C,0x08,0x04,0x04,0x08,0x00,0x00},//r-80
  22. {0x00,0x58,0x54,0x54,0x54,0x64,0x00,0x00},//s
  23. {0x00,0x04,0x3F,0x44,0x40,0x20,0x00,0x00},//t
 楼主| ccw1986 发表于 2015-12-25 17:44 | 显示全部楼层
  1. {0x00,0x3C,0x40,0x40,0x3C,0x40,0x00,0x00},//u
  2. {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},//v
  3. {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},//w
  4. {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},//x
  5. {0x00,0x1C,0xA0,0xA0,0x90,0x7C,0x00,0x00},//y
  6. {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},//z
  7. {0x00,0x00,0x08,0x36,0x41,0x00,0x00,0x00},//{
  8. {0x00,0x00,0x00,0x77,0x00,0x00,0x00,0x00},//|-90
  9. {0x00,0x00,0x41,0x36,0x08,0x00,0x00,0x00},//}
  10. {0x00,0x08,0x04,0x08,0x10,0x08,0x00,0x00},//~
  11. {0x00,0x5c,0x62,0x02,0x62,0x5c,0x00,0x00},//OM
  12. {0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14},//horiz lines-94
  13. };
  14. INT16U t0=0;
  15. //Delayer moster 65536X65535 system clock
  16. void delay(INT16U count){
  17. INT16U i,j;              
  18. for(i=0;i<count;i++){for(j=0;j<i;j++);}            
  19. }
 楼主| ccw1986 发表于 2015-12-25 17:45 | 显示全部楼层
  1. //Write Plus
  2. void wri(){
  3. GPIO_CLR(MKL_PORTD,0);
  4. GPIO_SET(MKL_PORTD,0);
  5. }
  6. //Write 1 byte to LCD,dt:data/comata-1,Command-0
  7. void b2l(unsigned char dt,unsigned char com){
  8. unsigned char i;
  9. if(com==1){GPIO_SET(MKL_PORTD,2);}else{GPIO_CLR(MKL_PORTD,2);}
  10. for(i=0;i<8;i++){
  11.   if(dt&0x80){GPIO_SET(MKL_PORTD,1);}else{GPIO_CLR(MKL_PORTD,1);}
  12.   dt=dt<<1;
  13.   wri();
  14. }
  15. }
  16. //Set LCD col:0-102 pag:0-8
  17. void setXY(unsigned char pag,unsigned char col){
  18. b2l(0xB0+pag,0);//page
  19. //col+=0x04;//+4-->4bit
  20. b2l(0x10+((col&0xF0)>>4),0);//row-H4
  21. b2l(col&0x0F,0);//row-L4
  22. }
 楼主| ccw1986 发表于 2015-12-25 17:45 | 显示全部楼层
  1. //LCD Clear
  2. void lcdClear(void){
  3. unsigned char pag,col;
  4. for(pag=0;pag<8;pag++){
  5.   setXY(pag,0);
  6.   for(col=0;col<132;col++){b2l(0x00,1);};}
  7. }
  8. //c:Char,cha[]
  9. void c2l(unsigned char pag,unsigned char col,unsigned char c){
  10. unsigned char line;
  11. setXY(pag,col*8);  
  12. for (line=0;line<8;line++)
  13.   b2l(asc2[c][line],1);
  14. }
 楼主| ccw1986 发表于 2015-12-25 17:46 | 显示全部楼层
  1. //Like 0108LCD Initial
  2. void lcdInit(void){
  3. delay(2000);
  4. GPIO_CLR(MKL_PORTD,3);//Reset LCD
  5. delay(2000);
  6. GPIO_SET(MKL_PORTD,3);
  7. delay(2000);
  8. b2l(0xAE,0);//AE= Off/AF=On
  9. b2l(0xE2,0);//LCD Initial
  10. delay(500);
  11. b2l(0xA0,0);//A0=1~132/A1=132~1
  12. b2l(0xC8,0);//C0=1~64/C8=64~1||A0+C8 col+4
  13. b2l(0xA2,0);//A2=1Big/65=1/7_A3=1Small/65=1/9
  14. delay(500);
  15. b2l(0x2F,0);//Base Vol 28+VC+VR+VF
  16. delay(1000);
  17. b2l(0x22,0);//20~27=1.9,2.19,2.55,3.02,3.61,4.35,5.29,6.48V/
  18. delay(1000);
  19. b2l(0x81,0);//V0-Next Num//Big20/small2C
  20. b2l(0x20,0);//000000~111111=0~63=8.83~11.17V/30=10V
  21. delay(1000);
 楼主| ccw1986 发表于 2015-12-25 17:47 | 显示全部楼层
  1. b2l(0xA4,0);//A4-Off/A5-On[??]
  2. b2l(0x10,0);//Column40x10+0000~1111
  3. b2l(0x00,0);//Column40x10+0000~1111
  4. b2l(0xAF,0);//LCD On
  5. b2l(0xAD,0);//AC=Cursor on/AD= off
  6. b2l(0x02,0);//??00=OFF/01=1S/02=0.5S/03=AllOn
  7. delay(2000);
  8. }
  9. //Display ASCiI Test
  10. void dispAsc2(void){
  11. int i,j;
  12. for(i=0;i<6;i++){
  13.   for(j=0;j<16;j++){c2l(i,j,i*16+j);}
  14. }
  15. }
 楼主| ccw1986 发表于 2015-12-25 17:48 | 显示全部楼层
  1. //Display BaseData
  2. void dispBase(void){
  3. c2l(0,0,52);c2l(0,1,69);c2l(0,2,83);c2l(0,3,84);c2l(0,5,33);c2l(0,6,36);c2l(0,7,35);//Test ADC
  4. c2l(0,9,42);c2l(0,10,51);c2l(0,11,49);c2l(0,13,48);c2l(0,14,55);c2l(0,15,45);//JSQ PWM
  5. c2l(3,0,42);c2l(3,1,51);c2l(3,2,49);c2l(3,3,26);//JSQ
  6. c2l(4,0,33);c2l(4,1,16);c2l(4,2,26);c2l(4,8,33);c2l(4,9,17);c2l(4,10,26);//A0:A1:
  7. c2l(5,0,33);c2l(5,1,18);c2l(5,2,26);c2l(5,8,33);c2l(5,9,19);c2l(5,10,26);//A2:A3:
  8. c2l(6,0,33);c2l(6,1,20);c2l(6,2,26);c2l(6,8,33);c2l(6,9,21);c2l(6,10,26);//A4:A5:
  9. c2l(7,0,33);c2l(7,1,22);c2l(7,2,26);c2l(7,8,33);c2l(7,9,23);c2l(7,10,26);//A6:A7:
  10. }
  11. //Display Messege data
  12. void dispMes(void){
  13. c2l(3,4,(t0/100000)%10+16);c2l(3,5,(t0/10000)%10+16);c2l(3,6,(t0/1000)%10+16);c2l(3,7,(t0/100)%10+16);c2l(3,8,(t0/10)%10+16);c2l(3,9,t0%10+16);
  14. }
 楼主| ccw1986 发表于 2015-12-25 17:48 | 显示全部楼层
  1. //I/O Instial
  2. void ioInit(void){
  3. //IO功能选择
  4. IO_FUN_SEL(MKL_PORTB,18,1);//Test Led1
  5. IO_FUN_SEL(MKL_PORTB,19,1);//Test Led2
  6. IO_FUN_SEL(MKL_PORTD,0,1);//LCD Clock
  7. IO_FUN_SEL(MKL_PORTD,1,1);//LCD Data
  8. IO_FUN_SEL(MKL_PORTD,2,1);//Cmd:1=Data & 0=Command
  9. IO_FUN_SEL(MKL_PORTD,3,1);//Reset LCD:- Enable
  10. //IO设置为输出模式
  11. GPIO_DDR_OUTPUT(MKL_PORTB,18);//Test Led1
  12. GPIO_DDR_OUTPUT(MKL_PORTB,19);//Test Led2
  13. GPIO_DDR_OUTPUT(MKL_PORTD,0);//LCD Clock
  14. GPIO_DDR_OUTPUT(MKL_PORTD,1);//LCD Data
  15. GPIO_DDR_OUTPUT(MKL_PORTD,2);//Cmd:1=Data & 0=Command
  16. GPIO_DDR_OUTPUT(MKL_PORTD,3);//Reset LCD:- Enable
  17. }
 楼主| ccw1986 发表于 2015-12-25 17:50 | 显示全部楼层
  1. //MAIN Program
  2. int main(void){
  3. SystemCoreClockUpdate();
  4. SIM_SCGC5 |=(SIM_SCGC5_PORTA_MASK|SIM_SCGC5_PORTB_MASK|SIM_SCGC5_PORTC_MASK|SIM_SCGC5_PORTD_MASK|SIM_SCGC5_PORTE_MASK);
  5. ioInit();
  6. lcdInit();
  7. lcdClear();
  8. GPIO_SET(MKL_PORTB,18);
  9. GPIO_CLR(MKL_PORTB,19);
  10. delay(1000);
  11. GPIO_CLR(MKL_PORTB,18);
  12. GPIO_SET(MKL_PORTB,19);
  13. dispBase();
 楼主| ccw1986 发表于 2015-12-25 17:51 | 显示全部楼层
  1. while(1){
  2.   GPIO_SET(MKL_PORTB,18);
  3.   GPIO_CLR(MKL_PORTB,19);
  4.   //dispAsc2();
  5.   dispMes();
  6.   GPIO_CLR(MKL_PORTB,18);
  7.   GPIO_SET(MKL_PORTB,19);
  8.   t0++;
  9.   delay(200);
  10.   //lcdClear();
  11. }
  12. }
 楼主| ccw1986 发表于 2015-12-25 17:52 | 显示全部楼层
运行后的照片:
顺便说一下,有时与老外们交流,他们看不懂中文。有不明白的地方直接问,我会细细解答的。可能无法即时,因为有活吧。


大128x64LCD显示结果,为以后ADC准备




                    
您需要登录后才可以回帖 登录 | 注册

本版积分规则

84

主题

925

帖子

6

粉丝
快速回复 在线客服 返回列表 返回顶部