This Automatic mode is the most simple lib for MCU Gear with LPC1114FN28. You don't need to think about Bank.

Dependents:   MCUGearALPC1114FN28

Fork of MCUGearA by mille feuille

You are viewing an older revision! See the latest version

MCUGearALPC1114

This is a MCU Gear Automatic mode library.

(日本語は英語の次に書いてあります。)

MCU Gear is a digital wiring extension board.(A kind of dynamic circuit changer.)

It can change its wiring dynamically, without the need of rewiring your device.

Your MCU can be connected to a theoretical maximum of 120 devices.

detail : http://mcugear.com/en/

You can save 8 schematics (bank 0-7) on Baseboard. But this Automatic mode is you don't think about Bank but little bit slow. Manual Mode is here -> http://mbed.org/users/Info/code/MCUGearM/

How to use it?

1,include library

1,include library

#include "mbed.h"
#include "TextLCD.h"

#include "MCUGearBaseALPC1114.h"
#include "MCUGearALPC1114.h"
#include "commonALPC1114.h"

2,Declare Module

2,Declare Module

MCUGear myModule1(dp5, dp27, N_***_***_***);
MCUGear myModule2(dp5, dp27, N_***_***_***);

myModule: Optional name for Module.

dp5, dp27 : set I2C bus.

N_*_*_* : Address. You can set it on the reverse side of the Module board.

3,Initialize IO

3,Initialize IO

//output pins = P0_3, P0_7, P0_11, P1_0, P1_1, P1_2, P1_4, P1_5
DigitalOut Dout1(dp26);
DigitalOut Dout2(dp28);
DigitalOut Dout3(dp4);
DigitalOut Dout4(dp9);
DigitalOut Dout5(dp10);
DigitalOut Dout6(dp11);
DigitalOut Dout7(dp14);
DigitalOut Dout8(dp15);

//inputpins = P1_8, P1_9
DigitalIn Din1(dp17);
DigitalIn Din2(dp18);

You should not change these setting. It is very easy for use without looking at pin assignment.

4,Initialize baseboard

4,Initialize baseboard

initBase();

5,Make wiring data

5,Call wiring register

//call functions

    setIOUni(&myModule1);
    setIOLCD(&myModule2);


void setIOUni(MCUGear *mcugear){  //Universal module : pin assignment
    mcugear->setWireA(IOin1, IO_REG_IN_DIR, 0);  //input for switch1
    mcugear->setWireA(IOin2, IO_REG_IN_DIR, 1);  //input for switch2
    mcugear->setWireA(IOout1, IO_REG_OUT_DIR,2);  //output for LED1
    mcugear->setWireA(IOout2, IO_REG_OUT_DIR,3);  //output for LED2
    mcugear->setWireA(IOout3, IO_REG_OUT_DIR,4);  //output for LED3
}

void setIOLCD(MCUGear *mcugear){  //LCD module : pin assignment
    mcugear->setWireA(IOout1, IO_REG_OUT_DIR,0);  //rs
    mcugear->setWireA(IOout2, IO_REG_OUT_DIR,1);  //e
    mcugear->setWireA(IOout3, IO_REG_OUT_DIR,2);  //d1
    mcugear->setWireA(IOout4, IO_REG_OUT_DIR,3);  //d2
    mcugear->setWireA(IOout5, IO_REG_OUT_DIR,4);  //d3
    mcugear->setWireA(IOout6, IO_REG_OUT_DIR,5);  //d4
}

see the reference on MCUGearBaseALPC1114.h file.

6,Call wiring register

