Programski_zadatak_23

Dependencies:   Display1602 mbed nRF24L01P

Committer:
DorijanMacek
Date:
Sat Jan 23 20:12:32 2016 +0000
Revision:
2:698c8f9140e6
Parent:
1:3213ce6cd7e1
Child:
3:77408dbd520c
radi oboje  iduce tickeri

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DorijanMacek 0:e67a9248e8f8 1 #include "mbed.h"
DorijanMacek 1:3213ce6cd7e1 2 #include "Display1602.h"
DorijanMacek 1:3213ce6cd7e1 3 //#include "nRF24L01P.h"
DorijanMacek 1:3213ce6cd7e1 4 I2C MSP430G(p9, p10); //sda, sc1
DorijanMacek 1:3213ce6cd7e1 5 //nRF24L01P odasiljac(p11,p12,p13,p14,p28,p27);
DorijanMacek 1:3213ce6cd7e1 6 //AnalogIn speed(p15);
DorijanMacek 1:3213ce6cd7e1 7 //AnalogIn direction(p26);
DorijanMacek 1:3213ce6cd7e1 8 Display1602 display(p19, p20, p21, p22, p23, p24,p25,p26,p29,p30,p18);
DorijanMacek 1:3213ce6cd7e1 9
DorijanMacek 1:3213ce6cd7e1 10
DorijanMacek 0:e67a9248e8f8 11
DorijanMacek 1:3213ce6cd7e1 12 Serial pc(USBTX, USBRX); //tx, rx
DorijanMacek 1:3213ce6cd7e1 13
DorijanMacek 1:3213ce6cd7e1 14 //void start();
DorijanMacek 2:698c8f9140e6 15 float readTempAndVoltage(int ,int, int , int);
DorijanMacek 1:3213ce6cd7e1 16
DorijanMacek 1:3213ce6cd7e1 17 int main()
DorijanMacek 1:3213ce6cd7e1 18 {
DorijanMacek 1:3213ce6cd7e1 19
DorijanMacek 0:e67a9248e8f8 20
DorijanMacek 1:3213ce6cd7e1 21 display.SetXY(0,0);
DorijanMacek 1:3213ce6cd7e1 22 display.Print("Glupost je ");
DorijanMacek 1:3213ce6cd7e1 23 display.SetXY(0,1);
DorijanMacek 1:3213ce6cd7e1 24 display.Print("neunistiva!!!");
DorijanMacek 1:3213ce6cd7e1 25
DorijanMacek 1:3213ce6cd7e1 26 float t,v;
DorijanMacek 1:3213ce6cd7e1 27
DorijanMacek 1:3213ce6cd7e1 28
DorijanMacek 1:3213ce6cd7e1 29
DorijanMacek 1:3213ce6cd7e1 30 while(1)
DorijanMacek 1:3213ce6cd7e1 31 {
DorijanMacek 2:698c8f9140e6 32 wait(0.1);
DorijanMacek 2:698c8f9140e6 33 t=readTempAndVoltage(0xC0,0x55,0x94,0);//55
DorijanMacek 2:698c8f9140e6 34 wait(0.1);
DorijanMacek 2:698c8f9140e6 35 v=readTempAndVoltage(0xC1,0xff,0x94,1);//55
DorijanMacek 2:698c8f9140e6 36
DorijanMacek 2:698c8f9140e6 37 //v=readTempAndVoltage(0xC1,0x55,0x94,1);
DorijanMacek 2:698c8f9140e6 38
DorijanMacek 1:3213ce6cd7e1 39 //v=voltage(0xC1,0x55,0x94) ;
DorijanMacek 1:3213ce6cd7e1 40
DorijanMacek 1:3213ce6cd7e1 41
DorijanMacek 1:3213ce6cd7e1 42
DorijanMacek 1:3213ce6cd7e1 43
DorijanMacek 1:3213ce6cd7e1 44 display.Clear();
DorijanMacek 1:3213ce6cd7e1 45 display.SetXY(0,0);
DorijanMacek 2:698c8f9140e6 46 display.printf("Temp = %.2f C", t); // print on screen
DorijanMacek 2:698c8f9140e6 47 display.SetXY(0,1);
DorijanMacek 2:698c8f9140e6 48 display.printf("Voltage = %.2f V", v); // print on screen//wait(1);
DorijanMacek 1:3213ce6cd7e1 49 //display.SetXY(0,1);
DorijanMacek 1:3213ce6cd7e1 50 //display.printf("Voltage = %.1f V", voltage(0xC1,0x55,0x94)); // print on screen
DorijanMacek 1:3213ce6cd7e1 51
DorijanMacek 0:e67a9248e8f8 52 }
DorijanMacek 0:e67a9248e8f8 53 }
DorijanMacek 1:3213ce6cd7e1 54
DorijanMacek 2:698c8f9140e6 55 float readTempAndVoltage(int config_b0,int config_b1, int addr, int mode)
DorijanMacek 1:3213ce6cd7e1 56 {
DorijanMacek 1:3213ce6cd7e1 57 char config_t[2]; // transmitt buffer
DorijanMacek 2:698c8f9140e6 58 char value_read[2]; // read buffer
DorijanMacek 2:698c8f9140e6 59
DorijanMacek 1:3213ce6cd7e1 60
DorijanMacek 1:3213ce6cd7e1 61 MSP430G.write(addr, config_t, 2);
DorijanMacek 1:3213ce6cd7e1 62 wait_us(20);
DorijanMacek 1:3213ce6cd7e1 63
DorijanMacek 2:698c8f9140e6 64 if (mode==0)
DorijanMacek 2:698c8f9140e6 65 {
DorijanMacek 2:698c8f9140e6 66 float temp;
DorijanMacek 2:698c8f9140e6 67 config_t[0] = config_b0; //0xC1; //config slave to int temp
DorijanMacek 2:698c8f9140e6 68 config_t[1] = config_b1; //0x55; // config data byte1, BOut
DorijanMacek 2:698c8f9140e6 69 MSP430G.read(addr, value_read, 2); //read the two-byte temp data
DorijanMacek 2:698c8f9140e6 70 temp = value_read[0]+value_read[1]*256;
DorijanMacek 2:698c8f9140e6 71 temp=temp/10.;
DorijanMacek 2:698c8f9140e6 72 return temp;
DorijanMacek 2:698c8f9140e6 73 }
DorijanMacek 2:698c8f9140e6 74 else if(mode==1)
DorijanMacek 2:698c8f9140e6 75 {
DorijanMacek 2:698c8f9140e6 76 float voltage;
DorijanMacek 2:698c8f9140e6 77 config_t[0] = config_b0; //0xC1; //config slave to int temp
DorijanMacek 2:698c8f9140e6 78 config_t[1] = config_b1; //0x55; // config data byte1, BOut
DorijanMacek 2:698c8f9140e6 79 MSP430G.read(addr, value_read, 2); //read the two-byte temp data
DorijanMacek 2:698c8f9140e6 80 voltage = value_read[0]+value_read[1]*256;
DorijanMacek 2:698c8f9140e6 81 voltage = 1.5 * (voltage / 1023);
DorijanMacek 2:698c8f9140e6 82 return voltage;
DorijanMacek 2:698c8f9140e6 83 }
DorijanMacek 2:698c8f9140e6 84 else
DorijanMacek 2:698c8f9140e6 85 return 0;
DorijanMacek 1:3213ce6cd7e1 86
DorijanMacek 2:698c8f9140e6 87 }