connect NuEZCam board whicih the code is located on https://github.com/OpenNuvoton/NuMaker_NuEZCam_Samples, NUC472 + NuEZCam ,

NuEZCam for NuMaker-PFM-NUC472 board. Please refer document before executing it. More details, please refer to https://github.com/OpenNuvoton/NuMaker_NuEZCam_Samples

Committer:
shliu1
Date:
Thu Nov 24 08:39:30 2016 +0000
Revision:
1:6a2040c019e0
Parent:
0:5cd6f0a0a7ed
support NUC472, M453, STM32F401 and NXP K64F by target definitions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shliu1 0:5cd6f0a0a7ed 1 #include "mbed.h"
shliu1 0:5cd6f0a0a7ed 2
shliu1 0:5cd6f0a0a7ed 3 #define HIGH 1
shliu1 0:5cd6f0a0a7ed 4 #define LOW 0
shliu1 0:5cd6f0a0a7ed 5 // connect N3290X by UART
shliu1 0:5cd6f0a0a7ed 6 //Serial pc(USBTX, USBRX); // tx, rx
shliu1 0:5cd6f0a0a7ed 7
shliu1 1:6a2040c019e0 8
shliu1 1:6a2040c019e0 9
shliu1 1:6a2040c019e0 10 #if defined(TARGET_NUMAKER_PFM_NUC472)
shliu1 1:6a2040c019e0 11 // The following definitions of LED and serial are for NUC472
shliu1 1:6a2040c019e0 12 DigitalOut led1(LED1);
shliu1 1:6a2040c019e0 13 Serial device(D1, D0); // tx, rx
shliu1 1:6a2040c019e0 14 DigitalIn button(SW1); // SW1 is OK
shliu1 1:6a2040c019e0 15
shliu1 1:6a2040c019e0 16 #elif defined(TARGET_NUMAKER_PFM_M453)
shliu1 1:6a2040c019e0 17 // The following definitions of LED and serial are for NUC_M453
shliu1 0:5cd6f0a0a7ed 18 DigitalOut led1(LED1);
shliu1 0:5cd6f0a0a7ed 19 Serial device(D1, D0); // tx, rx
shliu1 1:6a2040c019e0 20 DigitalIn button(SW2); // SW2 is OK
shliu1 1:6a2040c019e0 21
shliu1 1:6a2040c019e0 22 #elif defined(TARGET_K64F)
shliu1 1:6a2040c019e0 23 // The following definitions of LED and serial are for K64F
shliu1 1:6a2040c019e0 24
shliu1 1:6a2040c019e0 25 DigitalOut led1(LED_GREEN);
shliu1 1:6a2040c019e0 26 Serial device(PTC17, PTC16); // tx, rx
shliu1 1:6a2040c019e0 27 DigitalIn button(SW2); // SW2 is OK
shliu1 1:6a2040c019e0 28
shliu1 1:6a2040c019e0 29 #elif defined(TARGET_NUCLEO_F401RE)
shliu1 1:6a2040c019e0 30
shliu1 1:6a2040c019e0 31 //The following definitions are for STM32F401
shliu1 1:6a2040c019e0 32 DigitalOut led1(LED3);
shliu1 1:6a2040c019e0 33 Serial device(D8,D2);
shliu1 1:6a2040c019e0 34 DigitalIn button(USER_BUTTON); // User button is OK
shliu1 1:6a2040c019e0 35
shliu1 1:6a2040c019e0 36 #endif
shliu1 0:5cd6f0a0a7ed 37
shliu1 0:5cd6f0a0a7ed 38 void setupCommand(int number)
shliu1 0:5cd6f0a0a7ed 39 {
shliu1 0:5cd6f0a0a7ed 40 int no, readByte,i;
shliu1 0:5cd6f0a0a7ed 41 no = '0'+ number;
shliu1 0:5cd6f0a0a7ed 42
shliu1 0:5cd6f0a0a7ed 43 device.putc(no);
shliu1 0:5cd6f0a0a7ed 44 Thread::wait(1000);
shliu1 0:5cd6f0a0a7ed 45 while (1)
shliu1 0:5cd6f0a0a7ed 46 {
shliu1 0:5cd6f0a0a7ed 47 no = device.readable();
shliu1 0:5cd6f0a0a7ed 48 if ( no > 0 )
shliu1 0:5cd6f0a0a7ed 49 {
shliu1 0:5cd6f0a0a7ed 50 readByte = device.getc();
shliu1 0:5cd6f0a0a7ed 51 if (readByte == 0x39 ) // '9'
shliu1 0:5cd6f0a0a7ed 52 {
shliu1 0:5cd6f0a0a7ed 53 for (i=0; i<3; i++)
shliu1 0:5cd6f0a0a7ed 54 {
shliu1 0:5cd6f0a0a7ed 55 led1 = !led1;
shliu1 0:5cd6f0a0a7ed 56 Thread::wait(200);
shliu1 0:5cd6f0a0a7ed 57 led1 = !led1;
shliu1 0:5cd6f0a0a7ed 58 Thread::wait(200);
shliu1 0:5cd6f0a0a7ed 59 }
shliu1 0:5cd6f0a0a7ed 60 }
shliu1 0:5cd6f0a0a7ed 61 }
shliu1 0:5cd6f0a0a7ed 62 else
shliu1 0:5cd6f0a0a7ed 63 break;
shliu1 0:5cd6f0a0a7ed 64 }
shliu1 0:5cd6f0a0a7ed 65 }
shliu1 0:5cd6f0a0a7ed 66
shliu1 0:5cd6f0a0a7ed 67 int main() {
shliu1 0:5cd6f0a0a7ed 68 int buttonState;
shliu1 0:5cd6f0a0a7ed 69 int inByte; // incoming serial byte
shliu1 0:5cd6f0a0a7ed 70 int ifound;
shliu1 0:5cd6f0a0a7ed 71 int sendnum;
shliu1 0:5cd6f0a0a7ed 72
shliu1 0:5cd6f0a0a7ed 73 // pc.baud(115200);
shliu1 0:5cd6f0a0a7ed 74 // pc.printf("Hello World!\n");
shliu1 0:5cd6f0a0a7ed 75
shliu1 0:5cd6f0a0a7ed 76 device.baud(115200);
shliu1 0:5cd6f0a0a7ed 77 inByte= 0;
shliu1 0:5cd6f0a0a7ed 78 ifound = 0;
shliu1 0:5cd6f0a0a7ed 79 sendnum =0;
shliu1 0:5cd6f0a0a7ed 80
shliu1 0:5cd6f0a0a7ed 81 led1= 0;
shliu1 0:5cd6f0a0a7ed 82 while (1)
shliu1 0:5cd6f0a0a7ed 83 {
shliu1 0:5cd6f0a0a7ed 84 buttonState = button.read();
shliu1 0:5cd6f0a0a7ed 85 if (buttonState == HIGH ) {
shliu1 0:5cd6f0a0a7ed 86 // turn LED on:
shliu1 0:5cd6f0a0a7ed 87 if ( ifound == 1 )
shliu1 0:5cd6f0a0a7ed 88 {
shliu1 0:5cd6f0a0a7ed 89 sendnum++;
shliu1 0:5cd6f0a0a7ed 90 setupCommand(inByte);
shliu1 0:5cd6f0a0a7ed 91 ifound = 0;
shliu1 0:5cd6f0a0a7ed 92 inByte = 0;
shliu1 0:5cd6f0a0a7ed 93 }
shliu1 0:5cd6f0a0a7ed 94 }
shliu1 0:5cd6f0a0a7ed 95 else
shliu1 0:5cd6f0a0a7ed 96 {
shliu1 0:5cd6f0a0a7ed 97 // turn LED off:
shliu1 0:5cd6f0a0a7ed 98 led1=!led1;
shliu1 0:5cd6f0a0a7ed 99 inByte++;
shliu1 0:5cd6f0a0a7ed 100 ifound=1;
shliu1 0:5cd6f0a0a7ed 101 Thread::wait(200);
shliu1 0:5cd6f0a0a7ed 102 led1=!led1;
shliu1 0:5cd6f0a0a7ed 103 }
shliu1 0:5cd6f0a0a7ed 104 Thread::wait(500);
shliu1 0:5cd6f0a0a7ed 105 }
shliu1 0:5cd6f0a0a7ed 106 }