// CPU I/O
typedef enum {

    IOMOSI = 0x80,//P0_9
    IOSCK,//P0_6
    IOMISO,//P0_8
    IOout4,//P1_0
    NC1,//NC1
    IOout5,//P1_1
    IOout2,//P0_7
    IORX,//P1_6
    NC2,//NC2
    IOin2,//P1_9
    IOTX,//P1_7
    IOin1,//P1_8
    IOout7,//P1_5
    IOout8,//P1_4
    IOout6,//P1_2
    IOout3,//P0_11
    IOout1,//P0_3
    IOCS,//P0_2
    IOSDA,//P0_5
    IOSCL//0_4
            
/* //you can change if you want to use following expression.
    IOP0_6,//P0_6
    IOP0_8,//P0_8
    IOP1_0,//P1_0
    NC1,//NC1
    IOP1_1,//P1_1
    IOP0_7,//P0_7
    IOP1_6,//P1_6
    NC2,//NC2
    IOP1_9,//P1_9
    IOP1_7,//P1_7
    IOP1_8,//P1_8
    IOP1_5,//P1_5
    IOP1_4,//P1_4
    IOP1_2,//P1_2
    IOP0_11,//P0_11
    IOP0_3,//P0_3
    IOP0_2,//P0_2
    IOP0_5,//P0_5
    IO0_4//0_4
*/
} en_cpu_io;

setWire function

uint8_t setWire(uint8_t mcuIO, uint8_t direction, uint8_t moduleIO);

Set MCU's IO, Directionfrom MCU and module's IO number.

setWire() is wiring data to connect pin of MCU to pin of Module.

uint8_t mcuIO : You can choose 18 IOs.

uint8_t direction: choose signal direction IO_REG_OUT_DIR : output from MCU IO_REG_IN_DIR : input to MCU

uint8_t moduleIO: You can select module pin.

7,Open or close the module gate

7,Open or close the module gate

   myModule1.connectModule();
   ...
   (same as normal mbed code)
   ...
   myModule1.disconnectModule();


   myModule2.connectModule();
   ...
   (same as normal mbed code)
   ...
   myModule2.disconnectModule();

If you want to use many modules simultaneously as one circuit, you should use manual mode.

Sample code 1

Universal Module and LCD module test program.

I set test function board like the below picture.(Universal module)

/media/uploads/Info/test2.png

Sample code 1

#include "mbed.h"
#include "TextLCD.h"

#include "MCUGearBaseALPC1114.h"
#include "MCUGearALPC1114.h"
#include "commonALPC1114.h"

Serial pc(dp16, dp15); // tx, rx Set BaudRate = 115200 in main()

void setIOUni(MCUGear *mcugear);
void setIOLCD(MCUGear *mcugear);

MCUGear UniM(dp5, dp27, N_VDD_VDD_VDD);       //2 Connector Universal Module
MCUGear LCDM(dp5, dp27, N_VDD_VSS_VSS);        //LCD Module

//output pins = P0_3, P0_7, P0_11, P1_0, P1_1, P1_2, P1_4, P1_5
DigitalOut Dout1(dp26);
DigitalOut Dout2(dp28);
DigitalOut Dout3(dp4);
DigitalOut Dout4(dp9);
DigitalOut Dout5(dp10);
DigitalOut Dout6(dp11);
DigitalOut Dout7(dp14);
DigitalOut Dout8(dp15);

//inputpins = P1_8, P1_9
DigitalIn Din1(dp17);
DigitalIn Din2(dp18);

