Programski_zadatak_23

Dependencies:   Display1602 mbed nRF24L01P

Committer:
DorijanMacek
Date:
Sat Jan 23 18:06:49 2016 +0000
Revision:
1:3213ce6cd7e1
Parent:
0:e67a9248e8f8
Child:
2:698c8f9140e6
temp radi volt radi zajedno ne

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 1:3213ce6cd7e1 15 float temp(int ,int, int );
DorijanMacek 1:3213ce6cd7e1 16 float voltage(int ,int , int);
DorijanMacek 1:3213ce6cd7e1 17
DorijanMacek 1:3213ce6cd7e1 18
DorijanMacek 1:3213ce6cd7e1 19
DorijanMacek 1:3213ce6cd7e1 20
DorijanMacek 1:3213ce6cd7e1 21 int main()
DorijanMacek 1:3213ce6cd7e1 22 {
DorijanMacek 1:3213ce6cd7e1 23
DorijanMacek 0:e67a9248e8f8 24
DorijanMacek 1:3213ce6cd7e1 25 display.SetXY(0,0);
DorijanMacek 1:3213ce6cd7e1 26 display.Print("Glupost je ");
DorijanMacek 1:3213ce6cd7e1 27 display.SetXY(0,1);
DorijanMacek 1:3213ce6cd7e1 28 display.Print("neunistiva!!!");
DorijanMacek 1:3213ce6cd7e1 29
DorijanMacek 1:3213ce6cd7e1 30 float t,v;
DorijanMacek 1:3213ce6cd7e1 31
DorijanMacek 1:3213ce6cd7e1 32
DorijanMacek 1:3213ce6cd7e1 33
DorijanMacek 1:3213ce6cd7e1 34 while(1)
DorijanMacek 1:3213ce6cd7e1 35 {
DorijanMacek 1:3213ce6cd7e1 36 wait(1);
DorijanMacek 1:3213ce6cd7e1 37 t=temp(0xC0,0x55,0x94);
DorijanMacek 1:3213ce6cd7e1 38 wait(1);
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 1:3213ce6cd7e1 46 display.printf("Temp = %.1f degC", t); // print on screen
DorijanMacek 1:3213ce6cd7e1 47 //display.SetXY(0,1);
DorijanMacek 1:3213ce6cd7e1 48 //display.printf("Voltage = %.1f 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 1:3213ce6cd7e1 55 float temp(int config_t0,int config_t1, int addr)
DorijanMacek 1:3213ce6cd7e1 56 {
DorijanMacek 1:3213ce6cd7e1 57 float temp;
DorijanMacek 1:3213ce6cd7e1 58 char config_t[2]; // transmitt buffer
DorijanMacek 1:3213ce6cd7e1 59 char temp_read[2]; // read buffer
DorijanMacek 1:3213ce6cd7e1 60 config_t[0] = config_t0; //0xC1; //config slave to int temp
DorijanMacek 1:3213ce6cd7e1 61 config_t[1] = config_t1; //0x55; // config data byte1, BOut
DorijanMacek 1:3213ce6cd7e1 62
DorijanMacek 1:3213ce6cd7e1 63 MSP430G.write(addr, config_t, 2);
DorijanMacek 1:3213ce6cd7e1 64 wait_us(20);
DorijanMacek 1:3213ce6cd7e1 65
DorijanMacek 1:3213ce6cd7e1 66 MSP430G.read(addr, temp_read, 2); //read the two-byte temp data
DorijanMacek 1:3213ce6cd7e1 67 temp = temp_read[0]+temp_read[1]*256;
DorijanMacek 1:3213ce6cd7e1 68 temp=temp/10;
DorijanMacek 1:3213ce6cd7e1 69 return temp;
DorijanMacek 1:3213ce6cd7e1 70 }
DorijanMacek 1:3213ce6cd7e1 71
DorijanMacek 1:3213ce6cd7e1 72 float voltage(int config_v0,int config_v1, int addr)
DorijanMacek 1:3213ce6cd7e1 73 {
DorijanMacek 1:3213ce6cd7e1 74 float volts;
DorijanMacek 1:3213ce6cd7e1 75 char config_v[2]; // transmitt buffer
DorijanMacek 1:3213ce6cd7e1 76 char volt_read[2]; // read buffer
DorijanMacek 1:3213ce6cd7e1 77 config_v[0] = config_v0; //0xC1; //config slave to int temp
DorijanMacek 1:3213ce6cd7e1 78 config_v[1] = config_v1; //0x55; // config data byte1, BOut
DorijanMacek 1:3213ce6cd7e1 79
DorijanMacek 1:3213ce6cd7e1 80 MSP430G.write(addr, config_v, 2);
DorijanMacek 1:3213ce6cd7e1 81 wait_us(20);
DorijanMacek 1:3213ce6cd7e1 82
DorijanMacek 1:3213ce6cd7e1 83 MSP430G.read(addr, volt_read, 2); //read the two-byte temp data
DorijanMacek 1:3213ce6cd7e1 84 volts = volt_read[0]+volt_read[1]*256;
DorijanMacek 1:3213ce6cd7e1 85
DorijanMacek 1:3213ce6cd7e1 86 return volts;
DorijanMacek 1:3213ce6cd7e1 87 }