Morimoto Nozomi
/
digimatic
Mitutoyo ABS Digimatic Caliper Digital Read Out
main.cpp@0:b3cb4a71da01, 2011-10-20 (annotated)
- Committer:
- morimoto
- Date:
- Thu Oct 20 14:23:48 2011 +0000
- Revision:
- 0:b3cb4a71da01
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
morimoto | 0:b3cb4a71da01 | 1 | #include "mbed.h" |
morimoto | 0:b3cb4a71da01 | 2 | #include "TextLCD.h" |
morimoto | 0:b3cb4a71da01 | 3 | |
morimoto | 0:b3cb4a71da01 | 4 | TextLCD mylcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7 |
morimoto | 0:b3cb4a71da01 | 5 | |
morimoto | 0:b3cb4a71da01 | 6 | volatile int n; |
morimoto | 0:b3cb4a71da01 | 7 | int Raw_data[52]; |
morimoto | 0:b3cb4a71da01 | 8 | |
morimoto | 0:b3cb4a71da01 | 9 | DigitalOut REQUEST(p20); |
morimoto | 0:b3cb4a71da01 | 10 | DigitalIn DATA(p9); |
morimoto | 0:b3cb4a71da01 | 11 | InterruptIn CLOCK(p17); |
morimoto | 0:b3cb4a71da01 | 12 | |
morimoto | 0:b3cb4a71da01 | 13 | void trigger() { //interrupt when CLOCK falled |
morimoto | 0:b3cb4a71da01 | 14 | Raw_data[n] = DATA.read(); |
morimoto | 0:b3cb4a71da01 | 15 | n++; |
morimoto | 0:b3cb4a71da01 | 16 | } |
morimoto | 0:b3cb4a71da01 | 17 | |
morimoto | 0:b3cb4a71da01 | 18 | |
morimoto | 0:b3cb4a71da01 | 19 | int main() { |
morimoto | 0:b3cb4a71da01 | 20 | int Y; |
morimoto | 0:b3cb4a71da01 | 21 | int Measured_Data[6]; |
morimoto | 0:b3cb4a71da01 | 22 | int Decimal_point; |
morimoto | 0:b3cb4a71da01 | 23 | double temp_data , Indicate; |
morimoto | 0:b3cb4a71da01 | 24 | |
morimoto | 0:b3cb4a71da01 | 25 | while(1){ |
morimoto | 0:b3cb4a71da01 | 26 | wait(0.03); |
morimoto | 0:b3cb4a71da01 | 27 | n=0; |
morimoto | 0:b3cb4a71da01 | 28 | |
morimoto | 0:b3cb4a71da01 | 29 | REQUEST.write(1); |
morimoto | 0:b3cb4a71da01 | 30 | CLOCK.fall(&trigger); |
morimoto | 0:b3cb4a71da01 | 31 | |
morimoto | 0:b3cb4a71da01 | 32 | while(1){ |
morimoto | 0:b3cb4a71da01 | 33 | if(n>52) break; //number of data |
morimoto | 0:b3cb4a71da01 | 34 | } |
morimoto | 0:b3cb4a71da01 | 35 | |
morimoto | 0:b3cb4a71da01 | 36 | CLOCK.fall(NULL); |
morimoto | 0:b3cb4a71da01 | 37 | REQUEST.write(0); |
morimoto | 0:b3cb4a71da01 | 38 | |
morimoto | 0:b3cb4a71da01 | 39 | Y=20; |
morimoto | 0:b3cb4a71da01 | 40 | for(int i=0;i<=5;i++){ //Raw_data[20]-[43] is Measured_Data |
morimoto | 0:b3cb4a71da01 | 41 | Measured_Data[i] = Raw_data[Y+3]*pow(2.0,3) + Raw_data[Y+2]*pow(2.0,2) + Raw_data[Y+1]*pow(2.0,1) + Raw_data[Y]; |
morimoto | 0:b3cb4a71da01 | 42 | Y=Y+4; |
morimoto | 0:b3cb4a71da01 | 43 | } |
morimoto | 0:b3cb4a71da01 | 44 | |
morimoto | 0:b3cb4a71da01 | 45 | Decimal_point = Raw_data[Y+3]*pow(2.0,3)+ Raw_data[Y+2]*pow(2.0,2) +Raw_data[Y+1]*pow(2.0,1)+ Raw_data[Y]; ///Raw_data[44]-[47] is Decimal_point |
morimoto | 0:b3cb4a71da01 | 46 | |
morimoto | 0:b3cb4a71da01 | 47 | temp_data = Measured_Data[0]*100000 + Measured_Data[1]*10000 + Measured_Data[2]*1000 + Measured_Data[3]*100 + Measured_Data[4]*10 + Measured_Data[5]; |
morimoto | 0:b3cb4a71da01 | 48 | |
morimoto | 0:b3cb4a71da01 | 49 | if (Raw_data[19]==1) //19 is Sign. 0 is '+' , 1 is '-' |
morimoto | 0:b3cb4a71da01 | 50 | temp_data = -1* temp_data; |
morimoto | 0:b3cb4a71da01 | 51 | |
morimoto | 0:b3cb4a71da01 | 52 | Indicate = temp_data /pow(10.0,Decimal_point); |
morimoto | 0:b3cb4a71da01 | 53 | |
morimoto | 0:b3cb4a71da01 | 54 | mylcd.cls(); |
morimoto | 0:b3cb4a71da01 | 55 | mylcd.printf("%7.2f", Indicate); |
morimoto | 0:b3cb4a71da01 | 56 | |
morimoto | 0:b3cb4a71da01 | 57 | if(Raw_data[48]==0) |
morimoto | 0:b3cb4a71da01 | 58 | mylcd.printf("mm"); |
morimoto | 0:b3cb4a71da01 | 59 | else |
morimoto | 0:b3cb4a71da01 | 60 | mylcd.printf("inch"); |
morimoto | 0:b3cb4a71da01 | 61 | } |
morimoto | 0:b3cb4a71da01 | 62 | } |