int main() {
    
    int sw1 = 0;
    int sw2 = 0;
    pc.printf("Hello World!\r\n");
        
    wait(1);
    
    initBase(); //initialize Baseboard
    
    //set schematic select 0-7
    UniM.detectModule();    //save location data in MCUGear class.
    LCDM.detectModule();    //save location data in MCUGear class.
    
    //startReg(0);  //AutoMode can not use Bank
    setIOUni(&UniM);//make schematic Bank0
    setIOLCD(&LCDM);//make schematic Bank0
    //endReg(0);    //AutoMode can not use Bank
    
    //changeBank(0);//select Bank
    
    
    LCDM.connectModuleA();
    TextLCD lcd(dp26, dp28, dp4, dp9, dp10, dp11, TextLCD::LCD16x2); // rs, e, d4-d7//set output pins from Dout1 to Dout6.
    lcd.cls();
    lcd.printf("Hello World!\n");
    wait(1);
    LCDM.disconnectModule();
    
    while(1) { //after initialize IOs you do not think about pin assignment. 
        
        UniM.connectModuleA();
        sw1 = Din1.read();
        sw2 = Din2.read();
        printf("sw1 = %d  sw2 = %d\r\n",sw1,sw2);
        UniM.disconnectModule();
        
        LCDM.connectModuleA();
        lcd.printf(" ");    //set IO as a neutral position
        lcd.cls();   //clear LCD
        lcd.printf("sw1 = %d\nsw2 = %d",sw1,sw2);   //write LCD data
        wait_ms(10);    //delay for view the LCD
        LCDM.disconnectModule();
        
        UniM.connectModuleA();
        Dout1 = 0;
        Dout2 = 1;
        Dout3 = 1;
        wait(0.3);
        
        Dout1 = 1;
        Dout2 = 0;
        Dout3 = 1;
        wait(0.3);
        
        Dout1 = 1;
        Dout2 = 1;
        Dout3 = 0;
        wait(0.3);
        UniM.disconnectModule();

    }
}


void setIOUni(MCUGear *mcugear){
    mcugear->setWireA(IOin1, IO_REG_IN_DIR, 0);
    mcugear->setWireA(IOin2, IO_REG_IN_DIR, 1);
    mcugear->setWireA(IOout1, IO_REG_OUT_DIR,2);
    mcugear->setWireA(IOout2, IO_REG_OUT_DIR,3);
    mcugear->setWireA(IOout3, IO_REG_OUT_DIR,4);
}

void setIOLCD(MCUGear *mcugear){
    mcugear->setWireA(IOout1, IO_REG_OUT_DIR,0);
    mcugear->setWireA(IOout2, IO_REG_OUT_DIR,1);
    mcugear->setWireA(IOout3, IO_REG_OUT_DIR,2);
    mcugear->setWireA(IOout4, IO_REG_OUT_DIR,3);
    mcugear->setWireA(IOout5, IO_REG_OUT_DIR,4);
    mcugear->setWireA(IOout6, IO_REG_OUT_DIR,5);
}


日本語説明

MCU GearのLPC1114自動簡易モードライブラリです。

detail : http://mcugear.com/

自動モードは8つのBank設定は考えずに実行できます。同時に複数のモジュールをつなげたい場合はマニュアルモードをご利用ください -> http://mbed.org/users/Info/code/MCUGearM/

使い方

1,ライブラリーをインクルード

1,include library


#include "mbed.h"
#include "TextLCD.h"

#include "MCUGearBaseALPC1114.h"
#include "MCUGearALPC1114.h"
#include "commonALPC1114.h"


2,モジュールを定義します

2,Declare Module

MCUGear myModule1(dp5, dp27, N_***_***_***);
MCUGear myModule2(dp5, dp27, N_***_***_***);

myModule: モジュールの好きな名前を付けられます。

dp5, dp27 : I2C pins

N_*_*_* : Address. モジュールの裏面に設定したアドレスを入れます。

3, IOの初期設定

3,Initialize IO

//output pins = P0_3, P0_7, P0_11, P1_0, P1_1, P1_2, P1_4, P1_5
DigitalOut Dout1(dp26);
DigitalOut Dout2(dp28);
DigitalOut Dout3(dp4);
DigitalOut Dout4(dp9);
DigitalOut Dout5(dp10);
DigitalOut Dout6(dp11);
DigitalOut Dout7(dp14);
DigitalOut Dout8(dp15);

//inputpins = P1_8, P1_9
DigitalIn Din1(dp17);
DigitalIn Din2(dp18);

自動配線のセッティングと対応させて簡単化しているため、これらのセッティングは変更しないことをお勧めします。

4,ベースボード初期化

4,Initialize baseboard

initBase();

5,配線データの登録

5,Call wiring register

//call functions

    setIOUni(&myModule1);
    setIOLCD(&myModule2);


