3 fuc:fat sd eth

Dependencies:   FATFileSystem SDFileSystem WIZnetInterface mbed

Fork of adc_dac by jiang hao

Committer:
jh_ndm
Date:
Fri Jul 15 01:55:25 2016 +0000
Revision:
2:b67216fc6104
Parent:
1:2cd31d24d6fc
Child:
3:4132f3ef7d22
mbed test:uart1,uart2,digitalOut,analog,pwm

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jh_ndm 0:695e35fce077 1
jh_ndm 0:695e35fce077 2
jh_ndm 0:695e35fce077 3 #include "mbed.h"
jh_ndm 0:695e35fce077 4
jh_ndm 2:b67216fc6104 5 Serial uart1(PA_13, PA_14); // tx, rx
jh_ndm 2:b67216fc6104 6 Serial uart2(PC_10, PC_11); // tx, rx
jh_ndm 0:695e35fce077 7 DigitalOut num1(D10);
jh_ndm 0:695e35fce077 8 DigitalOut num2(D11);
jh_ndm 0:695e35fce077 9 DigitalOut num3(D12);
jh_ndm 0:695e35fce077 10 DigitalOut num4(D2);
jh_ndm 0:695e35fce077 11 DigitalOut num5(D3);
jh_ndm 2:b67216fc6104 12 DigitalOut num6(D5);
jh_ndm 2:b67216fc6104 13 DigitalOut num7(D6);
jh_ndm 2:b67216fc6104 14 AnalogIn battery1(A1);
jh_ndm 2:b67216fc6104 15 AnalogIn battery2(A2);
jh_ndm 2:b67216fc6104 16 AnalogIn battery3(A3);
jh_ndm 2:b67216fc6104 17 PwmOut PWM1(D3);
jh_ndm 2:b67216fc6104 18 PwmOut PWM2(D5);
jh_ndm 2:b67216fc6104 19 PwmOut PWM3(D6);
jh_ndm 2:b67216fc6104 20 float pv1=0;
jh_ndm 2:b67216fc6104 21 float pv2=0;
jh_ndm 2:b67216fc6104 22 float pv3=0;
jh_ndm 0:695e35fce077 23
jh_ndm 2:b67216fc6104 24 int main() {
jh_ndm 0:695e35fce077 25 while(1){
jh_ndm 2:b67216fc6104 26 uart2.printf("uart2:for Loopback test,please input something\n");
jh_ndm 2:b67216fc6104 27 char c = uart2.getc();
jh_ndm 2:b67216fc6104 28 uart2.printf("%c",c);
jh_ndm 2:b67216fc6104 29 uart1.printf("uart1:The following is digitalOut test\n");
jh_ndm 0:695e35fce077 30 wait(0.25);
jh_ndm 0:695e35fce077 31 num1 = 1;
jh_ndm 0:695e35fce077 32 num2 = 1;
jh_ndm 0:695e35fce077 33 num3 = 1;
jh_ndm 0:695e35fce077 34 num4 = 1;
jh_ndm 0:695e35fce077 35 num5 = 1;
jh_ndm 2:b67216fc6104 36 num6 = 1;
jh_ndm 2:b67216fc6104 37 num7 = 1;
jh_ndm 0:695e35fce077 38 wait(0.25);
jh_ndm 0:695e35fce077 39 num1 = 0;
jh_ndm 0:695e35fce077 40 num2 = 0;
jh_ndm 0:695e35fce077 41 num3 = 0;
jh_ndm 0:695e35fce077 42 num4 = 0;
jh_ndm 0:695e35fce077 43 num5 = 0;
jh_ndm 2:b67216fc6104 44 num6 = 0;
jh_ndm 2:b67216fc6104 45 num7 = 0;
jh_ndm 2:b67216fc6104 46 uart1.printf("uart1:The following is battery A1 A2 A3 test\n");
jh_ndm 2:b67216fc6104 47 if(battery1 > 0.5){
jh_ndm 2:b67216fc6104 48 uart1.printf("uart1:%02f\n",battery1.read()*3.3);
jh_ndm 2:b67216fc6104 49 wait(1);
jh_ndm 2:b67216fc6104 50 }
jh_ndm 2:b67216fc6104 51 if(battery2 > 0.5){
jh_ndm 2:b67216fc6104 52 uart1.printf("uart1:%02f\n",battery2.read()*3.3);
jh_ndm 2:b67216fc6104 53 wait(1);
jh_ndm 2:b67216fc6104 54 }
jh_ndm 2:b67216fc6104 55 if(battery3 > 0.5){
jh_ndm 2:b67216fc6104 56 uart1.printf("uart1:%02f\n",battery3.read()*3.3);
jh_ndm 2:b67216fc6104 57 wait(1);
jh_ndm 2:b67216fc6104 58 }
jh_ndm 2:b67216fc6104 59
jh_ndm 2:b67216fc6104 60 uart1.printf("uart1:The following is pwm test\n");
jh_ndm 2:b67216fc6104 61 PWM1.period_us(100);
jh_ndm 2:b67216fc6104 62 PWM2.period_us(100);
jh_ndm 2:b67216fc6104 63 PWM3.period_us(100);
jh_ndm 2:b67216fc6104 64 PWM1 = 0;
jh_ndm 2:b67216fc6104 65 PWM2 = 0.25;
jh_ndm 2:b67216fc6104 66 PWM3 = 0.5;
jh_ndm 2:b67216fc6104 67 for(int i=0;i<1000;i++)
jh_ndm 2:b67216fc6104 68 {
jh_ndm 2:b67216fc6104 69 PWM1=pv1;
jh_ndm 2:b67216fc6104 70 pv1=pv1+0.01;
jh_ndm 2:b67216fc6104 71 wait(0.05);
jh_ndm 2:b67216fc6104 72 if (pv1>1)
jh_ndm 2:b67216fc6104 73 pv1=0;
jh_ndm 2:b67216fc6104 74
jh_ndm 2:b67216fc6104 75 PWM2=pv2;
jh_ndm 2:b67216fc6104 76 pv2=pv2+0.01;
jh_ndm 2:b67216fc6104 77 wait(0.05);
jh_ndm 2:b67216fc6104 78 if (pv2>1)
jh_ndm 2:b67216fc6104 79 pv2=0;
jh_ndm 2:b67216fc6104 80
jh_ndm 2:b67216fc6104 81 PWM3=pv3;
jh_ndm 2:b67216fc6104 82 pv3=pv3+0.01;
jh_ndm 2:b67216fc6104 83 wait(0.05);
jh_ndm 2:b67216fc6104 84 if (pv3>1)
jh_ndm 2:b67216fc6104 85 pv3=0;
jh_ndm 2:b67216fc6104 86 }
jh_ndm 2:b67216fc6104 87 }
jh_ndm 0:695e35fce077 88 }
jh_ndm 0:695e35fce077 89
jh_ndm 0:695e35fce077 90
jh_ndm 2:b67216fc6104 91
jh_ndm 2:b67216fc6104 92