在线时间613 小时
UID252169
注册时间2010-12-5
NXP金币0
TA的每日心情 | 开心 2019-2-14 16:49 |
---|
签到天数: 296 天 [LV.8]以坛为家I
金牌会员
- 积分
- 4473
- 最后登录
- 2020-4-14
|
经过前期的折腾,LPC ContexM0有点明白了,借助简单的mbed工程设置了1路计数器,1路脉冲输出,2路ADC,2路PWM,5路中断输入——其中的1路作为超声波测距使用,见照片31。mbed写代码非常简单、具体如下:
- 6903.h:
- //7X5PCB
- DigitalOut dat(P2_23);
- DigitalOut clk(P2_22);
- DigitalOut reg(P2_21);
- DigitalOut res(P2_20);
- //6903 102X64LCD
- const unsigned char asc2[][6]={//8x6 Dots 0-40
- {0x00,0x3E,0x45,0x49,0x51,0x3E},//0
- {0x00,0x00,0x21,0x7F,0x01,0x00},//1
- {0x00,0x31,0x43,0x45,0x49,0x31},//2
- {0x00,0x22,0x49,0x49,0x49,0x36},//3
- {0x00,0x04,0x0C,0x14,0x7F,0x04},//4
- {0x00,0x72,0x51,0x51,0x51,0x4E},//5-5
- {0x00,0x3E,0x49,0x49,0x49,0x06},//6
- {0x00,0x40,0x43,0x4C,0x50,0x60},//7
- {0x00,0x36,0x49,0x49,0x49,0x36},//8
- {0x00,0x30,0x48,0x48,0x48,0x3F},//9
- {0x00,0x1F,0x24,0x64,0x24,0x1F},//A-10
- {0x00,0x41,0x7F,0x49,0x49,0x36},//B
- {0x00,0x3E,0x41,0x41,0x41,0x22},//C
- {0x00,0x41,0x7F,0x41,0x41,0x3E},//D
- {0x00,0x41,0x7F,0x49,0x49,0x63},//E
- {0x00,0x41,0x7F,0x49,0x5C,0x60},//F-15
- {0x00,0x3E,0x41,0x45,0x47,0x24},//G
- {0x41,0x7F,0x08,0x08,0x08,0x7F},//H
- {0x00,0x00,0x41,0x7F,0x41,0x00},//I
- {0x00,0x42,0x41,0x7F,0x40,0x40},//J
- {0x00,0x41,0x7F,0x59,0x24,0x43},//K-20
- {0x00,0x40,0x7F,0x41,0x01,0x03},//L
- {0x00,0x7F,0x20,0x1E,0x20,0x7F},//M
- {0x00,0x7F,0x30,0x18,0x06,0x7F},//N
- {0x00,0x3E,0x41,0x41,0x41,0x3E},//O
- {0x00,0x41,0x7F,0x49,0x48,0x30},//P-25
- {0x00,0x3E,0x41,0x47,0x42,0x3D},//Q
- {0x00,0x41,0x7F,0x49,0x4C,0x33},//R
- {0x00,0x32,0x49,0x49,0x49,0x26},//S
- {0x00,0x60,0x41,0x7F,0x41,0x60},//T
- {0x00,0x7E,0x01,0x01,0x01,0x7E},//U-30
- {0x00,0x7C,0x02,0x01,0x02,0x7C},//V
- {0x00,0x7C,0x03,0x3C,0x03,0x7C},//W
- {0x00,0x43,0x24,0x18,0x24,0x43},//X
- {0x00,0x60,0x18,0x07,0x18,0x60},//Y
- {0x00,0x63,0x45,0x49,0x51,0x63},//Z-35
- {0x00,0x00,0x00,0x01,0x00,0x00},//.
- {0x00,0x14,0x14,0x14,0x14,0x14},//=
- {0x00,0x08,0x08,0x3E,0x08,0x08},//+
- {0x00,0x08,0x08,0x08,0x08,0x08},//-
- {0x00,0x00,0x00,0x24,0x00,0x00},//:-40
- };
- //Write Plus
- void wri(void){clk=0;clk=1;}
- //a byte data to lcd||dt=data reg=command
- void b2l(unsigned char dt,unsigned char command){
- unsigned char i;
- reg=command;
- for(i=0;i<8;i++){
- if(dt&0x80) dat=1;else dat=0;
- dt=dt<<1;
- wri();
- }
- }
- //Set display X,Y
- void setXY(unsigned char X,unsigned char Y){
- b2l(0x40+Y,0);//column
- b2l(0x80+X,0);//row
- }
- //LCD Clear
- void lcdClear(void){
- unsigned char t,k;
- setXY(0,0);
- for(t=0;t<9;t++){for(k=0;k<102;k++){b2l(0x00,1);}}
- }
- //Display ASCII
- void c2l(unsigned char x,unsigned char y,unsigned char c){
- unsigned char line;
- setXY(x*6,y);
- for(line=0;line<6;line++)b2l(asc2[c][line],1);
- }
- //Initial 6903 LCD model
- void lcdInit(void){
- res=0;
- wait_ms(200);
- res=1;
- wait_ms(200);
- b2l(0x25,0);//00100 PD=1dcOn|=0Dcoff V=0Up|=1Left H==1
- wait_ms(5);
- b2l(0x15,0);//plus=L000~111=1/6-1/7-1/8-1/9//14=1/7
- wait_ms(5);
- b2l(0x9C,0);//Set VOP
- wait_ms(5);
- b2l(0x20,0);//PD=0,V=2,H=0
- b2l(0x0C,0);//LCD Set Final
- wait_ms(50);
- }
- //Display ASCII Test
- void dispAsc(void){
- int i,j,k=0;
- for(i=0;i<8;i++){
- for(j=0;j<17;j++){
- c2l(j,i,k);
- if(k>39){k=0;}else{k++;}
- }
- }
- }
- //END Files//
- mainTest.cpp代码:
- #include "mbed.h"
- #include "6903.h"
- //Never use The P0_10,P0_15,P0_0
- //Configuration GPIO 5X7LCD=P2_15,16,17,18
- DigitalOut led1(LED1);//LED1=P1_2
- DigitalOut plus0(P1_24);//输出脉冲类
- AnalogIn adc0(P0_23);//ADC类
- AnalogIn adc1(P0_13);
- PwmOut pwm0(P2_2);//PWM类
- PwmOut pwm1(P2_16);
- Ticker tick;//Ticker类
- Timer timer;//时钟类
- DigitalIn inPut0(P0_11);//5个输入口类
- DigitalIn inPut1(P0_12);
- DigitalIn inPut2(P0_14);
- DigitalIn inPut3(P0_16);
- DigitalIn inPut4(P0_17);
- InterruptIn plusIn11(P0_11);//5个输入口为中断输入类
- InterruptIn plusIn12(P0_12);
- InterruptIn plusIn14(P0_14);
- InterruptIn plusIn16(P0_16);
- InterruptIn plusIn17(P0_17);
- //Serial outPrt(USBTX,USBRX);//P0_19,P0_18
- void dispBase(void);
- void dispMes(void);
- int16_t pj11=0,pj12=0,pj14=0,pj16=0,pj17=0,ps11,ps12,ps14,ps16,ps17,mms=0;
- int32_t js;
- float val0,val1,dut0=0.95,dut1=0.96,ddt0=0.01,ddt1=0.008,begin,end,dist=10.1f;
- void myTick(){plus0=!plus0;}//Tick产生500Hz脉冲
- void PlusIn11(void){wait(0.001f);if(P0_11)ps11++;}//中断输入计数
- void PlusIn12(void){wait(0.001f);if(P0_12)ps12++;}
- void PlusIn14(void){wait(0.001f);if(P0_14)ps14++;}
- void PlusIn16(void){wait(0.001f);if(P0_16)ps16++;}
- void PlusIn17(void){//脉冲计数
- timer.start();
- begin=timer.read_us();
- while(plusIn17){;};
- end=timer.read_us();
- dist=(end-begin)/57;
- }
- void gpioInit(void){//GPIO定义
- pwm0.period(0.002f);//pwm0 Period
- pwm1.period(0.001f);//pwm1 Period
- inPut0.mode(PullNone);//P0_11
- inPut1.mode(PullNone);//P0_12
- inPut2.mode(PullNone);//P0_14
- inPut3.mode(PullNone);//P0_16
- }
- //MAIN Program
- int main(){
- int jj=0;
- gpioInit();
- lcdInit();
- lcdClear();
- dispBase();//基本LCD显示
- tick.attach(&myTick,0.001f);//Tick为1mS
- plusIn11.rise(&PlusIn11);//上升沿中断输入
- plusIn12.rise(&PlusIn12);
- plusIn14.rise(&PlusIn14);
- plusIn16.rise(&PlusIn16);
- plusIn17.rise(&PlusIn17);
- while(1){
- val0=adc0.read();//ADC shuru
- val1=adc1.read();
- if(dut0>0.95f){dut0=0;}//PWM产生
- dut0 +=ddt0;pwm0=dut0;
- if(dut1>0.96f){dut1=0;}
- dut1 +=ddt1;pwm1=dut1;
- if(mms>49){pj11=ps11;pj12=ps12;pj14=ps14;pj16=ps16;mms=ps11=ps12=ps14=ps16=0;}else{mms++;}
- if(js>9999999) js=0;else js++;
- //outPrt.printf("AD0=%f AD1=%f PWM1=%.2f PWM2=%.2f ",val0,val1,dut0,dut1);
- if(jj<10){jj++;}else{
- jj=0;
- led1=!led1;
- dispMes();//检测结果显示
- }
- //wait_ms(10);
- }
- }
- //LCD 6903
- void dispBase(void){
- c2l(0,0,19);c2l(1,0,28);//JS
- c2l(0,1,10);c2l(1,1,0);c2l(8,1,10);c2l(9,1,1);//A0,A1
- c2l(0,3,25);c2l(1,3,32);c2l(2,3,1);//PW0
- c2l(8,3,25);c2l(9,3,32);c2l(10,3,2);//PW1
- c2l(0,4,25);c2l(1,4,19);//PJ
- }
- void dispMes(void){
- c2l(3,0,(js/1000000)%10);c2l(4,0,(js/100000)%10);c2l(5,0,(js/10000)%10);c2l(6,0,(js/1000)%10);
- c2l(7,0,(js/100)%10);c2l(8,0,(js/10)%10);c2l(9,0,(js)%10);//c2l(10,0,(js)%10);
- c2l(11,0,int(dist/100)%10);c2l(12,0,int(dist/10)%10);c2l(13,0,int(dist)%10);c2l(14,0,36);c2l(15,0,int(dist*10)%10);//c2l(17,2,int(dist*100)%10+16);
- c2l(3,1,int(val0*10)%10);c2l(4,1,int(val0*100)%10);c2l(5,1,int(val0*1000)%10);c2l(6,1,int(val0*10000)%10);
- c2l(11,1,int(val1*10)%10);c2l(12,1,int(val1*100)%10);c2l(13,1,int(val1*1000)%10);c2l(14,1,int(val1*10000)%10);
- c2l(4,3,int((dut0*10))%10);c2l(5,3,int((dut0*100))%10);c2l(6,3,int((dut0*1000))%10);
- c2l(12,3,int((dut1*10))%10);c2l(13,3,int((dut1*100))%10);c2l(14,3,int((dut1*1000))%10);
- c2l(3,4,(pj11)%10);c2l(5,4,(pj12)%10);c2l(7,4,(pj14)%10);c2l(9,4,(pj16/100)%10);c2l(10,4,(pj16/10)%10);c2l(11,4,(pj16)%10);
- }
复制代码
代码就是以上所有的。下载的基础mbed工程是LPC11U68 for Keil的,在其中修改PinName.h以适应自己的开发板上的硬件资源。主要的是提出实验过程的问题:
1. 看PC11U68手册,分别可以有SCTimer0驱动的4路PWM输出和STCimer1的4路PWM输出,在实际实验中,无论选择SCTimeer0或SCTimer1都可以,全部仅1路PWM输出无任何问题,但只要选择了2路PWM输出就会只剩1路有效。本例的PWM分别为SCTimer的P2_2和SCTimer1的P2_16,结果为P2_2没有任何问题,而P2_16在手触摸某区域引脚时才会输出一段时间,有时能维持较长时间有,有事闪几下就没有了,原因不详。
2. 代码中设置Serial串口任何一个都没有问题,但是只要输出命令,例如printf或outPrt.printff则芯片宕机,不动了!
|
-
31
|