Use this version as starting point. Tested on Show2Me_V1 PCB (minor patches required).

Dependencies:   GPS Library QEI SDFileSystem mbed

Files at this revision

API Documentation at this revision

Comitter:
walter76
Date:
Mon Sep 03 01:54:41 2018 +0000
Commit message:
working code, initial version

Changed in this revision

GPS-Library.lib Show annotated file Show diff for this revision Revisions of this file
QEI.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
ST7565_LCD/ST7565_LCD.cpp Show annotated file Show diff for this revision Revisions of this file
ST7565_LCD/ST7565_LCD.h Show annotated file Show diff for this revision Revisions of this file
ST7565_LCD/font_5x7.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS-Library.lib	Mon Sep 03 01:54:41 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/nliu96/code/GPS-Library/#120983998da2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Mon Sep 03 01:54:41 2018 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Mon Sep 03 01:54:41 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Geo-Electronics-Show2Me/code/SDFileSystem/#2569592e758c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ST7565_LCD/ST7565_LCD.cpp	Mon Sep 03 01:54:41 2018 +0000
@@ -0,0 +1,445 @@
+
+
+#include "mbed.h"
+#include "ST7565_LCD.h"
+#include "font_5x7.h"
+
+unsigned int lcd_orientation, lcd_width, lcd_height;
+unsigned int p_size, p_x, p_y, p_bg, p_fg;
+
+//extern const unsigned short font_PGM[];
+
+int pagemap[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
+/*
+// CAUTION HIGH VOLTAGE
+unsigned int buffer[128*64/8] = { 
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x80, 0xE0, 0xF8, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0,
+0xF8, 0x0C, 0x04, 0x04, 0x04, 0x0C, 0x08, 0x00, 0x80, 0xF0, 0x7C, 0x0C, 0x7C, 0xF0, 0x80, 0x00,
+0x00, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0xFC, 0xFC, 0x00, 0x04, 0x04, 0x04, 0xFC, 0xFC, 0x04, 0x04,
+0x04, 0x00, 0xFC, 0xFC, 0x00, 0x00, 0xF0, 0xF8, 0x0C, 0x04, 0x04, 0x0C, 0xF8, 0xF0, 0x00, 0x00,
+0xFC, 0xFC, 0x38, 0xE0, 0x80, 0xFC, 0xFC, 0x00, 0x00, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0xFC, 0xFF,
+0xFF, 0x3F, 0x0F, 0x07, 0x01, 0x00, 0x01, 0x07, 0x0F, 0x3F, 0xFF, 0xFE, 0xFC, 0xF0, 0xC0, 0x80,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
+0x07, 0x0C, 0x08, 0x08, 0x08, 0x0C, 0x04, 0x0C, 0x0F, 0x03, 0x02, 0x02, 0x02, 0x03, 0x0F, 0x0C,
+0x00, 0x07, 0x0F, 0x08, 0x08, 0x08, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00,
+0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0C, 0x08, 0x08, 0x0C, 0x07, 0x03, 0x00, 0x00,
+0x0F, 0x0F, 0x00, 0x00, 0x03, 0x0F, 0x0F, 0x00, 0x00, 0x0D, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xF8, 0xFE, 0xFF, 0x7F, 0x1F, 0x07, 0x01,
+0x00, 0x80, 0xF8, 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0x3C, 0x00, 0x00, 0x01, 0x07, 0x1F, 0x3F, 0xFF,
+0xFE, 0xF8, 0xF0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0xFF, 0xFF, 0x10, 0x10, 0x10, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFC, 0xFE, 0x03,
+0x01, 0x21, 0x21, 0xE3, 0xE2, 0x00, 0x00, 0xFF, 0xFF, 0x10, 0x10, 0x10, 0xFF, 0xFF, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0xC0, 0xE0, 0xF8, 0xFE, 0xFF, 0x7F, 0x1F, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0xC0,
+0xFC, 0xFF, 0xFF, 0xFF, 0x7F, 0x1F, 0x07, 0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00,
+0x03, 0x07, 0x1F, 0x7F, 0xFF, 0xFE, 0xF8, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x80, 0xC0, 0x40, 0x40,
+0xC3, 0x83, 0x00, 0x00, 0x00, 0xC3, 0xC3, 0x00, 0x00, 0x03, 0x03, 0x00, 0x40, 0x40, 0x41, 0xC3,
+0xC2, 0x42, 0x42, 0x43, 0x01, 0x00, 0x00, 0xC3, 0xC3, 0xC0, 0x00, 0x00, 0x03, 0x03, 0x00, 0x80,
+0xC0, 0x40, 0x40, 0x40, 0xC0, 0x80, 0x00, 0x00, 0xC0, 0xC0, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF8,
+0xFC, 0xFF, 0x7F, 0x3F, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFC, 0x7F,
+0x7F, 0x3F, 0x3F, 0x1F, 0x1C, 0x0E, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x07, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F, 0x1F, 0x7F, 0xFF, 0xFC, 0xF8, 0xE0, 0x80, 0x00, 0x00,
+0x00, 0x00, 0x07, 0x3F, 0xF8, 0xC0, 0xF8, 0x3F, 0x07, 0x00, 0x00, 0x3F, 0x7F, 0xC0, 0x80, 0x80,
+0xC0, 0x7F, 0x3F, 0x00, 0x00, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0xFF,
+0xFF, 0x00, 0x00, 0x00, 0xC0, 0xF8, 0x3F, 0x27, 0x20, 0x27, 0x3F, 0xF8, 0xC0, 0x00, 0x3F, 0x7F,
+0xC0, 0x80, 0x88, 0x88, 0xF8, 0x78, 0x00, 0x00, 0xFF, 0xFF, 0x84, 0x84, 0x84, 0x84, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xF0, 0xFC, 0xFE, 0xFF, 0x3F, 0x1F,
+0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x80, 0x80, 0x00, 0xFC, 0xFF, 0xFF, 0x3F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x0F, 0x3F, 0x7F, 0xFF, 0xFC,
+0xF0, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xF8, 0xFE, 0xFF, 0x7F, 0x1F, 0x07, 0x03, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x01, 0x0F, 0xFF, 0xFF, 0x3F, 0x0F, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07,
+0x0F, 0x3F, 0xFF, 0xFF, 0xFC, 0xF0, 0xE0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x1E, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C,
+0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C,
+0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C,
+0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C, 0x3C,
+0x3C, 0x3C, 0x3C, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+*/
+
+// GEO ELECTRONICS 2017
+unsigned int buffer[128*64/8] = {
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xC0,
+0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0x30, 0x10, 0x08, 0x08, 0x58, 0x78,
+0x30, 0x00, 0x00, 0xC8, 0xF8, 0xB8, 0xC8, 0xC8, 0x08, 0x18, 0x18, 0x08, 0xC0, 0xE0, 0x30, 0x10,
+0x08, 0x08, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
+0x80, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0xF8, 0x78, 0x3C, 0x1E, 0x1F, 0x0F, 0x0F, 0x0F, 0x0F, 0x1F,
+0x9F, 0xDF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x10, 0x10, 0x19, 0x0D, 0x0F, 0x03, 0x11,
+0x10, 0x9C, 0x9F, 0x93, 0x90, 0x11, 0x19, 0x08, 0x00, 0x00, 0x00, 0x0F, 0x1B, 0x10, 0x10, 0x08,
+0x0C, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF, 0xFF,
+0xFF, 0xFF, 0xFF, 0x7F, 0x0F, 0x07, 0x03, 0x00, 0x00, 0xE0, 0xE0, 0xF8, 0xFC, 0x7E, 0xDE, 0xE0,
+0xF7, 0xFF, 0xFF, 0xFF, 0xFD, 0xFB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF8,
+0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF0, 0xB8, 0x2C, 0x2C, 0xAC, 0x38, 0x00, 0xC0,
+0xF0, 0x3C, 0x0F, 0xC3, 0xF0, 0xB8, 0x2C, 0x2C, 0xAC, 0x38, 0x00, 0xC0, 0xF0, 0xB8, 0x0C, 0x0C,
+0x84, 0x0C, 0xC0, 0xF4, 0x3C, 0x0F, 0x84, 0x04, 0x00, 0xC4, 0xFC, 0x38, 0x0C, 0x04, 0xEC, 0xF0,
+0x98, 0x0C, 0x84, 0xCC, 0x78, 0x00, 0x80, 0xF4, 0x3C, 0x0C, 0xC4, 0x3C, 0x1C, 0x00, 0xC0, 0xF4,
+0x3C, 0x0C, 0xC0, 0xF0, 0xB8, 0x08, 0x0C, 0x84, 0x0C, 0x80, 0xB8, 0x3C, 0xE4, 0xCC, 0x08, 0x00,
+0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0xF7, 0xE3, 0x47, 0x1F,
+0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x81, 0xC6, 0xEF, 0xF7,
+0xF3, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
+0x3F, 0x1F, 0x1F, 0xFC, 0xF0, 0xE0, 0xC0, 0x80, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
+0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
+0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01,
+0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
+0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00,
+0x06, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF, 0xFF, 0x80, 0x00, 0x41, 0xE1, 0xF3, 0xFF, 0xFF, 0xFF, 0xFE,
+0xFE, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x06, 0x1F, 0x3F, 0x7F, 0x7F, 0xFF,
+0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xFD, 0x0D, 0x04, 0x00,
+0x00, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x1E, 0x0C, 0x00, 0x00, 0x00, 0x04, 0x04,
+0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1F, 0x7C, 0xE0, 0x80, 0x01, 0x03, 0xFF, 0xFF, 0xFF,
+0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x77, 0x7B, 0x7D, 0x3E, 0x00, 0x80,
+0xE0, 0x78, 0x3F, 0x0F, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0xC7, 0xEE, 0xFF, 0xFF, 0xFF,
+0xFF, 0xE3, 0xC1, 0xC0, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x01, 0x03, 0x83, 0x83, 0xC3, 0xC3, 0xE1, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xF7, 0xF3,
+0xF1, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03,
+0x03, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x0F, 0x1F, 0x3F, 0x7E, 0xFE, 0xFE, 0x7E, 0x3E, 0x1E,
+0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07,
+0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+ 
+extern const unsigned short font_PGM[];
+
+
+DigitalOut  LCD_RST (D9);     // PC_7 LCD Reset
+DigitalOut  LCD_CS  (D10);    // PB_6 LCD Chip-Select 
+DigitalOut  LCD_SDI (D11);    // PA_7 LCD Serial Data In
+DigitalOut  LCD_A0  (D12);    // PA_6 LCD A0
+DigitalOut  LCD_CLK (D13);    // PA_5 LCD Serial Clock
+
+
+//==============================================================================
+
+void Delay_us(int howmany)
+{
+  int n;
+  Timer t;
+  t.start();
+  do
+  {
+    n=t.read_us();
+  }
+  while (n<= howmany);
+}
+
+
+//==============================================================================
+
+
+void SPI_Write(uint8_t data)
+{
+
+    uint8_t mask;  
+
+    for(mask=0x80; mask!=0; mask>>=1)
+    {
+      LCD_CLK=0;
+      if(mask & data)
+        LCD_SDI=1;
+        
+      else
+        LCD_SDI=0;
+        
+      LCD_CLK=1;
+      
+    }
+    LCD_CLK=0;
+
+    return;
+}
+
+
+//==============================================================================
+
+void LCD_cmd(uint8_t command)
+{
+  
+  LCD_A0=0;
+  
+  LCD_CS=0;
+  SPI_Write(command);
+  LCD_CS=1;
+
+  return;
+}
+
+
+//==============================================================================
+
+void LCD_data(uint8_t data)
+{
+  LCD_A0=1;
+  
+  LCD_CS=0;
+  SPI_Write(data);
+  LCD_CS=1;
+  
+  return;
+}
+
+
+
+//==============================================================================
+
+void LCD_clear(void) 
+{
+  unsigned int p, c;
+  
+  for(p = 0; p < 8; p++) 
+  {
+    LCD_cmd(CMD_SET_PAGE | p);
+    for(c = 0; c < 128; c++) 
+    {
+      LCD_cmd(CMD_SET_COLUMN_LOWER | (c & 0xf));
+      LCD_cmd(CMD_SET_COLUMN_UPPER | ((c >> 4) & 0xf));
+      LCD_data(0x0);
+    }     
+  }
+  
+  return;
+}
+
+
+//==============================================================================
+
+
+void LCD_reset(void)
+{
+
+  // toggle RST low to reset; CS high
+  LCD_CS=1;
+  LCD_RST=0;    
+  wait(0.01);
+  LCD_RST=1;  
+
+  LCD_cmd(CMD_SET_BIAS_7);  // LCD bias select
+  LCD_cmd(CMD_SET_ADC_NORMAL);  // ADC select ===
+  LCD_cmd(CMD_SET_COM_REVERSE);  // SHL select
+  LCD_cmd(CMD_SET_DISP_START_LINE);  // Initial display line  
+  
+  LCD_cmd(CMD_SET_POWER_CONTROL | 0x4);  // turn on voltage converter (VC=1, VR=0, VF=0)
+  wait(0.01);
+  LCD_cmd(CMD_SET_POWER_CONTROL | 0x6);  // turn on voltage regulator (VC=1, VR=1, VF=0)
+  wait(0.01);
+  LCD_cmd(CMD_SET_POWER_CONTROL | 0x7);  // turn on voltage follower (VC=1, VR=1, VF=1)
+  wait(0.01);
+
+  // set lcd operating voltage (regulator resistor, ref voltage resistor)
+  LCD_cmd(CMD_SET_RESISTOR_RATIO | 0x6);
+  
+  LCD_cmd(CMD_DISPLAY_ON);
+  LCD_cmd(CMD_SET_ALLPTS_NORMAL);
+  
+  // set contrast (0x0E for STN, 0x19 for enhanced STN)
+  LCD_cmd(CMD_SET_VOLUME_FIRST);
+  LCD_cmd(CMD_SET_VOLUME_SECOND | (0x09 & 0x3f));
+  LCD_clear();  
+    
+  return;
+}
+
+//==============================================================================
+
+void LCD_write_buffer(unsigned int *buffer) 
+{
+  unsigned int c, p;
+
+  for(p = 0; p < 8; p++) 
+  {
+    LCD_cmd(CMD_SET_PAGE | pagemap[p]);
+    LCD_cmd(CMD_SET_COLUMN_LOWER | (0x0 & 0xf));
+    LCD_cmd(CMD_SET_COLUMN_UPPER | ((0x0 >> 4) & 0xf));
+    LCD_cmd(CMD_RMW);
+    LCD_data(0xFF); // X-axis offset
+    LCD_data(0xFF);
+    LCD_data(0xFF);
+    LCD_data(0xFF);    
+    
+    for(c = 0; c < 128; c++) 
+    {
+      LCD_data(buffer[(128*p)+c]);
+    }
+  }
+  
+  return;
+  
+}
+
+
+
+
+//==============================================================================
+
+void LCD_setpixel(unsigned int *buff, uint8_t x, uint8_t y, uint8_t color) 
+{
+  if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT))
+    return;
+
+  if (color) 
+    buff[x+ (y/8)*128] |= (7-(y%8));  
+  else
+    buff[x+ (y/8)*128] &= ~(7-(y%8)); 
+  
+  return;
+}
+
+
+//==============================================================================
+
+void LCD_clearpixel(unsigned int *buff, uint8_t x, uint8_t y) 
+{
+  if ((x >= LCD_WIDTH) || (y >= LCD_HEIGHT))
+    return;
+  
+  buff[x+ (y/8)*128] &= ~(7-(y%8));
+  
+  return;
+}
+
+
+//==============================================================================
+
+void LCD_drawline(unsigned int *buff, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color) 
+{
+  uint8_t steep = abs(y1 - y0) > abs(x1 - x0);
+
+  if (steep) {
+    swap(x0, y0);
+    swap(x1, y1);
+  }
+
+  if (x0 > x1) {
+    swap(x0, x1);
+    swap(y0, y1);
+  }
+
+  uint8_t dx, dy;
+  dx = x1 - x0;
+  dy = abs(y1 - y0);
+
+  int err = dx / 2;
+  int ystep;
+
+  if (y0 < y1) {
+    ystep = 1;
+  } else {
+    ystep = -1;}
+
+  for (; x0<x1; x0++) {
+    if (steep) {
+      LCD_setpixel(buff, y0, x0, color);
+    } else {
+      LCD_setpixel(buff, x0, y0, color);
+    }
+    err -= dy;
+    if (err < 0) {
+      y0 += ystep;
+      err += dx;
+    }
+  }
+  
+  return;  
+}
+
+
+//==============================================================================
+
+void LCD_drawchar(unsigned int *buff, uint8_t x, uint8_t line, char c) 
+{
+  uint8_t i;
+  
+  for (i =0; i<5; i++ ) 
+  {
+    buff[x + (line*128) ] = font_PGM[((c-32)*5)+i];    
+    x++;
+  }
+  
+  return;
+}
+
+
+//==============================================================================
+// The 128x64 LCD allows 8 rows of 21 chars
+
+void LCD_drawstring(unsigned int *buff, uint8_t x, uint8_t line, char *c) 
+{
+  unsigned int i=0;
+  while (c[i] != 0) 
+  {
+    LCD_drawchar(buff, x, line, c[i]);
+    i++;
+    x += 6; // 6 pixels wide
+    if (x + 6 >= LCD_WIDTH) {
+      x = 0;    // ran out of this line
+      line++;
+    }
+    if (line >= (LCD_HEIGHT/8))
+      return;        // ran out of space :(
+  }
+  
+  return;  
+}
+
+
+//==============================================================================
+
+void Clear_buffer(unsigned int *buff) 
+{
+  unsigned short i;
+  
+  for(i=0; i<1024; i++)
+    buff[i]=0x00;
+  
+  return;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ST7565_LCD/ST7565_LCD.h	Mon Sep 03 01:54:41 2018 +0000
@@ -0,0 +1,77 @@
+/*******************************************************************************
+* File Name          : ST7565_LCD.c
+* Author             : Walter Trovò
+* Date First Issued  : 20/03/2012
+*******************************************************************************/
+
+// ST7565R LCD module driver
+
+#ifndef __ST7565_LCD_H
+#define __ST7565_LCD_H
+
+#include "mbed.h"
+
+// LCD commands and definitions
+
+#define LCD_WIDTH   128
+#define LCD_HEIGHT  64
+
+#define CMD_DISPLAY_OFF   0xAE
+#define CMD_DISPLAY_ON    0xAF
+
+#define CMD_SET_DISP_START_LINE  0x40
+#define CMD_SET_PAGE  0xB0
+
+#define CMD_SET_COLUMN_UPPER  0x10
+#define CMD_SET_COLUMN_LOWER  0x00
+
+#define CMD_SET_ADC_NORMAL  0xA0
+#define CMD_SET_ADC_REVERSE 0xA1
+
+#define CMD_SET_DISP_NORMAL 0xA6
+#define CMD_SET_DISP_REVERSE 0xA7
+
+#define CMD_SET_ALLPTS_NORMAL 0xA4
+#define CMD_SET_ALLPTS_ON  0xA5
+#define CMD_SET_BIAS_9 0xA2 
+#define CMD_SET_BIAS_7 0xA3
+
+#define CMD_RMW  0xE0
+#define CMD_RMW_CLEAR 0xEE
+#define CMD_INTERNAL_RESET  0xE2
+#define CMD_SET_COM_NORMAL  0xC0
+#define CMD_SET_COM_REVERSE  0xC8
+#define CMD_SET_POWER_CONTROL  0x28
+#define CMD_SET_RESISTOR_RATIO  0x20
+#define CMD_SET_VOLUME_FIRST  0x81
+#define CMD_SET_VOLUME_SECOND  0
+#define CMD_SET_STATIC_OFF  0xAC
+#define CMD_SET_STATIC_ON  0xAD
+#define CMD_SET_STATIC_REG  0x0
+#define CMD_SET_BOOSTER_FIRST  0xF8
+#define CMD_SET_BOOSTER_234  0
+#define CMD_SET_BOOSTER_5  1
+#define CMD_SET_BOOSTER_6  3
+#define CMD_NOP  0xE3
+#define CMD_TEST  0xF0
+
+#define swap(a, b) { unsigned short t = a; a = b; b = t; }
+
+// ------------- Functions prototype -----------------
+
+
+void SPI_Write(uint8_t data);
+void LCD_cmd(uint8_t command);
+void LCD_data(uint8_t data);
+void LCD_reset(void);
+void LCD_set_contrast(unsigned int level);
+void LCD_write_buffer(unsigned int *buffer);
+void LCD_clear(void);
+void LCD_setpixel(unsigned int *buff, uint8_t x, uint8_t y, uint8_t color);
+void LCD_clearpixel(unsigned int *buff, uint8_t x, uint8_t y);
+void LCD_drawline(unsigned int *buff, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, uint8_t color);
+void LCD_drawchar(unsigned int *buff, uint8_t x, uint8_t line, char c);
+void LCD_drawstring(unsigned int *buff, uint8_t x, uint8_t line, char *c);
+void Clear_buffer(unsigned int *buff);
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ST7565_LCD/font_5x7.h	Mon Sep 03 01:54:41 2018 +0000
@@ -0,0 +1,101 @@
+
+#ifndef _SDA5708_FONT_5x7_H
+#define _SDA5708_FONT_5x7_H
+
+const unsigned short font_PGM[] = { 
+0x00, 0x00, 0x00, 0x00, 0x00, // space (ASCII 0x20)
+0x00, 0x00, 0x5f, 0x00, 0x00, // ! 
+0x00, 0x07, 0x00, 0x07, 0x00, // " 
+0x14, 0x7f, 0x14, 0x7f, 0x14, // # 
+0x24, 0x2a, 0x7f, 0x2a, 0x12, // $ 
+0xc4, 0xc8, 0x10, 0x26, 0x46, // % 
+0x36, 0x49, 0x55, 0x22, 0x50, // & 
+0x00, 0x05, 0x03, 0x00, 0x00, // ' 
+0x00, 0x1c, 0x22, 0x41, 0x00, // ( 
+0x00, 0x41, 0x22, 0x1c, 0x00, // ) ????
+0x14, 0x08, 0x3E, 0x08, 0x14, // * 
+0x08, 0x08, 0x3E, 0x08, 0x08, // + 
+0x00, 0x00, 0x50, 0x30, 0x00, // , 
+0x08, 0x08, 0x08, 0x08, 0x08, // - 
+0x00, 0x60, 0x60, 0x00, 0x00, // . 
+0x20, 0x10, 0x08, 0x04, 0x02, // / 
+0x3E, 0x51, 0x49, 0x45, 0x3E, // 0 
+0x00, 0x42, 0x7F, 0x40, 0x00, // 1 
+0x42, 0x61, 0x51, 0x49, 0x46, // 2 
+0x21, 0x41, 0x45, 0x4B, 0x31, // 3 
+0x18, 0x14, 0x12, 0x7F, 0x10, // 4 
+0x27, 0x45, 0x45, 0x45, 0x39, // 5 
+0x3C, 0x4A, 0x49, 0x49, 0x30, // 6 
+0x01, 0x71, 0x09, 0x05, 0x03, // 7 
+0x36, 0x49, 0x49, 0x49, 0x36, // 8 
+0x06, 0x49, 0x49, 0x29, 0x1E, // 9 
+0x00, 0x36, 0x36, 0x00, 0x00, // : 
+0x00, 0x56, 0x36, 0x00, 0x00, // ; 
+0x08, 0x14, 0x22, 0x41, 0x00, // < 
+0x14, 0x14, 0x14, 0x14, 0x14, // = 
+0x00, 0x41, 0x22, 0x14, 0x08, // > 
+0x02, 0x01, 0x51, 0x09, 0x06, // ? 
+0x32, 0x49, 0x59, 0x51, 0x3E, // @ 
+0x7E, 0x11, 0x11, 0x11, 0x7E, // A 
+0x7F, 0x49, 0x49, 0x49, 0x36, // B 
+0x3E, 0x41, 0x41, 0x41, 0x22, // C 
+0x7F, 0x41, 0x41, 0x22, 0x1C, // D 
+0x7F, 0x49, 0x49, 0x49, 0x41, // E 
+0x7F, 0x09, 0x09, 0x09, 0x01, // F 
+0x3E, 0x41, 0x49, 0x49, 0x7A, // G 
+0x7F, 0x08, 0x08, 0x08, 0x7F, // H 
+0x00, 0x41, 0x7F, 0x41, 0x00, // I 
+0x20, 0x40, 0x41, 0x3F, 0x01, // J 
+0x7F, 0x08, 0x14, 0x22, 0x41, // K 
+0x7F, 0x40, 0x40, 0x40, 0x40, // L 
+0x7F, 0x02, 0x0C, 0x02, 0x7F, // M 
+0x7F, 0x04, 0x08, 0x10, 0x7F, // N 
+0x3E, 0x41, 0x41, 0x41, 0x3E, // O 
+0x7F, 0x09, 0x09, 0x09, 0x06, // P 
+0x3E, 0x41, 0x51, 0x21, 0x5E, // Q 
+0x7F, 0x09, 0x19, 0x29, 0x46, // R 
+0x46, 0x49, 0x49, 0x49, 0x31, // S 
+0x01, 0x01, 0x7F, 0x01, 0x01, // T 
+0x3F, 0x40, 0x40, 0x40, 0x3F, // U 
+0x1F, 0x20, 0x40, 0x20, 0x1F, // V 
+0x3F, 0x40, 0x38, 0x40, 0x3F, // W 
+0x63, 0x14, 0x08, 0x14, 0x63, // X 
+0x07, 0x08, 0x70, 0x08, 0x07, // Y 
+0x61, 0x51, 0x49, 0x45, 0x43, // Z 
+0x00, 0x7F, 0x41, 0x41, 0x00, // [ 
+0x55, 0x2A, 0x55, 0x2A, 0x55, // 55 
+0x00, 0x41, 0x41, 0x7F, 0x00, // ] 
+0x04, 0x02, 0x01, 0x02, 0x04, // ^ 
+0x40, 0x40, 0x40, 0x40, 0x40, // _ 
+0x00, 0x01, 0x02, 0x04, 0x00, // ' 
+0x20, 0x54, 0x54, 0x54, 0x78, // a 
+0x7F, 0x48, 0x44, 0x44, 0x38, // b 
+0x38, 0x44, 0x44, 0x44, 0x20, // c 
+0x38, 0x44, 0x44, 0x48, 0x7F, // d 
+0x38, 0x54, 0x54, 0x54, 0x18, // e 
+0x08, 0x7E, 0x09, 0x01, 0x02, // f 
+0x0C, 0x52, 0x52, 0x52, 0x3E, // g 
+0x7F, 0x08, 0x04, 0x04, 0x78, // h 
+0x00, 0x44, 0x7D, 0x40, 0x00, // i 
+0x20, 0x40, 0x44, 0x3D, 0x00, // j 
+0x7F, 0x10, 0x28, 0x44, 0x00, // k 
+0x00, 0x41, 0x7F, 0x40, 0x00, // l 
+0x7C, 0x04, 0x18, 0x04, 0x78, // m 
+0x7C, 0x08, 0x04, 0x04, 0x78, // n 
+0x38, 0x44, 0x44, 0x44, 0x38, // o 
+0x7C, 0x14, 0x14, 0x14, 0x08, // p 
+0x08, 0x14, 0x14, 0x18, 0x7C, // q 
+0x7C, 0x08, 0x04, 0x04, 0x08, // r 
+0x48, 0x54, 0x54, 0x54, 0x20, // s 
+0x04, 0x3F, 0x44, 0x40, 0x20, // t 
+0x3C, 0x40, 0x40, 0x20, 0x7C, // u 
+0x1C, 0x20, 0x40, 0x20, 0x1C, // v 
+0x3C, 0x40, 0x30, 0x40, 0x3C, // w 
+0x44, 0x28, 0x10, 0x28, 0x44, // x 
+0x0C, 0x50, 0x50, 0x50, 0x3C, // y 
+0x44, 0x64, 0x54, 0x4C, 0x44  // z 
+
+};
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Sep 03 01:54:41 2018 +0000
@@ -0,0 +1,829 @@
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include "ST7565_LCD.h"
+#include "QEI.h"
+
+#define BAT_GAIN    5.0     
+#define BKL_TH_OFF  0.83    // Ambient ligh threshold for auto backlight off
+#define BKL_TH_ON   0.81    // Ambient ligh threshold for auto backlight on
+#define BKL_LOW     0.0     // Ambient ligh offset for auto backlight
+#define FRM_ROW1    10      // Background frame, first horizontal line
+#define FRM_ROW2    60
+#define BUZZ_VOL    0.1     // Buzzer/speaker volume
+
+
+PwmOut      BEEP        (D2);      // PA_10 Buzzer/speaker (PWM output)
+PwmOut      BKL         (D3);      // PB_3 LCD backlight control (PMW output)
+DigitalOut  KAL         (PC_8);    // PC_8 Keep-Alive/turn-off
+DigitalOut  BTC         (PC_4);    // PC_4 Aux BT module control
+DigitalIn   Button      (D4);      // PB_5 Pushbutton (digital input)
+AnalogIn    BATT        (A0);      // PA_0 Battery monitor
+AnalogIn    ALS         (A1);      // PA_1 Ambient Light sensor
+AnalogIn    VCH1        (A2);      // PA_4 Analog input 1
+AnalogIn    VCH2        (A3);      // PB_0 Analog input 2
+AnalogIn    VCH3        (A4);      // PC_1 Analog input 3
+AnalogIn    VCH4        (A5);      // PC_0 Analog input 4
+InterruptIn TRIG1       (PC_13);   // PC_13 Counter 1 trigger
+InterruptIn TRIG2       (PC_2);    // PC_2 Counter 2 trigger
+InterruptIn TRIG3       (PA_15);   // PA_15 Counter 3 trigger
+DigitalOut  PLED        (PC_3);    // PC_3 Pulse LED
+DigitalOut  ALED        (PC_9);    // PC_9 Alarm LED
+DigitalIn   CHRG        (PC_10);   // PC_10 Charge in progress
+DigitalIn   EOCH        (PC_12);   // PC_12 Endo Of Charge
+DigitalOut  SDPW        (PB_2);    // PB_2 SD-Card power enable
+
+SDFileSystem sd(PB_15, PB_14, PB_13, PB_1, "sd"); // MOSI, MISO, SCK, CS
+
+// Quadrature encoder
+QEI Wheel(D6, D5, NC, 16); // PB_10, PB_4
+// Tickers
+Ticker Sec_Beat;            // Timer ticker
+Ticker Display_Refresh;     // Display refresh ticker
+
+//Serial ports
+Serial PC(USBTX, USBRX);    // Virtual COM via USB
+
+// GPS module
+Serial GPS(PA_11, PA_12, 9600);    // PA_11=TX, PA_12=RX, default baud-rate 
+I2C GPS_I2C(PB_9,PB_8);      // SDA=PB_9, SCL=PB_8
+
+extern unsigned int buffer[128*64/8];   // RAM buffer used by LCD
+time_t seconds;     // timestamp
+char Text[40]="";   // Text string used by LCD 
+float Vbatt, AmbLight;   // battery votage and ambient light level
+uint16_t    CNT1, CNT2, CNT3;   // pulse counters
+uint8_t FLASH_Status;
+float V1, V2, V3, V4;
+bool  Pulse=0, ExtPwr=0;
+
+// used by GPS:
+double latitude = 0.0;
+double longitude = 0.0;
+double altitude = 0.0;
+int num_sat;
+float hori_dilute;
+float alt = 0.0;
+float geoid, GPS_time;
+char ns = 'N', ew='E';
+char GPS_stream[256]="none";
+char gu, hu;
+//const int GPS_addr = 0x42;
+
+// ------------------- Prototypes ----------------------- 
+void Timer_tick(void);
+void Update_Display(void);
+void Set_Time(void);
+void Read_Voltages(void);
+void PowerOff(void);
+void DrawFrame(void);
+void CNT1_count(void);
+void CNT2_count(void);
+void CNT3_count(void);
+uint8_t WriteEEPROM(uint32_t, uint8_t);
+uint8_t ReadEEPROM(uint32_t);
+void SDCard_test(void);
+void EEPROM_test(void);
+void Init_All(void);
+int GPS_test(void);
+void GPS_getline(void);
+int GPS_get_stream(void);
+
+int main() 
+{
+    Init_All();
+   
+    if(Button)  // if turn-on via pushbutton
+    {   
+        KAL = 1;    // self sustain power from battery
+        ExtPwr=0;            
+    }    
+    else
+        ExtPwr = 1;  // otherwise power comes from USB
+
+    // debug: force 
+    //ExtPwr = 0;
+
+
+    // enable LCD refresh ticker        
+    Display_Refresh.attach(&Update_Display, 0.1);
+    
+    wait(1.5);
+    Clear_buffer(buffer);
+        
+    if(Button)   // if pushbutton still pressed after splash-screen
+        Set_Time();  // set RTC time and date  
+    
+    // launch self-tests   
+    SDCard_test();
+    wait(1);
+    //EEPROM_test();
+    
+    // draw background frame
+    Clear_buffer(buffer);    
+    DrawFrame();
+
+    if(ExtPwr)      // if powered via USB, no need for backlight (recharge)
+        BKL.write(0);
+
+    // enable sec-beat ticker  
+    Sec_Beat.attach(&Timer_tick, 1.113);
+
+    //tm t = RTC::getDefaultTM();
+    //RTC::attach(&Sec_Beat, RTC::Second);
+    
+    // enable & attach interrupts on rising edge of digital inputs
+    TRIG1.rise(&CNT1_count);     
+    TRIG2.rise(&CNT2_count);     
+    TRIG3.rise(&CNT3_count);    
+   
+    while(1) 
+    {   
+    
+        if(Button)   
+            PowerOff();   // Power-off test 
+        /*     
+        // DEBUG: PC/GPS serial pass-through
+        if(PC.readable()) 
+            GPS.putc(PC.getc());
+            
+        if(GPS.readable()) 
+            PC.putc(GPS.getc());
+        */                   
+                   
+    } 
+    
+}
+
+
+//===========================================================================
+
+// ------------- Called every second ----------------------
+
+void Timer_tick() 
+{ 
+    seconds = time(NULL); 
+    strftime(Text, 50, "%d-%b-%Y  %H:%M:%S", localtime(&seconds));
+    LCD_drawstring(buffer, 0, 0, Text);
+
+    //TRIG1.rise(NULL);      // detach counters
+    //TRIG2.rise(NULL);      //
+    //TRIG3.rise(NULL);      //
+
+    // read voltages 
+    if(ExtPwr)
+        KAL = 1;
+    Read_Voltages();
+    if(ExtPwr)
+        KAL = 0;
+
+
+    if(!ExtPwr)
+        if(AmbLight>BKL_TH_OFF)
+            BKL.write(BKL_LOW);
+        else
+            if(AmbLight<BKL_TH_ON)
+                BKL.write(AmbLight+(1-BKL_TH_ON));        
+    
+    // write values to buffer
+    sprintf(Text,"VBATT= %4.2f", Vbatt);
+    LCD_drawstring(buffer, 0, 2, Text);    
+    sprintf(Text,"%4.1f %4.1f %4.1f %4.1f", V1, V2, V3, V4 );
+    LCD_drawstring(buffer, 0, 3, Text);
+    sprintf(Text,"CPS1= %5d", CNT1);
+    LCD_drawstring(buffer, 0, 4, Text);
+    sprintf(Text,"CPS2= %5d", CNT2);
+    LCD_drawstring(buffer, 0, 5, Text);
+    sprintf(Text,"CPS3= %5d", CNT3);
+    LCD_drawstring(buffer, 0, 6, Text); 
+    
+    CNT1=CNT2=CNT3=0;            
+
+    //TRIG1.rise(&CNT1_count);      //attach CNT1_count(); to TRIG1
+    //TRIG2.rise(&CNT2_count);      //attach CNT2_count(); to TRIG2
+    //TRIG3.rise(&CNT3_count);      //attach CNT3_count(); to TRIG3
+                                  
+    GPS_get_stream(); // GPS test
+          
+    return;
+}
+
+
+//---------------------------------------------------------------------------
+void Update_Display(void)
+{
+
+    if(Pulse)
+    {
+        PLED = 0;
+        BEEP.write(0);
+        Pulse = 0;
+    }    
+    LCD_write_buffer(buffer);   // LCD update 
+    return;  
+}
+
+//---------------------------------------------------------------------------
+void Set_Time(void)
+{
+    uint8_t Year=0, Month=0, Day=0, Hours=0, Mins=0, Secs=0;
+    time_t seconds;
+    struct tm t;
+
+    Clear_buffer(buffer);
+    sprintf(Text,"TIME & DATE SETTING");
+    LCD_drawstring(buffer, 0, 0, Text); 
+    
+    // Set year
+    while(Button);
+    wait_ms(50);  
+
+    while(!Button)
+    { 
+        if(int(Wheel.getPulses())<0)
+            Wheel.reset();
+        Year = (uint8_t)(Wheel.getPulses());
+        
+        if(Year>99) 
+            Wheel.reset();
+             
+        sprintf(Text, "Year: %2d", Year);
+        LCD_drawstring(buffer, 0, 2, Text);
+   
+    }
+
+    // Set month
+    while(Button);
+    wait_ms(50);  
+    Wheel.reset();
+    while(!Button)
+    { 
+        if(int(Wheel.getPulses())<0)
+            Wheel.reset();
+        Month = (uint8_t)(Wheel.getPulses()/2);
+        
+        if(Month>11) 
+            Wheel.reset();
+            
+        sprintf(Text, "Month: %2d", Month+1);
+        LCD_drawstring(buffer, 0, 3, Text);
+   
+    }
+
+
+    // Set day
+    while(Button);
+    wait_ms(50);  
+    Wheel.reset();
+    while(!Button)
+    { 
+        if(int(Wheel.getPulses())<0)
+            Wheel.reset();
+        Day = (uint8_t)(Wheel.getPulses()/2);
+        
+        if(Day>30) 
+            Wheel.reset();
+            
+        sprintf(Text, "Day: %2d", Day+1);
+        LCD_drawstring(buffer, 0, 4, Text);
+   
+    }
+
+    // Set hours
+    while(Button);
+    wait_ms(50);  
+    Wheel.reset();
+    while(!Button)
+    { 
+        if(int(Wheel.getPulses())<0)
+            Wheel.reset();
+        Hours = (uint8_t)(Wheel.getPulses()/2);
+        
+        if(Hours>22) 
+            Wheel.reset();
+            
+        sprintf(Text, "Hours: %2d", Hours);
+        LCD_drawstring(buffer, 0, 5, Text);
+   
+    }
+    //Hours++;
+
+    // Set minutes
+    while(Button);
+    wait_ms(50);  
+    Wheel.reset();
+    while(!Button)
+    { 
+        if(int(Wheel.getPulses())<0)
+            Wheel.reset();
+        Mins = (uint8_t)(Wheel.getPulses()/2);
+        
+        if(Mins>59) 
+            Wheel.reset();
+            
+        sprintf(Text, "Minutes: %2d", Mins);
+        LCD_drawstring(buffer, 0, 6, Text);
+   
+    }
+
+    t.tm_year = Year + 100;
+    t.tm_mon  = Month;
+    t.tm_mday = Day + 1;
+    t.tm_hour = Hours;
+    t.tm_min  = Mins;
+    t.tm_sec  = Secs;
+
+    seconds = mktime(&t);
+    set_time(seconds);
+    
+    Clear_buffer(buffer);
+        
+    return;
+}    
+
+
+//---------------------------------------------------------------------------
+void Read_Voltages(void)
+{
+
+    double ADC_value;
+    uint8_t smooth = 10; // Number of samples to smooth
+    uint8_t i;
+    
+    // Read battery voltage
+    
+    ADC_value = BATT.read();    // cleanup
+    wait_ms(5);
+    ADC_value = 0;    
+    for(i=0;i<smooth;i++) 
+        ADC_value += BATT.read();       
+
+    ADC_value = ADC_value/smooth;
+    Vbatt = (float)(ADC_value*BAT_GAIN);
+    
+    
+    // Read Ambient Light Level
+    
+    ADC_value = ALS.read();    // cleanup
+    wait_ms(5);
+    ADC_value = 0;    
+    for(i=0;i<smooth;i++) 
+        ADC_value += ALS.read();       
+
+    ADC_value = ADC_value/smooth;
+    AmbLight = (float)(ADC_value);     
+    
+    
+    // Read AIN1
+    
+    ADC_value = VCH1.read();    // cleanup
+    wait_ms(5);
+    ADC_value = 0;    
+    for(i=0;i<smooth;i++) 
+        ADC_value += VCH1.read();       
+
+    ADC_value = ADC_value/smooth;
+    V1 = (float)(ADC_value);   
+    
+    // Read AIN2
+    
+    ADC_value = VCH2.read();    // cleanup
+    wait_ms(5);
+    ADC_value = 0;    
+    for(i=0;i<smooth;i++) 
+        ADC_value += VCH2.read();       
+
+    ADC_value = ADC_value/smooth;
+    V2 = (float)(ADC_value);  
+    
+    // Read AIN3
+    
+    ADC_value = VCH3.read();    // cleanup
+    wait_ms(5);
+    ADC_value = 0;    
+    for(i=0;i<smooth;i++) 
+        ADC_value += VCH3.read();       
+
+    ADC_value = ADC_value/smooth;
+    V3 = (float)(ADC_value);      
+    
+    // Read AIN4
+    
+    ADC_value = VCH4.read();    // cleanup
+    wait_ms(5);
+    ADC_value = 0;    
+    for(i=0;i<smooth;i++) 
+        ADC_value += VCH4.read();       
+
+    ADC_value = ADC_value/smooth;
+    V4 = (float)(ADC_value);          
+        
+   
+return;
+}
+
+
+//--------------------------------------------------------------------------- 
+void PowerOff(void) 
+{
+    BKL.write(1);
+    Display_Refresh.detach();
+    Clear_buffer(buffer);
+    sprintf(Text,"POWERING OFF");
+    LCD_drawstring(buffer, 30, 3, Text); 
+    LCD_write_buffer(buffer);
+    wait(2);
+    Clear_buffer(buffer);
+    KAL = 0;
+}
+
+
+//---------------------------------------------------------------------------
+void DrawFrame(void)
+{
+    uint8_t i;
+    
+    for(i=0; i<128; i++)
+    {       
+        LCD_setpixel(buffer, i, FRM_ROW1, 1);
+        //LCD_setpixel(buffer, i, FRM_ROW2, 1);
+    }
+    return;  
+}
+
+
+//---------------------------------------------------------------------------
+void CNT1_count(void)
+{                       //function to call upon interrupt
+    CNT1++;                      //increment counter object
+    PLED = 1;
+    BEEP.write(BUZZ_VOL);
+    Pulse = 1;    
+    return; 
+}
+
+
+//---------------------------------------------------------------------------
+void CNT2_count(void)
+{                       //function to call upon interrupt
+    CNT2++;                      //increment counter object    
+    return; 
+}
+
+
+//---------------------------------------------------------------------------
+void CNT3_count(void)
+{                       //function to call upon interrupt
+    CNT3++;                      //increment counter object
+    return; 
+}
+
+
+//---------------------------------------------------------------------------
+uint8_t WriteEEPROM(uint32_t address, uint8_t data)
+{                      
+    HAL_StatusTypeDef  status;
+    
+    address = address + 0x08000000;
+    HAL_FLASH_Unlock();
+    status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_BYTE, address, data);
+    HAL_FLASH_Lock();
+    
+    return status;        
+}
+
+
+//--------------------------------------------------------------------------- 
+uint8_t ReadEEPROM(uint32_t address) 
+{
+    uint8_t tmp = 0;
+    
+    address = address + 0x08000000;
+    tmp = *(__IO uint32_t*)address;
+    
+    return tmp;
+}
+
+
+
+//---------------------------------------------------------------------------
+void SDCard_test(void)
+{
+    // SD-Card test  
+    printf("SD-Card test... ");
+    //mkdir("/sd/system", 0777);
+    FILE *fp = fopen("/sd/system/version.dat", "a");
+    if(fp == NULL) 
+    {
+        printf("ERROR\n");
+        sprintf(Text,"SD-CARD ERROR");        
+        LCD_drawstring(buffer, 15, 2, Text);  
+        LCD_write_buffer(buffer); 
+    }
+    else
+    {
+        printf("OK\n");        
+        sprintf(Text,"SD-CARD DETECTED");        
+        LCD_drawstring(buffer, 15, 2, Text);  
+        LCD_write_buffer(buffer);    
+        fprintf(fp, "Geo Electronics 2107\n");
+        fprintf(fp, __DATE__);
+        fprintf(fp, "\t");        
+        fprintf(fp, __TIME__);                
+        fprintf(fp, "\n");
+        fclose(fp); 
+    }
+    printf("SD-Card end of test\n");
+
+    return;
+}    
+
+
+//---------------------------------------------------------------------------
+void EEPROM_test(void)
+{
+    // internal EEPROM test
+    PC.printf("Attempting to write to EEPROM...\n");
+
+    for (uint32_t i = 0; i < 8; i++) 
+    {
+        FLASH_Status = WriteEEPROM(i,(uint8_t)(i));
+        PC.printf("Writing %d at %d\n", i, i);
+    }
+    if(FLASH_Status == HAL_FLASH_ERROR_NONE) 
+        {PC.printf("Success!!\r\n");}
+    else
+        {PC.printf("Failed!!\r\n");}
+               
+    for (uint32_t i = 0; i < 8; i++) 
+    {    
+            uint8_t storedValue = ReadEEPROM(i);
+            PC.printf("Reading %d at %d\n", storedValue, i);
+    } 
+       
+    // end of EEPROM test
+    return;
+    
+}
+
+
+//---------------------------------------------------------------------------
+void Init_All(void)
+{
+    
+    GPS_I2C.frequency(300000);    // I2C GPS speed (400k max)
+    //Button.mode(PullUp);      // enable pushbutton pull-up
+    BKL.period_ms(5);         // set LCD backlight PWM
+    BKL.write(1.0);  
+    BEEP.period_us(2000);      // set initial buzzer period and duty-cycle
+    BEEP.write(0);
+    Wheel.reset();        // clear encoder
+    LCD_reset();   
+    CNT1=CNT2=CNT3=0;   // clear counters
+    SDPW = 0;   // Enable SC-card VDD
+    // splash screen with date and time
+    sprintf(Text,__DATE__);
+    LCD_drawstring(buffer, 60, 5, Text);
+    sprintf(Text,__TIME__);
+    LCD_drawstring(buffer, 78, 6, Text);  
+    LCD_write_buffer(buffer);
+    
+    // buzzer beep and blink LEDs
+    BEEP.write(BUZZ_VOL);
+    ALED = 1;
+    wait(0.2);
+    BEEP.period_us(1000);
+    ALED = 0;
+    PLED = 1;   
+    wait(0.2);
+    BEEP.write(0);         
+    PLED = 0;
+    // enable internal pull-ups for digital inputs
+    TRIG1.mode(PullUp);           
+    TRIG2.mode(PullUp);           
+    TRIG3.mode(PullUp);          
+       
+    return;
+    
+}
+
+
+
+//---------------------------------------------------------------------------
+int GPS_test() 
+{
+    //float time, hori_dilute, alt,geoid;
+
+// $GPGGA,104534.000,7791.0381,N,06727.4434,E,1,08,0.9,510.4,M,43.9,M,,*47
+// $GPGGA,HHMMSS.SSS,latitude,N,longitude,E,FQ,NOS,HDP,altitude,M,height,M,,checksum data
+   
+    int lock, n;
+
+    if(!GPS.readable())
+    {       
+        return -1;
+    }    
+        
+    
+    //PC.printf("Readable "); 
+
+    GPS_stream[0] = '\0';
+            
+    for (n = 0; n < 456; n++) 
+    {
+        GPS_stream[n] = GPS.getc(); 
+        if(GPS_stream[n] == '\r') 
+        {
+            GPS_stream[n] = '\0';
+            PC.printf("%s\n", GPS_stream); 
+            return;
+        }        
+               
+    }    
+       
+       
+ 
+       
+    while(GPS.readable()) 
+    {        
+        
+        GPS_getline();
+        
+        // Check if it is a GPGGA msg (matches both locked and non-locked msg)
+        //wait(5);
+        
+        PC.printf("GPS: %s\n", GPS_stream);
+        
+        if(sscanf(GPS_stream, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c,%f,%c", &GPS_time, &latitude, &ns, &longitude, &ew, &lock, &num_sat, &hori_dilute, &alt, &hu, &geoid, &gu/*, &age_diff, &diff_ID*/) >= 1) 
+        { 
+            if(!lock) 
+            {
+                longitude = 0.0;
+                latitude = 0.0;  
+                ns = 'Z';
+                ew = 'Z';
+                alt = 0.0;      
+                return 0;
+            } 
+            else 
+            {
+                //if(ns == 'S') {    latitude  *= -1.0; }
+//                if(ew == 'W') {    longitude *= -1.0; }
+//                float degrees = trunc(latitude / 100.0f);
+//                float minutes = latitude - (degrees * 100.0f);
+//                latitude = degrees + minutes / 60.0f;    
+//                degrees = trunc(longitude / 100.0f * 0.01f);
+//                minutes = longitude - (degrees * 100.0f);
+//                longitude = degrees + minutes / 60.0f;
+//                pc1.printf(msg);
+                PC.printf("\n\rlongitude is %f\n\r", longitude);
+                PC.printf("\n\rtime is %f\n\r", GPS_time);
+                PC.printf("ns is %c\n\r", ns);
+                PC.printf("ew is %c\n\r", ew);
+                PC.printf("alt is %f\n\r", alt);
+                
+                latitude /= 100;
+                longitude /= 100;
+                
+                return 1;
+            }
+        
+        }
+        
+        return 0;
+    }
+    
+ return(-1);
+    
+}
+
+
+//---------------------------------------------------------------------------
+void GPS_getline() 
+{
+    int i;
+    char a;
+    int n;
+    
+    //strcpy(GPS_stream, '\0');
+    GPS_stream[0] = '\0';
+      
+            
+    while(GPS.readable()) 
+    {
+    
+        i = 0;
+        a = GPS.getc();
+        
+        GPS_stream[i] = a;
+        
+        if (a == '$') 
+        {
+            //PC.printf("%c",a);
+            a = GPS.getc();
+            GPS_stream[i] = a;
+            i++;
+            if (a == 'G') 
+            {
+                //PC.printf("%c",a);
+                a = GPS.getc();
+                GPS_stream[i] = a;
+                i++;
+                if (a == 'P') 
+                {
+                    //PC.printf("%c",a);
+                    a = GPS.getc();
+                    GPS_stream[i] = a;
+                    i++;
+                    if (a == 'G') 
+                    {
+                        //PC.printf("%c",a);
+                        a = GPS.getc();
+                        GPS_stream[i] = a;
+                        i++;
+                        if (a == 'G') 
+                        {
+                            //PC.printf("%c",a);
+                            a = GPS.getc();
+                            GPS_stream[i] = a;
+                            i++;
+                            if (a == 'A') 
+                            {
+                                //PC.printf("%c",a);
+                                //a = GPS.getc();
+                                //msg[i] = a;
+                                //PC.printf(msg);
+                                //PC.printf("\r\n");
+        
+                                for (n = 5; n < 456; n++) 
+                                {
+                                    GPS_stream[n] = GPS.getc();
+                                    //PC.printf("%c", GPS_stream[n]);
+                                    if(GPS_stream[n] == '\r') 
+                                    {
+                                        GPS_stream[n] = '0';
+                                        return;
+                                    }
+                            }
+                         }
+                     }
+                 }
+            }
+       }
+       }                          
+//    while(GPS.getc() != '$') {
+//        //char a = GPS.getc();
+//        for(i = 0; i < 256; i++) {
+//            msg[i] = GPS.getc();
+//            pc1.printf("%c", msg[i]);
+//            if(msg[i] == '\r') {
+//             msg[i] = 0;
+//             return;
+//                }
+//                }
+//          
+//         
+//    }
+//    while(GPS.getc() != '$');    // wait for the start of a line
+//    for(int i=0; i<256; i++) {
+//        msg[i] = GPS.getc();
+//        if(msg[i] == '\r') {
+//            msg[i] = 0;
+//            return;
+//        }
+//    }
+//    error("Overflowed message limit");
+}
+
+    return;
+}
+
+
+//---------------------------------------------------------------------------
+
+int GPS_get_stream(void)
+{
+    char cmd[256];    
+    int i;
+
+    GPS_stream[0] = '\0';  // buffer cleanup
+        
+    cmd[0] = 0xFF;  
+    GPS_I2C.write(0x42, cmd, 1);
+    GPS_I2C.read(0x42, cmd, 100);
+    //cmd[21] = '\0';    
+    i=0;
+    while((i<100))
+    {    
+        PC.printf("%c", cmd[i]); 
+        //if(cmd[i]=='\n')
+        //    i=100;
+        //else
+            i++;    
+    }
+    
+    
+
+    return 1;
+}
+
+// ==========================================================================
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Sep 03 01:54:41 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a330f0fddbec
\ No newline at end of file