Tims125

Bios S4 v1 602 MA

Dec 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.25 KB | None | 0 0
  1. ' {$STAMP BS2P}
  2. ' {$PBASIC 2.5}
  3. ' {$PORT COM4}
  4.  
  5.  
  6. version CON 1602
  7.  
  8. '**********************
  9. ' Slot 4
  10. '**********************
  11.  
  12. '
  13. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  14. 'XXXXXXXX >> Start Here to Copy Header entries << XXXXXXXXXXXXXXXXXX
  15. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  16. '
  17. 'S0 contains the timing loop
  18. 'S2 contains the event table AND actions.
  19. 'S1 contains test code placeholder
  20. '
  21. ' 2012
  22. ' 1. added test for payload interface boards
  23. ' 2. clean slot 0, added time 0,1,2 for clock speed
  24. '
  25. '****************** Start of System Global lables *******************
  26. ' Conditional Assemblies
  27. '
  28. #DEFINE FlyConfig = 0 '1=Set to Flight Configuration, 0=Test Configuration
  29. #DEFINE fastclock = 0 '0=Normal Time X1, 1=Medium Time ~X17 2=Fast Time ~X60
  30. #DEFINE testreset = 1 '1=test reset and reset count
  31. #DEFINE SaySlot = 1 '1=Say Slot with vector
  32. #DEFINE Sayit = 1 '1=Say what is happening
  33. #DEFINE nodebug = 1 '1= nodebug outputs
  34. #DEFINE MasterEnabled = 1 '1= enable checking for master input
  35. '
  36. '
  37. '***************************************************************************************
  38. '********* EEPROM Data Storage Area ****************************************************
  39. 'Start storage at top of slot6 and work downwards, code can go in slot 4, but be carful
  40. 'not to overwrite the data storage. Programs go from botton to top, Data storage, and
  41. 'our data storage allocations are from the top down. MUST BE CHECKED MANUALLY, program
  42. 'does not know any better.
  43. '***************************************************************************************
  44. '
  45. DataStorage CON 4 'EEROM data is storaged in Slot 4
  46. '
  47. '
  48. 'Data storage is defined at the end of this slot (slot 4), the spaces and address must match up with
  49. 'the lables defined here which will be used across all slots, be careful in defining this
  50. '
  51. Cstatus CON 0 '00 See data at data storage area
  52. TestNumber CON Cstatus+1 'Test Sequence Counter 1112
  53. ResetNumber CON TestNumber+2 '00 Number of times reset sence downloaded
  54. IDcodefile CON ResetNumber+1 'MicroLab alpha ID 2 ascii values
  55. LastPhoto CON IDcodefile+2 '00000 Photo number 5 ascii values
  56. LastBKupload CON LastPhoto+5 'Number of the last command file uploaded
  57. NextBktoLoad CON LastBKupload+1 'NextBktoLoad next bank to load
  58. LastuploadCommand CON NextBktoLoad+1 'LastuploadCommand Number of the last command file uploaded
  59. Missionsec CON LastuploadCommand+2 'Missionsec clock sec count here 0-59
  60. Missionmin CON Missionsec+1 'Missionmin clock min count here 0-59
  61. Missionhour CON Missionmin+1 'Missionhour lock hour count here 0-23
  62. Missionday CON Missionhour+1 'Missionday lock day count here 0-xx
  63. TempStatus CON Missionday+1 'Temp storage for test status routines
  64. '
  65. ' 'ETC....
  66. '
  67. '**********************************************************************
  68. '******** Scrathpad Ram Defined Ram location across all slots *********
  69. '**********************************************************************
  70. '
  71. ScratchRam CON 0 'start of Scratch ram locations bytes
  72. '
  73. '----- Bios and User Scratch pad memory locations -----------------------------
  74. '
  75. Resetverify CON ScratchRam 'location is 0 on Power on Reset or not Zero for slot return
  76. VectorFromSlot CON Resetverify+1 'Slot to return to - who called the program vector
  77. VectorFromNum CON VectorFromSlot+1 'From Vector number within slot place to Return to
  78. SlotErrReturn CON VectorFromNum+1 'Error code return from Slot program run
  79. '
  80. sMissionday CON SlotErrReturn+1 'BIOS Mission clock day count here 0-xx
  81. sMissionhour CON sMissionday+1 'BIOS Mission clock hour count here 0-23
  82. sMissionmin CON sMissionhour+1 'BIOS Mission clock min count here 0-59
  83. sMissionsec CON sMissionmin+1 'BIOS Mission clock sec count here 0-59
  84. '
  85. '---------- Bios provided data for user -----------------------------------------
  86. '
  87. RTCsec CON sMissionsec+1 'BIOS Real Time clock sec count here 0-59
  88. RTCmin CON RTCsec+1 'BIOS Real Time clock min count here 0- 59
  89. RTChour CON RTCmin+1 'BIOS Real Time Clock hour count here 0-23
  90. RTCday CON RTChour+1 'BIOS Real Time clock day count here 1-31
  91. RTCmonth CON RTCday+1 'BIOS Real Time clock month count here 1-12
  92. RTCyear CON RTCmonth+1 'BIOS Real Time clock year count here 0-99
  93. '
  94. AmbTemperature CON RTCyear+1 'BIOS Ambient temperature in celcius (8 low bits of 10 bits)
  95. AmbTemperaturehigh CON AmbTemperature+1 'BIOS Ambient temperature in celcius (2 high bits of 10 bits)
  96. AmbHumidity CON AmbTemperaturehigh+1 'BIOS Ambient Humidity (8 low bits of 10 bits)
  97. AmbHumidityhigh CON AmbHumidity+1 'BIOS Ambient Humidity (2 high bits of 10 bits)
  98. '
  99. A2Dchannel0 CON AmbHumidityhigh+1 'BIOS Analog channel 0, (8 bits 0f 0v to 2.5v low-> high)
  100. A2Dchannel0high CON A2Dchannel0+1 'BIOS Analog channel 0, (2 bits 0f 0v to 2.5v low-> high)
  101. A2Dchannel1 CON A2Dchannel0high+1 'BIOS Analog channel 1, (8 bits 0f 0v to 2.5v low-> high)
  102. A2Dchannel1high CON A2Dchannel1+1 'BIOS Analog channel 1, (2 bits 0f 0v to 2.5v low-> high)
  103. A2Dchannel2 CON A2Dchannel1high+1 'BIOS Analog channel 2, (8 bits 0f 0v to 2.5v low-> high)
  104. A2Dchannel2high CON A2Dchannel2+1 'BIOS Analog channel 2, (2 bits 0f 0v to 2.5v low-> high)
  105. A2Dchannel3 CON A2Dchannel2high+1 'BIOS Analog channel 3, (8 bits 0f 0v to 2.5v low-> high)
  106. A2Dchannel3high CON A2Dchannel3+1 'BIOS Analog channel 3, (2 bits 0f 0v to 2.5v low-> high)
  107. InternTemp CON A2Dchannel3high+1 'Bios internal temp of msp430- Needs Calibration
  108. InternTemphigh CON InternTemp+1 'Bios internal temp of msp430- Needs Calibration
  109. VCCby2 CON InternTemphigh+1 'Bios VCC/2 for calabration - Regulator check
  110. VCCby2high CON VCCby2+1 'Bios VCC/2 for calabration - Regulator check
  111. '
  112. '----------- Bios Reserved working registers ----------------------------------------
  113. '
  114. CameraRes CON VCCby2high+1 'Name this Bios Register (camera Resolution 320 $05 640 $07)
  115. CameraQua CON CameraRes+1 'Name this Bios Register (Camera quality $02 normal, $01 Better, $00 Best)
  116. SlaveErr CON CameraQua+1 'slave MSP430 status byte (Local Slave Status)
  117. ActiveBank CON SlaveErr+1 'Name this Bios Register (Active bank)
  118. TextPointer CON ActiveBank+1 'Name 16 bit pointer to text in active bank
  119. '
  120. 'MicroLab Bios Status Byte given to Master on Status Request
  121. ' Location and Bits defined
  122. '
  123. MLabStatus CON TextPointer+2 'Current Status of MicroLab
  124. HighPower CON $80 ' Bit 7=high power request
  125. ExComplete CON $40 ' Bit 6 = execution of upload command completed
  126. ' Bit 5,4,3, don't care
  127. B2ready CON $04 ' Bit 2 = bank 2 ready for upload
  128. B1ready CON $02 ' Bit 1 = bank 1 ready for upload
  129. B0ready CON $01 ' Bit 0 = bank 0 ready for upload
  130. '
  131. 'MicroLab Power Status Registers
  132. ' '
  133. PowerStatus CON MLabStatus+1 'Power control value
  134. P300ma CON $80 'enable high power 300ma mode
  135. P75ma CON $40 'set to 75ma power usage
  136. P50ma CON $20 'set to low power 50ma
  137. P100ma CON $00 'default value of power 100ma
  138. '
  139. 'Reserved Bios Working Registers
  140. '
  141. BiosWord0 CON PowerStatus+1 'BIOS Reserved Word for Bios operations
  142. BiosWord0h CON BiosWord0+1 '
  143. BiosWord1 CON BiosWord0h+1 'BIOS Reserved Word for Bios operations
  144. BiosWord1h CON BiosWord1+1 '
  145. BiosWord2 CON BiosWord1h+1 'BIOS Reserved Word for Bios operations
  146. BiosWord2h CON BiosWord2+1 'BIOS Reserved Word for Bios operations
  147. BiosWord3 CON BiosWord2h+1 'BIOS Reserved Word for Bios operations
  148. BiosWord3h CON BiosWord3+1 'BIOS Reserved Word for Bios operations
  149. '
  150. '-----------General Purpose registers across Slots--------------------------------------
  151. '
  152. scr_Register0 CON BiosWord3h+1 'General use Scratchpad Ram location across all slots
  153. scr_Register1 CON scr_Register0+1 'General use Scratchpad Ram location across all slots
  154. scr_Register2 CON scr_Register1+1 'General use Scratchpad Ram location across all slots
  155. scr_Register3 CON scr_Register2+1 'General use Scratchpad Ram location across all slots
  156. scr_Register4 CON scr_Register3+1 'General use Scratchpad Ram location across all slots
  157. scr_Register5 CON scr_Register4+1 'General use Scratchpad Ram location across all slots
  158. scr_Register6 CON scr_Register5+1 'General use Scratchpad Ram location across all slots
  159. scr_Register7 CON scr_Register6+1 'General use Scratchpad Ram location across all slots
  160. '
  161. '--------- Location for Saved User Variables -----------------------------------------
  162. '
  163. Reg0low CON scr_Register7+1 'Storage of user variables during Bios operations
  164. Reg0high CON Reg0low+1 'Storage of user variables during Bios operations
  165. Reg1low CON Reg0high+1 'Storage of user variables during Bios operations
  166. Reg1high CON Reg1low+1 'Storage of user variables during Bios operations
  167. Reg2low CON Reg1high+1 'Storage of user variables during Bios operations
  168. Reg2high CON Reg2low+1 'Storage of user variables during Bios operations
  169. Reg3low CON Reg2high+1 'Storage of user variables during Bios operations
  170. Reg3high CON Reg3low+1 'Storage of user variables during Bios operations
  171. Reg4low CON Reg3high+1 'Storage of user variables during Bios operations
  172. Reg4high CON Reg4low+1 'Storage of user variables during Bios operations
  173. Reg5low CON Reg4high+1 'Storage of user variables during Bios operations
  174. Reg5high CON Reg5low+1 'Storage of user variables during Bios operations
  175. Reg6low CON Reg5high+1 'Storage of user variables during Bios operations
  176. Reg6high CON Reg6low+1 'Storage of user variables during Bios operations
  177. Reg7low CON Reg6high+1 'Storage of user variables during Bios operations
  178. Reg7high CON Reg7low+1 'Storage of user variables during Bios operations
  179. Reg8low CON Reg7high+1 'Storage of user variables during Bios operations
  180. Reg8high CON Reg8low+1 'Storage of user variables during Bios operations
  181. Reg9low CON Reg8high+1 'Storage of user variables during Bios operations
  182. Reg9high CON Reg9low+1 'Storage of user variables during Bios operations
  183. Reg10low CON Reg9high+1 'Storage of user variables during Bios operations
  184. Reg10high CON Reg10low+1 'Storage of user variables during Bios operations
  185. Reg11low CON Reg10high+1 'Storage of user variables during Bios operations
  186. Reg11high CON Reg11low+1 'Storage of user variables during Bios operations
  187. Reg12low CON Reg11high+1 'Storage of user variables during Bios operations
  188. Reg12high CON Reg12low+1 'Storage of user variables during Bios operations
  189. '
  190. '
  191. MoprClk0 CON Reg12high+1 'Mission Operations Clock0, fail safe operations
  192. MoprClk1 CON MoprClk0+2 'Mission Operations Clock1, fail safe operations
  193. MoprClk2 CON MoprClk1+2 'Mission Operations Clock1, fail safe operations
  194. MoprClk3 CON MoprClk2+2 'Mission Operations Clock1, fail safe operations
  195. '
  196. '
  197. NextAvailiable CON MoprClk3+2 'Next Availiable location for scratch pad ram storage
  198. '
  199. '------- User Scratchpad Locations open for use -------------
  200. '
  201. '
  202. '
  203. '------- User Scratchpad Locations open for use ------------- '
  204. '
  205. SlotInfo CON 127 'contains the current running slot.
  206. '
  207. 'location number 127 contains the number of the currently running program slot
  208. '
  209. '************* End of Scratchpad Ram Space difinations ****************
  210. '
  211. '**********************************************************************
  212. '----- MicroLab Pins and ports on the BS2p24 Defined for BIOS ------------
  213. '**********************************************************************
  214. internalscl CON 0 'BS2p24 interal I2c buss
  215. internalsda CON 1 'BS2p24 interal I2c buss
  216. cameraclk CON 2 'Camera Clock
  217. cameramiso CON 3 'Camera master in slave out
  218. cameramosi CON 4 'Camera msater out slave in
  219. camerahold CON 5 'Camera Hold
  220. masterin PIN 6 'Serial Input fm master
  221. 'masterin CON 6 'Serial Input fm master
  222. masterout CON 7 'Serial Output to master
  223. payloadsda CON 8 'SDA on payload expansion board
  224. payloadscl CON 9 'SCL on payload expansion board
  225. internawin CON 10 'Local slave A to D, watchdog serial in
  226. internawout CON 11 'Loacl slave A to D, watchdog serial out
  227. camerapower CON 12 'Camera on and off for recycle
  228. votedead CON 13 'AMicroLab vote that Master is dead
  229. payloadio14 CON 14 'I/O payload line
  230. cameraCS CON 15 'camrea chip select pin
  231. '
  232. '
  233. '---------------- Bios System General constants --------------------
  234. '
  235. ' Input terminal constants for test set to
  236. con_in CON 16 'Pin 16 is BS2P serial in from RS232 connector
  237. con_baud CON 240 'set to 9600 8bit true
  238. con_tout CON 250 'time out waiting for terminal input appx 100ms
  239. '
  240. '----------------- Bios General constants ---------------------------
  241. '
  242. InternI2c CON 0 'Internal I2C buss address control
  243. PLi2c CON 8 'Payload I2c BUSS address control
  244. PCF8574address CON $40 'internal I2C buss address of PFC8574
  245. Ebankaddress CON $A0 'Address of 256k eerom memory
  246. Ebank0 CON $00 'Ebank0 bank address 00000-0FFFF
  247. Ebank1 CON $02 'Ebank1 bank address 10000-1FFFF
  248. Ebank2 CON $04 'Ebank2 bank address 20000-2FFFF
  249. Ebank3 CON $06 'Ebank3 bank address 30000-3FFFF
  250. '
  251. TextBuffer CON $C000 'Text buffer in bank 0,1, and 2
  252. '
  253. Camera320 CON $05 'Camera Resolution 320X240
  254. Camera640 CON $07 'Camera Resolution 640X480
  255. CameraNormal CON $02 'Camera Quality Normal
  256. CameraBetter CON $01 'Camera Quality Better
  257. CameraBest CON $00 'Camera Quality Best
  258. '
  259. Baud9600T CON $00F0 'Baudrate of 9600 no parity True
  260. Baud2400T CON $03FD 'Baudrate of 2400 no parity true
  261. '
  262. Ack CON $5A 'Acknowledge response to McMek
  263. TimeOut CON 500 'input command timeout is .5 seconds
  264. Pace CON 1 'pace of output from MicroLab to System terminal
  265. ETX CON $03 'End of Text command
  266. EOF CON $FF 'end of file marker
  267. '
  268. '------------ Bios System Error and event codes for logging --------------------
  269. '
  270. NoError CON 0 'no error on return, all ok
  271. '
  272. '----------------- Variables Same for all program Slots ---------------
  273. ' Used By BIOS
  274. xcounter VAR Word 'General use 16 bit counter
  275. TempWord VAR Word 'General use Temp Word Register
  276. TempWord1 VAR Word 'General use Temp Word Register
  277. counter VAR Byte 'General use 8 bit counter
  278. TempReg0 VAR Byte 'General use location for values during processes
  279. TempReg1 VAR Byte 'General use location for values during processes
  280. TempReg2 VAR Byte 'General use location for values during processes
  281. TempReg3 VAR Byte 'General use location for values during processes
  282. Sdata VAR Byte 'data to send to uart
  283. text VAR Byte(8) 'make array for text
  284. '
  285. ' Variables open for use by User (9 Bytes)and not touched by the BIOS
  286. ' Note: above BIOS Variables can/may be used by the user, however
  287. ' the value may be destroyed by a Call to the BIOS or BIOS operation
  288. '
  289. UserVar0 VAR Byte 'user Varible space - Should be same across all slots
  290. UserVar1 VAR Byte 'user Varible space - Should be same across all slots
  291. UserVar2 VAR Byte 'user Varible space - Should be same across all slots
  292. UserVar3 VAR Byte 'user Varible space - Should be same across all slots
  293. UserVar4 VAR Byte 'user Varible space - Should be same across all slots
  294. UserVar5 VAR Byte 'user Varible space - Should be same across all slots
  295.  
  296. '
  297. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  298. ' Calibration values must be calculated and writen through the test system write eeram
  299. ' not automatically done, this is a one time event. Calibrate CPU temp, may be as
  300. ' much as 60 degrees C off from the factory.
  301. '
  302. SysCalBank CON Ebank3 'Bank for system calibration
  303. SysCPUcal CON $C002 'External E2RAM calibration locations
  304. '
  305. '
  306. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  307. 'XXXXXXXXXXXXXXXXXXXXX >> End of Header Copy Entries << XXXXXXXXXXXXXXXXXXXXXXX
  308. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  309. '
  310. ''*************************************************************************
  311. ' Enter with TempReg1 containing the program index to run in this slot
  312. '*************************************************************************
  313. '
  314. #IF SaySlot = 1 #THEN
  315. DEBUG ">S4-V",DEC TempReg1,CR
  316. #ENDIF
  317. BRANCH TempReg1,[HeartBeattextReturn, '0 vector flight condition setup override
  318. WriteTextBuffer, '1 vector to this program
  319. P2vector, '2 vector to this program
  320. P3vector] '3 vector to this program
  321. '
  322.  
  323. '*************************************************************************
  324. ' To Run program in another slot Set TempReg1 to the vector index of
  325. ' that program within the target slot then "RUN" that slot, If a return
  326. ' to originating slot is desired then the return vector index must be stored
  327. ' in the VectorFromNum location in the scratch pad memory, and the return
  328. ' slot is stored in the VectorFromSlot scratch pad memory. Then a general
  329. ' routine can be used to return to the originating program.
  330. '*************************************************************************
  331. '
  332. InSlot CON 4 'Define this slot, each slot is numbered
  333. '
  334. '***********************************************************************
  335. ' To go to a slot and set a return
  336. 'TempReg0 = Returning vector indes
  337. 'TempReg1 = vector index to run in next slot
  338. 'TempReg3 = the slot number to go to
  339. '**********************************************************************
  340. '
  341. GotoSlot:
  342. PUT VectorFromNum,TempReg0 'this is the vector when returning back to this slot
  343. PUT VectorFromSlot,InSlot 'To vector back to this Slot
  344. RUN TempReg3
  345. '
  346. '
  347. '***************************************************************************
  348. 'When returning back, Set TempReg1 to the return vector in the calling slot
  349. 'get the returning slot and RUN that slot
  350. '***************************************************************************
  351. '
  352. ReturnBack:
  353. GET VectorFromNum,TempReg1 'fetch the vector to run when returning to calling slot
  354. GET VectorFromSlot,TempReg0 'fetch the program slot where the routine was called
  355. RUN TempReg0 'RETURNback now....!!!!
  356. '
  357.  
  358. '
  359. '
  360. '
  361. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  362. 'XXXXXXXXXXXXXXXXXXXX Programs in this slot XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  363. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  364. '
  365. '======================================================================
  366. P1vector:
  367. GOTO ReturnBack 'back to calling routine
  368. '======================================================================
  369. P2vector:
  370. GOTO ReturnBack 'back to calling routine
  371. '======================================================================
  372. P3vector:
  373. GOTO ReturnBack 'back to calling routine
  374. '
  375. '
  376. '********************************************************
  377. ' Heart Beat Proceedure, Place the return index vector number
  378. ' in TempReg0 so when Heart Beat is finished the program knows
  379. ' where to return. Heart Beat, updats time,A2D, watchdog, plus
  380. ' other maintance functions.
  381. '********************************************************
  382. '
  383. HeartBeatUpdate:
  384. TempReg0 = 0 'Index to vector to return in this slot HeartBeatReturn
  385. TempReg1 = 1 'program to run in slot 1
  386. TempReg3 = 7 'Heart Beat slot 7 program 1 vector 1
  387. GOTO Gotoslot 'Execute a slot goto proceedure now doit
  388. '
  389. '********************************************************
  390.  
  391. '
  392. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  393. ' Default Text with values from the scratch pad memory
  394. ' Default Text with values in place
  395. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  396. '
  397. 'Should enter here after photo was taken and transfered to the active bank
  398. ' end of this routine set up for next photo/text session
  399. 'Enter with:
  400. ' ActiveBank = Set to active bank (0 2 or 4)where text will go!!!!
  401. ' '
  402. 'Exit with: xcounter = 16 bits - pointer to the next text location in
  403. ' Text Bank pointer updated to point to the next text location
  404. '
  405. '
  406. WriteTextBuffer:
  407. 'do a heartbeat first forced jump and back
  408. TempReg1=2 'Forced Heartbeat direct jumps
  409. RUN 7 'Run it is slot 7 forced vector 2
  410. HeartBeattextReturn:
  411. '
  412. '
  413. STORE DataStorage 'set for stamp eerom storage
  414. GET ActiveBank,TempReg2 'Set TempReg2 to the Active Bank 0 2 4
  415. xcounter = TextBuffer 'Set xcounter to point to text location $C000 16k
  416. TempWord = ID 'point TempWord to the beginning of text
  417. '
  418. ' now TempReg2 => ActiveBank, xcounter => address in ee2ram, TempWord => phrase to write
  419. ' This will store the default Text Output file and fill in the values
  420. '
  421. GetnextChar:
  422. READ TempWord,TempReg0 'get the charator
  423. IF TempReg0 = EOF THEN GOTO TextFinished 'found end of phase now finished
  424. TempWord = TempWord+1 'point to next charator
  425. I2COUT InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg0] 'write charator in ee2ram
  426. PAUSE 10 'wait for the write to chip to complete internal to chips
  427. xcounter=xcounter+1 'xcounter points to next text charator location
  428. IF xcounter=$FFFF THEN GOTO TextFinished ' ERROR CONDITION
  429. GOTO GetnextChar 'not finished yet get the next charator
  430. TextFinished:
  431. TempReg0 = EOF 'write end of file marker
  432. I2COUT InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg0] 'write charator in ee2ram
  433. PAUSE 10
  434. PUT TextPointer,Word xcounter 'Put Text pointer into Scratchpad for additional text to be written
  435. ' 'The user can use the Text pointer in the current bank to add their on text
  436. ' 'to the output file...
  437. '
  438. '****** Now fill in the values in the text (dont touch TempReg2) *****
  439. '
  440. ' file name
  441. '
  442. TempWord = (IDcodefile-Cstatus) 'point to current file name with id stored in stamp eerom
  443. xcounter = TextBuffer+(LastPN-ID) 'point to EERAM where file name lives in the text file output
  444. FOR xcounter = TextBuffer+(LastPN-ID) TO TextBuffer+(LastPN-ID)+6 'loop to move file name XX0000
  445. READ TempWord,TempReg0 'get the value from stamp ee storage location
  446. I2COUT InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg0] 'write charator in ee2ram
  447. PAUSE 10 'wait for write
  448. TempWord = TempWord+1
  449. NEXT
  450. '
  451. ' Enter Date and Time - place ascii values in text buffer output
  452. '
  453. GET RTCmonth,TempWord 'get month in
  454. xcounter=TextBuffer+(ADate-ID) 'point to place to write
  455. GOSUB ConvertWrite2 'get ascii values and write in bank
  456. xcounter=xcounter+2 ' over /
  457. GET RTCday,TempWord 'get day
  458. GOSUB ConvertWrite2 'write the day in bank
  459. xcounter=xcounter+2 'over /
  460. GET RTCyear,TempWord 'get year
  461. GOSUB ConvertWrite2 'write the year in bank
  462. xcounter=xcounter+5 'over" at "
  463. GET RTChour,TempWord 'get hour from scratch
  464. GOSUB ConvertWrite2 'write the hour in bank
  465. xcounter=xcounter+2 'over :
  466. GET RTCmin,TempWord 'get the Minute
  467. GOSUB ConvertWrite2 'write the minute in bank
  468. xcounter=xcounter +2 'over :
  469. GET RTCsec,TempWord 'get seconds in bank
  470. GOSUB ConvertWrite2 'write seconds in text for output
  471. '
  472. ' Enter Mission Clock - place ascii values in text buffer output
  473. '
  474. STORE DataStorage 'set to point to slot EERAM
  475. READ Missionday,TempWord 'get the mission day count
  476. xcounter=TextBuffer+(Mtime-ID) 'point to missionday entry in text buffer
  477. GOSUB ConvertWrite2 'get convert and write ascii in test
  478. READ Missionhour,TempWord 'get the hour
  479. xcounter=xcounter+3 'pointer move to hour
  480. GOSUB ConvertWrite2 'get, convert, write ascii in text
  481. READ Missionmin,TempWord 'get the min
  482. xcounter=xcounter+3 'point to min
  483. GOSUB ConvertWrite2 'convert,write ascii
  484. READ Missionsec,TempWord 'get the sec
  485. xcounter=xcounter+3 'point to sec
  486. GOSUB ConvertWrite2 'place sec in text buffer
  487. '
  488. ' say active bank for storage of text and photo this bank
  489. '
  490. GET ActiveBank,TempWord 'get the active bank from scratchpad
  491. xcounter = TextBuffer+(Abank-ID) 'point to bank in text output
  492. GOSUB ConvertWrite2 'convert and write it '
  493. '
  494. ' Enter Reset counter
  495. '
  496. READ ResetNumber,TempReg0 'get reset counter
  497. TempWord = TempReg0 'put it in the correcr register
  498. GOSUB Convert2BCD 'convert the number
  499. xcounter = TextBuffer+(Rcnt-ID) 'point to text buffer to write
  500. GOSUB writeXXX 'write three BCD values
  501. '
  502. ' Ambient Temperature
  503. '
  504. GET AmbTemperature,TempReg0 'get the temp low 8 bits
  505. GET AmbTemperature+1,TempReg1 'get the temp high 2 bits
  506. TempWord = (((TempReg0 + (TempReg1*256))*64)/52) 'convert to centergrade
  507. GOSUB Convert2BCD 'ascii values in text(0)(1)(2), convert to 3 bcd digits ascii
  508. xcounter = TextBuffer+(ATV-ID) 'point xcounter to entry in default text
  509. GOSUB writeXXpointX 'write text in eeram
  510. '
  511. ' Ambient Humidity
  512. '
  513. GET AmbHumidity,TempReg0 'get the humid
  514. GET AmbHumidity+1,TempReg1 'get the humid
  515. TempWord = (((TempReg0 + (TempReg1*256))*10)-2048)/86 'convert to %
  516. GOSUB Convert2BCD 'convert to BCD ascii to write in text buffer
  517. xcounter = TextBuffer+(AHV-ID) 'point to humidity in text
  518. GOSUB writeXX 'write 2 digits only
  519. '
  520. ' Ambient CPU Temp
  521. '
  522. ' need to get calibration - unique to CPU
  523. ' 355/c<Calibration for slave temperature sensor, could be 60 degrees off
  524. '
  525. PUT Reg0low,TempReg2 'save current value of TempReg2
  526. TempReg2 = SysCalBank 'point TempReg2 to systems bank
  527. xcounter = SysCPUcal 'point xcounter to calibration value in e2ram
  528. I2CIN InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempWord1.LOWBYTE] 'get to low value
  529. xcounter = xcounter+1 'now for the high byte
  530. I2CIN InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempWord1.HIGHBYTE] 'get to high value
  531. GET Reg0low,TempReg2 'replace TempReg2 value
  532. '
  533. '>355/c<Calibration for slave temperature sensor, could be 60 degrees off
  534. GET InternTemp,TempReg0
  535. GET InternTemp+1,TempReg1
  536. TempWord = (((((TempReg0 + (TempReg1*256))-397)*250)+TempWord1)/355) 'convert to internal temp of cpu
  537. GOSUB Convert2BCD 'ascii values in text(0)(1)(2), convert to 3 bcd digits ascii
  538. xcounter = TextBuffer+(CTV-ID) 'point xcounter to entry in default text
  539. GOSUB writeXX 'write text in eeram
  540. '
  541. ' Analog channels and Voltage readings
  542. '
  543. GET A2Dchannel0,TempReg0 'get from scratch pad
  544. GET A2Dchannel0high,TempReg1 'get from scratch pad
  545. xcounter = TextBuffer+(AV0-ID) 'point to text buffer
  546. GOSUB WriteAnalog 'write the values in text
  547. '
  548. GET A2Dchannel1,TempReg0 'get from scratch pad
  549. GET A2Dchannel1high,TempReg1 'get from scratch pad
  550. xcounter = TextBuffer+(AV1-ID) 'point to text buffer
  551. GOSUB WriteAnalog 'write the values in text
  552. '
  553. GET A2Dchannel2,TempReg0 'get from scratch pad
  554. GET A2Dchannel2high,TempReg1 'get from scratch pad
  555. xcounter = TextBuffer+(AV2-ID) 'point to text buffer
  556. GOSUB WriteAnalog 'write the values in text
  557. '
  558. GET A2Dchannel3,TempReg0 'get from scratch pad
  559. GET A2Dchannel3high,TempReg1 'get from scratch pad
  560. xcounter = TextBuffer+(AV3-ID) 'point to text buffer
  561. GOSUB WriteAnalog 'write the values in text
  562. '
  563. GET VCCby2,TempReg0 'get from scratch pad
  564. GET VCCby2high,TempReg1 'get from scratch pad
  565. xcounter = TextBuffer+(VcV-ID) 'point to text buffer
  566. TempWord = ((((TempReg0 + (TempReg1*256))/2)*25)/51)*2 'for 3.3 not 1/2 3.3 number
  567. GOSUB WriteAnalog33 'write the values in text
  568. '
  569. ' Systems Status
  570. '
  571. GET MLabStatus,TempReg0 'get system status
  572. FOR xcounter = TextBuffer+(SStat-ID)TO TextBuffer+(SStat-ID)+7 'point to status bytes in text output
  573. IF TempReg0 >= $80 THEN TempReg1="1":GOTO SS1or0 'check MSB bits shifted to MSB to test
  574. TempReg1="0" 'was less than $80 then the bit was a "0"
  575. SS1or0:
  576. I2COUT InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg1] 'write charator in ee2ram
  577. PAUSE 10 'wait for write
  578. TempReg0 = TempReg0 << 1 'shift in next bit
  579. NEXT
  580. '
  581. ' To Add additional Text To the Text output file => Add it here
  582. ' Be carful with pointers, and write to the
  583. '
  584. '***********************************************************************
  585. ' TEST NOT NECESSARY TO FLY
  586. 'read back test here $$$$$ output the Text buffer until the EOF end of file
  587. '***********************************************************************
  588. '
  589. GET ActiveBank,TempReg2 'Set TempReg2 to the Active Bank 0 2 4
  590. xcounter = TextBuffer 'Set xcounter to point to text location $C000 16k
  591. RBnext:
  592. I2CIN InternI2c, $A1 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg0] 'write charator in ee2ram
  593. IF TempReg0 = EOF THEN GOTO RBfinished
  594. IF TempReg0 < CR THEN TempReg0 = $20
  595. DEBUG TempReg0
  596. xcounter=xcounter+1:GOTO RBnext
  597. RBfinished:
  598. '************************************************************************
  599. '************************************************************************
  600. '
  601. ' Here when Text Buffer has been written and data updated in the text output file
  602. ' Now get ready for the next Photo and Text event
  603. '
  604. '*********************************************************************
  605. 'Inc Photo Bank with rollover, Go to the next Bank of 0,1,2 to store the photo
  606. ' and set the status flag that photo and text is ready to upload
  607. '*********************************************************************
  608. '
  609. ' Set Bit in Status Register to state photo and text is availiable to upload
  610. '
  611. GET ActiveBank,TempReg0 'GET this active bank number
  612. IF TempReg0 = 0 THEN TempReg0 = $01 'mask to set bit is status
  613. GET MLabStatus,TempReg1 'get current status
  614. TempReg0 = TempReg0 | TempReg1 'Set the bit in the status register to state data ready
  615. PUT MLabStatus,TempReg0 'Replace Status with the bit set
  616. '
  617. ' Inc active Bank to the next bank, banks 0,2,4,0,2,4,etc
  618. '
  619. GET ActiveBank,TempReg0 'GET this active bank number
  620. TempReg0 = TempReg0 + 2 'offset to point to next bank 0,2,4,6
  621. IF TempReg0 > 4 THEN TempReg0 = 0 'Photo and text bank can not be larger than 4 wrap
  622. PUT ActiveBank,TempReg0 'replace Active Bank counter in memory
  623. '
  624. ' Now need a new file name use the next number in the sequence....
  625. '
  626. '*********************************************************************
  627. 'Inc Photo and File number in ascii format in EEROM bank 4
  628. '*********************************************************************
  629. '
  630. STORE DataStorage 'set for read and write for data in EEROM
  631. TempReg2 = 1 'this is the carry flag to next digit, add 1 to lsd
  632. FOR TempReg1 = 4 TO 0 'lets do 5 ascii digits and inc total by one
  633. READ LastPhoto+TempReg1,TempReg0 'read the first or next digit from memory
  634. TempReg0 = TempReg0+TempReg2 'Add carry from last digit 0 if frst
  635. IF TempReg0 <= "9" THEN TempReg2=0:GOTO IncP1 'undo carry then store it store it '
  636. TempReg0 = "0" 'to set digit to "0" because it carried
  637. TempReg2 = 1 'set the carry for next digit in loop
  638. IncP1:
  639. WRITE LastPhoto+TempReg1,TempReg0 'no carry Replace inc count for next time
  640. NEXT 'next digit ascci number inc routine 5 digits
  641. '
  642. 'We now have a new photo and text bank, a new file name for that data
  643. 'The status register is updated
  644. ' This should be the last thing in the process of photo and text storage and
  645. ' getting ready to up load to the Master.....
  646. '
  647. ' TempReg0 =
  648. ' TempReg1=
  649. ' DEBUG CR,"Pdone",CR
  650. '
  651. ' SEROUT masterout,Baud9600T,Pace,[CR,"Pdone",CR,$1B] 'send "ascii esc" termination charator
  652. '
  653. GOTO ReturnBack 'return to calling slot and routine
  654. '
  655. '************************************************************************************
  656. '************************************************************************************
  657. '
  658. '-----------------------------------------------------------------
  659. ' Write text(0) text(1) . text(2) in eeram for text values
  660. ' xcounter=>EERAM to put text ascii
  661. ' ----------------------------------------------------------------
  662. WriteAnalog:
  663. TempWord = ((((TempReg0 + (TempReg1*256))/2)*25)/51) 'convert to voltage number
  664. WriteAnalog33:
  665. GOSUB Convert2BCD 'convert to ascii BCD
  666. TempReg0 = text(0) 'never over 100% get ascii to first digit
  667. I2COUT InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg0] 'write charator in ee2ram
  668. PAUSE 10 'wait for write
  669. xcounter = xcounter+2 'over point
  670. GOTO writeXX 'write the next two digits
  671. writeXXpointX:
  672. ' DEBUG CR,"xcounter=",HEX4 xcounter,CR 'test
  673. TempReg0 = text(0) 'get ascii to first digit
  674. I2COUT InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg0] 'write charator in ee2ram
  675. PAUSE 10 'wait for write
  676. xcounter = xcounter+1
  677. TempReg0 = text(1)
  678. I2COUT InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg0] 'write charator in ee2ram
  679. PAUSE 10 'wait for write
  680. xcounter=xcounter+2 'skip point (dot)
  681. TempReg0 = text(2)
  682. I2COUT InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg0] 'write charator in ee2ram
  683. PAUSE 10 'wait for write
  684. RETURN
  685. ConvertWrite2:
  686. GOSUB Convert2BCD 'convert number in TempWord to BCD ascii text
  687. GOTO writeXX 'only write 2 digits
  688. writeXXX:
  689. TempReg0 = text(0) 'never over 100% get ascii to first digit
  690. I2COUT InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg0] 'write charator in ee2ram
  691. PAUSE 10 'wait for write
  692. xcounter = xcounter+1
  693. writeXX:
  694. TempReg0 = text(1) 'never over 100% get ascii to first digit
  695. I2COUT InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg0] 'write charator in ee2ram
  696. PAUSE 10 'wait for write
  697. xcounter = xcounter+1
  698. TempReg0 = text(2) 'never over 100% get ascii to first digit
  699. I2COUT InternI2c, $A0 | TempReg2,xcounter.HIGHBYTE\xcounter.LOWBYTE, [TempReg0] 'write charator in ee2ram
  700. PAUSE 10 'wait for write
  701. RETURN
  702. '
  703. '******************************************************************
  704. ' Subroutine to convert binary to ascii BCD and put in text(x) array
  705. ' enter - TempWord 16 bit value, this routine will output
  706. ' three BCD digits, Therefore it is 000 to 999 only
  707. ' used as a general routine
  708. ' exit = text(0), text(1), text(2) have bcd ascii values msd to lsd
  709. ' uses - TempWord, TempReg0, TempReg1, text(0), text(1), text(2)
  710. '*****************************************************************
  711. '
  712. Convert2BCD:
  713. TempReg0 = TempWord/100 'waht is the 100 digit?
  714. IF TempReg0 = 0 THEN text(0) = " ":GOTO Convert2BCD1 'this is MSD of XXX number " " or "
  715. TempReg1 = TempReg0 + $30 'make hundredth ascii
  716. text(0) = TempReg1 'put it in the text buffer
  717. Convert2BCD1:
  718. TempWord = TempWord - (TempReg0 * 100) 'subtract the 100th value
  719. TempReg0 = TempWord/10 'what is the 10 digit
  720. IF TempReg0 = 0 THEN Text(1) = "0" :GOTO Convert2BCD2 'this is 10th digit
  721. TempReg1 = TempReg0 +$30 'make 10th ascii
  722. text(1) = TempReg1 'put it in the array
  723. Convert2BCD2:
  724. TempWord = TempWord - (TempReg0 * 10) 'subtract 10s value
  725. TempReg0 = TempWord 'set to units value
  726. TempReg1 = TempReg0 +$30 'make it ascii
  727. text(2) = TempReg1 'put it in the array
  728. RETURN
  729. '
  730.  
  731. '
  732.  
  733. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  734. 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  735. '
  736. 'Variable Data Storage locations for non volitale memory
  737. '
  738. '*****DATA************** LABLE DEFINED AT TOP OF SLOT ***********************************
  739. DATA $00 'Cstatus state and status of testing chamber
  740. DATA Word $0000 'TestNumber location in EEROM
  741. DATA $00 'ResetNumber Store number of reset sense last program load
  742. DATA "J2" 'IDcodefile 2 alpha ID of MicroLab "ML,FF,XX,??"
  743. DATA "00000" 'LastPhoto MSD $30,$30,$30,$30,$30 lsd
  744. DATA $00 'LastBKupload last bank uploaded
  745. DATA $00 'NextBktoLoad next bank to load
  746. DATA Word $0000 'LastuploadCommand Number of the last command file uploaded
  747. DATA $00 'Missionsec clock sec count here 0-59
  748. DATA $00 'Missionmin clock min count here 0-59
  749. DATA $00 'Missionhour lock hour count here 0-23
  750. DATA $00 'Missionday lock day count here 0-xx
  751. 'ETC....
  752. '**************
  753. ' For text
  754. '**************
  755. '
  756. ID DATA "BIOS Templet Program 2013-2014 Ver 131",CR 'Name of School/Project
  757. DATA "Data Download Number "
  758. LastPN DATA "ML00000",CR 'photo file name
  759. ADate DATA "00/00/00 at " 'RTC date
  760. Atime DATA "00:00:00",CR 'RTC time
  761. DATA "ML Mission clock = "
  762. Mtime DATA "00D 00H 00M 00S",CR 'Now Mission clock
  763. DATA "Storage Bank = " 'where in the photo
  764. Abank DATA "00",CR 'this bank for storage
  765. DATA "Reset counter " 'How many resets since last program load
  766. Rcnt DATA "000",CR 'reset count
  767. DATA "Ambient Temperature = " 'temperature inside the Microlab
  768. ATV DATA "00.0 C",CR 'Abinent Temp
  769. DATA "Ambient Humidity = " 'humidity inside the Microlab
  770. AHV DATA "00%",CR 'ambient humidity
  771. DATA "Slave CPU Temperature = " 'Tempature inside slave cpu +/- 60 dC
  772. CTV DATA "00.0 C",CR ' 'not accurate, but relative correct
  773. DATA "Channel 0 Analog input = "
  774. AV0 DATA "0.00 Volts",CR 'Analog voltage input scaled to 0 to 2.5 volts
  775. DATA "Channel 1 Analog input = "
  776. AV1 DATA "0.00 Volts",CR
  777. DATA "Channel 2 Analog input = "
  778. AV2 DATA "0.00 Volts",CR
  779. DATA "Channel 3 Analog input = "
  780. AV3 DATA "0.00 Volts",CR
  781. DATA "3.3 Vcc = "
  782. VcV DATA "0.00 Volts",CR
  783. DATA "System Status = " 'status of photo buffers and download/upload
  784. SStat DATA "00xxx000",CR
  785. DATA "Ver 080313.00",CR
  786. ' DATA EOF
  787. ' To place additional Statements in the Text file for output - the EOF
  788. ' byte must be removed and added at the end of the additional statements as
  789. ' shown below. Space is limited due to the text being in the same space as the
  790. ' program. look at the memory map to determine the space that can be used for
  791. ' additional text.
  792. '
  793. 'Payload1 DATA "User Statement 2",CR '
  794. 'Payload2 DATA "User Statement 3",CR
  795. 'Payload3 DATA "User Statement 4",CR
  796. '
  797. EOFmark DATA EOF,EOF,$00
Add Comment
Please, Sign In to add comment