aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rwxr-xr-x[-rw-r--r--]board.c4
-rwxr-xr-x[-rw-r--r--]board.h12
-rwxr-xr-x[-rw-r--r--]delay.c15
-rwxr-xr-x[-rw-r--r--]delay.h2
-rwxr-xr-x[-rw-r--r--]i2c.c0
-rwxr-xr-x[-rw-r--r--]i2c.h0
-rwxr-xr-xlcd.c61
-rwxr-xr-xlcd.h6
-rwxr-xr-x[-rw-r--r--]main.c26
-rwxr-xr-x[-rw-r--r--]temp.c15
-rwxr-xr-x[-rw-r--r--]temp.h2
12 files changed, 124 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index f56590a..a472005 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,7 @@ CFLAGS = -mmcu=msp430g2553 -std=gnu99 \
CSRC = board.c \
delay.c \
i2c.c \
+ lcd.c \
temp.c \
main.c
COBJ = $(patsubst %.c, %.o, $(CSRC))
diff --git a/board.c b/board.c
index 27af0da..769d1db 100644..100755
--- a/board.c
+++ b/board.c
@@ -25,6 +25,10 @@ static void boardInitPins(void);
void boardInit(void)
{
+ // Slow down needed for LCD
+ BCSCTL1 = CALBC1_1MHZ;
+ DCOCTL = CALDCO_1MHZ;
+
boardInitWatchdog();
boardInitPins();
}
diff --git a/board.h b/board.h
index abbc952..7c796a8 100644..100755
--- a/board.h
+++ b/board.h
@@ -25,19 +25,19 @@
#include <stdint.h>
// Port 1 pins
-#define LED (1 << 0)
+#define LCD_DATL (0x0F)
+#define LCD_RW (1 << 4)
+#define LCD_RS (1 << 5)
#define TEMP_SCL (1 << 6)
#define TEMP_SDA (1 << 7)
-#define PORT1_PINS (LED | TEMP_SCL | TEMP_SDA)
+#define PORT1_PINS (LCD_DATL | LCD_RW | LCD_RS | TEMP_SCL | TEMP_SDA)
// Port 2 pins
-#define LCD_DAT (0x0F)
+#define LCD_DATH (0x0F)
#define LCD_E (1 << 4)
-#define LCD_RW (1 << 5)
-#define LCD_RS (1 << 6)
-#define PORT2_PINS (LCD_DAT | LCD_E | LCD_RW | LCD_RS)
+#define PORT2_PINS (LCD_DATH | LCD_E)
/**
* Initializes pins and core functionality.
diff --git a/delay.c b/delay.c
index a259fe3..05960e6 100644..100755
--- a/delay.c
+++ b/delay.c
@@ -20,18 +20,23 @@
#include "board.h"
-static unsigned int delayTicks = 0;
+volatile unsigned int delayTicks = 0;
void delayInit(void)
{
TACCTL0 |= CCIE;
- TACCR0 = 1000;
- TACTL |= TASSEL_1 | MC_1;
+ TACCR0 = 128;
+ TACTL |= TASSEL_2 | MC_1 | ID_3;
+}
+
+void delay(unsigned int ms)
+{
+ unsigned int target = delayTicks + ms;
+ while (delayTicks < target);
}
__attribute__((__interrupt__(TIMER0_A0_VECTOR)))
static void delayInterruptHandler(void)
{
- P1OUT ^= LED;
- delayTicks++;
+ delayTicks++;
}
diff --git a/delay.h b/delay.h
index 1a46286..f806a76 100644..100755
--- a/delay.h
+++ b/delay.h
@@ -23,5 +23,7 @@
void delayInit(void);
+void delay(unsigned int ms);
+
#endif // DELAY_H_
diff --git a/i2c.c b/i2c.c
index a10141c..a10141c 100644..100755
--- a/i2c.c
+++ b/i2c.c
diff --git a/i2c.h b/i2c.h
index 987d109..987d109 100644..100755
--- a/i2c.h
+++ b/i2c.h
diff --git a/lcd.c b/lcd.c
new file mode 100755
index 0000000..3405782
--- /dev/null
+++ b/lcd.c
@@ -0,0 +1,61 @@
+#include "board.h"
+#include "delay.h"
+#include "lcd.h"
+
+static void lcdPulseE(void);
+static void lcdSetDAT(uint8_t value);
+static void lcdSendCommand(uint8_t command);
+static void lcdSendData(uint8_t data);
+
+void lcdInit(void)
+{
+ // Give time for LCD to prepare itself
+ delay(100);
+ lcdSendCommand(0x38);
+ lcdSendCommand(0x10);
+ lcdSendCommand(0x0D);
+ delay(5);
+ lcdClear();
+}
+
+void lcdClear(void)
+{
+ lcdSendCommand(0x01);
+ delay(2);
+}
+
+void lcdPuts(const char *s)
+{
+ lcdSendCommand(0x06);
+ while (*s != '\0')
+ lcdSendData(*s++);
+}
+
+void lcdPulseE(void)
+{
+ P2OUT |= LCD_E;
+ delay(2);
+ P2OUT &= ~(LCD_E);
+}
+
+void lcdSetDAT(uint8_t value)
+{
+ P2OUT &= ~(LCD_DATH);
+ P2OUT |= (value >> 4) & LCD_DATH;
+ P1OUT &= ~(LCD_DATL);
+ P1OUT |= value & LCD_DATL;
+}
+
+void lcdSendCommand(uint8_t command)
+{
+ P1OUT &= ~(LCD_RS);
+ lcdSetDAT(command);
+ lcdPulseE();
+}
+
+void lcdSendData(uint8_t data)
+{
+ P1OUT |= LCD_RS;
+ lcdSetDAT(data);
+ lcdPulseE();
+}
diff --git a/lcd.h b/lcd.h
new file mode 100755
index 0000000..134652d
--- /dev/null
+++ b/lcd.h
@@ -0,0 +1,6 @@
+
+void lcdInit(void);
+
+void lcdClear(void);
+void lcdPuts(const char *s);
+
diff --git a/main.c b/main.c
index 8a4b74a..3cab384 100644..100755
--- a/main.c
+++ b/main.c
@@ -20,20 +20,36 @@
#include "board.h"
#include "delay.h"
+#include "lcd.h"
#include "temp.h"
-void main(void)
+#include <stdio.h>
+
+int main(void)
{
// Prepare processor and IO
boardInit();
delayInit();
+ _NOP();
__enable_interrupt();
- // Prepare temperature sensor
- //if (tempInit() != 0)
- // while (1); // Sensor error, halt
+ lcdInit();
+
+ if (tempInit() != 0) {
+ lcdPuts("Sensor broken.");
+ while (1);
+ }
+
+ char buf[8];
+ while (1) {
+ lcdClear();
+ int16_t temp = tempGetDieTemperature();
+ sprintf(buf, "%04d", temp);
+ lcdPuts(buf);
+ delay(1000);
+ }
- while (1);
+ return 0;
}
diff --git a/temp.c b/temp.c
index 95b74f7..e094d6f 100644..100755
--- a/temp.c
+++ b/temp.c
@@ -55,13 +55,20 @@ int tempInit(void)
TMP006_CFG_16SAMPLE);
// Check that the device is in fact the TMP006
- if (tempI2CRead(TMP006_MANID) != 0x5449 ||
- tempI2CRead(TMP006_DEVID) != 0x67)
- return -1;
+ uint16_t manid = tempI2CRead(TMP006_MANID);
+ uint16_t devid = tempI2CRead(TMP006_DEVID);
+ if (manid != 0x5449 || devid != 0x67)
+ return 1;
return 0;
}
+int16_t tempGetDieTemperature(void)
+{
+ int16_t raw = tempI2CRead(TMP006_TAMB);
+ return (raw >> 2) / 32;
+}
+
void tempI2CWrite(uint8_t reg, uint16_t value)
{
uint8_t data[3] = {
@@ -80,6 +87,6 @@ uint16_t tempI2CRead(uint8_t reg)
};
I2C_write(1, data);
I2C_read(2, data);
- return *((uint16_t *)data);
+ return (data[0] << 8) | data[1];
}
diff --git a/temp.h b/temp.h
index 184becd..aec66c9 100644..100755
--- a/temp.h
+++ b/temp.h
@@ -27,5 +27,7 @@
*/
int tempInit(void);
+int16_t tempGetDieTemperature(void);
+
#endif // TEMP_H_