打印
[Kinetis]

YL-KL26Z adc实验

[复制链接]
753|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
芙蓉洞|  楼主 | 2016-1-16 08:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近有个项目需操作,我将显示ASCII码和屏幕上显示JSQ:、AD0:~AD7:以及其他固定信息和计数器计数显示的完整程序放上,有时间了,会将ADC程序与此程序结合实现ADC分次测试和取n次平均后的显示。看看此板的ADC的精度如何。当然LCD显示有了,其他的实验数据都可以直接显示出来以便后来的操作。
//2.4Inch TFT LCD Test I/O for SPI--Changge gpio & M051
#include "includes.h"
const unsigned char asc2[][8]={//8x6 Dots 32 to 127 + caratteri alfa_omega a seguire
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},// space
{0x00,0x1c,0x22,0x24,0x18,0x16,0x00,0x00},//!-1=32
{0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},//"
{0x00,0x02,0x04,0x78,0x10,0x0c,0x02,0x00},//#
{0x00,0x7e,0x15,0x15,0x15,0x0a,0x00,0x00},//$
{0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},//%
{0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},//&
{0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},//'
{0x00,0x00,0x1C,0x22,0x41,0x00,0x00,0x00},//(
{0x00,0x00,0x41,0x22,0x1C,0x00,0x00,0x00},//)
{0x00,0x14,0x08,0x3E,0x08,0x14,0x00,0x00},//**/-10=42
{0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},//+
{0x00,0x00,0x50,0x30,0x00,0x00,0x00,0x00},//;
{0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},//-
{0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00},//.
{0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},///
{0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},//0
{0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},//1
{0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00},//2
{0x00,0x21,0x41,0x45,0x4B,0x31,0x00,0x00},//3
{0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},//4-20
{0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},//5
{0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},//6
{0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00},//7
{0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},//8
{0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},//9
{0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},//:
{0x00,0x00,0x56,0x36,0x00,0x00,0x00,0x00},//;
{0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},//<
{0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},//=
{0x00,0x00,0x41,0x22,0x14,0x08,0x00,0x00},//>-30
{0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},//?
{0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},//@
{0x00,0x7E,0x11,0x11,0x11,0x7E,0x00,0x00},//A
{0x00,0x41,0x7F,0x49,0x49,0x36,0x00,0x00},//B
{0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},//C
{0x00,0x41,0x7F,0x41,0x41,0x3E,0x00,0x00},//D
{0x00,0x7F,0x49,0x49,0x49,0x49,0x00,0x00},//E
{0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},//F
{0x00,0x3E,0x41,0x41,0x49,0x7A,0x00,0x00},//G
{0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},//H
{0x00,0x00,0x41,0x7F,0x41,0x00,0x00,0x00},//I-40
{0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},//J
{0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},//K
{0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},//L
{0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},//M
{0x00,0x7F,0x06,0x08,0x30,0x7F,0x00,0x00},//N
{0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},//O
{0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},//P
{0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},//Q
{0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},//R
{0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},//S
{0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},//T-50
{0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},//U
{0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},//V
{0x00,0x7F,0x20,0x18,0x20,0x7F,0x00,0x00},//W
{0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},//X
{0x00,0x07,0x08,0x70,0x08,0x07,0x00,0x00},//Y
{0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},//Z
{0x00,0x00,0x7F,0x41,0x41,0x00,0x00,0x00},//[
{0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},//\//
{0x00,0x00,0x41,0x41,0x7F,0x00,0x00,0x00},//]
{0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},//^-60
{0x00,0x40,0x40,0x40,0x40,0x40,0x00,0x00},//_
{0x00,0x00,0x00,0x07,0x05,0x07,0x00,0x00},//' Insty
{0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},//a
{0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},//b
{0x00,0x38,0x44,0x44,0x44,0x28,0x00,0x00},//c
{0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},//d
{0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},//e
{0x00,0x00,0x08,0x7E,0x09,0x02,0x00,0x00},//f
{0x00,0x0C,0x52,0x52,0x4C,0x3E,0x00,0x00},//g
{0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},//h-70
{0x00,0x00,0x44,0x7D,0x40,0x00,0x00,0x00},//i
{0x00,0x20,0x40,0x44,0x3D,0x00,0x00,0x00},//j
{0x00,0x00,0x7F,0x10,0x28,0x44,0x00,0x00},//k
{0x00,0x00,0x41,0x7F,0x40,0x00,0x00,0x00},//l
{0x00,0x7C,0x04,0x78,0x04,0x78,0x00,0x00},//m
{0x00,0x7C,0x08,0x04,0x04,0x78,0x00,0x00},//n
{0x00,0x38,0x44,0x44,0x44,0x38,0x00,0x00},//o
{0x00,0x7E,0x0C,0x12,0x12,0x0C,0x00,0x00},//p
{0x00,0x0C,0x12,0x12,0x0C,0x7E,0x00,0x00},//q
{0x00,0x7C,0x08,0x04,0x04,0x08,0x00,0x00},//r-80
{0x00,0x58,0x54,0x54,0x54,0x64,0x00,0x00},//s
{0x00,0x04,0x3F,0x44,0x40,0x20,0x00,0x00},//t
{0x00,0x3C,0x40,0x40,0x3C,0x40,0x00,0x00},//u
{0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},//v
{0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},//w
{0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},//x
{0x00,0x1C,0xA0,0xA0,0x90,0x7C,0x00,0x00},//y
{0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},//z
{0x00,0x00,0x08,0x36,0x41,0x00,0x00,0x00},//{
{0x00,0x00,0x00,0x77,0x00,0x00,0x00,0x00},//|-90
{0x00,0x00,0x41,0x36,0x08,0x00,0x00,0x00},//}
{0x00,0x08,0x04,0x08,0x10,0x08,0x00,0x00},//~
{0x00,0x5c,0x62,0x02,0x62,0x5c,0x00,0x00},//OM
{0x14,0x14,0x14,0x14,0x14,0x14,0x14,0x14},//horiz lines-94
};