void setIOUni(MCUGear *mcugear){  //Universal module : pin assignment
    mcugear->setWireA(IOin1, IO_REG_IN_DIR, 0);  //input for switch1
    mcugear->setWireA(IOin2, IO_REG_IN_DIR, 1);  //input for switch2
    mcugear->setWireA(IOout1, IO_REG_OUT_DIR,2);  //output for LED1
    mcugear->setWireA(IOout2, IO_REG_OUT_DIR,3);  //output for LED2
    mcugear->setWireA(IOout3, IO_REG_OUT_DIR,4);  //output for LED3
}

void setIOLCD(MCUGear *mcugear){  //LCD module : pin assignment
    mcugear->setWireA(IOout1, IO_REG_OUT_DIR,0);  //rs
    mcugear->setWireA(IOout2, IO_REG_OUT_DIR,1);  //e
    mcugear->setWireA(IOout3, IO_REG_OUT_DIR,2);  //d1
    mcugear->setWireA(IOout4, IO_REG_OUT_DIR,3);  //d2
    mcugear->setWireA(IOout5, IO_REG_OUT_DIR,4);  //d3
    mcugear->setWireA(IOout6, IO_REG_OUT_DIR,5);  //d4
}

MCUGearBaseboardA.h ファイルも参考にしてください。

6,Call wiring register

// CPU I/O
typedef enum {

    IOMOSI = 0x80,//P0_9
    IOSCK,//P0_6
    IOMISO,//P0_8
    IOout4,//P1_0
    NC1,//NC1
    IOout5,//P1_1
    IOout2,//P0_7
    IORX,//P1_6
    NC2,//NC2
    IOin2,//P1_9
    IOTX,//P1_7
    IOin1,//P1_8
    IOout7,//P1_5
    IOout8,//P1_4
    IOout6,//P1_2
    IOout3,//P0_11
    IOout1,//P0_3
    IOCS,//P0_2
    IOSDA,//P0_5
    IOSCL//0_4
            
/* //you can change if you want to use following expression.
    IOP0_6,//P0_6
    IOP0_8,//P0_8
    IOP1_0,//P1_0
    NC1,//NC1
    IOP1_1,//P1_1
    IOP0_7,//P0_7
    IOP1_6,//P1_6
    NC2,//NC2
    IOP1_9,//P1_9
    IOP1_7,//P1_7
    IOP1_8,//P1_8
    IOP1_5,//P1_5
    IOP1_4,//P1_4
    IOP1_2,//P1_2
    IOP0_11,//P0_11
    IOP0_3,//P0_3
    IOP0_2,//P0_2
    IOP0_5,//P0_5
    IO0_4//0_4
*/
} en_cpu_io;

setWire function

uint8_t setWire(uint8_t mcuIO, uint8_t direction, uint8_t moduleIO);

引数はマイコンのIO、マイコンからの入出力方向とモジュールの端子番号 setWire()関数はmbedの端子とモジュールの端子の割り振り方を決める関数です。

uint8_t mcuIO : mbedの18端子がアダプターボード(MCUボード)を介してベースボードに接続されています。(残りの端子はアダプターボード(MCUボード)から端子が出ています。)

uint8_t direction: mbedから見て入力か出力かを設定します。 IO_REG_OUT_DIR : output from MCU IO_REG_IN_DIR : input to MCU

uint8_t moduleIO: モジュールの出口の端子をどれにするかを決めます。

7,モジュールのゲート開閉

7,Open or close the module gate

   myModule1.connectModule();
   ...
   (same as normal mbed code)
   ...
   myModule1.disconnectModule();


   myModule2.connectModule();
   ...
   (same as normal mbed code)
   ...
   myModule2.disconnectModule();

If you want to use many modules simultaneously as one circuit, you should use manual mode. 同時に複数のモジュールに接続して動かすには

Sample code 1

ユニバーサルモジュールとLCDモジュールを接続した例です。

ユニバーサルモジュールは以下の図のように接続します。

/media/uploads/Info/test2.png

Sample code 1

#include "mbed.h"
#include "TextLCD.h"

#include "MCUGearBaseALPC1114.h"
#include "MCUGearALPC1114.h"
#include "commonALPC1114.h"

