Real Time Lab Program

Dependencies:   C12832_lcd mbed

Committer:
robt
Date:
Sun Jan 25 16:30:48 2015 +0000
Revision:
0:bc00a9403da0
Real Time Lab Program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:bc00a9403da0 1 #include "mbed.h"
robt 0:bc00a9403da0 2 #include "C12832_lcd.h"
robt 0:bc00a9403da0 3
robt 0:bc00a9403da0 4 C12832_LCD lcd;
robt 0:bc00a9403da0 5 I2C i2c(p28, p27);
robt 0:bc00a9403da0 6
robt 0:bc00a9403da0 7 const int addr = 0x90;
robt 0:bc00a9403da0 8
robt 0:bc00a9403da0 9 int main() {
robt 0:bc00a9403da0 10 char cmd[2];
robt 0:bc00a9403da0 11 while (1) {
robt 0:bc00a9403da0 12 cmd[0] = 0x01;
robt 0:bc00a9403da0 13 cmd[1] = 0x00;
robt 0:bc00a9403da0 14 i2c.write(addr, cmd, 2);
robt 0:bc00a9403da0 15
robt 0:bc00a9403da0 16 wait(0.5);
robt 0:bc00a9403da0 17
robt 0:bc00a9403da0 18 cmd[0] = 0x00;
robt 0:bc00a9403da0 19 i2c.write(addr, cmd, 1);
robt 0:bc00a9403da0 20 i2c.read(addr, cmd, 2);
robt 0:bc00a9403da0 21
robt 0:bc00a9403da0 22 float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
robt 0:bc00a9403da0 23 lcd.locate(2,5);
robt 0:bc00a9403da0 24 lcd.printf("Temperature = %.2f degC", tmp);
robt 0:bc00a9403da0 25 }
robt 0:bc00a9403da0 26 }