相关帖子

沙发
芙蓉洞|  楼主 | 2016-1-16 08:47 | 只看该作者
INT16U t0=0;
//Delayer moster 65536X65535 system 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);
}
//Write 1 byte to LCD,dt:data/comata-1,Command-0
void b2l(unsigned char dt,unsigned char com){
unsigned char i;
if(com==1){GPIO_SET(MKL_PORTD,2);}else{GPIO_CLR(MKL_PORTD,2);}
for(i=0;i<8;i++){
  if(dt&0x80){GPIO_SET(MKL_PORTD,1);}else{GPIO_CLR(MKL_PORTD,1);}
  dt=dt<<1;
  wri();
}
}
//Set LCD col:0-102 pag:0-8
void setXY(unsigned char pag,unsigned char col){
b2l(0xB0+pag,0);//page
//col+=0x04;//+4-->4bit
b2l(0x10+((col&0xF0)>>4),0);//row-H4
b2l(col&0x0F,0);//row-L4
}
//LCD Clear
void lcdClear(void){
unsigned char pag,col;
for(pag=0;pag<8;pag++){
  setXY(pag,0);
  for(col=0;col<132;col++){b2l(0x00,1);};}
}
//c:Char,cha[]
void c2l(unsigned char pag,unsigned char col,unsigned char c){
unsigned char line;
setXY(pag,col*8);  
for (line=0;line<8;line++)
  b2l(asc2[c][line],1);
}
//Like 0108LCD Initial
void lcdInit(void){
delay(2000);
GPIO_CLR(MKL_PORTD,3);//Reset LCD
delay(2000);
GPIO_SET(MKL_PORTD,3);
delay(2000);
b2l(0xAE,0);//AE= Off/AF=On
b2l(0xE2,0);//LCD Initial
delay(500);
b2l(0xA0,0);//A0=1~132/A1=132~1
b2l(0xC8,0);//C0=1~64/C8=64~1||A0+C8 col+4
b2l(0xA2,0);//A2=1Big/65=1/7_A3=1Small/65=1/9
delay(500);
b2l(0x2F,0);//Base Vol 28+VC+VR+VF
delay(1000);
b2l(0x22,0);//20~27=1.9,2.19,2.55,3.02,3.61,4.35,5.29,6.48V/
delay(1000);
b2l(0x81,0);//V0-Next Num//Big20/small2C
b2l(0x20,0);//000000~111111=0~63=8.83~11.17V/30=10V
delay(1000);
b2l(0xA4,0);//A4-Off/A5-On[??]
b2l(0x10,0);//Column40x10+0000~1111
b2l(0x00,0);//Column40x10+0000~1111
b2l(0xAF,0);//LCD On
b2l(0xAD,0);//AC=Cursor on/AD= off
b2l(0x02,0);//??00=OFF/01=1S/02=0.5S/03=AllOn
delay(2000);
}
//Display ASCiI Test
void dispAsc2(void){
int i,j;
for(i=0;i<6;i++){
  for(j=0;j<16;j++){c2l(i,j,i*16+j);}
}
}

使用特权

评论回复
板凳
芙蓉洞|  楼主 | 2016-1-16 08:48 | 只看该作者
//Display BaseData
void dispBase(void){
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
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
c2l(3,0,42);c2l(3,1,51);c2l(3,2,49);c2l(3,3,26);//JSQ
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:
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:
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:
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:
}
//Display Messege data
void dispMes(void){
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);
}
//I/O Instial
void ioInit(void){
//IO功能选择
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:- Enable
//IO设置为输出模式
GPIO_DDR_OUTPUT(MKL_PORTB,18);//Test Led1
GPIO_DDR_OUTPUT(MKL_PORTB,19);//Test Led2
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
}
//MAIN Program
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);
ioInit();
lcdInit();
lcdClear();
GPIO_SET(MKL_PORTB,18);
GPIO_CLR(MKL_PORTB,19);
delay(1000);
GPIO_CLR(MKL_PORTB,18);
GPIO_SET(MKL_PORTB,19);
dispBase();
while(1){
  GPIO_SET(MKL_PORTB,18);
  GPIO_CLR(MKL_PORTB,19);
  //dispAsc2();
  dispMes();
  GPIO_CLR(MKL_PORTB,18);
  GPIO_SET(MKL_PORTB,19);
  t0++;
  delay(200);
  //lcdClear();
}
}

使用特权

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

本版积分规则

42

主题

398

帖子

3

粉丝