Datalogger for DS1920 iButton using the MAX32630FTHR and my 1-Wire-Wing https://github.com/j3270/1-Wire-Wing-pcb.

Dependencies:   OneWire SDFileSystem Sharp_LS012B7DD01 max32630fthr mbed

Committer:
j3
Date:
Fri Feb 17 19:21:02 2017 +0000
Revision:
1:0ae128a7daba
Parent:
0:0cdbc206e85f
Updated OneWire lib to official release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 0:0cdbc206e85f 1 /******************************************************************************
j3 0:0cdbc206e85f 2 * MIT License
j3 0:0cdbc206e85f 3 *
j3 0:0cdbc206e85f 4 * Copyright (c) 2017 Justin J. Jordan
j3 0:0cdbc206e85f 5 *
j3 0:0cdbc206e85f 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
j3 0:0cdbc206e85f 7 * of this software and associated documentation files (the "Software"), to deal
j3 0:0cdbc206e85f 8 * in the Software without restriction, including without limitation the rights
j3 0:0cdbc206e85f 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
j3 0:0cdbc206e85f 10 * copies of the Software, and to permit persons to whom the Software is
j3 0:0cdbc206e85f 11 * furnished to do so, subject to the following conditions:
j3 0:0cdbc206e85f 12
j3 0:0cdbc206e85f 13 * The above copyright notice and this permission notice shall be included in all
j3 0:0cdbc206e85f 14 * copies or substantial portions of the Software.
j3 0:0cdbc206e85f 15
j3 0:0cdbc206e85f 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
j3 0:0cdbc206e85f 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
j3 0:0cdbc206e85f 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
j3 0:0cdbc206e85f 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
j3 0:0cdbc206e85f 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
j3 0:0cdbc206e85f 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
j3 0:0cdbc206e85f 22 * SOFTWARE.
j3 0:0cdbc206e85f 23 ******************************************************************************/
j3 0:0cdbc206e85f 24
j3 0:0cdbc206e85f 25
j3 0:0cdbc206e85f 26 #include "mbed.h"
j3 0:0cdbc206e85f 27 #include "OneWire.h"
j3 0:0cdbc206e85f 28 #include "max32630fthr.h"
j3 0:0cdbc206e85f 29 #include "SDFileSystem.h"
j3 0:0cdbc206e85f 30 #include "Sharp_LS012B7DD01.h"
j3 0:0cdbc206e85f 31
j3 0:0cdbc206e85f 32 using namespace OneWire;
j3 0:0cdbc206e85f 33 using namespace RomCommands;
j3 0:0cdbc206e85f 34
j3 0:0cdbc206e85f 35 uint8_t printMessage(SharpLS012B7DD01 &lcd, const char * msg, uint8_t ln);
j3 0:0cdbc206e85f 36 uint8_t printRomId(SharpLS012B7DD01 &lcd, RomId &romId, uint8_t ln);
j3 0:0cdbc206e85f 37
j3 0:0cdbc206e85f 38
j3 0:0cdbc206e85f 39 Ticker oneSecondTicker;
j3 0:0cdbc206e85f 40 volatile uint32_t secondCounter = 0;
j3 0:0cdbc206e85f 41 void oneSecond()
j3 0:0cdbc206e85f 42 {
j3 0:0cdbc206e85f 43 secondCounter++;
j3 0:0cdbc206e85f 44 }
j3 0:0cdbc206e85f 45
j3 0:0cdbc206e85f 46 //Setup start/stop button
j3 0:0cdbc206e85f 47 DigitalIn sw2(P2_3, PullUp);
j3 0:0cdbc206e85f 48 InterruptIn startStopLog(P2_3);
j3 0:0cdbc206e85f 49 volatile bool startLog = false;
j3 0:0cdbc206e85f 50 void startStopLogISR()
j3 0:0cdbc206e85f 51 {
j3 0:0cdbc206e85f 52 startLog = !startLog;
j3 0:0cdbc206e85f 53 }
j3 0:0cdbc206e85f 54
j3 0:0cdbc206e85f 55
j3 0:0cdbc206e85f 56 int main ()
j3 0:0cdbc206e85f 57 {
j3 0:0cdbc206e85f 58 //Init board and set GPIO to 3.3V logic
j3 0:0cdbc206e85f 59 MAX32630FTHR pegasus;
j3 0:0cdbc206e85f 60 pegasus.init(MAX32630FTHR::VIO_3V3);
j3 0:0cdbc206e85f 61
j3 0:0cdbc206e85f 62
j3 0:0cdbc206e85f 63 //Turn RGB LED off
j3 0:0cdbc206e85f 64 DigitalOut rLED(LED1, LED_ON);
j3 0:0cdbc206e85f 65 DigitalOut gLED(LED2, LED_OFF);
j3 0:0cdbc206e85f 66 DigitalOut bLED(LED3, LED_OFF);
j3 0:0cdbc206e85f 67
j3 0:0cdbc206e85f 68
j3 0:0cdbc206e85f 69 //Get LCD instance
j3 0:0cdbc206e85f 70 SPI spiBus(P5_1, P5_2, P5_0);
j3 0:0cdbc206e85f 71 SharpLS012B7DD01 lcd(P5_3, P5_4, P5_5, spiBus);
j3 0:0cdbc206e85f 72 printMessage(lcd, "Starting...", 0);
j3 0:0cdbc206e85f 73 wait(2.0);
j3 0:0cdbc206e85f 74 lcd.clear_display();
j3 0:0cdbc206e85f 75
j3 0:0cdbc206e85f 76
j3 0:0cdbc206e85f 77 //Get 1-Wire Master (owm) instance
j3 0:0cdbc206e85f 78 #if defined(TARGET_MAX32630FTHR)
j3 0:0cdbc206e85f 79 MCU_OWM owm(true, true);
j3 0:0cdbc206e85f 80 #else //some other FTHR on mbed?
j3 0:0cdbc206e85f 81 //Replace with appropriate pin names for your FTHR
j3 0:0cdbc206e85f 82 I2C i2cBus(P3_4, P3_5);
j3 0:0cdbc206e85f 83 DS2484 owm(i2cBus);
j3 0:0cdbc206e85f 84 #endif
j3 0:0cdbc206e85f 85
j3 0:0cdbc206e85f 86 //Make sure owm is initialized
j3 0:0cdbc206e85f 87 OneWireMaster::CmdResult result = owm.OWInitMaster();
j3 0:0cdbc206e85f 88 while(result != OneWireMaster::Success)
j3 0:0cdbc206e85f 89 {
j3 0:0cdbc206e85f 90 printMessage(lcd, "Failed to init OWM...", 0);
j3 0:0cdbc206e85f 91 result = owm.OWInitMaster();
j3 0:0cdbc206e85f 92 wait(0.5);
j3 0:0cdbc206e85f 93 }
j3 0:0cdbc206e85f 94 lcd.clear_display();
j3 0:0cdbc206e85f 95 printMessage(lcd, "OWM Initialized...", 0);
j3 0:0cdbc206e85f 96 wait(2.0);
j3 0:0cdbc206e85f 97 lcd.clear_display();
j3 0:0cdbc206e85f 98
j3 0:0cdbc206e85f 99
j3 0:0cdbc206e85f 100 //Check for DS1920 iButton
j3 0:0cdbc206e85f 101 SearchState search_state;
j3 0:0cdbc206e85f 102 search_state.findFamily(0x10);
j3 0:0cdbc206e85f 103 do
j3 0:0cdbc206e85f 104 {
j3 0:0cdbc206e85f 105 result = OWNext(owm, search_state);
j3 0:0cdbc206e85f 106 if(search_state.romId.familyCode() != 0x10)
j3 0:0cdbc206e85f 107 {
j3 0:0cdbc206e85f 108 printMessage(lcd, "Failed to find DS1920...", 0);
j3 0:0cdbc206e85f 109 printMessage(lcd, "Please connect DS1920...", 1);
j3 0:0cdbc206e85f 110 wait(0.5);
j3 0:0cdbc206e85f 111 }
j3 0:0cdbc206e85f 112 else
j3 0:0cdbc206e85f 113 {
j3 0:0cdbc206e85f 114 lcd.clear_display();
j3 0:0cdbc206e85f 115 printMessage(lcd, "Found DS1920...", 0);
j3 0:0cdbc206e85f 116 printRomId(lcd, search_state.romId, 1);
j3 0:0cdbc206e85f 117 wait(2.0);
j3 0:0cdbc206e85f 118 lcd.clear_display();
j3 0:0cdbc206e85f 119 }
j3 0:0cdbc206e85f 120 }
j3 0:0cdbc206e85f 121 while(search_state.romId.familyCode() != 0x10);
j3 0:0cdbc206e85f 122
j3 0:0cdbc206e85f 123 //Get instance of DS1920 object
j3 0:0cdbc206e85f 124 MultidropRomIterator selector(owm);
j3 0:0cdbc206e85f 125 DS1920 tempSensor(selector);
j3 0:0cdbc206e85f 126 tempSensor.setRomId(search_state.romId);
j3 0:0cdbc206e85f 127
j3 0:0cdbc206e85f 128
j3 0:0cdbc206e85f 129 //Get instance of sd card file system
j3 0:0cdbc206e85f 130 SDFileSystem sd(P0_5, P0_6, P0_4, P0_7, "sd"); // mosi, miso, sclk, cs
j3 0:0cdbc206e85f 131
j3 0:0cdbc206e85f 132 //Configure pin for sd card detect
j3 0:0cdbc206e85f 133 DigitalIn uSDdetect(P2_2, PullUp);
j3 0:0cdbc206e85f 134
j3 0:0cdbc206e85f 135 static const char FILE_NAME[] = "/sd/log.txt";
j3 0:0cdbc206e85f 136 FILE *fp;
j3 0:0cdbc206e85f 137
j3 0:0cdbc206e85f 138 //Check for card
j3 0:0cdbc206e85f 139 if(uSDdetect)
j3 0:0cdbc206e85f 140 {
j3 0:0cdbc206e85f 141 printMessage(lcd, "Please insert uSD card", 0);
j3 0:0cdbc206e85f 142 while(uSDdetect);
j3 0:0cdbc206e85f 143 }
j3 0:0cdbc206e85f 144 lcd.clear_display();
j3 0:0cdbc206e85f 145
j3 0:0cdbc206e85f 146 rLED = LED_ON;
j3 0:0cdbc206e85f 147 gLED = LED_ON;
j3 0:0cdbc206e85f 148 do
j3 0:0cdbc206e85f 149 {
j3 0:0cdbc206e85f 150 fp = fopen(FILE_NAME, "w");
j3 0:0cdbc206e85f 151 if(fp != NULL)
j3 0:0cdbc206e85f 152 {
j3 0:0cdbc206e85f 153 lcd.clear_display();
j3 0:0cdbc206e85f 154 printMessage(lcd, "Card detected...", 0);
j3 0:0cdbc206e85f 155 printMessage(lcd, "Preparing log file...", 1);
j3 0:0cdbc206e85f 156 fprintf(fp, "Time-Stamp, Battery Voltage, Temperature\n");
j3 0:0cdbc206e85f 157 fclose(fp);
j3 0:0cdbc206e85f 158 }
j3 0:0cdbc206e85f 159 else
j3 0:0cdbc206e85f 160 {
j3 0:0cdbc206e85f 161 lcd.clear_display();
j3 0:0cdbc206e85f 162 printMessage(lcd, "Failed to open file...", 0);
j3 0:0cdbc206e85f 163 printMessage(lcd, "Press Reset Button...", 1);
j3 0:0cdbc206e85f 164 wait(2.0);
j3 0:0cdbc206e85f 165 }
j3 0:0cdbc206e85f 166 }
j3 0:0cdbc206e85f 167 while(fp == NULL);
j3 0:0cdbc206e85f 168 rLED = LED_OFF;
j3 0:0cdbc206e85f 169 gLED = LED_ON;
j3 0:0cdbc206e85f 170 wait(2.0);
j3 0:0cdbc206e85f 171 lcd.clear_display();
j3 0:0cdbc206e85f 172
j3 0:0cdbc206e85f 173
j3 0:0cdbc206e85f 174 enum UiStates
j3 0:0cdbc206e85f 175 {
j3 0:0cdbc206e85f 176 Reset,
j3 0:0cdbc206e85f 177 NoLog_NoCardDetected,
j3 0:0cdbc206e85f 178 NoLog_CardDetected,
j3 0:0cdbc206e85f 179 Log_NoCardDetected,
j3 0:0cdbc206e85f 180 Log_CardDetected
j3 0:0cdbc206e85f 181 };
j3 0:0cdbc206e85f 182
j3 0:0cdbc206e85f 183 UiStates currentState = Reset, oldState = Reset;
j3 0:0cdbc206e85f 184
j3 0:0cdbc206e85f 185 static const uint32_t SAMPLE_INTERVAL = 5; // In seconds
j3 0:0cdbc206e85f 186 bool firstSampleTaken = false;
j3 0:0cdbc206e85f 187 uint32_t sampleTime = 0;
j3 0:0cdbc206e85f 188 float batteryVoltage, temperature;
j3 0:0cdbc206e85f 189
j3 0:0cdbc206e85f 190 //attach timer to callback for 1 second tick
j3 0:0cdbc206e85f 191 oneSecondTicker.attach(&oneSecond, 1);
j3 0:0cdbc206e85f 192
j3 0:0cdbc206e85f 193 //Tie SW2 to callback fx
j3 0:0cdbc206e85f 194 startStopLog.fall(&startStopLogISR);
j3 0:0cdbc206e85f 195
j3 0:0cdbc206e85f 196
j3 0:0cdbc206e85f 197 while(1)
j3 0:0cdbc206e85f 198 {
j3 0:0cdbc206e85f 199 //card detect is active low
j3 0:0cdbc206e85f 200 //Determine state, house keeping
j3 0:0cdbc206e85f 201 if(!startLog && uSDdetect) //False, False
j3 0:0cdbc206e85f 202 {
j3 0:0cdbc206e85f 203 currentState = NoLog_NoCardDetected;
j3 0:0cdbc206e85f 204 secondCounter = 0;
j3 0:0cdbc206e85f 205 sampleTime = 0;
j3 0:0cdbc206e85f 206 firstSampleTaken = false;
j3 0:0cdbc206e85f 207 }
j3 0:0cdbc206e85f 208 else if(!startLog && !uSDdetect) //False, True
j3 0:0cdbc206e85f 209 {
j3 0:0cdbc206e85f 210 currentState = NoLog_CardDetected;
j3 0:0cdbc206e85f 211 secondCounter = 0;
j3 0:0cdbc206e85f 212 sampleTime = 0;
j3 0:0cdbc206e85f 213 firstSampleTaken = false;
j3 0:0cdbc206e85f 214 }
j3 0:0cdbc206e85f 215 else if(startLog && uSDdetect) //True, False
j3 0:0cdbc206e85f 216 {
j3 0:0cdbc206e85f 217 currentState = Log_NoCardDetected;
j3 0:0cdbc206e85f 218 secondCounter = 0;
j3 0:0cdbc206e85f 219 sampleTime = 0;
j3 0:0cdbc206e85f 220 firstSampleTaken = false;
j3 0:0cdbc206e85f 221 }
j3 0:0cdbc206e85f 222 else //True, True
j3 0:0cdbc206e85f 223 {
j3 0:0cdbc206e85f 224 currentState = Log_CardDetected;
j3 0:0cdbc206e85f 225
j3 0:0cdbc206e85f 226 //get t = 0 sample
j3 0:0cdbc206e85f 227 if(!firstSampleTaken)
j3 0:0cdbc206e85f 228 {
j3 0:0cdbc206e85f 229 firstSampleTaken = true;
j3 0:0cdbc206e85f 230 lcd.clear_display();
j3 0:0cdbc206e85f 231 oldState = currentState;
j3 0:0cdbc206e85f 232
j3 0:0cdbc206e85f 233 printMessage(lcd, "Logging Data...", 0);
j3 0:0cdbc206e85f 234 pegasus.getBatteryVoltage(&batteryVoltage);
j3 0:0cdbc206e85f 235 tempSensor.convertTemperature(temperature);
j3 0:0cdbc206e85f 236
j3 0:0cdbc206e85f 237 rLED = LED_ON;
j3 0:0cdbc206e85f 238 fp = fopen(FILE_NAME, "a");
j3 0:0cdbc206e85f 239 if(fp != NULL)
j3 0:0cdbc206e85f 240 {
j3 0:0cdbc206e85f 241 fprintf(fp, "%d, %f, %f\n", sampleTime, batteryVoltage, temperature);
j3 0:0cdbc206e85f 242 fclose(fp);
j3 0:0cdbc206e85f 243 }
j3 0:0cdbc206e85f 244 else
j3 0:0cdbc206e85f 245 {
j3 0:0cdbc206e85f 246 lcd.clear_display();
j3 0:0cdbc206e85f 247 printMessage(lcd, "Failed to open file", 0);
j3 0:0cdbc206e85f 248 printMessage(lcd, "Press Reset Button...", 1);
j3 0:0cdbc206e85f 249 printMessage(lcd, "MBED DIE!!...", 2);
j3 0:0cdbc206e85f 250 mbed_die();
j3 0:0cdbc206e85f 251 }
j3 0:0cdbc206e85f 252 rLED = LED_OFF;
j3 0:0cdbc206e85f 253 }
j3 0:0cdbc206e85f 254 }
j3 0:0cdbc206e85f 255
j3 0:0cdbc206e85f 256 //If state has changed, clear dispaly
j3 0:0cdbc206e85f 257 if(oldState != currentState)
j3 0:0cdbc206e85f 258 {
j3 0:0cdbc206e85f 259 lcd.clear_display();
j3 0:0cdbc206e85f 260 oldState = currentState;
j3 0:0cdbc206e85f 261 }
j3 0:0cdbc206e85f 262
j3 0:0cdbc206e85f 263 //State based actions
j3 0:0cdbc206e85f 264 switch(currentState)
j3 0:0cdbc206e85f 265 {
j3 0:0cdbc206e85f 266 case NoLog_NoCardDetected:
j3 0:0cdbc206e85f 267 printMessage(lcd, "Please insert uSD card...", 0);
j3 0:0cdbc206e85f 268 break;
j3 0:0cdbc206e85f 269
j3 0:0cdbc206e85f 270 case NoLog_CardDetected:
j3 0:0cdbc206e85f 271 printMessage(lcd, "Press SW2 to start logging", 0);
j3 0:0cdbc206e85f 272 printMessage(lcd, "data...", 1);
j3 0:0cdbc206e85f 273 break;
j3 0:0cdbc206e85f 274
j3 0:0cdbc206e85f 275 case Log_NoCardDetected:
j3 0:0cdbc206e85f 276 startLog = false;
j3 0:0cdbc206e85f 277 printMessage(lcd, "Please insert uSD card", 0);
j3 0:0cdbc206e85f 278 break;
j3 0:0cdbc206e85f 279
j3 0:0cdbc206e85f 280 case Log_CardDetected:
j3 0:0cdbc206e85f 281
j3 0:0cdbc206e85f 282 if(secondCounter >= SAMPLE_INTERVAL)
j3 0:0cdbc206e85f 283 {
j3 0:0cdbc206e85f 284 secondCounter = 0;
j3 0:0cdbc206e85f 285 sampleTime += SAMPLE_INTERVAL;
j3 0:0cdbc206e85f 286
j3 0:0cdbc206e85f 287 printMessage(lcd, "Logging Data...", 0);
j3 0:0cdbc206e85f 288 pegasus.getBatteryVoltage(&batteryVoltage);
j3 0:0cdbc206e85f 289 tempSensor.convertTemperature(temperature);
j3 0:0cdbc206e85f 290
j3 0:0cdbc206e85f 291 rLED = LED_ON;
j3 0:0cdbc206e85f 292 fp = fopen(FILE_NAME, "a");
j3 0:0cdbc206e85f 293 if(fp != NULL)
j3 0:0cdbc206e85f 294 {
j3 0:0cdbc206e85f 295 fprintf(fp, "%d, %f, %f\n", sampleTime, batteryVoltage, temperature);
j3 0:0cdbc206e85f 296 fclose(fp);
j3 0:0cdbc206e85f 297 }
j3 0:0cdbc206e85f 298 else
j3 0:0cdbc206e85f 299 {
j3 0:0cdbc206e85f 300 lcd.clear_display();
j3 0:0cdbc206e85f 301 printMessage(lcd, "Failed to open file", 0);
j3 0:0cdbc206e85f 302 printMessage(lcd, "Press Reset Button...", 1);
j3 0:0cdbc206e85f 303 printMessage(lcd, "MBED DIE!!...", 2);
j3 0:0cdbc206e85f 304 mbed_die();
j3 0:0cdbc206e85f 305 }
j3 0:0cdbc206e85f 306 rLED = LED_OFF;
j3 0:0cdbc206e85f 307 }
j3 0:0cdbc206e85f 308
j3 0:0cdbc206e85f 309 break;
j3 0:0cdbc206e85f 310
j3 0:0cdbc206e85f 311 default:
j3 0:0cdbc206e85f 312 lcd.clear_display();
j3 0:0cdbc206e85f 313 printMessage(lcd, "Bad State...", 0);
j3 0:0cdbc206e85f 314 printMessage(lcd, "Press Reset Button...", 1);
j3 0:0cdbc206e85f 315 printMessage(lcd, "MBED DIE!!...", 2);
j3 0:0cdbc206e85f 316 mbed_die();
j3 0:0cdbc206e85f 317 break;
j3 0:0cdbc206e85f 318 }
j3 0:0cdbc206e85f 319 }
j3 0:0cdbc206e85f 320 }
j3 0:0cdbc206e85f 321
j3 0:0cdbc206e85f 322
j3 0:0cdbc206e85f 323 //*********************************************************************
j3 0:0cdbc206e85f 324 uint8_t printMessage(SharpLS012B7DD01 &lcd, const char * msg, uint8_t ln)
j3 0:0cdbc206e85f 325 {
j3 0:0cdbc206e85f 326 char temp_buff[31];
j3 0:0cdbc206e85f 327 uint8_t buf_idx = 0;
j3 0:0cdbc206e85f 328 temp_buff[buf_idx++] = '>';
j3 0:0cdbc206e85f 329 temp_buff[buf_idx++] = '>';
j3 0:0cdbc206e85f 330 for(; buf_idx < 30; buf_idx++)
j3 0:0cdbc206e85f 331 {
j3 0:0cdbc206e85f 332 temp_buff[buf_idx] = ' ';
j3 0:0cdbc206e85f 333 }
j3 0:0cdbc206e85f 334 buf_idx = 2;
j3 0:0cdbc206e85f 335
j3 0:0cdbc206e85f 336 if(strlen(msg) <= 28)
j3 0:0cdbc206e85f 337 {
j3 0:0cdbc206e85f 338 memcpy((temp_buff + buf_idx), msg, strlen(msg));
j3 0:0cdbc206e85f 339 temp_buff[buf_idx + strlen(msg)] = NULL;
j3 0:0cdbc206e85f 340
j3 0:0cdbc206e85f 341 if(ln > 3)
j3 0:0cdbc206e85f 342 {
j3 0:0cdbc206e85f 343 lcd.clear_display();
j3 0:0cdbc206e85f 344 ln = 0;
j3 0:0cdbc206e85f 345 }
j3 0:0cdbc206e85f 346 lcd.print_str(ln++, 0, temp_buff);
j3 0:0cdbc206e85f 347 }
j3 0:0cdbc206e85f 348 return ln;
j3 0:0cdbc206e85f 349 }
j3 0:0cdbc206e85f 350
j3 0:0cdbc206e85f 351
j3 0:0cdbc206e85f 352 //*********************************************************************
j3 0:0cdbc206e85f 353 uint8_t printRomId(SharpLS012B7DD01 &lcd, RomId &romId, uint8_t ln)
j3 0:0cdbc206e85f 354 {
j3 0:0cdbc206e85f 355 int8_t idx = 7;
j3 0:0cdbc206e85f 356 uint8_t temp_hi, temp_lo;
j3 0:0cdbc206e85f 357
j3 0:0cdbc206e85f 358 char temp_buff[31];
j3 0:0cdbc206e85f 359 uint8_t buf_idx = 0;
j3 0:0cdbc206e85f 360 temp_buff[buf_idx++] = '>';
j3 0:0cdbc206e85f 361 temp_buff[buf_idx++] = '>';
j3 0:0cdbc206e85f 362 for(; buf_idx < 30; buf_idx++)
j3 0:0cdbc206e85f 363 {
j3 0:0cdbc206e85f 364 temp_buff[buf_idx] = ' ';
j3 0:0cdbc206e85f 365 }
j3 0:0cdbc206e85f 366 buf_idx = 2;
j3 0:0cdbc206e85f 367
j3 0:0cdbc206e85f 368 do
j3 0:0cdbc206e85f 369 {
j3 0:0cdbc206e85f 370
j3 0:0cdbc206e85f 371 temp_hi = ((romId.buffer[idx] & 0xF0) >> 4);
j3 0:0cdbc206e85f 372 temp_lo = (romId.buffer[idx--] & 0x0F);
j3 0:0cdbc206e85f 373
j3 0:0cdbc206e85f 374 //get high nib in ascii
j3 0:0cdbc206e85f 375 if(temp_hi < 10)
j3 0:0cdbc206e85f 376 {
j3 0:0cdbc206e85f 377 temp_buff[buf_idx++] = (temp_hi + 0x30);
j3 0:0cdbc206e85f 378 }
j3 0:0cdbc206e85f 379 else
j3 0:0cdbc206e85f 380 {
j3 0:0cdbc206e85f 381 temp_buff[buf_idx++] = ((temp_hi - 10) + 0x41);
j3 0:0cdbc206e85f 382 }
j3 0:0cdbc206e85f 383
j3 0:0cdbc206e85f 384 //get low nib in ascii
j3 0:0cdbc206e85f 385 if(temp_lo < 10)
j3 0:0cdbc206e85f 386 {
j3 0:0cdbc206e85f 387 temp_buff[buf_idx++] = (temp_lo + 0x30);
j3 0:0cdbc206e85f 388 }
j3 0:0cdbc206e85f 389 else
j3 0:0cdbc206e85f 390 {
j3 0:0cdbc206e85f 391 temp_buff[buf_idx++] = ((temp_lo - 10) + 0x41);
j3 0:0cdbc206e85f 392 }
j3 0:0cdbc206e85f 393
j3 0:0cdbc206e85f 394 temp_buff[buf_idx++] = ' ';
j3 0:0cdbc206e85f 395 }
j3 0:0cdbc206e85f 396 while(idx >= 0);
j3 0:0cdbc206e85f 397 temp_buff[buf_idx++] = NULL;
j3 0:0cdbc206e85f 398
j3 0:0cdbc206e85f 399 if(ln > 3)
j3 0:0cdbc206e85f 400 {
j3 0:0cdbc206e85f 401 lcd.clear_display();
j3 0:0cdbc206e85f 402 ln = 0;
j3 0:0cdbc206e85f 403 }
j3 0:0cdbc206e85f 404 lcd.print_str(ln++, 0, temp_buff);
j3 0:0cdbc206e85f 405
j3 0:0cdbc206e85f 406 return ln;
j3 0:0cdbc206e85f 407 }