TVZ test

Dependencies:   mbed

Committer:
cvitas
Date:
Fri Feb 07 12:12:33 2014 +0000
Revision:
4:4620184bbb1f
Parent:
3:a4a5d9c0bc13
Child:
5:77ff08b129c0
ugra?ene izborne sklopke

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cvitas 0:5918d7a4ad04 1 #include "mbed.h"
cvitas 0:5918d7a4ad04 2
cvitas 0:5918d7a4ad04 3 Serial async_port(p9, p10); //set up TX and RX on pins 9 and 10
cvitas 0:5918d7a4ad04 4 DigitalOut red_led(LED4); //red led
cvitas 0:5918d7a4ad04 5 DigitalOut green_led(LED3); //green led
cvitas 0:5918d7a4ad04 6 DigitalOut RXDIN (LED1);
cvitas 4:4620184bbb1f 7
cvitas 0:5918d7a4ad04 8 DigitalIn switch_ip1(p5);
cvitas 0:5918d7a4ad04 9 DigitalIn switch_ip2(p6);
cvitas 4:4620184bbb1f 10 DigitalIn switch_ip3(p7);
cvitas 4:4620184bbb1f 11 DigitalIn switch_ip4(p8);
cvitas 4:4620184bbb1f 12
cvitas 2:2e261aa02cd0 13 Serial pc(USBTX, USBRX);
cvitas 0:5918d7a4ad04 14
cvitas 3:a4a5d9c0bc13 15 char header_read ; //first byte we will send
cvitas 3:a4a5d9c0bc13 16 char param_ads; // parameter address
cvitas 4:4620184bbb1f 17 char recd_val; //the received value
cvitas 0:5918d7a4ad04 18 int valueADC;
cvitas 3:a4a5d9c0bc13 19 char Outbuff[12];
cvitas 3:a4a5d9c0bc13 20 char Inbuff[12];
cvitas 4:4620184bbb1f 21 int valueSensA, valueSensB, valueSensC, valueSensD;
cvitas 4:4620184bbb1f 22 float fAzimuthErr;
cvitas 4:4620184bbb1f 23 float fElevationErr;
cvitas 4:4620184bbb1f 24 unsigned char *pointnavar;
cvitas 4:4620184bbb1f 25
cvitas 4:4620184bbb1f 26 int main()
cvitas 4:4620184bbb1f 27 {
cvitas 4:4620184bbb1f 28 async_port.baud(9600); //set baud rate to 9600 (ie default)
cvitas 4:4620184bbb1f 29 switch_ip1.mode(PullUp); // Pull up internal resistor
cvitas 4:4620184bbb1f 30 switch_ip2.mode(PullUp);
cvitas 4:4620184bbb1f 31 switch_ip3.mode(PullUp);
cvitas 4:4620184bbb1f 32 switch_ip4.mode(PullUp);
cvitas 4:4620184bbb1f 33
cvitas 4:4620184bbb1f 34 //accept default format, of 8 bits, no parity
cvitas 4:4620184bbb1f 35 while (1) {
cvitas 4:4620184bbb1f 36
cvitas 4:4620184bbb1f 37 // read or write mode ?
cvitas 4:4620184bbb1f 38 if (switch_ip1==0) {
cvitas 4:4620184bbb1f 39 header_read=0x10; // read output pattern
cvitas 4:4620184bbb1f 40 if (switch_ip2==0) {
cvitas 4:4620184bbb1f 41 param_ads = 0;
cvitas 4:4620184bbb1f 42 } else {
cvitas 4:4620184bbb1f 43 param_ads = 1;
cvitas 4:4620184bbb1f 44 }
cvitas 4:4620184bbb1f 45
cvitas 4:4620184bbb1f 46 /*
cvitas 4:4620184bbb1f 47 valueADC = 0x0302;
cvitas 4:4620184bbb1f 48 Outbuff[0] = valueADC;
cvitas 4:4620184bbb1f 49 Outbuff[1] = valueADC >> 8; */
cvitas 4:4620184bbb1f 50
cvitas 4:4620184bbb1f 51 while (async_port.writeable()==0); //is there a place to write?
cvitas 4:4620184bbb1f 52 async_port.putc(header_read); //transmit haeder
cvitas 4:4620184bbb1f 53 while (async_port.writeable()==0); //is there a place to write?
cvitas 4:4620184bbb1f 54 async_port.putc(param_ads); //transmit parameter address
cvitas 4:4620184bbb1f 55
cvitas 4:4620184bbb1f 56
cvitas 4:4620184bbb1f 57
cvitas 4:4620184bbb1f 58 if (async_port.readable()==1) { //is there a character to be read?
cvitas 4:4620184bbb1f 59 Inbuff[0] = async_port.getc(); //if yes, t
cvitas 4:4620184bbb1f 60 }
cvitas 4:4620184bbb1f 61 if (async_port.readable()==1) { //is there a character to be read?
cvitas 4:4620184bbb1f 62 Inbuff[1] = async_port.getc(); //if yes, t
cvitas 4:4620184bbb1f 63 }
cvitas 4:4620184bbb1f 64 if (async_port.readable()==1) { //is there a character to be read?
cvitas 4:4620184bbb1f 65 Inbuff[2] = async_port.getc(); //if yes, t
cvitas 4:4620184bbb1f 66 }
cvitas 4:4620184bbb1f 67 if (async_port.readable()==1) { //is there a character to be read?
cvitas 4:4620184bbb1f 68 Inbuff[3] = async_port.getc(); //if yes, t
cvitas 4:4620184bbb1f 69 }
cvitas 4:4620184bbb1f 70 if (async_port.readable()==1) { //is there a character to be read?
cvitas 4:4620184bbb1f 71 Inbuff[4] = async_port.getc(); //if yes, t
cvitas 4:4620184bbb1f 72 }
cvitas 4:4620184bbb1f 73 if (async_port.readable()==1) { //is there a character to be read?
cvitas 4:4620184bbb1f 74 Inbuff[5] = async_port.getc(); //if yes, t
cvitas 4:4620184bbb1f 75 }
cvitas 4:4620184bbb1f 76 if (async_port.readable()==1) { //is there a character to be read?
cvitas 4:4620184bbb1f 77 Inbuff[6] = async_port.getc(); //if yes, t
cvitas 4:4620184bbb1f 78 }
cvitas 4:4620184bbb1f 79 if (async_port.readable()==1) { //is there a character to be read?
cvitas 4:4620184bbb1f 80 Inbuff[7] = async_port.getc(); //if yes, t
cvitas 4:4620184bbb1f 81 }
cvitas 4:4620184bbb1f 82 if (async_port.readable()==1) { //is there a character to be read?
cvitas 4:4620184bbb1f 83 Inbuff[8] = async_port.getc(); //if yes, t
cvitas 4:4620184bbb1f 84 }
cvitas 4:4620184bbb1f 85 if (async_port.readable()==1) { //is there a character to be read?
cvitas 4:4620184bbb1f 86 Inbuff[9] = async_port.getc(); //if yes, t
cvitas 4:4620184bbb1f 87 }
cvitas 4:4620184bbb1f 88 if (async_port.readable()==1) { //is there a character to be read?
cvitas 4:4620184bbb1f 89 Inbuff[10] = async_port.getc(); //if yes, t
cvitas 4:4620184bbb1f 90 }
cvitas 4:4620184bbb1f 91
cvitas 4:4620184bbb1f 92 RXDIN = 1;
cvitas 4:4620184bbb1f 93 wait(1);
cvitas 4:4620184bbb1f 94 RXDIN = 0;
cvitas 4:4620184bbb1f 95 if (param_ads==0x00) {
cvitas 4:4620184bbb1f 96 valueSensA = Inbuff[2]+ Inbuff[3]*256;
cvitas 4:4620184bbb1f 97 valueSensB = Inbuff[4]+ Inbuff[5]*256;
cvitas 4:4620184bbb1f 98 valueSensC = Inbuff[6]+ Inbuff[7]*256;
cvitas 4:4620184bbb1f 99 valueSensD = Inbuff[8]+ Inbuff[9]*256;
cvitas 4:4620184bbb1f 100 pc.printf("SensA: %d SensB: %d SensC: %d SensD: %d \n\r", valueSensA, valueSensB, valueSensC, valueSensD);
cvitas 4:4620184bbb1f 101 }
cvitas 4:4620184bbb1f 102 if (param_ads==0x01) {
cvitas 4:4620184bbb1f 103 pointnavar = (unsigned char*) &fAzimuthErr;
cvitas 4:4620184bbb1f 104 for (int i=2; i<6; i++) {
cvitas 4:4620184bbb1f 105 *pointnavar = Inbuff[i];
cvitas 4:4620184bbb1f 106 pointnavar++;
cvitas 4:4620184bbb1f 107 }
cvitas 4:4620184bbb1f 108 pointnavar = (unsigned char*) &fElevationErr;
cvitas 4:4620184bbb1f 109 for (int i=6; i<10; i++) {
cvitas 4:4620184bbb1f 110 *pointnavar = Inbuff[i];
cvitas 4:4620184bbb1f 111 pointnavar++;
cvitas 4:4620184bbb1f 112 }
cvitas 4:4620184bbb1f 113 pc.printf("AZIMUT: %+3.0f ELEVATION; %+3.0f \n\r", fAzimuthErr, fElevationErr);
cvitas 4:4620184bbb1f 114 }
cvitas 4:4620184bbb1f 115 } // if (switch_ip1==0)
cvitas 4:4620184bbb1f 116
cvitas 4:4620184bbb1f 117 else {
cvitas 4:4620184bbb1f 118 header_read=0x20; // write output pattern
cvitas 4:4620184bbb1f 119 param_ads = 2; // parameter to write
cvitas 4:4620184bbb1f 120
cvitas 4:4620184bbb1f 121
cvitas 4:4620184bbb1f 122 } // else
cvitas 4:4620184bbb1f 123 } // while(1)
cvitas 4:4620184bbb1f 124 } //main