[Kinetis] YL-KL26Z adc实验

[复制链接]
1024|2
 楼主| 芙蓉洞 发表于 2016-1-16 08:46 | 显示全部楼层 |阅读模式
最近有个项目需操作,我将显示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"
  3. const unsigned char asc2[][8]={//8x6 Dots 32 to 127 + caratteri alfa_omega a seguire
  4. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},// space
  5. {0x00,0x1c,0x22,0x24,0x18,0x16,0x00,0x00},//!-1=32
  6. {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},//"
  7. {0x00,0x02,0x04,0x78,0x10,0x0c,0x02,0x00},//#
  8. {0x00,0x7e,0x15,0x15,0x15,0x0a,0x00,0x00},//$
  9. {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},//%
  10. {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},//&
  11. {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},//'
  12. {0x00,0x00,0x1C,0x22,0x41,0x00,0x00,0x00},//(
  13. {0x00,0x00,0x41,0x22,0x1C,0x00,0x00,0x00},//)
  14. {0x00,0x14,0x08,0x3E,0x08,0x14,0x00,0x00},//**/-10=42
  15. {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},//+
  16. {0x00,0x00,0x50,0x30,0x00,0x00,0x00,0x00},//;
  17. {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},//-
  18. {0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00},//.
  19. {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},///
  20. {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},//0
  21. {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},//1
  22. {0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00},//2
  23. {0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00},//3
  24. {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},//4-20
  25. {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},//5
  26. {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},//6
  27. {0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00},//7
  28. {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},//8
  29. {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},//9
  30. {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},//:
  31. {0x00,0x00,0x56,0x36,0x00,0x00,0x00,0x00},//;
  32. {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},//<
  33. {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},//=
  34. {0x00,0x00,0x41,0x22,0x14,0x08,0x00,0x00},//>-30
  35. {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},//?
  36. {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},//@
  37. {0x00,0x7E,0x11,0x11,0x11,0x7E,0x00,0x00},//A
  38. {0x00,0x41,0x7F,0x49,0x49,0x36,0x00,0x00},//B
  39. {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},//C
  40. {0x00,0x41,0x7F,0x41,0x41,0x3E,0x00,0x00},//D
  41. {0x00,0x7F,0x49,0x49,0x49,0x49,0x00,0x00},//E
  42. {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},//F
  43. {0x00,0x3E,0x41,0x41,0x49,0x7A,0x00,0x00},//G
  44. {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},//H
  45. {0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00},//I-40
  46. {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},//J
  47. {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},//K
  48. {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},//L
  49. {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},//M
  50. {0x00,0x7F,0x06,0x08,0x30,0x7F,0x00,0x00},//N
  51. {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},//O
  52. {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},//P
  53. {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},//Q
  54. {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},//R
  55. {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},//S
  56. {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},//T-50
  57. {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},//U
  58. {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},//V
  59. {0x00,0x7F,0x20,0x18,0x20,0x7F,0x00,0x00},//W
  60. {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},//X
  61. {0x00,0x07,0x08,0x70,0x08,0x07,0x00,0x00},//Y
  62. {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},//Z
  63. {0x00,0x00,0x7F,0x41,0x41,0x00,0x00,0x00},//[
  64. {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},//\//
  65. {0x00,0x00,0x41,0x41,0x7F,0x00,0x00,0x00},//]
  66. {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},//^-60
  67. {0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00},//_
  68. {0x00,0x00,0x00,0x07,0x05,0x07,0x00,0x00},//' Insty
  69. {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},//a
  70. {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},//b
  71. {0x00,0x38,0x44,0x44,0x44,0x28,0x00,0x00},//c
  72. {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},//d
  73. {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},//e
  74. {0x00,0x00,0x08,0x7E,0x09,0x02,0x00,0x00},//f
  75. {0x00,0x0C,0x52,0x52,0x4C,0x3E,0x00,0x00},//g
  76. {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},//h-70
  77. {0x00,0x00,0x44,0x7D,0x40,0x00,0x00,0x00},//i
  78. {0x00,0x20,0x40,0x44,0x3D,0x00,0x00,0x00},//j
  79. {0x00,0x00,0x7F,0x10,0x28,0x44,0x00,0x00},//k
  80. {0x00,0x00,0x41,0x7F,0x40,0x00,0x00,0x00},//l
  81. {0x00,0x7C,0x04,0x78,0x04,0x78,0x00,0x00},//m
  82. {0x00,0x7C,0x08,0x04,0x04,0x78,0x00,0x00},//n
  83. {0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00},//o
  84. {0x00,0x7E,0x0C,0x12,0x12,0x0C,0x00,0x00},//p
  85. {0x00,0x0C,0x12,0x12,0x0C,0x7E,0x00,0x00},//q
  86. {0x00,0x7C,0x08,0x04,0x04,0x08,0x00,0x00},//r-80
  87. {0x00,0x58,0x54,0x54,0x54,0x64,0x00,0x00},//s
  88. {0x00,0x04,0x3F,0x44,0x40,0x20,0x00,0x00},//t
  89. {0x00,0x3C,0x40,0x40,0x3C,0x40,0x00,0x00},//u
  90. {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},//v
  91. {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},//w
  92. {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},//x
  93. {0x00,0x1C,0xA0,0xA0,0x90,0x7C,0x00,0x00},//y
  94. {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},//z
  95. {0x00,0x00,0x08,0x36,0x41,0x00,0x00,0x00},//{
  96. {0x00,0x00,0x00,0x77,0x00,0x00,0x00,0x00},//|-90
  97. {0x00,0x00,0x41,0x36,0x08,0x00,0x00,0x00},//}
  98. {0x00,0x08,0x04,0x08,0x10,0x08,0x00,0x00},//~
  99. {0x00,0x5c,0x62,0x02,0x62,0x5c,0x00,0x00},//OM
  100. {0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14},//horiz lines-94
  101. };


 楼主| 芙蓉洞 发表于 2016-1-16 08:47 | 显示全部楼层
  1. INT16U t0=0;
  2. //Delayer moster 65536X65535 system clock
  3. void delay(INT16U count){
  4. INT16U i,j;              
  5. for(i=0;i<count;i++){for(j=0;j<i;j++);}            
  6. }
  7. //Write Plus
  8. void wri(){
  9. GPIO_CLR(MKL_PORTD,0);
  10. GPIO_SET(MKL_PORTD,0);
  11. }
  12. //Write 1 byte to LCD,dt:data/comata-1,Command-0
  13. void b2l(unsigned char dt,unsigned char com){
  14. unsigned char i;
  15. if(com==1){GPIO_SET(MKL_PORTD,2);}else{GPIO_CLR(MKL_PORTD,2);}
  16. for(i=0;i<8;i++){
  17.   if(dt&0x80){GPIO_SET(MKL_PORTD,1);}else{GPIO_CLR(MKL_PORTD,1);}
  18.   dt=dt<<1;
  19.   wri();
  20. }
  21. }
  22. //Set LCD col:0-102 pag:0-8
  23. void setXY(unsigned char pag,unsigned char col){
  24. b2l(0xB0+pag,0);//page
  25. //col+=0x04;//+4-->4bit
  26. b2l(0x10+((col&0xF0)>>4),0);//row-H4
  27. b2l(col&0x0F,0);//row-L4
  28. }
  29. //LCD Clear
  30. void lcdClear(void){
  31. unsigned char pag,col;
  32. for(pag=0;pag<8;pag++){
  33.   setXY(pag,0);
  34.   for(col=0;col<132;col++){b2l(0x00,1);};}
  35. }
  36. //c:Char,cha[]
  37. void c2l(unsigned char pag,unsigned char col,unsigned char c){
  38. unsigned char line;
  39. setXY(pag,col*8);  
  40. for (line=0;line<8;line++)
  41.   b2l(asc2[c][line],1);
  42. }
  43. //Like 0108LCD Initial
  44. void lcdInit(void){
  45. delay(2000);
  46. GPIO_CLR(MKL_PORTD,3);//Reset LCD
  47. delay(2000);
  48. GPIO_SET(MKL_PORTD,3);
  49. delay(2000);
  50. b2l(0xAE,0);//AE= Off/AF=On
  51. b2l(0xE2,0);//LCD Initial
  52. delay(500);
  53. b2l(0xA0,0);//A0=1~132/A1=132~1
  54. b2l(0xC8,0);//C0=1~64/C8=64~1||A0+C8 col+4
  55. b2l(0xA2,0);//A2=1Big/65=1/7_A3=1Small/65=1/9
  56. delay(500);
  57. b2l(0x2F,0);//Base Vol 28+VC+VR+VF
  58. delay(1000);
  59. b2l(0x22,0);//20~27=1.9,2.19,2.55,3.02,3.61,4.35,5.29,6.48V/
  60. delay(1000);
  61. b2l(0x81,0);//V0-Next Num//Big20/small2C
  62. b2l(0x20,0);//000000~111111=0~63=8.83~11.17V/30=10V
  63. delay(1000);
  64. b2l(0xA4,0);//A4-Off/A5-On[??]
  65. b2l(0x10,0);//Column40x10+0000~1111
  66. b2l(0x00,0);//Column40x10+0000~1111
  67. b2l(0xAF,0);//LCD On
  68. b2l(0xAD,0);//AC=Cursor on/AD= off
  69. b2l(0x02,0);//??00=OFF/01=1S/02=0.5S/03=AllOn
  70. delay(2000);
  71. }
  72. //Display ASCiI Test
  73. void dispAsc2(void){
  74. int i,j;
  75. for(i=0;i<6;i++){
  76.   for(j=0;j<16;j++){c2l(i,j,i*16+j);}
  77. }
  78. }
 楼主| 芙蓉洞 发表于 2016-1-16 08: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. }
  15. //I/O Instial
  16. void ioInit(void){
  17. //IO功能选择
  18. IO_FUN_SEL(MKL_PORTB,18,1);//Test Led1
  19. IO_FUN_SEL(MKL_PORTB,19,1);//Test Led2
  20. IO_FUN_SEL(MKL_PORTD,0,1);//LCD Clock
  21. IO_FUN_SEL(MKL_PORTD,1,1);//LCD Data
  22. IO_FUN_SEL(MKL_PORTD,2,1);//Cmd:1=Data & 0=Command
  23. IO_FUN_SEL(MKL_PORTD,3,1);//Reset LCD:- Enable
  24. //IO设置为输出模式
  25. GPIO_DDR_OUTPUT(MKL_PORTB,18);//Test Led1
  26. GPIO_DDR_OUTPUT(MKL_PORTB,19);//Test Led2
  27. GPIO_DDR_OUTPUT(MKL_PORTD,0);//LCD Clock
  28. GPIO_DDR_OUTPUT(MKL_PORTD,1);//LCD Data
  29. GPIO_DDR_OUTPUT(MKL_PORTD,2);//Cmd:1=Data & 0=Command
  30. GPIO_DDR_OUTPUT(MKL_PORTD,3);//Reset LCD:- Enable
  31. }
  32. //MAIN Program
  33. int main(void){
  34. SystemCoreClockUpdate();
  35. SIM_SCGC5 |=(SIM_SCGC5_PORTA_MASK|SIM_SCGC5_PORTB_MASK|SIM_SCGC5_PORTC_MASK|SIM_SCGC5_PORTD_MASK|SIM_SCGC5_PORTE_MASK);
  36. ioInit();
  37. lcdInit();
  38. lcdClear();
  39. GPIO_SET(MKL_PORTB,18);
  40. GPIO_CLR(MKL_PORTB,19);
  41. delay(1000);
  42. GPIO_CLR(MKL_PORTB,18);
  43. GPIO_SET(MKL_PORTB,19);
  44. dispBase();
  45. while(1){
  46.   GPIO_SET(MKL_PORTB,18);
  47.   GPIO_CLR(MKL_PORTB,19);
  48.   //dispAsc2();
  49.   dispMes();
  50.   GPIO_CLR(MKL_PORTB,18);
  51.   GPIO_SET(MKL_PORTB,19);
  52.   t0++;
  53.   delay(200);
  54.   //lcdClear();
  55. }
  56. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

42

主题

398

帖子

3

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