test

Dependencies:   MINI8I8O5A000 mbed EEPROM_P4 IICLCD_LOWCOST

Committer:
tsuparit
Date:
Mon Oct 10 10:42:45 2016 +0000
Revision:
7:3cb877cb7393
Parent:
6:96d89c2f4bf9
Child:
8:055a85e600dd
Simple jude IO test OK.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tsuparit 6:96d89c2f4bf9 1 float firmware_version = 1.20;
tsuparit 0:5e60f85d6c26 2
tsuparit 0:5e60f85d6c26 3 #include "mbed.h"
tsuparit 2:82dbbbff7518 4
tsuparit 6:96d89c2f4bf9 5 #define BUZZVSP7 // Enable P7 for Buzzer..
tsuparit 2:82dbbbff7518 6 //#include "USBSerial.h"
tsuparit 2:82dbbbff7518 7 //SBSerial pc;
tsuparit 2:82dbbbff7518 8
tsuparit 2:82dbbbff7518 9
tsuparit 2:82dbbbff7518 10
tsuparit 2:82dbbbff7518 11 //#define USBSerialOption
tsuparit 2:82dbbbff7518 12
tsuparit 2:82dbbbff7518 13 #ifdef USBSerialOption
tsuparit 2:82dbbbff7518 14 #include "USBSerial.h"
tsuparit 2:82dbbbff7518 15 USBSerial pc;
tsuparit 7:3cb877cb7393 16
tsuparit 2:82dbbbff7518 17 #else
tsuparit 2:82dbbbff7518 18
tsuparit 4:c08d713f8cfc 19 //Serial pc(USBTX, USBRX); // SDA serail port
tsuparit 4:c08d713f8cfc 20 Serial pc(PTE0, PTE1); // tx, rx
tsuparit 2:82dbbbff7518 21 #endif
tsuparit 2:82dbbbff7518 22
tsuparit 2:82dbbbff7518 23
tsuparit 2:82dbbbff7518 24
tsuparit 0:5e60f85d6c26 25 #include "LiquidCrystal_I2C.h"
tsuparit 0:5e60f85d6c26 26 #include "mini8i8o5a.h"
tsuparit 0:5e60f85d6c26 27 #define EEPROMBUFFERSIZE 16
tsuparit 0:5e60f85d6c26 28 #include "eepromlib.h"
tsuparit 0:5e60f85d6c26 29
tsuparit 0:5e60f85d6c26 30
tsuparit 0:5e60f85d6c26 31 DigitalOut myled(LED1);
tsuparit 0:5e60f85d6c26 32
tsuparit 5:a693866be4b3 33 int loopinilcd=0;
tsuparit 0:5e60f85d6c26 34
tsuparit 0:5e60f85d6c26 35 char str[50];
tsuparit 0:5e60f85d6c26 36 char strbuf[50];
tsuparit 0:5e60f85d6c26 37
tsuparit 0:5e60f85d6c26 38
tsuparit 0:5e60f85d6c26 39 int rxchar_count=0;
tsuparit 0:5e60f85d6c26 40 #define RXBUFFERSIZE 100
tsuparit 0:5e60f85d6c26 41 char rx_buffer[RXBUFFERSIZE];
tsuparit 0:5e60f85d6c26 42 char rx_buffer_CMD[RXBUFFERSIZE];
tsuparit 0:5e60f85d6c26 43 char rx_buffer_ARG[RXBUFFERSIZE];
tsuparit 0:5e60f85d6c26 44 char rx_pointer=0;
tsuparit 0:5e60f85d6c26 45 char inchar=0;
tsuparit 0:5e60f85d6c26 46
tsuparit 0:5e60f85d6c26 47 char remote_control=0;
tsuparit 0:5e60f85d6c26 48
tsuparit 0:5e60f85d6c26 49 float ser_para_reset=0;
tsuparit 0:5e60f85d6c26 50 //float ser_para_stab=3.25;
tsuparit 0:5e60f85d6c26 51 float ser_para_time=1.19;
tsuparit 0:5e60f85d6c26 52 float ser_para_result=0.0;
tsuparit 0:5e60f85d6c26 53
tsuparit 0:5e60f85d6c26 54 char ser_para_state=0;
tsuparit 0:5e60f85d6c26 55 char ser_para_err=0;
tsuparit 0:5e60f85d6c26 56 char ser_para_range=0;
tsuparit 0:5e60f85d6c26 57
tsuparit 0:5e60f85d6c26 58 char ser_trigger=0;
tsuparit 0:5e60f85d6c26 59 char ser_para_cont_mode=1; //serial continue print out
tsuparit 0:5e60f85d6c26 60
tsuparit 0:5e60f85d6c26 61 Timer com_timer;
tsuparit 0:5e60f85d6c26 62
tsuparit 0:5e60f85d6c26 63
tsuparit 0:5e60f85d6c26 64 char boardaddress =1;
tsuparit 0:5e60f85d6c26 65
tsuparit 7:3cb877cb7393 66
tsuparit 7:3cb877cb7393 67
tsuparit 7:3cb877cb7393 68
tsuparit 7:3cb877cb7393 69 int CAMERROR =0;
tsuparit 7:3cb877cb7393 70 int CAMTOTAL =0;
tsuparit 7:3cb877cb7393 71 #define CAMTRIGGER OUT0
tsuparit 7:3cb877cb7393 72 #define CAMBUSY IN1
tsuparit 7:3cb877cb7393 73
tsuparit 7:3cb877cb7393 74
tsuparit 0:5e60f85d6c26 75 void serial_pc_rx_services()
tsuparit 0:5e60f85d6c26 76 {
tsuparit 7:3cb877cb7393 77 int i,j;
tsuparit 2:82dbbbff7518 78 #ifdef USBSerialOption
tsuparit 2:82dbbbff7518 79 while (pc.available())
tsuparit 2:82dbbbff7518 80 #else
tsuparit 2:82dbbbff7518 81 while(pc.readable())
tsuparit 2:82dbbbff7518 82 #endif
tsuparit 3:e658376f6e27 83 {
tsuparit 3:e658376f6e27 84 inchar =pc.getc();
tsuparit 2:82dbbbff7518 85 if ( rx_pointer==0) //first incoming character clear old buffer
tsuparit 0:5e60f85d6c26 86 {
tsuparit 0:5e60f85d6c26 87 for (i=0;i<RXBUFFERSIZE;i++) rx_buffer[i]=0; //clear old buffer
tsuparit 3:e658376f6e27 88 com_timer.reset();
tsuparit 3:e658376f6e27 89 com_timer.start();
tsuparit 0:5e60f85d6c26 90 }
tsuparit 0:5e60f85d6c26 91
tsuparit 5:a693866be4b3 92 loopinilcd=0;
tsuparit 2:82dbbbff7518 93
tsuparit 3:e658376f6e27 94 rx_buffer[rx_pointer]=inchar; //keep char in buffer...
tsuparit 0:5e60f85d6c26 95 rx_pointer++;
tsuparit 7:3cb877cb7393 96
tsuparit 0:5e60f85d6c26 97 if (rx_pointer>=(RXBUFFERSIZE-10))
tsuparit 0:5e60f85d6c26 98 {
tsuparit 0:5e60f85d6c26 99 rx_pointer=0;//Error buffer overflow
tsuparit 2:82dbbbff7518 100 pc.printf("ERR:buffer overflow\n");
tsuparit 0:5e60f85d6c26 101 }
tsuparit 7:3cb877cb7393 102
tsuparit 0:5e60f85d6c26 103 if ((inchar=='\r')|(inchar=='\n'))
tsuparit 0:5e60f85d6c26 104 {
tsuparit 2:82dbbbff7518 105
tsuparit 0:5e60f85d6c26 106 rx_buffer[rx_pointer-1]=0;//mark end of string, remove terminate char
tsuparit 0:5e60f85d6c26 107
tsuparit 0:5e60f85d6c26 108 i=0;
tsuparit 0:5e60f85d6c26 109 j=0;
tsuparit 0:5e60f85d6c26 110 char cmd_done=0;
tsuparit 0:5e60f85d6c26 111 while (rx_buffer[i]!=0)
tsuparit 0:5e60f85d6c26 112 {
tsuparit 0:5e60f85d6c26 113 if (cmd_done==0)
tsuparit 0:5e60f85d6c26 114 {
tsuparit 0:5e60f85d6c26 115 rx_buffer_CMD[i]=rx_buffer[i];//copy cmd part
tsuparit 0:5e60f85d6c26 116 if (rx_buffer_CMD[i]==' ')
tsuparit 0:5e60f85d6c26 117 {
tsuparit 0:5e60f85d6c26 118 cmd_done=1;
tsuparit 0:5e60f85d6c26 119 rx_buffer_CMD[i+1]=0;
tsuparit 0:5e60f85d6c26 120 }
tsuparit 0:5e60f85d6c26 121 }
tsuparit 0:5e60f85d6c26 122 else
tsuparit 0:5e60f85d6c26 123 {
tsuparit 0:5e60f85d6c26 124 rx_buffer_ARG[j]=rx_buffer[i];//copy cmd part
tsuparit 0:5e60f85d6c26 125 j++;
tsuparit 0:5e60f85d6c26 126 }
tsuparit 0:5e60f85d6c26 127 i++;
tsuparit 0:5e60f85d6c26 128
tsuparit 0:5e60f85d6c26 129 }
tsuparit 7:3cb877cb7393 130
tsuparit 1:d9ab13cdf377 131 rx_buffer_ARG[j]=0; //end of string ++++
tsuparit 0:5e60f85d6c26 132
tsuparit 7:3cb877cb7393 133
tsuparit 7:3cb877cb7393 134
tsuparit 7:3cb877cb7393 135 #define IDELBUSYLOOP 10000
tsuparit 7:3cb877cb7393 136 BUZZER=1;
tsuparit 7:3cb877cb7393 137
tsuparit 7:3cb877cb7393 138
tsuparit 7:3cb877cb7393 139 if (rx_buffer[0]=='t')
tsuparit 7:3cb877cb7393 140 {
tsuparit 7:3cb877cb7393 141 //pulse trigger
tsuparit 7:3cb877cb7393 142 CAMTRIGGER=0; //edge trigger
tsuparit 7:3cb877cb7393 143 i=0;
tsuparit 7:3cb877cb7393 144 while(1) //wait camera run busy
tsuparit 7:3cb877cb7393 145 {
tsuparit 7:3cb877cb7393 146 Input_sampling(8);
tsuparit 7:3cb877cb7393 147 if(CAMBUSY!=0) break;
tsuparit 7:3cb877cb7393 148 if (i++>IDELBUSYLOOP)
tsuparit 7:3cb877cb7393 149 {
tsuparit 7:3cb877cb7393 150 CAMERROR=1;
tsuparit 7:3cb877cb7393 151 break;
tsuparit 7:3cb877cb7393 152 }
tsuparit 7:3cb877cb7393 153 }
tsuparit 7:3cb877cb7393 154 //cmaera process run
tsuparit 7:3cb877cb7393 155 CAMTRIGGER=1; //edge trigger
tsuparit 7:3cb877cb7393 156 i=0;
tsuparit 7:3cb877cb7393 157 while(1) //wait camera complete run
tsuparit 7:3cb877cb7393 158 {
tsuparit 7:3cb877cb7393 159 Input_sampling(8);
tsuparit 7:3cb877cb7393 160 if(CAMBUSY==0) break;
tsuparit 7:3cb877cb7393 161 if (i++>IDELBUSYLOOP)
tsuparit 7:3cb877cb7393 162 {
tsuparit 7:3cb877cb7393 163 CAMERROR=1;
tsuparit 7:3cb877cb7393 164 break;
tsuparit 7:3cb877cb7393 165 }
tsuparit 7:3cb877cb7393 166 }
tsuparit 7:3cb877cb7393 167
tsuparit 7:3cb877cb7393 168 }
tsuparit 7:3cb877cb7393 169 else if (rx_buffer[0]=='j')
tsuparit 7:3cb877cb7393 170 {
tsuparit 7:3cb877cb7393 171 wait(0.1);
tsuparit 7:3cb877cb7393 172 }
tsuparit 7:3cb877cb7393 173 else if (rx_buffer[0]=='r')
tsuparit 7:3cb877cb7393 174 {
tsuparit 7:3cb877cb7393 175 wait(0.1);
tsuparit 7:3cb877cb7393 176
tsuparit 7:3cb877cb7393 177 }
tsuparit 7:3cb877cb7393 178 else if (rx_buffer[0]=='p')
tsuparit 7:3cb877cb7393 179 {
tsuparit 7:3cb877cb7393 180 wait(0.1);
tsuparit 7:3cb877cb7393 181
tsuparit 7:3cb877cb7393 182 }
tsuparit 7:3cb877cb7393 183
tsuparit 7:3cb877cb7393 184 BUZZER=0;
tsuparit 7:3cb877cb7393 185 Input_sampling(8);
tsuparit 7:3cb877cb7393 186 if (IN0) // Total result
tsuparit 7:3cb877cb7393 187 {
tsuparit 7:3cb877cb7393 188 CAMTOTAL=1;
tsuparit 7:3cb877cb7393 189 OUT1=0;
tsuparit 7:3cb877cb7393 190 }
tsuparit 7:3cb877cb7393 191 else
tsuparit 7:3cb877cb7393 192 {
tsuparit 7:3cb877cb7393 193 CAMTOTAL=0;
tsuparit 7:3cb877cb7393 194 OUT1=1;
tsuparit 7:3cb877cb7393 195 }
tsuparit 7:3cb877cb7393 196
tsuparit 7:3cb877cb7393 197
tsuparit 7:3cb877cb7393 198
tsuparit 7:3cb877cb7393 199
tsuparit 7:3cb877cb7393 200 //+++++
tsuparit 7:3cb877cb7393 201 pc.printf("%dOK\n",CAMTOTAL+4*CAMERROR);
tsuparit 7:3cb877cb7393 202 //pc.printf("123OK");
tsuparit 7:3cb877cb7393 203 //pc.printf("rxbuffer: %s",rx_buffer); //test direct echo
tsuparit 7:3cb877cb7393 204 //++++
tsuparit 7:3cb877cb7393 205
tsuparit 2:82dbbbff7518 206 //pc.printf("rxbuffer: %s",rx_buffer); //test direct echo
tsuparit 7:3cb877cb7393 207 /*
tsuparit 0:5e60f85d6c26 208 if (strcmp(rx_buffer,"*IDN?")==0)
tsuparit 0:5e60f85d6c26 209 {
tsuparit 0:5e60f85d6c26 210 pc.printf("Schaffner SerIO, ver %.1f\n",firmware_version);
tsuparit 0:5e60f85d6c26 211 }
tsuparit 0:5e60f85d6c26 212 else if (strcmp(rx_buffer,"*RST")==0)
tsuparit 0:5e60f85d6c26 213 {
tsuparit 0:5e60f85d6c26 214 pc.printf("Instrumnet Reset\n");
tsuparit 0:5e60f85d6c26 215 ser_para_reset=1; //pass flag stop all operation
tsuparit 0:5e60f85d6c26 216 //LCDI2C4Bit_init();
tsuparit 0:5e60f85d6c26 217 LiquidCrystal_I2Cinit();
tsuparit 0:5e60f85d6c26 218 LCDI2C4Bit_clear();
tsuparit 0:5e60f85d6c26 219 //LCDI2C4Bit_backLight(true);
tsuparit 0:5e60f85d6c26 220 LiquidCrystal_I2Cbacklight();
tsuparit 0:5e60f85d6c26 221
tsuparit 0:5e60f85d6c26 222 LCDI2C4Bit_cursorTo(0,0);
tsuparit 0:5e60f85d6c26 223 sprintf (str," --- RESET ----");
tsuparit 0:5e60f85d6c26 224 LCDI2C4Bit_printIn(str);
tsuparit 0:5e60f85d6c26 225 wait(0.25);
tsuparit 3:e658376f6e27 226 NVIC_SystemReset();//softreser
tsuparit 0:5e60f85d6c26 227 }
tsuparit 0:5e60f85d6c26 228 else if (strcmp(rx_buffer,":SYS:VER")==0)
tsuparit 0:5e60f85d6c26 229 {
tsuparit 0:5e60f85d6c26 230 pc.printf("%.1f\n",firmware_version);
tsuparit 0:5e60f85d6c26 231 }
tsuparit 0:5e60f85d6c26 232 else if (strcmp(rx_buffer,":SYST:ERR")==0)
tsuparit 0:5e60f85d6c26 233 {
tsuparit 0:5e60f85d6c26 234 pc.printf("0\n");
tsuparit 0:5e60f85d6c26 235 }
tsuparit 0:5e60f85d6c26 236 //else if (strcmp(rx_buffer,"a11000")==0) //Read Input "aX1"
tsuparit 0:5e60f85d6c26 237 else if ( (rx_buffer[0]=='a') & (rx_buffer[1]==('0'+boardaddress)) & (rx_buffer[2]=='1')) // Write Output "aX1"
tsuparit 0:5e60f85d6c26 238 {
tsuparit 3:e658376f6e27 239 pc.printf("%dOK\n",INPUT);
tsuparit 0:5e60f85d6c26 240 }
tsuparit 0:5e60f85d6c26 241 else if ( (rx_buffer[0]=='a') & (rx_buffer[1]==('0'+boardaddress)) & (rx_buffer[2]=='2')) // Write Output "aX2"
tsuparit 0:5e60f85d6c26 242 {
tsuparit 2:82dbbbff7518 243 //writer
tsuparit 2:82dbbbff7518 244 unsigned char b3,b2,b1;
tsuparit 2:82dbbbff7518 245 unsigned int outdata=0;
tsuparit 2:82dbbbff7518 246
tsuparit 2:82dbbbff7518 247 if (rx_buffer[3]!=0)
tsuparit 2:82dbbbff7518 248 {
tsuparit 2:82dbbbff7518 249 outdata=rx_buffer[3]-'0';
tsuparit 2:82dbbbff7518 250 }
tsuparit 2:82dbbbff7518 251 if (rx_buffer[4]!=0)
tsuparit 2:82dbbbff7518 252 {
tsuparit 2:82dbbbff7518 253 outdata=outdata*10+rx_buffer[4]-'0';
tsuparit 2:82dbbbff7518 254 }
tsuparit 2:82dbbbff7518 255 if (rx_buffer[5]!=0)
tsuparit 2:82dbbbff7518 256 {
tsuparit 2:82dbbbff7518 257 outdata=outdata*10+rx_buffer[5]-'0';
tsuparit 2:82dbbbff7518 258 }
tsuparit 3:e658376f6e27 259 int OUTBUF=0;
tsuparit 3:e658376f6e27 260 if bitchk(outdata,0) {OUT0=ON;OUTBUF=OUTBUF+1;} else OUT0=OFF;
tsuparit 3:e658376f6e27 261 if bitchk(outdata,1) {OUT1=ON;OUTBUF=OUTBUF+2;} else OUT1=OFF;
tsuparit 3:e658376f6e27 262 if bitchk(outdata,2) {OUT2=ON;OUTBUF=OUTBUF+4;} else OUT2=OFF;
tsuparit 3:e658376f6e27 263 if bitchk(outdata,3) {OUT3=ON;OUTBUF=OUTBUF+8;} else OUT3=OFF;
tsuparit 2:82dbbbff7518 264
tsuparit 3:e658376f6e27 265 if bitchk(outdata,4) {OUT4=ON;OUTBUF=OUTBUF+16;} else OUT4=OFF;
tsuparit 3:e658376f6e27 266 if bitchk(outdata,5) {OUT5=ON;OUTBUF=OUTBUF+32;} else OUT5=OFF;
tsuparit 3:e658376f6e27 267 if bitchk(outdata,6) {OUT6=ON;OUTBUF=OUTBUF+64;} else OUT6=OFF;
tsuparit 6:96d89c2f4bf9 268 if bitchk(outdata,7)
tsuparit 6:96d89c2f4bf9 269 {OUT7=ON;OUTBUF=OUTBUF+128;
tsuparit 6:96d89c2f4bf9 270 #ifdef BUZZVSP7
tsuparit 6:96d89c2f4bf9 271 BUZZER=1;
tsuparit 6:96d89c2f4bf9 272 #endif
tsuparit 6:96d89c2f4bf9 273
tsuparit 6:96d89c2f4bf9 274 }
tsuparit 6:96d89c2f4bf9 275 else
tsuparit 6:96d89c2f4bf9 276 {
tsuparit 6:96d89c2f4bf9 277 #ifdef BUZZVSP7
tsuparit 6:96d89c2f4bf9 278 BUZZER=1;
tsuparit 6:96d89c2f4bf9 279 #endif
tsuparit 6:96d89c2f4bf9 280
tsuparit 6:96d89c2f4bf9 281
tsuparit 6:96d89c2f4bf9 282 OUT7=OFF;
tsuparit 6:96d89c2f4bf9 283 }
tsuparit 3:e658376f6e27 284 OUTPUT=OUTBUF;
tsuparit 3:e658376f6e27 285 pc.printf("%dOK\n",outdata);
tsuparit 0:5e60f85d6c26 286 }
tsuparit 0:5e60f85d6c26 287 else if ( (rx_buffer[0]=='a') & (rx_buffer[1]==('0'+boardaddress)) & (rx_buffer[2]=='3')) // Write Output "aX2"
tsuparit 0:5e60f85d6c26 288 {
tsuparit 3:e658376f6e27 289 pc.printf("%dOK\n",OUTPUT);
tsuparit 0:5e60f85d6c26 290 }
tsuparit 0:5e60f85d6c26 291 else
tsuparit 0:5e60f85d6c26 292 {//unknow / handle comand
tsuparit 2:82dbbbff7518 293 //pc.printf( "UNKNOWN %s=>%s,%s\n",rx_buffer,rx_buffer_CMD,rx_buffer_ARG);
tsuparit 2:82dbbbff7518 294 pc.printf( "UNKNOWN %s=>%s,%s\n",rx_buffer);
tsuparit 7:3cb877cb7393 295 }
tsuparit 7:3cb877cb7393 296
tsuparit 7:3cb877cb7393 297
tsuparit 7:3cb877cb7393 298 */
tsuparit 7:3cb877cb7393 299
tsuparit 7:3cb877cb7393 300
tsuparit 7:3cb877cb7393 301
tsuparit 7:3cb877cb7393 302
tsuparit 0:5e60f85d6c26 303 rx_pointer=0;//Reset at the end
tsuparit 0:5e60f85d6c26 304 com_timer.stop();
tsuparit 2:82dbbbff7518 305 break;//exit while
tsuparit 2:82dbbbff7518 306 } //end foud "terminal of command//
tsuparit 2:82dbbbff7518 307
tsuparit 0:5e60f85d6c26 308
tsuparit 2:82dbbbff7518 309
tsuparit 2:82dbbbff7518 310 } //end while data read aviable
tsuparit 3:e658376f6e27 311
tsuparit 2:82dbbbff7518 312
tsuparit 0:5e60f85d6c26 313
tsuparit 0:5e60f85d6c26 314 }
tsuparit 0:5e60f85d6c26 315
tsuparit 0:5e60f85d6c26 316
tsuparit 0:5e60f85d6c26 317 int main()
tsuparit 0:5e60f85d6c26 318 {
tsuparit 0:5e60f85d6c26 319
tsuparit 0:5e60f85d6c26 320
tsuparit 0:5e60f85d6c26 321
tsuparit 0:5e60f85d6c26 322
tsuparit 5:a693866be4b3 323 LiquidCrystal_I2C_SETUP(0x27,20,4);
tsuparit 0:5e60f85d6c26 324 LiquidCrystal_I2Cinit();
tsuparit 0:5e60f85d6c26 325 LiquidCrystal_I2Cbacklight();
tsuparit 0:5e60f85d6c26 326
tsuparit 0:5e60f85d6c26 327 LiquidCrystal_I2CsetCursor(0,1);
tsuparit 0:5e60f85d6c26 328 sprintf (str, " SCHAFFNER ");
tsuparit 0:5e60f85d6c26 329 LCDI2C4Bit_printIn(str);
tsuparit 0:5e60f85d6c26 330 LiquidCrystal_I2CsetCursor(0,0);
tsuparit 0:5e60f85d6c26 331 sprintf (str, "SerailDIO v:%.2f ",1.00) ;
tsuparit 0:5e60f85d6c26 332 LCDI2C4Bit_printIn(str);
tsuparit 0:5e60f85d6c26 333
tsuparit 2:82dbbbff7518 334 #ifdef USBSerialOption
tsuparit 2:82dbbbff7518 335
tsuparit 2:82dbbbff7518 336 #else
tsuparit 2:82dbbbff7518 337 pc.baud(9600); // set what you want here depending on your terminal program speed
tsuparit 2:82dbbbff7518 338 #endif
tsuparit 2:82dbbbff7518 339
tsuparit 0:5e60f85d6c26 340
tsuparit 0:5e60f85d6c26 341 com_timer.start();
tsuparit 0:5e60f85d6c26 342 com_timer.stop();
tsuparit 0:5e60f85d6c26 343 com_timer.reset();
tsuparit 0:5e60f85d6c26 344
tsuparit 3:e658376f6e27 345 wait(0.1);
tsuparit 3:e658376f6e27 346
tsuparit 3:e658376f6e27 347 pc.attach(&serial_pc_rx_services); // Use interrupt services !!
tsuparit 5:a693866be4b3 348
tsuparit 7:3cb877cb7393 349 OUT1=0;
tsuparit 7:3cb877cb7393 350
tsuparit 7:3cb877cb7393 351 #define BUZZER_EN 0
tsuparit 7:3cb877cb7393 352
tsuparit 7:3cb877cb7393 353
tsuparit 7:3cb877cb7393 354
tsuparit 7:3cb877cb7393 355 CAMTRIGGER=1; // set signal ready for cam trigger
tsuparit 7:3cb877cb7393 356 while(1);
tsuparit 7:3cb877cb7393 357
tsuparit 7:3cb877cb7393 358 while(0)
tsuparit 7:3cb877cb7393 359 {
tsuparit 7:3cb877cb7393 360 if (BUZZER_EN!=0) BUZZER=1;
tsuparit 7:3cb877cb7393 361 OUT0=0;
tsuparit 7:3cb877cb7393 362 wait(0.1);
tsuparit 7:3cb877cb7393 363 if (BUZZER_EN!=0) BUZZER=0;
tsuparit 7:3cb877cb7393 364 wait(0.1);
tsuparit 7:3cb877cb7393 365 OUT0=1;
tsuparit 7:3cb877cb7393 366
tsuparit 7:3cb877cb7393 367
tsuparit 7:3cb877cb7393 368 wait(1.0);
tsuparit 7:3cb877cb7393 369
tsuparit 7:3cb877cb7393 370
tsuparit 7:3cb877cb7393 371 }
tsuparit 7:3cb877cb7393 372
tsuparit 7:3cb877cb7393 373
tsuparit 0:5e60f85d6c26 374 while(1)
tsuparit 0:5e60f85d6c26 375 {
tsuparit 5:a693866be4b3 376
tsuparit 5:a693866be4b3 377 if (loopinilcd++>100)
tsuparit 5:a693866be4b3 378 {
tsuparit 5:a693866be4b3 379 loopinilcd=0;
tsuparit 5:a693866be4b3 380 LiquidCrystal_I2Cinit();
tsuparit 5:a693866be4b3 381 LiquidCrystal_I2Cbacklight();
tsuparit 5:a693866be4b3 382 }
tsuparit 5:a693866be4b3 383
tsuparit 3:e658376f6e27 384 Input_sampling(512);
tsuparit 0:5e60f85d6c26 385 LiquidCrystal_I2CsetCursor(0,0);
tsuparit 5:a693866be4b3 386 sprintf (str, "IN:%d OUT:%d ",INPUT,OUTPUT);
tsuparit 3:e658376f6e27 387 LCDI2C4Bit_printIn(str);
tsuparit 0:5e60f85d6c26 388 LiquidCrystal_I2CsetCursor(0,1);
tsuparit 5:a693866be4b3 389
tsuparit 5:a693866be4b3 390
tsuparit 3:e658376f6e27 391 float processtime=1000.0*com_timer.read();
tsuparit 3:e658376f6e27 392 if (processtime<10.0)
tsuparit 3:e658376f6e27 393 {
tsuparit 3:e658376f6e27 394 sprintf (str, "%.1f ms:%s ",processtime,rx_buffer);
tsuparit 3:e658376f6e27 395 }
tsuparit 3:e658376f6e27 396 else
tsuparit 3:e658376f6e27 397 {
tsuparit 3:e658376f6e27 398 sprintf (str, " %.1f ms:%s ",processtime,rx_buffer);
tsuparit 5:a693866be4b3 399 }
tsuparit 5:a693866be4b3 400
tsuparit 0:5e60f85d6c26 401 LCDI2C4Bit_printIn(str);
tsuparit 5:a693866be4b3 402
tsuparit 5:a693866be4b3 403
tsuparit 5:a693866be4b3 404
tsuparit 5:a693866be4b3 405 char strbuf[50];
tsuparit 5:a693866be4b3 406
tsuparit 5:a693866be4b3 407
tsuparit 5:a693866be4b3 408 LiquidCrystal_I2CsetCursor(0,3);
tsuparit 5:a693866be4b3 409 sprintf (str, "#");
tsuparit 5:a693866be4b3 410 sprintf (strbuf, " ");
tsuparit 5:a693866be4b3 411
tsuparit 5:a693866be4b3 412 if (OUT0)
tsuparit 5:a693866be4b3 413 {
tsuparit 5:a693866be4b3 414 sprintf (strbuf, "K1 ");
tsuparit 5:a693866be4b3 415 strcat(str,strbuf);
tsuparit 5:a693866be4b3 416 }
tsuparit 5:a693866be4b3 417
tsuparit 5:a693866be4b3 418 if (OUT1)
tsuparit 5:a693866be4b3 419 {
tsuparit 5:a693866be4b3 420 sprintf (strbuf, "K2 ");
tsuparit 5:a693866be4b3 421 strcat(str,strbuf);
tsuparit 5:a693866be4b3 422 }
tsuparit 5:a693866be4b3 423
tsuparit 5:a693866be4b3 424 if (OUT2)
tsuparit 5:a693866be4b3 425 {
tsuparit 5:a693866be4b3 426 sprintf (strbuf, "K3 ");
tsuparit 5:a693866be4b3 427 strcat(str,strbuf);
tsuparit 5:a693866be4b3 428 }
tsuparit 5:a693866be4b3 429
tsuparit 5:a693866be4b3 430 if (OUT3)
tsuparit 5:a693866be4b3 431 {
tsuparit 5:a693866be4b3 432 sprintf (strbuf, "K4 ");
tsuparit 5:a693866be4b3 433 strcat(str,strbuf);
tsuparit 5:a693866be4b3 434 }
tsuparit 5:a693866be4b3 435
tsuparit 5:a693866be4b3 436
tsuparit 5:a693866be4b3 437
tsuparit 5:a693866be4b3 438
tsuparit 5:a693866be4b3 439
tsuparit 5:a693866be4b3 440 if (OUT4)
tsuparit 5:a693866be4b3 441 {
tsuparit 5:a693866be4b3 442 sprintf (strbuf, "RE ");
tsuparit 5:a693866be4b3 443 }
tsuparit 5:a693866be4b3 444 else
tsuparit 5:a693866be4b3 445 {
tsuparit 5:a693866be4b3 446 sprintf (strbuf, "V.");
tsuparit 5:a693866be4b3 447 }
tsuparit 5:a693866be4b3 448 strcat(str,strbuf);
tsuparit 5:a693866be4b3 449
tsuparit 5:a693866be4b3 450 if (OUT5)
tsuparit 5:a693866be4b3 451 {
tsuparit 5:a693866be4b3 452 sprintf (strbuf, "AC ");
tsuparit 5:a693866be4b3 453 }
tsuparit 5:a693866be4b3 454 else
tsuparit 5:a693866be4b3 455 {
tsuparit 5:a693866be4b3 456 sprintf (strbuf, "DC ");
tsuparit 5:a693866be4b3 457 }
tsuparit 5:a693866be4b3 458 strcat(str,strbuf);
tsuparit 5:a693866be4b3 459
tsuparit 5:a693866be4b3 460 if (OUT6)
tsuparit 5:a693866be4b3 461 {
tsuparit 5:a693866be4b3 462 sprintf (strbuf, "Di ");
tsuparit 5:a693866be4b3 463 strcat(str,strbuf);
tsuparit 5:a693866be4b3 464 }
tsuparit 5:a693866be4b3 465
tsuparit 5:a693866be4b3 466 if (OUT7)
tsuparit 5:a693866be4b3 467 {
tsuparit 5:a693866be4b3 468 sprintf (strbuf, "POW ");
tsuparit 5:a693866be4b3 469 strcat(str,strbuf);
tsuparit 5:a693866be4b3 470 }
tsuparit 5:a693866be4b3 471 sprintf (strbuf, " ");
tsuparit 5:a693866be4b3 472 strcat(str,strbuf);
tsuparit 5:a693866be4b3 473
tsuparit 5:a693866be4b3 474
tsuparit 5:a693866be4b3 475 LCDI2C4Bit_printIn(str);
tsuparit 5:a693866be4b3 476
tsuparit 5:a693866be4b3 477
tsuparit 5:a693866be4b3 478
tsuparit 5:a693866be4b3 479
tsuparit 0:5e60f85d6c26 480 if (com_timer.read()>5.0)
tsuparit 0:5e60f85d6c26 481 {
tsuparit 5:a693866be4b3 482 rx_pointer=0;//Reset at the end
tsuparit 5:a693866be4b3 483 com_timer.stop();
tsuparit 0:5e60f85d6c26 484 }
tsuparit 0:5e60f85d6c26 485
tsuparit 0:5e60f85d6c26 486 }
tsuparit 0:5e60f85d6c26 487
tsuparit 0:5e60f85d6c26 488
tsuparit 0:5e60f85d6c26 489 }