Serial pc(dp16, dp15); // tx, rx Set BaudRate = 115200 in main()

void setIOUni(MCUGear *mcugear);
void setIOLCD(MCUGear *mcugear);

MCUGear UniM(dp5, dp27, N_VDD_VDD_VDD);       //2 Connector Universal Module
MCUGear LCDM(dp5, dp27, N_VDD_VSS_VSS);        //LCD Module

//output pins = P0_3, P0_7, P0_11, P1_0, P1_1, P1_2, P1_4, P1_5
DigitalOut Dout1(dp26);
DigitalOut Dout2(dp28);
DigitalOut Dout3(dp4);
DigitalOut Dout4(dp9);
DigitalOut Dout5(dp10);
DigitalOut Dout6(dp11);
DigitalOut Dout7(dp14);
DigitalOut Dout8(dp15);

//inputpins = P1_8, P1_9
DigitalIn Din1(dp17);
DigitalIn Din2(dp18);

int main() {
    
    int sw1 = 0;
    int sw2 = 0;
    pc.printf("Hello World!\r\n");
        
    wait(1);
    
    initBase(); //initialize Baseboard
    
    //set schematic select 0-7
    UniM.detectModule();    //save location data in MCUGear class.
    LCDM.detectModule();    //save location data in MCUGear class.
    
    //startReg(0);  //AutoMode can not use Bank
    setIOUni(&UniM);//make schematic Bank0
    setIOLCD(&LCDM);//make schematic Bank0
    //endReg(0);    //AutoMode can not use Bank
    
    //changeBank(0);//select Bank
    
    
    LCDM.connectModuleA();
    TextLCD lcd(dp26, dp28, dp4, dp9, dp10, dp11, TextLCD::LCD16x2); // rs, e, d4-d7//set output pins from Dout1 to Dout6.
    lcd.cls();
    lcd.printf("Hello World!\n");
    wait(1);
    LCDM.disconnectModule();
    
    while(1) {
        
        UniM.connectModuleA();
        sw1 = Din1.read();
        sw2 = Din2.read();
        printf("sw1 = %d  sw2 = %d\r\n",sw1,sw2);
        UniM.disconnectModule();
        
        LCDM.connectModuleA();
        lcd.printf(" ");    //set IO as a neutral position
        lcd.cls();   //clear LCD
        lcd.printf("sw1 = %d\nsw2 = %d",sw1,sw2);   //write LCD data
        wait_ms(10);    //delay for view the LCD
        LCDM.disconnectModule();
        
        UniM.connectModuleA();
        Dout1 = 0;
        Dout2 = 1;
        Dout3 = 1;
        wait(0.3);
        
        Dout1 = 1;
        Dout2 = 0;
        Dout3 = 1;
        wait(0.3);
        
        Dout1 = 1;
        Dout2 = 1;
        Dout3 = 0;
        wait(0.3);
        UniM.disconnectModule();

    }
}


void setIOUni(MCUGear *mcugear){
    mcugear->setWireA(IOin1, IO_REG_IN_DIR, 0);
    mcugear->setWireA(IOin2, IO_REG_IN_DIR, 1);
    mcugear->setWireA(IOout1, IO_REG_OUT_DIR,2);
    mcugear->setWireA(IOout2, IO_REG_OUT_DIR,3);
    mcugear->setWireA(IOout3, IO_REG_OUT_DIR,4);
}

void setIOLCD(MCUGear *mcugear){
    mcugear->setWireA(IOout1, IO_REG_OUT_DIR,0);
    mcugear->setWireA(IOout2, IO_REG_OUT_DIR,1);
    mcugear->setWireA(IOout3, IO_REG_OUT_DIR,2);
    mcugear->setWireA(IOout4, IO_REG_OUT_DIR,3);
    mcugear->setWireA(IOout5, IO_REG_OUT_DIR,4);
    mcugear->setWireA(IOout6, IO_REG_OUT_DIR,5);
}



All wikipages