MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ;************************************************************************** 00002 ; SC001_multichip.ASM 00003 ; 00004 ; PROGRAM: Solar Garden Light Logger based upon Simple Serial Project 00005 ; 00006 ; 00007 ; NOTE: Chips oscillator calibration is stored in this source and the HEX file. 00008 ; Adjust to suit your chip. 00009 ; 00010 ; DESCRIPTION: 00011 ; I brought a Garden Light logger, and found its performance disappointing. 00012 ; 00013 ; I wanted to know how long the battery was being charged, and how long the LED is on at BRIGHT, DIM and EXHUSTED. 00014 ; 00015 ; Also, how long is the battery above a threshold voltage when the SOLAR CELL is not charging? 00016 ; 00017 ; This project uses a PIC 16F676 to measure the three voltages of interest on the garden light. 00018 ; 00019 ; Instead of storing each voltage sample, it processes the voltages using logic and increments cou nters. 00020 ; 00021 ; The counters are MMcntTimeH,MMcntSolarCellH,MMcntBrightH,MMcntDimH,MMcntVbattH 00022 ; 00023 ; MMcntTimeH, Incremented every tick 00024 ; MMcntSolarCellH, Incremented every tick when the solar Cell is charging battery 00025 ; MMcntBrightH, Incremented every tick when the LED is bright 00026 ; MMcntDimH, Incremented every tick when the LED is DIM 00027 ; MMcntVbattH Incremented every tick when the battery is not being charged and is abov e a threshold voltage. 00028 ; 00029 ; The ticks are every 4 seconds. 00030 ; 00031 ; The onlytime when the counters are not being activily incremented is just before dawn at about 0 3:00 00032 ; 00033 ; It uses TMR1 to provides a realtime clock and ticks at 15 seconds. Once a day it saves the count s and resets them. 00034 ; 00035 ; It uses the 128 byte EEPROM to store calibration parameters and the days counts for about 9 day' s worth of samples. 00036 ; 00037 ; It is based on a simple serial project that receives serial commands from a tty program. 00038 ; 00039 ; This allows simple access to the logger while it is running, using a tty terminal program. 00040 ; 00041 ; 00042 ; 00043 ; Serial Commands:- 00044 ; 00045 ; ; w,p,r,g,f,a 00046 ; 00047 ; Logger instructions MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00048 ; 00049 ; On reset, Counts are reset, and after 4 seconds the chip will auto sample at rate set in eeprom[ 14] 00050 ; 00051 ; m; Display Vsolar,Vbatt,VtopLED,count,SolarCont,brightCount,DimmCount,Vbatt&NoChrgeCnt 00052 ; M; ResetCounts 00053 ; s; Start ticks 00054 ; S; Stop ticks 00055 ; d; dump Conts stored in EEPROM 00056 ; 00057 ; gaa; get EEPROM values 00058 ; paadd; put EEPROM values 00059 ; 00060 ; raa; read FILE or RAM values 00061 ; waadd; write FILE or RAM values 00062 ; 00063 ; The voltages are measured relative to Vref. Vref is connected to the top of a BLUE LED, which pr ovides 3.25 volts 00064 ; This is only turned on to make the measurements, one every 4 seconds. 00065 ; 00066 ; tnn; toggle pin that turns on the BLUE LED that acts as a reference, 00067 ; 1nn; sets pin that turns on the BLUE LED that acts as a reference, turns of f LED 00068 ; 0nn; resets pin that turns on the BLUE LED that acts as a reference, turns on LED 00069 ; 00070 ; 00071 ; NOTE: when repeat sampling the output is: ,count,SolarCont,brightCount,DimmCountVsolar,Vbatt,Vto pLED,* 00072 ; 00073 ; AN1 is VREF, so the A to D can be made more sensitive and more stable when measuring V6,V5,V4. 00074 ; AN6 V6 = Vsolar, 00075 ; AN5 V5 = Vbattery - AN1 is VREF, so the A to D can be made more sensitive when measuring V4. 00076 ; AN4 V4 = VtopOfLED 00077 ; 00078 ; the EEPROM can be used to store config data, use pAADD; and gAA; 00079 ; the ee[n] values need to be < 0 00080 ; 00081 ; g00; Get V6-V5+ee[g00] - If >0 then inc Solar Count 00082 ; g01; Get V5-v4-ee[g01] - If >0 then inc Dim Count 00083 ; g02; Get V5-v4-ee[g01]-ee[g02] - If >0 then inc Bright Count 00084 ; g03; Get V6-0xFF*ee[g03]-ee[g04] - If >0 then inc Vbattery 00085 ; g04; Get V6-0xFF*ee[g03]-ee[g04] - If >0 then inc Vbattery 00086 ; 00087 ; I started with left justified values, but ended up with right justified 16 bit subtracts. 00088 ; 00089 ; Measured Voltages: 00090 ; Vdd = 3.82 00091 ; Vbatt = 0.94 00092 ; Vref = 3.25 - using a BLUE LED 00093 ; 00094 ; Measured values of Solar Cell batter voltage for Dim 00095 ; 0 volts MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 3 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00096 ; Off 00097 ; 1.74volts 00098 ; Vbattery - dim 00099 ; 2.2volts 00100 ; Vbattery - Bright 00101 ; 00102 ; 00103 ; Uses TMR1 and MMloopCount: 00104 ; 00105 ; TMR1 overflows Fosc/4, 1e6/2^16m = 1/15.2587890625 00106 ; 00107 ; My Serial LCD display needs an inter Character delay to process the last character. 00108 ; You can configure an inter character deleay here. 00109 ; 00110 ; g05; Get delay between characters in bits to allow a serial LCD to be used. 00111 ; 00112 ; Here we use the EEPROM to store the counters. 00113 ; g07; Pointer to Samples 00114 ; g08 to g7F; Samples - there are 103 bytes, there are 5 counts so 10 sets can be stored. 00115 ; 00116 ; 00117 ; Special Instructions. 00118 ; tDD; Toggle for DD ms 00119 ; 1DD; Set 1 for DD ms wait for DD and then set to 1 00120 ; 0DD; Set 0 for DD ms wait for DD and reset 00121 ; 00122 ; aDD; read AtoD converter and output in hex, DD is ADCON0 00123 ; 00124 ; File Registers 00125 ; wAADD; write DD to register AA 00126 ; rAA; read AA and output to serial port 00127 ; 00128 ; File reg 25,26,27 stores the time to the next save of the EEPROM counts. 00129 ; R25; hours to next store 00130 ; R26; minutes to next store 00131 ; R27; seconds to next store 00132 ; 00133 ; This is needed as you want to save the counts when they are not being incremented, 00134 ; which is just before dawn. 00135 ; 00136 ; If you reset the PIC at 18:00, the chip will save at about 03:00 00137 ; 00138 ; EEPROM 00139 ; pAADD; write DD to EEPROM register AA 00140 ; gAA; read EEPROM register AA and output to serial port 00141 ; 00142 ; PRIPHERALS 00143 ; 00144 ; SERIAL PORT CONTROL: 00145 ; 00146 ; PORT RA0 is Serial input 00147 ; PORT RA0 is serial output 00148 ; MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00149 ; usb gmus-03 USB Serial Adapter 00150 ; 00151 ; TX D9 Pin 3 -[4k7]----+-----PA0 00152 ; RX D9 Pin 2 ----------/ 00153 ; 00154 ; GND D9 Pin 5 ---------------- 0V 00155 ; 00156 ; 29/09/2008 discovered that using PA0 affects AtoD Reading. 00157 ; 00158 ; TX D9 Pin 3 -[4k7]----+-----PC5 00159 ; RX D9 Pin 2 ----------/ 00160 ; 00161 ; GND D9 Pin 5 ---------------- 0V 00162 ; 00163 ; 00164 ; Crystal: 4MHz - Uses Internal RC oscillator 00165 ; 00166 ; I/O used:- 00167 ; 00168 ; ; Port B is used for the LCD 00169 ; 00170 ; OPERATION: 00171 ; The TMR1 ticks overflow and trigger the AtoD process periodically. 00172 ; The three volatages are measured, and then compared using logic. 00173 ; The appropriate counters are incremented. 00174 ; 00175 ; Every sample the current counts are output on the serial port. 00176 ; 00177 ; It is possible to use the serail port to update the EEPROM and start and stop the sampling. 00178 ; 00179 ; 00180 ; MMcntTimeH,MMcntSolarCellH,MMcntBrightH,MMcntDimH,MMcntVbattH 00181 ; 00182 ; Samples from logger - Vref is relative to Vdd, others are relative to Vref 00183 ;CNT ,SolC,Bright,Dim,Vbatt,,/,INTCON,T1,,t,HHMM,SS ,,,Vsc,Vba,Vled,Vref 00184 ; 00185 ;MMcntTimeH,MMcntSolarCellH,MMcntBrightH,MMcntDimH,MMcntVbattH,/t,hhmmss,Vsolar,Vbattery,VtopOfLED,Vref, //s,Vsolar-Vbatt,Vbatt-Vled 00186 ;007B,007B,0000,0000,0000,/t,08380D,0360,02B0,02B2,0345,//s,00B0,l,FFFE,,* 00187 ;007C,007C,0000,0000,0000,/t,08380C,0360,02B3,02B0,0345,//s,00AD,l,0003,,* 00188 ; 00189 ; 00190 ; MMcntTimeH,MMcntSolarCellH,MMcntBrightH,MMcntDimH,MMcntVbattH 00191 ; Every day the counts are stored and backed up, in the order: 00192 ; MMcntTimeH,MMcntSolarCellH,MMcntBrightH,MMcntDimH,MMcntVbattH 00193 ; 00194 ; Use the d; command to dump the EEPROM counts. 00195 ;d;* 00196 ;19,* 00197 ;19,,FFFF,FFFF,FFFF,FFFF,FFFF,* 00198 ;23,,FFFF,FFFF,FFFF,FFFF,FFFF,* 00199 ;2D,,FFFF,FFFF,FFFF,FFFF,FFFF,* 00200 ;37,,FFFF,FFFF,FFFF,FFFF,FFFF,* MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 5 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00201 ;41,,FFFF,FFFF,FFFF,FFFF,FFFF,* 00202 ;4B,,FFFF,FFFF,FFFF,FFFF,FFFF,* 00203 ;55,,FFFF,FFFF,FFFF,FFFF,FFFF,* 00204 ;5F,,FFFF,FFFF,FFFF,FFFF,FFFF,* 00205 ;69,,FFFF,FFFF,FFFF,FFFF,FFFF,* 00206 ;73,,FFFF,,** 00207 ; 00208 ; 00209 ; Future Enhancements: 00210 ; 00211 ; 00212 ; AUTHOR: Douglas Rice 00213 ; Copyright 2006 00214 ; 00215 ;************************************************************************** 00216 00217 00218 ;-------------------------------------------------------------------------- 00219 ; Sec 0. #Defines tofor different chips 00220 ;-------------------------------------------------------------------------- 00221 00222 ; uncomment only one of these 00223 ; 00224 00225 #define pic16F676 1 00226 ;#define pic12F675 1 00227 00228 LIST w=1, R=DEC 00229 00230 00231 ;-------------------------------------------------------------------------- 00232 ; Sec 0.1 #Defines for 16F676 00233 ;-------------------------------------------------------------------------- 00234 00235 ifdef pic16F676 00236 #define wantAtoD 00237 00238 LIST P=16F676, R=DEC 00239 INCLUDE "p16F676.inc" 00001 LIST 00002 ; P16F676.INC Standard Header File, Version 1.00 Microchip Technology, Inc. 00261 LIST 00240 2000 0000 0006 0007 00241 __idlocs 0x0676 0006 00242 ;__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _INTRC_OSC_CLKOUT _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & 0x31FF 2007 3184 00243 __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & 0x31F F 00244 00245 cblock 0x20 00246 endc 00247 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 6 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00248 ; *********** I/O EQUATES ************** 00000000 00249 PA0 EQU 0 ; Serial Out and Serial In - moved. This affects AtoD result. 00000001 00250 PA1 EQU 1 ; Output 00000002 00251 PA2 EQU 2 ; Output 00000007 00252 PA7 EQU 7 ; Output 00253 00000005 00254 PC5 EQU 5 ; Serial Out and Serial In 00255 00256 00257 00258 ;PORT_RS232 EQU PORTA 00259 ;TRIS_RS232 EQU TRISA 00260 ;RS232tx EQU PA0 ; Serial Out 00261 ;RS232rx EQU PA0 ; Serial In needs to be equal to BUTTON_RS232 00262 00000007 00263 PORT_RS232 EQU PORTC 00000087 00264 TRIS_RS232 EQU TRISC 00000005 00265 RS232tx EQU PC5 ; Serial Out 00000005 00266 RS232rx EQU PC5 ; Serial In needs to be equal to BUTTON_RS232 00267 00268 00000003 00269 OUTPUTPIN EQU 3 ; 00270 00271 00272 00273 endif 00274 00275 00276 00277 ;-------------------------------------------------------------------------- 00278 ; Sec 0.2 #Defines for 16F876 00279 ;-------------------------------------------------------------------------- 00280 00281 ifdef pic16F876 00282 #define buildPWM 1 00283 LIST P=16F876, R=DEC 00284 INCLUDE "p16F876.inc" 00285 00286 __idlocs 0x0876 00287 __CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_ON & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF 00288 00289 cblock 0x20 00290 endc 00291 00292 ; *********** I/O EQUATES ************** 00293 00294 PORT_RS232 EQU PORTA 00295 TRIS_RS232 EQU TRISA 00296 RS232tx EQU 0 ; Serial Out 00297 RS232rx EQU 0 ; Serial In needs to be equal to BUTTON_RS232 00298 00299 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 7 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00300 endif 00301 00302 00303 ;-------------------------------------------------------------------------- 00304 ; Sec 0.3 #Defines for 12F675 00305 ;-------------------------------------------------------------------------- 00306 00307 ifdef pic12F675 00308 #define wantAtoD 00309 LIST P=12F675, R=DEC 00310 00311 INCLUDE "p12F675.inc" 00312 __idlocs 0x0675 00313 __config _PWRTE_ON & _WDT_OFF & _BODEN_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF 00314 00315 00316 cblock 0x20 00317 endc 00318 00319 ; *********** I/O EQUATES ************** 00320 00321 PORT_RS232 EQU GPIO 00322 TRIS_RS232 EQU TRISIO 00323 RS232tx EQU 5 ; Serial Out 00324 RS232rx EQU 5 ; Serial In needs to be equal to BUTTON_RS232 00325 00326 OUTPUTPIN EQU 3 00327 00328 PORTA EQU GPIO 00329 PORTB EQU GPIO 00330 00331 TRISA EQU TRISIO 00332 TRISB EQU TRISIO 00333 00334 endif 00335 00336 00337 00338 ;-------------------------------------------------------------------------- 00339 ; Sec 1. Equates and Constants 00340 ;-------------------------------------------------------------------------- 00341 ; The General Purpose Registers start at the end of the 00342 ; Special Purpose Registers. 00343 00344 ; IPMentState values 00345 ; in normal running or in time setting modes 00346 ; 00347 00348 ; DoTimeSlice bits 00349 ; these bits are set to schedule a timer chain event 00000000 00350 DTsS4event EQU 0 ; 00000000 00351 RUN_BUFF EQU 0 ; 00352 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 8 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00353 ; IPtrigMenu 00000000 00354 DTSFast EQU 0 00355 00356 ;-------------------------------------------------------------------------- 00357 ; Sec 1.1 Button and LED 00358 ;-------------------------------------------------------------------------- 00359 00000005 00360 BUTTON_RS232 EQU RS232rx ; EDG - Bottom Buttom 00000003 00361 BUTTON_DOWN EQU 3 ; EDG - STore Counts Button. 00362 00363 ;-------------------------------------------------------------------------- 00364 ; Sec 1.2 EEPROM LOCATIONS 00365 ;-------------------------------------------------------------------------- 00366 ; g00; Get V6-V5-ee[g00] - If >0 then inc Solar Count 00367 ; g01; Get V5-v4-ee[g01] - If >0 then inc Dim Count 00368 ; g02; Get V5-v4-ee[g01]-ee[g02] - If >0 then inc Bright Count 00369 ; g03; Get V6- ee[g03],ee[g04]- If >0 then inc Vbattery 00370 ; 00371 ; g00,g01,g02,are too insensitive, and the values have to be -2,-2,-1 00372 ; g03 = 0x78 00373 00000000 00374 EEsolarOffset EQU 0x00 00000001 00375 EEdimOffset EQU 0x01 00000002 00376 EEbrightOffset EQU 0x02 00000003 00377 EEbatteryOffsetH EQU 0x03 00000004 00378 EEbatteryOffsetL EQU 0x04 00000005 00379 EEinterCharDelay EQU 0x05 00000006 00380 EEAtoDappatureDelay EQU 0x06 00381 ; EQU 0x06 00382 ; EQU 0x07 00000005 00383 EEinterCharDelay EQU 0x05 00384 00385 00000008 00386 EEFILESTART EQU 0x08 00000007 00387 EEFILEPTR EQU EEFILESTART-1 00388 00389 00390 ;-------------------------------------------------------------------------- 00391 ; Sec 2.0 Variables 00392 ;-------------------------------------------------------------------------- 00393 ; Variables start 0x0C 00394 ; 00395 00396 ; DoTimeSlice Bits, to schedule, set bit 00397 00398 cblock 00399 00400 ; 00401 ; AD AtoD routine Variables. 00402 ; 00000020 00403 ADrl 00000021 00404 ADansel 00405 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 9 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00406 00407 00000022 00408 BTdelay 00409 00000023 00410 BTdelayCnt 00000024 00411 BTdelayCnt1ms 00412 00413 00000025 00414 CLhh 00000026 00415 CLmm 00000027 00416 CLss 00000028 00417 DoTimeSlice 00418 00419 00000029 00420 IPnew 0000002A 00421 IPlast 0000002B 00422 IPbuttonEvent 00423 0000002C 00424 IPnewFast 0000002D 00425 IPlastFast 0000002E 00426 IPbuttonEventUp 00427 0000002F 00428 IPtrigMenu 00429 00430 ; 00431 ; MM Solar Cell Measurement Code. 00432 ; 00000030 00433 MMtmph 00000031 00434 MMtmp 00435 00436 ; Using Vref as Max 00000032 00437 MMV6h 00000033 00438 MMV6l 00000034 00439 MMV5h 00000035 00440 MMV5l 00000036 00441 MMV4h 00000037 00442 MMV4l 00443 ; Using Vdd as Max 00000038 00444 MMV1h 00000039 00445 MMV1l 00446 00447 00448 ; count, time, solarCell, bright, dim , 0000003A 00449 MMcntTimeH 0000003B 00450 MMcntTimeL 0000003C 00451 MMcntSolarCellH 0000003D 00452 MMcntSolarCellL 0000003E 00453 MMcntBrightH 0000003F 00454 MMcntBrightL 00000040 00455 MMcntDimH 00000041 00456 MMcntDimL 00000042 00457 MMcntVbattH 00000043 00458 MMcntVbattL MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 10 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00459 ; 00460 ;MMloopCount 00461 00000044 00462 EEptrEEPROM ; pointer to EEPROM 00000045 00463 EEptrMEM ; pointer to Memory - count, time, solarCell, bright, dim 00000046 00464 EEloopCount 00000047 00465 EEloopCount2 00466 00467 00468 ; variables used by Serial input and output routines 00000048 00469 RStxTemp 00000049 00470 RStxTemp2 0000004A 00471 RSloopCnt 00472 0000004B 00473 RSdelayCnt 0000004C 00474 RSin 0000004D 00475 RSout 0000004E 00476 RSinterCharDelay 0000004F 00477 RSafterCRCharDelay 00478 00479 ; Serial input buffer 00000050 00480 RSipBuffCnt ; input buffer counter 00481 ; start of buffer 00000051 00482 RScmd 00000052 00483 RSAa ; 00000053 00484 RSaA ; 00000054 00485 RSDd ; 00000055 00486 RSdD ; 00000056 00487 RSterminator 00488 ; end of buffer 00489 00490 ; temporary variables 00000057 00491 RSaddr 00000058 00492 RSdata 00493 ; 00494 ENDC 00495 00496 ;-------------------------------------------------------------------------- 00497 ; Sec 3. MACROS 00498 ;-------------------------------------------------------------------------- 00499 00500 TEST_STRADDLE MACRO START 00501 if high( $ ) != high( START ) 00502 Error "Table straddles Page Boundary " + Start 00503 endif 00504 endm 00505 00506 ;-------------------------------------------------------------------------- 00507 ; Sec 4. Program Code 00508 ;-------------------------------------------------------------------------- 0000 00509 ORG 0 0000 2806 00510 GOTO Start 00511 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 11 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0004 00512 ORG 4 0004 0009 00513 RETFIE 0005 2B3D 00514 GOTO Intrtn 00515 00516 ;-------------------------------------------------------------------------- 00517 ; Sec 4.1 Main Program Init Code 00518 ;-------------------------------------------------------------------------- 00519 0006 00520 Start 00521 00522 ;MOVLW 0x6C ; load the Calib 0006 3098 00523 movlw 0x98 00524 00525 ;CALL OscCalValue 0007 1683 1303 00526 banksel OSCCAL 0009 0090 00527 MOVWF OSCCAL 00528 00529 00530 ; Debug jumps: 00531 ; CALL MMtsSample1false 00532 ; CALL MMtsSampleProcess 00533 00534 000A 1683 1303 00535 BANKSEL TRISA 000C 3037 00536 MOVLW 1 << 4 | 1 << 5 | 0 << 3 | 1 << 2 | 1 << 1 | 1 << 0 000D 0085 00537 MOVWF TRISA 00538 00539 ;BANKSEL TRISC 000E 3037 00540 MOVLW 1 << 4 | 1 << 5 | 1 << 2 | 1 << 1 | 1 << 0 000F 0087 00541 MOVWF TRISC 00542 00543 ; There is currently a conflict as serial is on RA0 0010 1683 1303 00544 banksel ANSEL 0012 3032 00545 MOVLW 1 << ANS5 | 1 << ANS4 | 0 << ANS2 | 1 << ANS1 | 0 << ANS0 0013 0091 00546 movwf ANSEL 00547 00548 ; Turn off the comparator. 0014 3007 00549 MOVLW 1 << CM2 | 1 << CM1 | 1 << CM0 0015 1283 1303 00550 banksel CMCON 0017 0099 00551 MOVWF CMCON 00552 0018 220C 00553 CALL MMts 00554 0019 3032 00555 MOVLW 1 << ANS5 | 1 << ANS4 | 1 << ANS1 001A 00A1 00556 movwf ADansel 00557 001B 21C5 00558 CALL ADconvert 00559 001C 2140 00560 CALL INinit 001D 2158 00561 CALL INsayHello 00562 00563 ; set up for manual start, get repeat time in g14 00564 ; reset logger and delay first time for 8 seconds MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 12 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00565 ; to allow user to type S; on reset. 00566 001E 21EB 00567 CALL MMinit ; init 001F 21F6 00568 CALL MMinitTime 00569 0020 2310 00570 CALL EEfileDump 00571 0021 2822 00572 GOTO MainLoop 00573 00574 00575 ;-------------------------------------------------------------------------- 00576 ; Sec 4.2 Main Program 00577 ;-------------------------------------------------------------------------- 00578 0022 00579 MainLoop 0022 1283 1303 00580 BANKSEL DoTimeSlice 0024 2037 00581 CALL IPtimesliceFast 00582 00583 ; test for rising edge 0025 1AAE 00584 BTFSC IPbuttonEventUp,BUTTON_RS232 ; RS232 input start 0026 2046 00585 CALL IPrs232 00586 0027 180C 00587 BTFSC PIR1,TMR1IF 0028 220C 00588 CALL MMts 00589 0029 0828 00590 MOVF DoTimeSlice,w 002A 1903 2822 00591 Bz MainLoop 00592 002C 1828 00593 BTFSC DoTimeSlice,RUN_BUFF 002D 203F 00594 CALL DLrunBuff 00595 002E 2822 00596 GOTO MainLoop 00597 00598 00599 00600 ;-------------------------------------------------------------------------- 00601 ; Sec 5. Subroutines, procedures and functions 00602 ;-------------------------------------------------------------------------- 00603 00604 00605 ;-------------------------------------------------------------------------- 00606 ; Sec 5.1 Button Poll Routine 00607 ;-------------------------------------------------------------------------- 00608 002F 00609 IPtimeslice 00610 ; --_____ button press 00611 ; ----___ 00612 00613 ; __----- /IPnew 00614 ; ----___ IPlast 00615 ; __--___ 00616 ; 00617 ; MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 13 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00618 ; 00619 ; This reads all Port A inputs and looks for Press 002F 0829 00620 MOVFW IPnew 0030 00AA 00621 MOVWF IPlast 0031 0805 00622 MOVFW PORTA 0032 00A9 00623 MOVWF IPnew 00624 ; IP last contains new setting, IPlast contains previous 00625 ; look for falling edges 0033 0929 00626 COMF IPnew,W 0034 052A 00627 ANDWF IPlast,W 00628 ; now force IPbuttonEvent bits to high for new pressed button 00629 ; the service routine should reset the bit to clear the event. 0035 04AB 00630 IORWF IPbuttonEvent,F 0036 0008 00631 RETURN 00632 0037 00633 IPtimesliceFast 00634 ; Look for rising edges 0037 082C 00635 MOVFW IPnewFast 0038 00AD 00636 MOVWF IPlastFast 0039 0807 00637 MOVFW PORT_RS232 003A 00AC 00638 MOVWF IPnewFast 00639 003B 092D 00640 COMF IPlastFast,W 003C 052C 00641 ANDWF IPnewFast,W 003D 04AE 00642 IORWF IPbuttonEventUp,F 003E 0008 00643 RETURN 00644 ;-------------------------------------------------------------------------- 00645 ; Sec 5.2 00646 ;-------------------------------------------------------------------------- 00647 00648 ;-------------------------------------------------------------------------- 00649 ; Sec 5.2 .1 run process on request 00650 ;-------------------------------------------------------------------------- 00651 003F 00652 DLrunBuff 003F 1283 1303 00653 BANKSEL DoTimeSlice 0041 1028 00654 BCF DoTimeSlice,RUN_BUFF 00655 0042 084C 00656 MOVFW RSin 0043 28C1 00657 GOTO RSbuffInput 00658 ;return 00659 00660 00661 00662 00663 ;-------------------------------------------------------------------------- 00664 ; Sec 5.3 Button Input functions 00665 ;-------------------------------------------------------------------------- 00666 00667 0044 00668 IPdownPressed 0044 11AB 00669 BCF IPbuttonEvent,BUTTON_DOWN 0045 2AF7 00670 GOTO EEfileCounts MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 14 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00671 00672 0046 00673 IPrs232 0046 12AE 00674 BCF IPbuttonEventUp,BUTTON_RS232 0047 286D 00675 GOTO RSrs232in 00676 00677 00678 ;-------------------------------------------------------------------------- 00679 ; Sec 5.4 Clock Chain Routine 00680 ;-------------------------------------------------------------------------- 00681 0048 00682 CLtimeslice 00683 ; 0048 1D0B 00684 BTFSS INTCON,T0IF 0049 0008 00685 RETURN 00686 00687 ; TMR0 timeout 004A 110B 00688 BCF INTCON,T0IF 004B 1428 00689 BSF DoTimeSlice,DTsS4event 00690 004C 202F 00691 CALL IPtimeslice 004D 0008 00692 RETURN 00693 00694 00695 ;-------------------------------------------------------------------------- 00696 ; Sec 5.5 Serial Input Routine 00697 ;-------------------------------------------------------------------------- 00698 004E 00699 RSjumpTable 00700 ; Its not a CLICK or HOLD 004E 3000 00701 MOVLW high ( $ ) 004F 008A 00702 MOVWF PCLATH ; Assume that the tabel is in the bottom 256 byte 00703 ; restrict to 32 states 00704 ;ANDLW 0x03 0050 084A 00705 MOVFW RSloopCnt 0051 0782 00706 ADDWF PCL,f 00707 ; set choice State Table - limited to 8 states 0052 3477 00708 RETLW 'w' 0053 28F5 00709 GOTO RSbuffInput2start 0054 3470 00710 RETLW 'p' 0055 28FA 00711 GOTO RSbuffInput3start 0056 3472 00712 RETLW 'r' 0057 2903 00713 GOTO RSbuffInput4start 0058 3467 00714 RETLW 'g' 0059 290E 00715 GOTO RSbuffInput5start 00716 ; RETLW 'f' 00717 ; GOTO RSbuffInput6start 005A 3474 00718 RETLW 't' 005B 2912 00719 GOTO RSbuffInput7start 005C 3431 00720 RETLW '1' 005D 2914 00721 GOTO RSbuffInput8start 005E 3430 00722 RETLW '0' 005F 2916 00723 GOTO RSbuffInput9start MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 15 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0060 3461 00724 RETLW 'a' 0061 2918 00725 GOTO RSbuffInput10start 0062 344D 00726 RETLW 'M' 0063 291A 00727 GOTO RSbuffInput11start 0064 346D 00728 RETLW 'm' 0065 291C 00729 GOTO RSbuffInput12start 0066 3473 00730 RETLW 's' 0067 2924 00731 GOTO RSbuffInput13start 0068 3453 00732 RETLW 'S' 0069 2926 00733 GOTO RSbuffInput14start 006A 3464 00734 RETLW 'd' 006B 2928 00735 GOTO RSbuffInput15start 006C 3400 00736 RETLW 0 00737 00738 TEST_STRADDLE RSjumpTable M if high( $ ) != high( RSjumpTable ) M Error "Table straddles Page Boundary " + Start M endif 00739 00740 00741 00742 00743 00744 ;************************************************** 006D 00745 RSrs232in 00746 00747 ; Test is in main loop or uncomment code below to 00748 ; spin for a start bit 00749 ; CLRWDT 00750 ; BTFSS PORT_RS232,RS232rx 00751 ; GOTO RSrs232in 00752 00753 00754 ; CALL RSdelayBit ; delay through Stop Bit 006D 20B3 00755 CALL RSdelayHalfBit ; delay halfway into first bit 00756 006E 3008 00757 movlw 8 006F 00CA 00758 movwf RSloopCnt 0070 00759 RSrs232inL0 0070 20B5 00760 CALL RSdelayBit ; delay halfway into first bit 00761 0071 0807 00762 MOVFW PORT_RS232 0072 3920 00763 ANDLW 1<< RS232rx ; mask off bit 0073 3EE0 00764 ADDLW -1<< RS232rx ; use ripple carry to move into C 0074 0CCC 00765 RRF RSin,F 00766 00767 ; CALL RSdelayBit 0075 0BCA 00768 DECFSZ RSloopCnt,f 0076 2870 00769 goto RSrs232inL0 00770 00771 ; do not test for Stop bit 0077 09CC 00772 COMF RSin,f 0078 1428 00773 BSF DoTimeSlice,RUN_BUFF MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 16 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0079 0008 00774 RETURN 00775 00776 00777 ;-------------------------------------------------------------------------- 00778 ; Sec 5.6 Serial Output Routines 00779 ;-------------------------------------------------------------------------- 00780 007A 00781 RSwrtWasHex 00782 ; 00783 ; Write W reg as HEX to RS232 00784 ; 007A 00C9 00785 MOVWF RStxTemp2 007B 0E49 00786 SWAPF RStxTemp2,W 007C 207F 00787 CALL RSwrtHexNibble 007D 0849 00788 MOVFW RStxTemp2 007E 287F 00789 GOTO RSwrtHexNibble 00790 00791 007F 00792 RSwrtHexNibble ; currently only displays 0..9, A..F 007F 390F 00793 ANDLW 0x0F 0080 3E06 00794 ADDLW 0x06 ; is it A..F, if so trigger a digit overflow 0081 1883 00795 SKPNDC 0082 3E07 00796 ADDLW 7; subtract 10, then add 'A'-'0' 0083 3E2A 00797 ADDLW 0x30-6 ; Subtract extra 6 added to cause DC 0084 00CD 00798 MOVWF RSout 0085 2890 00799 GOTO RStxChar 00800 00801 0086 00802 RS232sendCR 0086 300D 00803 MOVLW 0x0D 0087 2890 00804 GOTO RS232sendWByte 00805 0088 00806 RS232sendLF 0088 300A 00807 MOVLW 0x0A 0089 2890 00808 GOTO RS232sendWByte 00809 008A 00810 RS232sendSpace 008A 3020 00811 MOVLW ' ' 008B 2890 00812 GOTO RS232sendWByte 00813 008C 00814 RS232sendComma 008C 302C 00815 MOVLW ',' 008D 2890 00816 GOTO RS232sendWByte 00817 008E 00818 RS232sendStar 008E 302A 00819 MOVLW '*' 008F 2890 00820 GOTO RS232sendWByte 00821 00822 0090 00823 RS232sendWByte 0090 00824 RStxChar 00825 ; 00826 ; Output Start Bit MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 17 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00827 ; Start bit is low, data bits are inverted 00828 ; 00829 0090 00C8 00830 movwf RStxTemp 0091 09C8 00831 comf RStxTemp,f 0092 1287 00832 BCF PORT_RS232,RS232tx 00833 00834 ; Make RS232 pin an ouput while transmitting character 0093 1683 1303 00835 BANKSEL TRIS_RS232 0095 1287 00836 BCF TRIS_RS232,RS232tx 0096 1283 1303 00837 BANKSEL PORT_RS232 00838 00839 ; 1200 baud output 00840 ; move the char into RStxtemp, it is destroyed. 00841 ;Start Bit 0098 1687 00842 BSF PORT_RS232,RS232tx 00843 0099 20B5 00844 call RSdelayBit 009A 3008 00845 movlw 8 009B 00CA 00846 movwf RSloopCnt 00847 009C 00848 RStxCharLp1 00849 00850 ; After start bit, which is 1, then test each bit 00851 ; I need to set PA:0 to same as LSB RStxTemp 00852 ; this compares PA:0 with RStxTemp so see if it needs toggling 00853 ; The xorwf PORT_RS232,f causes the bit to be toggled if required. 00854 009C 0CC8 00855 RRF RStxTemp,f 009D 0803 00856 movfw STATUS 009E 3901 00857 andlw 1 << C ; mask off bit 009F 3E1F 00858 addlw ( 1 << RS232tx) -1 ; shift bit by using a ripple carry 00A0 0607 00859 xorwf PORT_RS232,W ; Doeas output need toggling ? 00A1 3920 00860 andlw 1 << RS232tx ; Mask off output pin 00A2 0687 00861 xorwf PORT_RS232,f ; Toggle output pin if needed 00A3 20B5 00862 call RSdelayBit ; delay bit 00863 00864 00A4 0BCA 00865 decfsz RSloopCnt,f 00A5 289C 00866 goto RStxCharLp1 00867 00A6 1287 00868 BCF PORT_RS232,RS232tx 00A7 20B5 00869 call RSdelayBit ; apply stop bit 00870 00871 ; apply an inter character delay of 4 bits 00872 ; call RSdelayBit 00873 ; get inter character delay from the EEPROM 00874 00875 ; you have to read from RAM, and not EEPROM as pXXXX; does not work as EEwrt needs delay before EEread 00A8 084E 00876 MOVFW RSinterCharDelay 00A9 00877 RStxCharInterDelay 00A9 00CA 00878 movwf RSloopCnt MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 18 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00879 00AA 00880 RStxCharLp2 00AA 20B5 00881 call RSdelayBit 00AB 0BCA 00882 decfsz RSloopCnt,f 00AC 28AA 00883 goto RStxCharLp2 00884 00885 00886 ; Make RS232 pin an input so that main loop can test for start bit 00AD 1683 1303 00887 BANKSEL TRIS_RS232 00AF 1687 00888 BSF TRIS_RS232,RS232tx 00B0 1283 1303 00889 BANKSEL PORT_RS232 00890 00B2 0008 00891 RETURN 00892 00893 00894 ; timing functions to delay serial routines for a bit or half bit. 00895 00B3 00896 RSdelayHalfBit 00B3 301D 00897 MOVLW 0x1D ; shorten delay as edge detector takes about 22 us for 4800 baud 00B4 28B7 00898 GOTO RSdelayBit0 00899 00B5 00900 RSdelayBit 00B5 0000 00901 NOP 00B6 3040 00902 MOVLW 0x40 ; for 4800 baud 00903 00B7 00904 RSdelayBit0 00B7 00CB 00905 MOVWF RSdelayCnt 00B8 00906 RSdelayBit1 00B8 0BCB 00907 DECFSZ RSdelayCnt,f ; 1 00B9 28B8 00908 GOTO RSdelayBit1 ; 2 clk 00BA 0064 00909 CLRWDT 00BB 0008 00910 RETURN 00911 00912 00913 00914 ;-------------------------------------------------------------------------- 00915 ; Sec 5.7 Serial Output Format Routines 00916 ;-------------------------------------------------------------------------- 00917 00BC 00918 RSasciiToNibble 00BC 00CC 00919 MOVWF RSin 00920 ; if 0..1 then 0x30 to 0x39 00921 ; if A..F then 0x41 to 0x46 00922 ; if a..f then 0x61 to 0x66 00923 ; test if bit 4 set and assume a letter or number 00BD 1E4C 00924 BTFSS RSin,4 00BE 3E09 00925 ADDLW 0x09 ; letter so add 9 00BF 390F 00926 ANDLW 0x0F ; mask of nibble 00C0 0008 00927 return 00928 00929 00930 ;-------------------------------------------------------------------------- 00931 ; Sec 5.8 Serial Input Buffer Routine MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 19 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00932 ;-------------------------------------------------------------------------- 00933 00934 ; take serial input CAADD and put into buffer 00935 ; if char id ; the do command 00936 ; if char is CR reset buffer pointer 00937 ; if buff end then reset buff pointer 00938 00000051 00939 RSipbuffStart EQU RScmd 00000056 00940 RSipbuffEnd EQU RSterminator 00941 00C1 00942 RSbuffInput 00C1 00CC 00943 MOVWF RSin 00944 ; look for line feed and reset buff cnt 00C2 3EF3 00945 ADDLW -0x0D 00C3 1D03 28C8 00946 BNZ RSbuffInput1 00947 00C5 00948 RSbuffInput1start 00C5 3051 00949 MOVLW RSipbuffStart 00C6 00D0 00950 MOVWF RSipBuffCnt 00C7 0008 00951 RETURN 00952 00C8 00953 RSbuffInput1 00954 ; end of line command - do command 00C8 3ED2 00955 ADDLW -';'+0x0D 00C9 1D03 28CC 00956 BNZ RSbuffInput2 00CB 28D9 00957 GOTO RSbuffInputProcess 00958 00CC 00959 RSbuffInput2 00960 ; Store the current time into the next register. 00CC 0850 00961 MOVFW RSipBuffCnt 00CD 0084 00962 MOVWF FSR 00CE 084C 00963 MOVFW RSin 00CF 0080 00964 MOVWF INDF 00D0 0FD0 00965 INCFSZ RSipBuffCnt,f 00D1 0850 00966 MOVFW RSipBuffCnt 00967 00D2 3EA9 00968 ADDLW -(RSipbuffEnd+1) 00969 ; Check if the end of memory 00D3 1D03 00970 SKPZ 00D4 2931 00971 GOTO RSbuffInputEnd1 00D5 3051 00972 MOVLW RSipbuffStart 00D6 00D0 00973 MOVWF RSipBuffCnt 00974 00975 ; reset cursor 00976 00D7 2086 00977 CALL RS232sendCR 00D8 0008 00978 RETURN 00979 00980 00D9 00981 RSbuffInputProcess 00D9 3051 00982 MOVLW RSipbuffStart 00DA 00D0 00983 MOVWF RSipBuffCnt 00984 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 20 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00DB 0852 00985 MOVFW RSAa 00986 ; if 0..1 then 0x30 to 0x39 00987 ; if A..F then 0x41 to 0x46 00988 ; if a..f then 0x61 to 0x66 00989 ; test if bit 4 set and assume a letter or number 00990 00DC 1E52 00991 BTFSS RSAa,4 00DD 3E09 00992 ADDLW 0x09 ; letter so add 9 00DE 390F 00993 ANDLW 0x0F ; mask of nibble 00DF 00CC 00994 MOVWF RSin 00E0 0ECC 00995 SWAPF RSin,F 00996 00E1 0853 00997 MOVFW RSaA 00E2 1E53 00998 BTFSS RSaA,4 00E3 3E09 00999 ADDLW 0x09 ; letter so add 9 00E4 390F 01000 ANDLW 0x0F ; mask of nibble 00E5 074C 01001 ADDWF RSin,w 00E6 00D7 01002 MOVWF RSaddr 01003 00E7 0854 01004 MOVFW RSDd 00E8 1E54 01005 BTFSS RSDd,4 00E9 3E09 01006 ADDLW 0x09 ; letter so add 9 00EA 390F 01007 ANDLW 0x0F ; mask of nibble 00EB 00CC 01008 MOVWF RSin 00EC 0ECC 01009 SWAPF RSin,F 01010 00ED 0855 01011 MOVFW RSdD 00EE 1E55 01012 BTFSS RSdD,4 00EF 3E09 01013 ADDLW 0x09 ; letter so add 9 00F0 390F 01014 ANDLW 0x0F ; mask of nibble 00F1 074C 01015 ADDWF RSin,w 00F2 00D8 01016 MOVWF RSdata 01017 01018 ; CALL RStxChar 01019 01020 ; got to end of buffer so process. does not allow for backspace 01021 00F3 0851 01022 MOVFW RScmd 01023 00F4 2132 01024 CALL RSfindAndRunCommand 01025 01026 ; ; Write to file register 01027 ; MOVLW -'w' 01028 ; ADDWF RScmd,w ; test to see if command is s, if so save into register. 01029 ; bnz RSbuffInput3 01030 00F5 01031 RSbuffInput2start 01032 ; Write to file register 00F5 0857 01033 MOVFW RSaddr 00F6 0084 01034 MOVWF FSR 01035 00F7 0858 01036 MOVFW RSdata 00F8 0080 01037 MOVWF INDF MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 21 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01038 00F9 292D 01039 GOTO RSbuffInputEndOK 01040 01041 01042 00FA 01043 RSbuffInput3start 01044 ; put octet in EEPROM 00FA 1283 1303 01045 BANKSEL RSaddr 00FC 0857 01046 MOVFW RSaddr 00FD 2169 01047 CALL EEsetAddr 01048 00FE 1283 1303 01049 BANKSEL RSdata 0100 0858 01050 MOVFW RSdata 0101 216D 01051 CALL EEwrt 01052 0102 292D 01053 GOTO RSbuffInputEndOK 01054 01055 01056 0103 01057 RSbuffInput4start 01058 ; read from file register 0103 0857 01059 MOVFW RSaddr 0104 0084 01060 MOVWF FSR 01061 0105 0800 01062 MOVFW INDF 0106 00CC 01063 MOVWF RSin 01064 0107 01065 RSbuffInput4display 0107 303D 01066 MOVLW '=' 0108 2090 01067 CALL RStxChar 01068 0109 0E4C 01069 SWAPF RSin,w 010A 207F 01070 CALL RSwrtHexNibble 01071 010B 084C 01072 MOVFW RSin 010C 207F 01073 CALL RSwrtHexNibble 01074 010D 292F 01075 GOTO RSbuffInputEnd 01076 01077 01078 010E 01079 RSbuffInput5start 01080 ; get from EEPROM register 010E 0857 01081 MOVFW RSaddr 010F 2161 01082 CALL EEread 0110 00CC 01083 MOVWF RSin 01084 0111 2907 01085 GOTO RSbuffInput4display 01086 01087 01088 0112 01089 RSbuffInput7start 01090 ; Toggle A0 for AA ms MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 22 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0112 219A 01091 CALL BTtoggle 0113 292D 01092 GOTO RSbuffInputEndOK 01093 01094 0114 01095 RSbuffInput8start 01096 ; Set A0 0114 21A0 01097 CALL BTdelaySet 0115 292D 01098 GOTO RSbuffInputEndOK 01099 01100 0116 01101 RSbuffInput9start 01102 ; Reset A0 0116 21A3 01103 CALL BTdelayReset 0117 292D 01104 GOTO RSbuffInputEndOK 01105 01106 01107 01108 0118 01109 RSbuffInput10start 0118 21C5 01110 CALL ADconvert 0119 292F 01111 GOTO RSbuffInputEnd 01112 01113 011A 01114 RSbuffInput11start 011A 21EB 01115 CALL MMinit 011B 292D 01116 GOTO RSbuffInputEndOK 01117 01118 011C 01119 RSbuffInput12start 011C 3005 01120 MOVLW EEinterCharDelay ;0x15 011D 2161 01121 CALL EEread 011E 00CE 01122 MOVWF RSinterCharDelay 01123 011F 222B 01124 CALL MMtsSample 0120 302C 01125 MOVLW ',' 0121 2090 01126 CALL RStxChar 01127 0122 22CE 01128 CALL MMdisplay 0123 292D 01129 GOTO RSbuffInputEndOK 01130 01131 0124 01132 RSbuffInput13start 0124 21FF 01133 CALL MMstartTicks 0125 292D 01134 GOTO RSbuffInputEndOK 01135 01136 0126 01137 RSbuffInput14start 01138 ; STOP measure Solar Cells 0126 2207 01139 CALL MMstopTicks 0127 292D 01140 GOTO RSbuffInputEndOK 01141 01142 ;RSbuffInput15 01143 ; ; dump EEPROM MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 23 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01144 ; MOVLW -'d' 01145 ; ADDWF RScmd,w 01146 ; bnz RSbuffInput16 01147 0128 01148 RSbuffInput15start 01149 ; dump EEPROM 0128 2310 01150 CALL EEfileDump 0129 292D 01151 GOTO RSbuffInputEndOK 01152 012A 01153 RSbuffInput16 012A 01154 RSbuffInputEndNOK 012A 303F 01155 MOVLW '?' 012B 2090 01156 CALL RStxChar 012C 292F 01157 GOTO RSbuffInputEnd 01158 012D 01159 RSbuffInputEndOK 012D 302A 01160 MOVLW '*' 012E 2090 01161 CALL RStxChar 01162 012F 01163 RSbuffInputEnd 012F 2086 01164 CALL RS232sendCR 0130 2088 01165 CALL RS232sendLF 01166 01167 0131 01168 RSbuffInputEnd1 0131 0008 01169 return 01170 01171 01172 ;-------------------------------------------------------------------------- 01173 ; Sec 5.9 Lookup command letter by doing a linear search 01174 ;-------------------------------------------------------------------------- 01175 01176 0132 01177 RSfindAndRunCommand 01178 ; look up command 0132 00CC 01179 MOVWF RSin 0133 01CA 01180 CLRF RSloopCnt 0134 01181 RSfindCmd1 0134 204E 01182 CALL RSjumpTable 01183 ; Increment pointer onto the command. 0135 0ACA 01184 INCF RSloopCnt,f 01185 01186 ; test if command char has ben found in the list. 0136 064C 01187 XORWF RSin,w 0137 1903 293E 01188 BZ RSfindCmdFound 0139 064C 01189 XORWF RSin,w 013A 1903 293F 01190 BZ RSfindCmdEnd 01191 01192 ; point onto next command 013C 0ACA 01193 INCF RSloopCnt,f 013D 2934 01194 GOTO RSfindCmd1 01195 013E 01196 RSfindCmdFound MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 24 LOC OBJECT CODE LINE SOURCE TEXT VALUE 013E 284E 01197 GOTO RSjumpTable 01198 013F 01199 RSfindCmdEnd 013F 292A 01200 GOTO RSbuffInputEndNOK 01201 01202 ;-------------------------------------------------------------------------- 01203 ; Sec 5.10 Initilization code - 01204 ;-------------------------------------------------------------------------- 01205 01206 0140 01207 INinit 01208 ; Enable Interupts 0140 3000 01209 MOVLW H'00' 01210 ; BANKSEL INTCON is available in both banks. 0141 008B 01211 MOVWF INTCON 01212 0142 0187 01213 CLRF PORT_RS232 ;Initialize PORT_RS232 by setting 01214 ;output data latches 01215 01216 ifdef wantAtoD 01217 ; get the Oscillator calibration 01218 01219 ;MOVLW 0x6C ; load the Calib 01220 ; BSF STATUS,RP0 01221 ; CALL OscCalValue 01222 ; MOVWF OSCCAL 01223 01224 0143 1283 1303 01225 BANKSEL CMCON 0145 3007 01226 MOVLW 0X07 ;Turn comparators off and 0146 0099 01227 MOVWF CMCON ;enable pins for I/O 01228 01229 ; BANKSEL ANSEL 01230 ; CLRF ANSEL 01231 01232 endif 01233 01234 01235 01236 ifdef pic16F628 01237 BANKSEL CMCON 01238 MOVLW 0X07 ;Turn comparators off and 01239 MOVWF CMCON ;enable pins for I/O 01240 01241 endif 01242 01243 ifdef pic16F876 01244 ;make AtoD inputs digital 01245 BANKSEL ADCON1 01246 MOVLW 0X07 ;Turn comparators off and 01247 MOVWF ADCON1 ;enable pins for I/O 01248 endif 01249 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 25 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01250 01251 ifndef pic16F676 01252 banksel TRISB 01253 MOVLW 0XF0 01254 MOVWF TRISB 01255 endif 01256 0147 1683 1303 01257 banksel TRIS_RS232 0149 1687 01258 BSF TRIS_RS232, RS232tx ; Make PORT_RS232 3:0 INPUTS. 014A 1187 01259 BCF TRIS_RS232, OUTPUTPIN 01260 01261 014B 1283 1303 01262 banksel RSipbuffStart 01263 ; reset input buffer 014D 3051 01264 MOVLW RSipbuffStart 014E 00D0 01265 MOVWF RSipBuffCnt 01266 01267 ; Change Prescaler 014F 0064 01268 CLRWDT 01269 01270 ; Configure Tmr 0 0150 1683 01271 BSF STATUS,RP0 01272 ; Set up prescaller for 8192 / 16 = 512 ticks perseconds. 01273 0151 3002 01274 MOVLW 0x0 + 2 ; For Tmr0 0=/2, 1=/4, 2=/8,3=/16 0152 0081 01275 MOVWF OPTION_REG 0153 1283 01276 BCF STATUS,RP0 01277 01278 ifdef buildPWM 01279 01280 ; Configure Tmr 1 01281 MOVLW 0x0 | 1<|---+------- Vbattery 01533 ; | | 01534 ; | +-[==]-- VLEDresitor 01535 ; | 01536 ; +---------------- 0 Volts 01537 ; 01538 ; V4 SolarCell 01539 ; V5 Vbattery 01540 ; V6 VLEDresistor 01541 ; 01542 ; if V5 > V2+Vdiode then charging 01543 ; if (V2-V3) = Vres 01544 ; 01545 ; if Vres > k1 then Bright 01546 ; if Vres < k2 then Off 01547 ; Else Dim 01548 ; 01549 01EB 01550 MMinit 01EB 01BA 01551 CLRF MMcntTimeH 01EC 01BB 01552 CLRF MMcntTimeL 01ED 01BC 01553 CLRF MMcntSolarCellH 01EE 01BD 01554 CLRF MMcntSolarCellL 01EF 01BE 01555 CLRF MMcntBrightH 01F0 01BF 01556 CLRF MMcntBrightL 01F1 01C0 01557 CLRF MMcntDimH 01F2 01C1 01558 CLRF MMcntDimL 01F3 01C2 01559 CLRF MMcntVbattH 01F4 01C3 01560 CLRF MMcntVbattL 01F5 0008 01561 return 01562 01563 01564 01F6 01565 MMinitTime 01566 ; 01567 ; time in binary to time when samples are stored in EEPROM MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 31 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01568 ; 01569 ; If you want to logger to sample at 03:00 and it is 18:00 01570 ; you want the time to be 01571 ; 24:00 01572 ; + 03:00 01573 ; - 18:00 01574 ; ===== 01575 ; 09:00 9 hours time 01576 ; 01577 01578 ; banksel CLhh 01579 ; MOVLW .24 01580 ; MOVWF CLhh 01581 01582 ; MOVLW .60 01583 ; MOVWF CLmm 01584 01585 ; MOVLW .15 01586 ; MOVWF CLss 01587 01588 01F6 1283 1303 01589 banksel CLhh 01F8 300A 01590 MOVLW .09+1 01591 ; MOVLW .00+1 01F9 00A5 01592 MOVWF CLhh 01593 01FA 3001 01594 MOVLW .00+1 01FB 00A6 01595 MOVWF CLmm 01596 01FC 3001 01597 MOVLW .00+1 01FD 00A7 01598 MOVWF CLss ; CLss is in seconds / seconds between TMR1 timeout 01599 01600 01601 01602 01FE 0008 01603 return 01604 01605 01FF 01606 MMstartTicks 01607 ;Clear and init TMR1, this will be used as a time base. 01FF 1283 1303 01608 banksel T1CON 0201 0190 01609 CLRF T1CON 0202 018F 01610 CLRF TMR1H 0203 018E 01611 CLRF TMR1L 01612 01613 ; 01614 ; Start TMR1 to use the external oscillator. 01615 ; This should be a 32K768 Hz crystal, so the overflow is every 2 seconds. 01616 ; 0204 301F 01617 MOVLW 1 << T1OSCEN | 1 << T1CKPS0 | 1 << NOT_T1SYNC | 1 << TMR1CS | 1 << TMR1ON 0205 0090 01618 MOVWF T1CON 0206 0008 01619 return 01620 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 32 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0207 01621 MMstopTicks 01622 ;Clear and init TMR1, this will be used as a time base. 0207 1283 1303 01623 banksel T1CON 0209 3016 01624 MOVLW 0 << T1OSCEN | 1 << T1CKPS0 | 1 << NOT_T1SYNC | 1 << TMR1CS | 0 << TMR1ON 020A 0090 01625 MOVWF T1CON 020B 0008 01626 return 01627 01628 020C 01629 MMts 020C 1283 1303 01630 BANKSEL PIR1 020E 100C 01631 BCF PIR1,TMR1IF 01632 020F 1187 01633 BCF PORTC,3 01634 01635 ; tick every 4 seconds 01636 ; and reset chain for 24 hours timeout 01637 ; 0210 0BA7 01638 DECFSZ CLss,F 0211 2A1E 01639 GOTO MMts1 0212 300F 01640 MOVLW .15 0213 00A7 01641 MOVWF CLss 01642 0214 0BA6 01643 DECFSZ CLmm,F 0215 2A1E 01644 GOTO MMts1 0216 303C 01645 MOVLW .60 0217 00A6 01646 MOVWF CLmm 01647 0218 0BA5 01648 DECFSZ CLhh,F 0219 2A1E 01649 GOTO MMts1 021A 3018 01650 MOVLW .24 021B 00A5 01651 MOVWF CLhh 01652 01653 ; buffer counts once a day. 021C 22F7 01654 CALL EEfileCounts 021D 21EB 01655 CALL MMinit 01656 01657 021E 01658 MMts1 021E 3005 01659 MOVLW EEinterCharDelay ;0x15 021F 2161 01660 CALL EEread 0220 00CE 01661 MOVWF RSinterCharDelay 01662 0221 2088 01663 CALL RS232sendLF 0222 2086 01664 CALL RS232sendCR 01665 0223 22CE 01666 CALL MMdisplay 01667 01668 ; ouput the counts first, then the voltages 01669 ; so that the 24Char display shows the counts 0224 222B 01670 CALL MMtsSample 0225 302C 01671 MOVLW ',' 0226 2090 01672 CALL RStxChar 01673 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 33 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0227 302A 01674 MOVLW '*' 0228 2090 01675 CALL RStxChar 01676 0229 1587 01677 BSF PORTC,3 01678 022A 0008 01679 RETURN 01680 01681 ; run into MMtsSample 01682 01683 022B 01684 MMtsSample 01685 ; tick once a second 022B 22BA 01686 CALL MMincCntTime 01687 01688 ; Measure VsolarCell 022C 3006 01689 MOVLW 6 022D 00D7 01690 movwf RSaddr 01691 022E 21C5 01692 CALL ADconvert 01693 022F 1283 1303 01694 banksel ADRESH 0231 081E 01695 movfw ADRESH 0232 00B2 01696 movwf MMV6h 0233 1683 1303 01697 banksel ADRESL 0235 081E 01698 movfw ADRESL 0236 00B3 01699 movwf MMV6l 01700 0237 3032 01701 MOVLW MMV6h 0238 22E9 01702 CALL MMdisplayIndirect 01703 01704 01705 ; Measure Vbattery 0239 3005 01706 MOVLW 5 023A 00D7 01707 movwf RSaddr 01708 023B 21C5 01709 CALL ADconvert 01710 023C 1283 1303 01711 banksel ADRESH 023E 081E 01712 movfw ADRESH 023F 00B4 01713 movwf MMV5h 0240 1683 1303 01714 banksel ADRESL 0242 081E 01715 movfw ADRESL 0243 00B5 01716 movwf MMV5l 01717 0244 3034 01718 MOVLW MMV5h 0245 22E9 01719 CALL MMdisplayIndirect 01720 01721 01722 ; Measure VtopOfLED 0246 3004 01723 MOVLW 4 0247 00D7 01724 movwf RSaddr 01725 0248 21C5 01726 CALL ADconvert MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 34 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01727 0249 1283 1303 01728 banksel ADRESH 024B 081E 01729 movfw ADRESH 024C 00B6 01730 movwf MMV4h 024D 1683 1303 01731 banksel ADRESL 024F 081E 01732 movfw ADRESL 0250 00B7 01733 movwf MMV4l 01734 0251 3036 01735 MOVLW MMV4h 0252 22E9 01736 CALL MMdisplayIndirect 01737 01738 01739 ; Measure Vref but relative to Vdd 0253 3001 01740 MOVLW 1 0254 00D7 01741 movwf RSaddr 01742 0255 21B2 01743 CALL ADconvertVdd 01744 0256 1283 1303 01745 banksel ADRESH 0258 081E 01746 movfw ADRESH 0259 00B8 01747 movwf MMV1h 025A 1683 1303 01748 banksel ADRESL 025C 081E 01749 movfw ADRESL 025D 00B9 01750 movwf MMV1l 01751 025E 3038 01752 MOVLW MMV1h 025F 22E9 01753 CALL MMdisplayIndirect 01754 0260 302F 01755 movlw '/' 0261 2090 01756 call RStxChar 0262 302C 01757 movlw ',' 01758 01759 0263 01760 MMtsSampleProcess 01761 01762 ; Subtract MMV6h - MMV5H+eeprom[10] 01763 ; The difference 01764 01765 ; if MMV6h < MMV5H then Vbat > Vsolar so do not carry on with calc. 01766 01767 01768 ; 00 00 - 01769 ; 00 01 01770 ;======== 01771 ; ff 01772 0263 0835 01773 MOVFW MMV5l 0264 0233 01774 SUBWF MMV6l,w ; w = F-W or MM6L-MMV5 -> W 0265 00B1 01775 MOVWF MMtmp 01776 0266 0834 01777 MOVFW MMV5h 01778 ; Apply Borrow 0267 1C03 01779 SKPC MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 35 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0268 3E01 01780 ADDLW 0x01 01781 01782 ; suntract the difference of the low bytes 01783 ; Note MMV5 - MMV6 to get negative value 0269 0232 01784 SUBWF MMV6h,w ; w = F-W or MM6L-MMV5 -> W 026A 00B0 01785 MOVWF MMtmph 01786 01787 ;; MMV6 = MMV5 01788 ;; MMV6 > MMV5 01789 01790 ; Output difference between Solar Call and Vbattery 01791 ; This is the compliment 01792 026B 302F 01793 movlw '/' 026C 2090 01794 call RStxChar 026D 3073 01795 movlw 's' 026E 2090 01796 call RStxChar 026F 302C 01797 movlw ',' 0270 2090 01798 call RStxChar 01799 0271 0830 01800 MOVFW MMtmph 0272 207A 01801 CALL RSwrtWasHex 01802 0273 0831 01803 MOVFW MMtmp 0274 207A 01804 CALL RSwrtWasHex 01805 0275 302C 01806 movlw ',' 0276 2090 01807 call RStxChar 01808 01809 01810 ; V6,V5,V4 use Vref, the voltage across a blue LED 01811 ; Also measure the voltage of the BLUE LED relative to Vref. 01812 ; 01813 ; V6 = 0E0 - Solar cell in darkness 01814 ; V5 = A70 - Vbattery when LED is on bright 01815 ; V4 = 8EC - Vtop of LED when LED is bright 01816 ; 01817 ; Vref = D7C - Vdd ~ 3.82 Vref=3.25 volts 01818 ; this right shift reduces the sensitivity 01819 ; 01820 01821 ; 01822 ; w = w-f 01823 ; 01824 01825 ; MMtmp contains Vsolar-Vbat 01826 ; MMtmp = MMtmp - ( 0x0000 + EE[00] ) 0277 3000 01827 MOVLW EEsolarOffset ;0x00 0278 2161 01828 CALL EEread ; 0279 3C00 01829 SUBLW 0 ; Negate W 01830 027A 07B1 01831 ADDWF MMtmp,f 027B 30FF 01832 MOVLW 0xFF ; Assume -ve MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 36 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01833 01834 ; Apply CARRY 027C 1803 01835 SKPNC 027D 3E01 01836 ADDLW 0x01 01837 027E 07B0 01838 ADDWF MMtmph,f 01839 01840 01841 01842 ; if V6-V5-EEprom[10] < 0 then increment MMincCntSolarCell 027F 1BB0 01843 BTFSC MMtmph,7 ; test MSB to see if negative 0280 2A83 01844 GOTO MMtsSample1false 01845 0281 01846 MMtsSample1true 0281 22BE 01847 CALL MMincCntSolarCell 0282 2A90 01848 GOTO MMtsSample1 01849 0283 01850 MMtsSample1false 01851 ; So Solar Cell is not charging, 01852 ; Is battery above eeprom[13]and eeprom[14] 01853 01854 ; MMtmp = MM5V - EEPROM[13,14] 0283 3004 01855 MOVLW EEbatteryOffsetL ;0x14 0284 2161 01856 CALL EEread 0285 0235 01857 SUBWF MMV5l,w ; w=w-f 0286 00B1 01858 MOVWF MMtmp 01859 0287 3003 01860 MOVLW EEbatteryOffsetH ; 0x13 0288 2161 01861 CALL EEread 01862 ; Apply Borrow 0289 1C03 01863 SKPC 028A 3E01 01864 ADDLW 0x01 01865 028B 0234 01866 SUBWF MMV5h,w 028C 00B0 01867 MOVWF MMtmph 01868 028D 1FB0 01869 BTFSS MMtmph, 7 028E 22CA 01870 CALL MMincCntVbatt 01871 028F 2A90 01872 GOTO MMtsSample1 01873 01874 0290 01875 MMtsSample1 01876 01877 ; Subtrac VtopOfLED from Vbatt 01878 ; if Negative, then LED on 01879 01880 ; Subtract MMV5h - MMv4H+eeprom[11] 01881 ; The subtraction really needs the low voltages 01882 01883 ;MOVFW MMv4h 01884 ;SUBWF MMV5h,w 01885 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 37 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01886 ; If Vbat < Vtop of Led 01887 01888 0290 0837 01889 MOVFW MMV4l 0291 0235 01890 SUBWF MMV5l,w ; w = F-W or MM6L-MMV5 -> W 0292 00B1 01891 MOVWF MMtmp 01892 0293 0836 01893 MOVFW MMV4h 01894 ; Apply Borrow 0294 1C03 01895 SKPC 0295 3E01 01896 ADDLW 0x01 01897 01898 ; suntract the difference of the low bytes 01899 ; Note MMV5 - MMV6 to get negative value 0296 0234 01900 SUBWF MMV5h,w ; w = F-W or MM6L-MMV5 -> W 0297 00B0 01901 MOVWF MMtmph 01902 01903 ; NOTE: MMV4L - MMV5 to get negative value 0298 0837 01904 MOVFW MMV4l 0299 0235 01905 SUBWF MMV5l,w 029A 00B1 01906 MOVWF MMtmp 01907 029B 306C 01908 movlw 'l' 029C 2090 01909 call RStxChar 029D 302C 01910 movlw ',' 029E 2090 01911 call RStxChar 01912 029F 0830 01913 MOVFW MMtmph 02A0 207A 01914 CALL RSwrtWasHex 01915 02A1 0831 01916 MOVFW MMtmp 02A2 207A 01917 CALL RSwrtWasHex 02A3 302C 01918 movlw ',' 02A4 2090 01919 call RStxChar 01920 01921 ; 01922 ; MMtmp contains Voltage across 20R 01923 ; 01924 ; Is LED DIM, BRIGHT or OFF 01925 ; get constants from EEPROM 01926 01927 ; if (V5-V4)-EEprom[11] < 0 then OFF 02A5 3001 01928 MOVLW EEdimOffset ; 0x11 02A6 2161 01929 CALL EEread 02A7 3C00 01930 SUBLW 0 ; W = 0 - W 02A8 07B1 01931 ADDWF MMtmp,f 01932 01933 ; ADD Carry 02A9 30FF 01934 MOVLW 0xFF ; promote -ve EE[01] to 0xFFXX 02AA 1803 01935 SKPNC 02AB 3E01 01936 ADDLW 1 02AC 07B0 01937 ADDWF MMtmph,f 01938 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 38 LOC OBJECT CODE LINE SOURCE TEXT VALUE 02AD 1BB0 01939 BTFSC MMtmph,7 01940 ; Not +ve so dim constant not reached 02AE 0008 01941 RETURN 01942 01943 ; If Still +ve, then the LED is Bright or DIM 01944 ; Subtract a bit more off 01945 ; Subtract some to see if it is bright or dim. 01946 02AF 3002 01947 MOVLW EEbrightOffset ; 0x12 02B0 2161 01948 CALL EEread 02B1 3C00 01949 SUBLW 0 ; W = 0 - W 02B2 07B1 01950 ADDWF MMtmp,f 01951 01952 ; ADD Carry 02B3 30FF 01953 MOVLW 0xFF ; promote -ve EE[02] to 0xFFXX 02B4 1803 01954 SKPNC 02B5 3E01 01955 ADDLW 1 02B6 07B0 01956 ADDWF MMtmph,f 01957 02B7 1BB0 01958 BTFSC MMtmph,7 02B8 2AC6 01959 GOTO MMincCntDim 02B9 2AC2 01960 GOTO MMincCntBright 01961 02BA 01962 MMincCntTime 02BA 0FBB 01963 incfsz MMcntTimeL 02BB 0008 01964 return 02BC 0ABA 01965 incf MMcntTimeH,f 02BD 0008 01966 return 01967 02BE 01968 MMincCntSolarCell 02BE 0FBD 01969 incfsz MMcntSolarCellL 02BF 0008 01970 return 02C0 0ABC 01971 incf MMcntSolarCellH,f 02C1 0008 01972 return 01973 02C2 01974 MMincCntBright 02C2 0FBF 01975 incfsz MMcntBrightL 02C3 0008 01976 return 02C4 0ABE 01977 incf MMcntBrightH,f 02C5 0008 01978 return 01979 02C6 01980 MMincCntDim 02C6 0FC1 01981 incfsz MMcntDimL 02C7 0008 01982 return 02C8 0AC0 01983 incf MMcntDimH,f 02C9 0008 01984 return 01985 02CA 01986 MMincCntVbatt 02CA 0FC3 01987 incfsz MMcntVbattL 02CB 0008 01988 return 02CC 0AC2 01989 incf MMcntVbattH,f 02CD 0008 01990 return 01991 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 39 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01992 02CE 01993 MMdisplay 02CE 303A 01994 MOVLW MMcntTimeH 02CF 22E9 01995 CALL MMdisplayIndirect 01996 02D0 303C 01997 MOVLW MMcntSolarCellH 02D1 22E9 01998 CALL MMdisplayIndirect 01999 02D2 303E 02000 MOVLW MMcntBrightH 02D3 22E9 02001 CALL MMdisplayIndirect 02002 02D4 3040 02003 MOVLW MMcntDimH 02D5 22E9 02004 CALL MMdisplayIndirect 02005 02D6 3042 02006 MOVLW MMcntVbattH 02D7 22E9 02007 CALL MMdisplayIndirect 02008 02009 02010 ; 02011 ; Display - 02012 ; 02013 02D8 302F 02014 movlw '/' 02D9 2090 02015 call RStxChar 02016 02DA 3074 02017 movlw 't' 02DB 2090 02018 call RStxChar 02019 02DC 302C 02020 movlw ',' 02DD 2090 02021 call RStxChar 02022 02023 02DE 1283 1303 02024 banksel CLhh 02E0 3025 02025 MOVLW CLhh 02E1 22E3 02026 CALL MMdisplayIndirectThreeByte 02E2 0008 02027 return 02028 02029 02030 02E3 02031 MMdisplayIndirectThreeByte 02032 ; display file pointed to by W as 4 HEX nibbles. 02033 ; ; MOVLW MMcntTimeH 02034 ; ; CALL MMdisplayIndirect 02035 02036 ; move address of file into FSR and then use INDF to get values. 02E3 0084 02037 MOVWF FSR 02038 02E4 0E00 02039 SWAPF INDF,w 02E5 207F 02040 CALL RSwrtHexNibble 02041 02E6 0800 02042 MOVFW INDF 02E7 207F 02043 CALL RSwrtHexNibble 02044 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 40 LOC OBJECT CODE LINE SOURCE TEXT VALUE 02045 ; now increment point onto next byte 02E8 0A04 02046 INCF FSR,W 02047 02048 02E9 02049 MMdisplayIndirect 02050 ; display file pointed to by W as 4 HEX nibbles. 02051 ; ; MOVLW MMcntTimeH 02052 ; ; CALL MMdisplayIndirect 02053 02054 ; move address of file into FSR and then use INDF to get values. 02E9 0084 02055 MOVWF FSR 02056 02EA 0E00 02057 SWAPF INDF,w 02EB 207F 02058 CALL RSwrtHexNibble 02059 02EC 0800 02060 MOVFW INDF 02ED 207F 02061 CALL RSwrtHexNibble 02062 02063 ; now increment point onto next byte 02EE 0A04 02064 INCF FSR,W 02065 02EF 02066 MMdisplayIndirectOneByte 02EF 0084 02067 MOVWF FSR 02068 02F0 0E00 02069 SWAPF INDF,w 02F1 207F 02070 CALL RSwrtHexNibble 02071 02F2 0800 02072 MOVFW INDF 02F3 207F 02073 CALL RSwrtHexNibble 02074 02F4 302C 02075 movlw ',' 02F5 2090 02076 call RStxChar 02077 02F6 0008 02078 RETURN 02079 02080 02081 ;-------------------------------------------------------------------------- 02082 ; Sec 5.15 EE Routines to copy the counts into the EEPROM 02083 ;-------------------------------------------------------------------------- 02084 ; 02085 ; 02086 ;MMcntTimeH 02087 ;MMcntTimeL 02088 ;MMcntSolarCellH 02089 ;MMcntSolarCellL 02090 ;MMcntBrightH 02091 ;MMcntBrightL 02092 ;MMcntDimH 02093 ;MMcntDimL 02094 ;MMcntVbattH 02095 ;MMcntVbattL 02096 ; 02097 ; Copy the bytes into the EEPROM. MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 41 LOC OBJECT CODE LINE SOURCE TEXT VALUE 02098 ; Use the value at 0x17 as a pointer 02099 ; If the file pointer gets too big just return 02100 ; 02101 ; 02102 02F7 02103 EEfileCounts 02104 02105 ; 02106 02107 02F7 3007 02108 MOVLW EEFILEPTR 02F8 2161 02109 CALL EEread 02110 02F9 00C4 02111 MOVWF EEptrEEPROM 02112 02113 ; Add some overflow protection 02FA 3E8B 02114 ADDLW -(0x7f-(MMcntVbattL-MMcntTimeH+1)) 02FB 1803 02115 SKPNC 02FC 0008 02116 RETURN 02117 02FD 300A 02118 MOVLW MMcntVbattL-MMcntTimeH+1 02FE 00C6 02119 MOVWF EEloopCount 02120 02FF 303A 02121 MOVLW MMcntTimeH 0300 0084 02122 MOVWF FSR 02123 0301 02124 EEfileCounts1 02125 0301 0844 02126 MOVFW EEptrEEPROM 0302 2169 02127 CALL EEsetAddr 02128 0303 0800 02129 MOVFW INDF 0304 216D 02130 CALL EEwrt 02131 0305 1283 1303 02132 BANKSEL EEptrEEPROM 0307 0AC4 02133 INCF EEptrEEPROM,f 0308 0A84 02134 INCF FSR,f 02135 0309 0BC6 02136 DECFSZ EEloopCount 030A 2B01 02137 GOTO EEfileCounts1 02138 02139 ; now update the EEPROM pointer. 02140 ; There is no overflow test. 030B 3007 02141 MOVLW EEFILEPTR 030C 2169 02142 CALL EEsetAddr 030D 0844 02143 MOVFW EEptrEEPROM 030E 216D 02144 CALL EEwrt 02145 030F 0008 02146 RETURN 02147 02148 02149 02150 ;EEptrEEPROM ; pointer to EEPROM MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 42 LOC OBJECT CODE LINE SOURCE TEXT VALUE 02151 ;EEptrMEM ; pointer to Memory - count, time, solarCell, bright, dim 02152 02153 02154 02155 ;************************************************* 02156 ; Upload the DDATA from the logger 02157 0310 02158 EEfileDump 0310 2086 02159 CALL RS232sendCR 0311 2088 02160 CALL RS232sendLF 02161 0312 208E 02162 CALL RS232sendStar 0313 2086 02163 CALL RS232sendCR 0314 2088 02164 CALL RS232sendLF 02165 0315 3007 02166 MOVLW EEFILEPTR 0316 2161 02167 CALL EEread 0317 207A 02168 CALL RSwrtWasHex 0318 208C 02169 CALL RS232sendComma 02170 0319 3008 02171 MOVLW EEFILESTART 031A 00C4 02172 MOVWF EEptrEEPROM 02173 031B 02174 BA0 031B 2333 02175 CALL BA4_addrToRS232 02176 031C 3005 02177 MOVLW (MMcntVbattL-MMcntTimeH)/2+1 031D 00C6 02178 MOVWF EEloopCount 031E 02179 BA2 02180 031E 0844 02181 MOVFW EEptrEEPROM 031F 2161 02182 CALL EEread 0320 207A 02183 CALL RSwrtWasHex 02184 0321 0AC4 02185 INCF EEptrEEPROM,f 0322 0844 02186 MOVFW EEptrEEPROM 0323 2161 02187 CALL EEread 0324 207A 02188 CALL RSwrtWasHex 02189 0325 208C 02190 CALL RS232sendComma 0326 0AC4 02191 INCF EEptrEEPROM,f 0327 0844 02192 MOVFW EEptrEEPROM 02193 ; Add some overflow protection 0328 3E8B 02194 ADDLW -(0x7f-(MMcntVbattL-MMcntTimeH+1)) 0329 1803 02195 SKPNC 032A 2B2E 02196 GOTO BA3 02197 032B 0BC6 02198 DECFSZ EEloopCount,f 032C 2B1E 02199 GOTO BA2 032D 2B1B 02200 GOTO BA0 02201 02202 032E 02203 BA3 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 43 LOC OBJECT CODE LINE SOURCE TEXT VALUE 032E 208C 02204 CALL RS232sendComma 032F 208E 02205 CALL RS232sendStar 0330 2086 02206 CALL RS232sendCR 0331 2088 02207 CALL RS232sendLF 0332 0008 02208 RETURN 02209 02210 02211 02212 0333 02213 BA4_addrToRS232 0333 208E 02214 CALL RS232sendStar 0334 2086 02215 CALL RS232sendCR 0335 2088 02216 CALL RS232sendLF 02217 0336 0E44 02218 SWAPF EEptrEEPROM,W 0337 207F 02219 CALL RSwrtHexNibble 0338 0844 02220 MOVFW EEptrEEPROM 0339 207F 02221 CALL RSwrtHexNibble 033A 208C 02222 CALL RS232sendComma 033B 208C 02223 CALL RS232sendComma 033C 0008 02224 RETURN 02225 02226 02227 02228 02229 02230 ;-------------------------------------------------------------------------- 02231 ; Sec 6.0 Interrupt Routines 02232 ;-------------------------------------------------------------------------- 02233 033D 02234 Intrtn 033D 0009 02235 RETFIE 02236 02237 ;-------------------------------------------------------------------------- 02238 ; Program End 02239 ;-------------------------------------------------------------------------- 02240 ifdef pic12F675 02241 02242 org 0x3FD 02243 RETLW 0x6C 02244 RETLW 0x6C 02245 OscCalValue 02246 RETLW 0x6C 02247 endif 02248 02249 ifdef pic16F676 02250 02251 02252 ; Read from the chip being used. 02253 ; 34A8 02254 03FD 02255 org 0x3FD 03FD 346C 02256 RETLW 0x6C MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 44 LOC OBJECT CODE LINE SOURCE TEXT VALUE 03FE 346C 02257 RETLW 0x6C 03FF 02258 OscCalValue 02259 ; RETLW 0x80 ; first chip 02260 ; RETLW 0xA8 ; second chip 03FF 3498 02261 RETLW 0x98 ; first chip 02262 02263 endif 02264 02265 0400 02266 LastProgWord 02267 02268 ;-------------------------------------------------------------------------- 02269 ; Sec 7.0 EEPROM data 02270 ;-------------------------------------------------------------------------- 00000000 02271 EEsolarOffset EQU 0x00 00000001 02272 EEdimOffset EQU 0x01 00000002 02273 EEbrightOffset EQU 0x02 00000003 02274 EEbatteryOffsetH EQU 0x03 00000004 02275 EEbatteryOffsetL EQU 0x04 00000005 02276 EEinterCharDelay EQU 0x05 00000006 02277 EEAtoDappatureDelay EQU 0x06 02278 2100 02279 ORG 0x2100 02280 ; solar,off,bright/dim,Timer 61=~41 seconds ticks 1e6/2^16m = 1/15.2587890625 2100 0033 02281 DE 0x33 ; EEsolarOffset ; delta Vsolar-Vbattery 2101 0014 02282 DE 0x14 ; EEdimOffset ; delta Vbattery-VtopOfLED - thresehold of DIM 2102 0010 02283 DE 0x10 ; EEbrightOffset ; Subtract this to see if BRIGHT 2103 0002 02284 DE 0x02 ; EEbatteryOffsetH ; VbattH 2104 0050 02285 DE 0x50 ; EEbatteryOffsetL ; VbattL 2105 0008 02286 DE 0x08 ; EEinterCharDelay ; inter sample delay 0x3d = 4 seconds 2106 000A 02287 DE 0x0A ; EEAtoDappatureDelay ; Appature delay - time from setting up switches to start of sample and hold. 02288 02289 2107 02290 ORG 0x2107 2107 0008 02291 DE EEFILEPTR+1 ; INIT pointer to EEPROM file. 02292 02293 cblock 00000059 02294 LastVar 02295 endc 02296 END MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 45 SYMBOL TABLE LABEL VALUE ADCON0 0000001F ADCON1 0000009F ADCS0 00000004 ADCS1 00000005 ADCS2 00000006 ADFM 00000007 ADIE 00000006 ADIF 00000006 ADON 00000000 ADRESH 0000001E ADRESL 0000009E ADStartConvert 000001D7 ADStartConvertAgain 000001E2 ADansel 00000021 ADconvert 000001C5 ADconvertVdd 000001B2 ADrl 00000020 ADwait 000001DE ADwaitAgain 000001E6 ANS0 00000000 ANS1 00000001 ANS2 00000002 ANS3 00000003 ANS4 00000004 ANS5 00000005 ANS6 00000006 ANS7 00000007 ANSEL 00000091 BA0 0000031B BA2 0000031E BA3 0000032E BA4_addrToRS232 00000333 BT1msdelay 000001AC BT1msdelay1 000001AE BTdelay 00000022 BTdelayCnt 00000023 BTdelayCnt1ms 00000024 BTdelayNms 000001A6 BTdelayNms1 000001A8 BTdelayReset 000001A3 BTdelaySet 000001A0 BTdelayW10us 000001AD BTtoggle 0000019A BUTTON_DOWN 00000003 BUTTON_RS232 00000005 C 00000000 CAL0 00000002 CAL1 00000003 CAL2 00000004 CAL3 00000005 CAL4 00000006 CAL5 00000007 CHS0 00000002 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 46 SYMBOL TABLE LABEL VALUE CHS1 00000003 CHS2 00000004 CINV 00000004 CIS 00000003 CLhh 00000025 CLmm 00000026 CLss 00000027 CLtimeslice 00000048 CM0 00000000 CM1 00000001 CM2 00000002 CMCON 00000019 CMIE 00000003 CMIF 00000003 COUT 00000006 DC 00000001 DLrunBuff 0000003F DTSFast 00000000 DTsS4event 00000000 DoTimeSlice 00000028 EEADR 0000009B EEAtoDappatureDelay 00000006 EECON1 0000009C EECON2 0000009D EEDAT 0000009A EEDATA 0000009A EEFILEPTR 00000007 EEFILESTART 00000008 EEIE 00000007 EEIF 00000007 EEbatteryOffsetH 00000003 EEbatteryOffsetL 00000004 EEbrightOffset 00000002 EEdimOffset 00000001 EEfileCounts 000002F7 EEfileCounts1 00000301 EEfileDump 00000310 EEinterCharDelay 00000005 EEloopCount 00000046 EEloopCount2 00000047 EEptrEEPROM 00000044 EEptrMEM 00000045 EEread 00000161 EEsetAddr 00000169 EEsolarOffset 00000000 EEwaitForWrt 0000018A EEwrt 0000016D F 00000001 FSR 00000004 GIE 00000007 GO 00000001 GO_DONE 00000001 INDF 00000000 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 47 SYMBOL TABLE LABEL VALUE INTCON 0000000B INTE 00000004 INTEDG 00000006 INTF 00000001 INinit 00000140 INsayHello 00000158 IOC 00000096 IOCA 00000096 IPbuttonEvent 0000002B IPbuttonEventUp 0000002E IPdownPressed 00000044 IPlast 0000002A IPlastFast 0000002D IPnew 00000029 IPnewFast 0000002C IPrs232 00000046 IPtimeslice 0000002F IPtimesliceFast 00000037 IPtrigMenu 0000002F IRP 00000007 Intrtn 0000033D LastProgWord 00000400 LastVar 00000059 MMV1h 00000038 MMV1l 00000039 MMV4h 00000036 MMV4l 00000037 MMV5h 00000034 MMV5l 00000035 MMV6h 00000032 MMV6l 00000033 MMcntBrightH 0000003E MMcntBrightL 0000003F MMcntDimH 00000040 MMcntDimL 00000041 MMcntSolarCellH 0000003C MMcntSolarCellL 0000003D MMcntTimeH 0000003A MMcntTimeL 0000003B MMcntVbattH 00000042 MMcntVbattL 00000043 MMdisplay 000002CE MMdisplayIndirect 000002E9 MMdisplayIndirectOneByte 000002EF MMdisplayIndirectThreeByte 000002E3 MMincCntBright 000002C2 MMincCntDim 000002C6 MMincCntSolarCell 000002BE MMincCntTime 000002BA MMincCntVbatt 000002CA MMinit 000001EB MMinitTime 000001F6 MMstartTicks 000001FF MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 48 SYMBOL TABLE LABEL VALUE MMstopTicks 00000207 MMtmp 00000031 MMtmph 00000030 MMts 0000020C MMts1 0000021E MMtsSample 0000022B MMtsSample1 00000290 MMtsSample1false 00000283 MMtsSample1true 00000281 MMtsSampleProcess 00000263 MainLoop 00000022 NOT_BOD 00000000 NOT_DONE 00000001 NOT_GPPU 00000007 NOT_PD 00000003 NOT_POR 00000001 NOT_RAPU 00000007 NOT_T1SYNC 00000002 NOT_TO 00000004 OPTION_REG 00000081 OSCCAL 00000090 OUTPUTPIN 00000003 OscCalValue 000003FF PA0 00000000 PA1 00000001 PA2 00000002 PA7 00000007 PC5 00000005 PCL 00000002 PCLATH 0000000A PCON 0000008E PEIE 00000006 PIE1 0000008C PIR1 0000000C PORTA 00000005 PORTC 00000007 PORT_RS232 00000007 PS0 00000000 PS1 00000001 PS2 00000002 PSA 00000003 RAIE 00000003 RAIF 00000000 RD 00000000 RP0 00000005 RP1 00000006 RS232rx 00000005 RS232sendCR 00000086 RS232sendComma 0000008C RS232sendLF 00000088 RS232sendSpace 0000008A RS232sendStar 0000008E RS232sendWByte 00000090 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 49 SYMBOL TABLE LABEL VALUE RS232tx 00000005 RSAa 00000052 RSDd 00000054 RSaA 00000053 RSaddr 00000057 RSafterCRCharDelay 0000004F RSasciiToNibble 000000BC RSbuffInput 000000C1 RSbuffInput1 000000C8 RSbuffInput10start 00000118 RSbuffInput11start 0000011A RSbuffInput12start 0000011C RSbuffInput13start 00000124 RSbuffInput14start 00000126 RSbuffInput15start 00000128 RSbuffInput16 0000012A RSbuffInput1start 000000C5 RSbuffInput2 000000CC RSbuffInput2start 000000F5 RSbuffInput3start 000000FA RSbuffInput4display 00000107 RSbuffInput4start 00000103 RSbuffInput5start 0000010E RSbuffInput7start 00000112 RSbuffInput8start 00000114 RSbuffInput9start 00000116 RSbuffInputEnd 0000012F RSbuffInputEnd1 00000131 RSbuffInputEndNOK 0000012A RSbuffInputEndOK 0000012D RSbuffInputProcess 000000D9 RScmd 00000051 RSdD 00000055 RSdata 00000058 RSdelayBit 000000B5 RSdelayBit0 000000B7 RSdelayBit1 000000B8 RSdelayCnt 0000004B RSdelayHalfBit 000000B3 RSfindAndRunCommand 00000132 RSfindCmd1 00000134 RSfindCmdEnd 0000013F RSfindCmdFound 0000013E RSin 0000004C RSinterCharDelay 0000004E RSipBuffCnt 00000050 RSipbuffEnd 00000056 RSipbuffStart 00000051 RSjumpTable 0000004E RSloopCnt 0000004A RSout 0000004D RSrs232in 0000006D RSrs232inL0 00000070 MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 50 SYMBOL TABLE LABEL VALUE RSterminator 00000056 RStxChar 00000090 RStxCharInterDelay 000000A9 RStxCharLp1 0000009C RStxCharLp2 000000AA RStxTemp 00000048 RStxTemp2 00000049 RSwrtHexNibble 0000007F RSwrtWasHex 0000007A RUN_BUFF 00000000 STATUS 00000003 Start 00000006 T0CS 00000005 T0IE 00000005 T0IF 00000002 T0SE 00000004 T1CKPS0 00000004 T1CKPS1 00000005 T1CON 00000010 T1IE 00000000 T1IF 00000000 T1OSCEN 00000003 TEST_STRADDLE TMR0 00000001 TMR1CS 00000001 TMR1GE 00000006 TMR1H 0000000F TMR1IE 00000000 TMR1IF 00000000 TMR1L 0000000E TMR1ON 00000000 TRISA 00000085 TRISC 00000087 TRIS_RS232 00000087 VCFG 00000006 VR0 00000000 VR1 00000001 VR2 00000002 VR3 00000003 VRCON 00000099 VREN 00000007 VRR 00000005 W 00000000 WPU 00000095 WPUA 00000095 WR 00000001 WREN 00000002 WRERR 00000003 Z 00000002 _BODEN 00003FFF _BODEN_OFF 00003FBF _CP 00003F7F _CPD 00003EFF MPASM 5.05 SC001_MULTICHIP.ASM 10-1-2008 20:03:52 PAGE 51 SYMBOL TABLE LABEL VALUE _CPD_OFF 00003FFF _CP_OFF 00003FFF _EC_OSC 00003FFB _EXTRC_OSC_CLKOUT 00003FFF _EXTRC_OSC_NOCLKOUT 00003FFE _HS_OSC 00003FFA _INTRC_OSC_CLKOUT 00003FFD _INTRC_OSC_NOCLKOUT 00003FFC _LP_OSC 00003FF8 _MCLRE_OFF 00003FDF _MCLRE_ON 00003FFF _PWRTE_OFF 00003FFF _PWRTE_ON 00003FEF _WDT_OFF 00003FF7 _WDT_ON 00003FFF _XT_OSC 00003FF9 __16F676 00000001 pic16F676 1 wantAtoD MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : X---XXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 00C0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0100 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0140 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0180 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 01C0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0200 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0240 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0280 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 02C0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0300 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXX-- 03C0 : ---------------- ---------------- ---------------- -------------XXX 2000 : XXXX---X-------- ---------------- ---------------- ---------------- 2100 : XXXXXXXX-------- ---------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 830 Program Memory Words Free: 194 Errors : 0 Warnings : 0 reported, 0 suppressed Messages : 0 reported, 39 suppressed