You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

804 lines
18 KiB

  1. ;**** **** **** **** ****
  2. ;
  3. ; BLHeli program for controlling brushless motors in helicopters and multirotors
  4. ;
  5. ; Copyright 2011, 2012 Steffen Skaug
  6. ; This program is distributed under the terms of the GNU General Public License
  7. ;
  8. ; This file is part of BLHeli.
  9. ;
  10. ; BLHeli is free software: you can redistribute it and/or modify
  11. ; it under the terms of the GNU General Public License as published by
  12. ; the Free Software Foundation, either version 3 of the License, or
  13. ; (at your option) any later version.
  14. ;
  15. ; BLHeli is distributed in the hope that it will be useful,
  16. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ; GNU General Public License for more details.
  19. ;
  20. ; You should have received a copy of the GNU General Public License
  21. ; along with BLHeli. If not, see <http://www.gnu.org/licenses/>.
  22. ;
  23. ;**** **** **** **** ****
  24. ;
  25. ; BLHeliTxPgm SiLabs
  26. ;
  27. ; EEPROM is not available in SiLabs MCUs
  28. ; Therefore a segment of the flash is used as "EEPROM"
  29. ;
  30. ;**** **** **** **** ****
  31. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  32. ;
  33. ; Read all eeprom parameters routine
  34. ;
  35. ; No assumptions
  36. ;
  37. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  38. read_all_eeprom_parameters:
  39. ; Check initialized signature
  40. mov DPTR, #Eep_Initialized_L
  41. mov Temp1, #Bit_Access
  42. call read_eeprom_byte
  43. mov A, Bit_Access
  44. cjne A, #055h, read_eeprom_store_defaults
  45. inc DPTR ; Now Eep_Initialized_H
  46. call read_eeprom_byte
  47. mov A, Bit_Access
  48. cjne A, #0AAh, read_eeprom_store_defaults
  49. jmp read_eeprom_read
  50. read_eeprom_store_defaults:
  51. call set_default_parameters
  52. call erase_and_store_all_in_eeprom
  53. jmp read_eeprom_exit
  54. read_eeprom_read:
  55. ; Read eeprom
  56. mov DPTR, #Eep_Pgm_Gov_P_Gain
  57. mov Temp1, #Pgm_Gov_P_Gain
  58. mov Temp4, #33;10
  59. read_eeprom_block1:
  60. call read_eeprom_byte
  61. inc DPTR
  62. inc Temp1
  63. djnz Temp4, read_eeprom_block1
  64. /*
  65. mov DPTR, #Eep_Enable_TX_Program
  66. mov Temp1, #Pgm_Enable_TX_Program
  67. mov Temp4, #19
  68. read_eeprom_block2:
  69. call read_eeprom_byte
  70. inc DPTR
  71. inc Temp1
  72. djnz Temp4, read_eeprom_block2
  73. */
  74. mov DPTR, #Eep_Dummy ; Set pointer to uncritical area
  75. read_eeprom_exit:
  76. ret
  77. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  78. ;
  79. ; Erase flash and store all parameter value in EEPROM routine
  80. ;
  81. ; No assumptions
  82. ;
  83. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  84. erase_and_store_all_in_eeprom:
  85. clr EA ; Disable interrupts
  86. ;call read_tags
  87. mov A,#0x0D
  88. mov UpDate_Flg,#1
  89. call erase_flash ; Erase flash
  90. /*
  91. mov DPTR, #Eep_FW_Main_Revision ; Store firmware main revision
  92. mov A, #EEPROM_FW_MAIN_REVISION
  93. call write_eeprom_byte_from_acc
  94. inc DPTR ; Now firmware sub revision
  95. mov A, #EEPROM_FW_SUB_REVISION
  96. call write_eeprom_byte_from_acc
  97. inc DPTR ; Now layout revision
  98. mov A, #EEPROM_LAYOUT_REVISION
  99. call write_eeprom_byte_from_acc
  100. */
  101. ; Write eeprom
  102. mov DPTR, #Eep_Pgm_Gov_P_Gain
  103. mov Temp1, #Pgm_Gov_P_Gain
  104. mov Temp4, #33;#10
  105. write_eeprom_block1:
  106. call write_eeprom_byte
  107. inc DPTR
  108. inc Temp1
  109. djnz Temp4, write_eeprom_block1
  110. /*
  111. mov DPTR, #Eep_Enable_TX_Program
  112. mov Temp1, #Pgm_Enable_TX_Program
  113. mov Temp4, #19
  114. write_eeprom_block2:
  115. call write_eeprom_byte
  116. inc DPTR
  117. inc Temp1
  118. djnz Temp4, write_eeprom_block2
  119. ;call write_tags
  120. call write_eeprom_signature
  121. */
  122. mov DPTR, #Eep_Dummy ; Set pointer to uncritical area
  123. ret
  124. ;**;**** **** **** **** **** **** **** **** **** **** **** **** ****
  125. ;
  126. ; Wait 1 second routine
  127. ;
  128. ; No assumptions
  129. ;
  130. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  131. wait1s:
  132. mov Temp5, #5
  133. wait1s_loop:
  134. call wait200ms
  135. djnz Temp5, wait1s_loop
  136. ret
  137. ;**;**** **** **** **** **** **** **** **** **** **** **** **** ****
  138. ;
  139. ; Success beep routine
  140. ;
  141. ; No assumptions
  142. ;
  143. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  144. success_beep:
  145. clr EA ; Disable all interrupts
  146. call beep_f1
  147. call beep_f2
  148. call beep_f3
  149. call beep_f4
  150. call wait10ms
  151. call beep_f1
  152. call beep_f2
  153. call beep_f3
  154. call beep_f4
  155. call wait10ms
  156. call beep_f1
  157. call beep_f2
  158. call beep_f3
  159. call beep_f4
  160. setb EA ; Enable all interrupts
  161. ret
  162. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  163. ;
  164. ; Write eeprom signature routine
  165. ;
  166. ; No assumptions
  167. ;
  168. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  169. write_eeprom_signature:
  170. mov DPTR, #Eep_Initialized_L
  171. mov A, #055h
  172. call write_eeprom_byte_from_acc
  173. mov DPTR, #Eep_Initialized_H
  174. mov A, #0AAh
  175. call write_eeprom_byte_from_acc
  176. ret
  177. ;**;**** **** **** **** **** **** **** **** **** **** **** **** ****
  178. ;
  179. ; Success beep inverted routine
  180. ;
  181. ; No assumptions
  182. ;
  183. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  184. /*
  185. success_beep_inverted:
  186. clr EA ; Disable all interrupts
  187. call beep_f4
  188. call beep_f3
  189. call beep_f2
  190. call beep_f1
  191. call wait10ms
  192. call beep_f4
  193. call beep_f3
  194. call beep_f2
  195. call beep_f1
  196. call wait10ms
  197. call beep_f4
  198. call beep_f3
  199. call beep_f2
  200. call beep_f1
  201. setb EA ; Enable all interrupts
  202. ret
  203. */
  204. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  205. CSEG AT 1C00h ; Last code segment. Take care that there is enough space!
  206. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  207. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  208. ;
  209. ; Read eeprom byte routine
  210. ;
  211. ; Gives data in A and in address given by Temp1. Assumes address in DPTR
  212. ; Also assumes address high byte to be zero
  213. ;
  214. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  215. read_eeprom_byte:
  216. clr A
  217. movc A, @A+DPTR ; Read from flash
  218. mov @Temp1, A
  219. ret
  220. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  221. ;
  222. ; Write eeprom byte routine
  223. ;
  224. ; Assumes data in address given by Temp1, or in accumulator. Assumes address in DPTR
  225. ; Also assumes address high byte to be zero
  226. ;
  227. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  228. write_eeprom_byte:
  229. mov A, @Temp1
  230. write_eeprom_byte_from_acc:
  231. orl PSCTL, #01h ; Set the PSWE bit
  232. anl PSCTL, #0FDh ; Clear the PSEE bit
  233. mov RSTSRC, #02h ; Set VDD monitor as a reset source (PORSF)
  234. mov FLKEY, #0A5h ; First key code
  235. mov FLKEY, #0F1h ; Second key code
  236. movx @DPTR, A ; Write to flash
  237. anl PSCTL, #0FEh ; Clear the PSWE bit
  238. ret
  239. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  240. ;
  241. ; Erase flash routine (erases the flash segment used for "eeprom" variables)
  242. ;
  243. ; No assumptions
  244. ;
  245. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  246. erase_flash:
  247. djnz UpDate_Flg,ret_ret
  248. ;mov Temp1,A
  249. ;mov A,RSTSRC
  250. ;jnb ACC.0,ret_ret
  251. ;mov A,Temp1
  252. orl PSCTL, #02h ; Set the PSEE bit
  253. orl PSCTL, #01h ; Set the PSWE bit
  254. mov RSTSRC, #02h ; Set VDD monitor as a reset source (PORSF)
  255. mov FLKEY, #0A5h ; First key code
  256. mov FLKEY, #0F1h ; Second key code
  257. add A,ACC
  258. mov DPL,#0x00
  259. mov DPH,A
  260. clr A
  261. ; mov DPTR, #Eep_Initialized_L
  262. movx @DPTR, A
  263. anl PSCTL, #0FCh ; Clear the PSEE and PSWE bits
  264. ret_ret:
  265. mov UpDate_Flg,#0
  266. ret
  267. SEND_ONEBYTE:
  268. jnb TI0,$
  269. clr TI0
  270. orl P0MDOUT,#10h
  271. mov SBUF0,A
  272. jnb RI0,$
  273. clr RI0
  274. anl P0MDOUT,#0EFh
  275. ret
  276. boot:
  277. clr A
  278. mov Power_On_Wait_Cnt_L,A ;buflen
  279. mov Power_On_Wait_Cnt_H,A
  280. mov Stepper_Step_Beg_L,A ;flashPos
  281. mov Stepper_Step_Beg_H,A
  282. mov Initial_Arm,A ;Had13
  283. mov Stepper_Step_End_L,A
  284. mov Stepper_Step_End_H,A ;Reclen
  285. mov Startup_Rot_Cnt,A ;Page
  286. clr EA
  287. mov SP,#0x40
  288. setb TI0
  289. mov A,#0xE4
  290. call SEND_ONEBYTE
  291. DIE_LOOP:
  292. mov A,Initial_Arm
  293. xrl A,#0x03
  294. jz LOOPREAD
  295. jmp HAD13_EQU2
  296. LOOPREAD:
  297. clr C
  298. mov A,Power_On_Wait_Cnt_L
  299. subb A,Stepper_Step_End_L
  300. mov A,Power_On_Wait_Cnt_H
  301. subb A,Stepper_Step_End_H
  302. jnc SKIP_READ
  303. jnb RI0,$
  304. clr RI0
  305. mov A,#0x00
  306. add A,Power_On_Wait_Cnt_L
  307. mov DPL,A
  308. mov A,#0x00
  309. addc A,Power_On_Wait_Cnt_H
  310. mov DPH,A
  311. mov A,SBUF0
  312. movx @DPTR,A
  313. inc Power_On_Wait_Cnt_L
  314. mov A,Power_On_Wait_Cnt_L
  315. jnz LOOPREAD
  316. inc Power_On_Wait_Cnt_H
  317. jmp LOOPREAD
  318. SKIP_READ:
  319. clr RI0
  320. mov A,Startup_Rot_Cnt
  321. mov UpDate_Flg,#1
  322. call erase_flash
  323. inc Startup_Rot_Cnt
  324. clr A
  325. mov Temp8,A
  326. mov Temp7,A
  327. PRO_FLASH:
  328. clr C
  329. mov A,Temp8
  330. subb A,Power_On_Wait_Cnt_L
  331. mov A,Temp7
  332. subb A,Power_On_Wait_Cnt_H
  333. jnc SEND_OK
  334. clr C
  335. mov A,#0x00
  336. add A,Temp8
  337. mov DPL,A
  338. mov A,#0x00
  339. addc A,Temp7
  340. mov DPH,A
  341. movx A,@DPTR
  342. mov Temp1,A
  343. mov A,Stepper_Step_Beg_L
  344. mov DPL,A
  345. mov A,Stepper_Step_Beg_H
  346. mov DPH,A
  347. mov A,Temp1
  348. call write_eeprom_byte_from_acc
  349. inc Stepper_Step_Beg_L
  350. mov A,Stepper_Step_Beg_L
  351. /* cjne A,0xFF,Zero_D
  352. inc Stepper_Step_Beg_L
  353. mov A,Stepper_Step_Beg_L
  354. Zero_D: */
  355. cjne A,#0x00,$+5
  356. inc Stepper_Step_Beg_H
  357. inc Temp8
  358. cjne Temp8,#0x00,$+4
  359. inc Temp7
  360. jmp PRO_FLASH
  361. SEND_OK:
  362. mov A,#0x6F
  363. call SEND_ONEBYTE
  364. mov A,#0x6B
  365. call SEND_ONEBYTE
  366. clr C
  367. mov A,Stepper_Step_Beg_L
  368. subb A,Prev_Comm_L
  369. mov A,Stepper_Step_Beg_H
  370. subb A,Prev_Comm_H
  371. jnc $+5
  372. ljmp SIGNED_2
  373. mov Initial_Arm,#0x00
  374. ljmp DIE_LOOP
  375. HAD13_EQU2:
  376. mov A,Initial_Arm
  377. xrl A,#0x02
  378. jnz HAD13_EQU1
  379. clr A
  380. mov Power_On_Wait_Cnt_L,A ;buflen
  381. mov Power_On_Wait_Cnt_H,A
  382. jnb RI0,$
  383. clr RI0
  384. mov A,SBUF0
  385. mov Stepper_Step_End_H,A
  386. jnb RI0,$
  387. clr RI0
  388. mov A,SBUF0
  389. mov Stepper_Step_End_L,A
  390. mov Initial_Arm,#0x03
  391. ljmp DIE_LOOP
  392. HAD13_EQU1:
  393. mov A,Initial_Arm
  394. xrl A,#0x01
  395. jnz HAD13_DEFAULT
  396. jnb RI0,$
  397. clr RI0
  398. mov A,SBUF0
  399. add A,#0x7F
  400. jz H81_DET
  401. add A,#0xB2
  402. jz CF_DET
  403. add A,#0x51
  404. jnz DEFA_DET
  405. mov A,#0x6F
  406. call SEND_ONEBYTE
  407. mov A,#0x6B
  408. call SEND_ONEBYTE
  409. mov Initial_Arm,#0x01
  410. ljmp DIE_LOOP
  411. H81_DET:
  412. mov Initial_Arm,#0x00
  413. setb TI0
  414. mov A,#0x6F
  415. call SEND_ONEBYTE
  416. mov A,#0x6B
  417. call SEND_ONEBYTE
  418. ljmp DIE_LOOP
  419. CF_DET:
  420. mov Temp2, #200
  421. waitxms_o1:
  422. mov Temp1, #23
  423. waitxms_m1:
  424. clr A
  425. djnz ACC, $ ; Inner loop (42.7us - 1024 cycles)
  426. djnz Temp1, waitxms_m1
  427. djnz Temp2, waitxms_o1
  428. orl RSTSRC,#0x10
  429. ljmp DIE_LOOP
  430. DEFA_DET:
  431. mov A,SBUF0
  432. mov Prev_Comm_H,A
  433. jnb RI0,$
  434. clr RI0
  435. mov A,SBUF0
  436. mov Prev_Comm_L,A
  437. SIGNED_2:
  438. mov Initial_Arm,#0x02
  439. ljmp DIE_LOOP
  440. HAD13_DEFAULT:
  441. jnb RI0,$
  442. clr RI0
  443. mov A,SBUF0
  444. cjne A,#0xE4,H13_DET
  445. mov Initial_Arm,#0x00
  446. mov A,#0xE4
  447. call SEND_ONEBYTE
  448. ljmp DIE_LOOP
  449. H13_DET:
  450. xrl A,#0x13
  451. jz $+5
  452. ljmp DIE_LOOP
  453. mov Initial_Arm,#0x01
  454. ljmp DIE_LOOP
  455. /*
  456. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  457. ;
  458. ; Read all tags from flash and store in temporary storage
  459. ;
  460. ; No assumptions
  461. ;
  462. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  463. read_tags:
  464. mov Temp3, #48 ; Number of tags
  465. mov Temp2, #Temparry ; Set RAM address
  466. mov Temp1, #Bit_Access
  467. mov DPTR, #Eep_ESC_Layout ; Set flash address
  468. read_tag:
  469. call read_eeprom_byte
  470. mov A, Bit_Access
  471. mov @Temp2, A ; Write to RAM
  472. inc Temp2
  473. inc DPTR
  474. djnz Temp3, read_tag
  475. ret
  476. write_tags:
  477. mov Temp3, #48 ; Number of tags
  478. mov Temp2, #Temparry ; Set RAM address
  479. mov DPTR, #Eep_ESC_Layout ; Set flash address
  480. write_tag:
  481. mov A, @Temp2 ; Read from RAM
  482. call write_eeprom_byte_from_acc
  483. inc Temp2
  484. inc DPTR
  485. djnz Temp3, write_tag
  486. ret
  487. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  488. ;
  489. ; Store new parameter value in ram routine
  490. ;
  491. ; No assumptions
  492. ;
  493. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  494. store_new_value_in_ram:
  495. mov Temp4, Tx_Pgm_Func_No ; Function no
  496. mov Temp1, Tx_Pgm_Paraval_No ; Parameter value no
  497. IF MODE == 0
  498. store_main_func_1:
  499. cjne Temp4, #1, store_main_func_2
  500. mov Temp2, #Pgm_Gov_P_Gain
  501. store_main_func_2:
  502. cjne Temp4, #2, store_main_func_3
  503. mov Temp2, #Pgm_Gov_I_Gain
  504. store_main_func_3:
  505. cjne Temp4, #3, store_main_func_4
  506. mov Temp2, #Pgm_Gov_Mode
  507. store_main_func_4:
  508. cjne Temp4, #4, store_main_func_5
  509. mov Temp2, #Pgm_Gov_Range
  510. store_main_func_5:
  511. cjne Temp4, #5, store_main_func_6
  512. mov Temp2, #Pgm_Low_Voltage_Lim
  513. store_main_func_6:
  514. cjne Temp4, #6, store_main_func_7
  515. mov Temp2, #Pgm_Startup_Pwr
  516. store_main_func_7:
  517. cjne Temp4, #7, store_main_func_8
  518. mov Temp2, #Pgm_Comm_Timing
  519. store_main_func_8:
  520. cjne Temp4, #8, store_main_func_9
  521. mov Temp2, #Pgm_Pwm_Freq
  522. store_main_func_9:
  523. cjne Temp4, #9, store_main_func_10
  524. mov Temp2, #Pgm_Demag_Comp
  525. store_main_func_10:
  526. cjne Temp4, #10, store_main_func_11
  527. mov Temp2, #Pgm_Direction
  528. store_main_func_11:
  529. cjne Temp4, #11, store_in_ram_exit
  530. mov Temp2, #Pgm_Input_Pol
  531. ENDIF
  532. IF MODE == 1
  533. store_tail_func_1:
  534. cjne Temp4, #1, store_tail_func_2
  535. mov Temp2, #Pgm_Motor_Gain
  536. store_tail_func_2:
  537. cjne Temp4, #2, store_tail_func_3
  538. mov Temp2, #Pgm_Motor_Idle
  539. store_tail_func_3:
  540. cjne Temp4, #3, store_tail_func_4
  541. mov Temp2, #Pgm_Startup_Pwr
  542. store_tail_func_4:
  543. cjne Temp4, #4, store_tail_func_5
  544. mov Temp2, #Pgm_Comm_Timing
  545. store_tail_func_5:
  546. cjne Temp4, #5, store_tail_func_6
  547. mov Temp2, #Pgm_Pwm_Freq
  548. store_tail_func_6:
  549. cjne Temp4, #6, store_tail_func_7
  550. mov Temp2, #Pgm_Demag_Comp
  551. store_tail_func_7:
  552. cjne Temp4, #7, store_tail_func_8
  553. mov Temp2, #Pgm_Direction
  554. store_tail_func_8:
  555. cjne Temp4, #8, store_in_ram_exit
  556. mov Temp2, #Pgm_Input_Pol
  557. ENDIF
  558. IF MODE == 2
  559. store_multi_func_1:
  560. cjne Temp4, #1, store_multi_func_2
  561. mov Temp2, #Pgm_Gov_P_Gain
  562. store_multi_func_2:
  563. cjne Temp4, #2, store_multi_func_3
  564. mov Temp2, #Pgm_Gov_I_Gain
  565. store_multi_func_3:
  566. cjne Temp4, #3, store_multi_func_4
  567. mov Temp2, #Pgm_Gov_Mode
  568. store_multi_func_4:
  569. cjne Temp4, #4, store_multi_func_5
  570. mov Temp2, #Pgm_Motor_Gain
  571. store_multi_func_5:
  572. cjne Temp4, #5, store_multi_func_6
  573. mov Temp2, #Pgm_Low_Voltage_Lim
  574. store_multi_func_6:
  575. cjne Temp4, #6, store_multi_func_7
  576. mov Temp2, #Pgm_Startup_Pwr
  577. store_multi_func_7:
  578. cjne Temp4, #7, store_multi_func_8
  579. mov Temp2, #Pgm_Comm_Timing
  580. store_multi_func_8:
  581. cjne Temp4, #8, store_multi_func_9
  582. mov Temp2, #Pgm_Pwm_Freq
  583. store_multi_func_9:
  584. cjne Temp4, #9, store_multi_func_10
  585. mov Temp2, #Pgm_Demag_Comp
  586. store_multi_func_10:
  587. cjne Temp4, #10, store_multi_func_11
  588. mov Temp2, #Pgm_Direction
  589. store_multi_func_11:
  590. cjne Temp4, #11, store_in_ram_exit
  591. mov Temp2, #Pgm_Input_Pol
  592. ENDIF
  593. store_in_ram_exit:
  594. mov A, Temp1
  595. mov @Temp2, A
  596. ret
  597. function_paraval_beep:
  598. mov Temp7, Tx_Pgm_Func_No ; Function no
  599. mov Temp8, Tx_Pgm_Paraval_No ; Parameter value no
  600. clr EA ; Disable all interrupts
  601. function_beep:
  602. call beep_f1
  603. call beep_f1
  604. call beep_f1
  605. call wait10ms
  606. djnz Temp7, function_beep
  607. paraval_beep:
  608. call beep_f4
  609. call wait10ms
  610. djnz Temp8, paraval_beep
  611. setb EA ; Enable all interrupts
  612. ret
  613. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  614. ;
  615. ; Program by TX routine
  616. ;
  617. ; No assumptions
  618. ;
  619. ;**** **** **** **** **** **** **** **** **** **** **** **** ****
  620. program_by_tx:
  621. ; Programming mode entry beeps
  622. call success_beep
  623. call wait1s
  624. call wait1s
  625. ; Start at function 1, parameter value 1
  626. mov Tx_Pgm_Func_No, #1
  627. paraval_no_entry:
  628. mov Tx_Pgm_Paraval_No, #1
  629. beep_no_entry:
  630. mov Tx_Pgm_Beep_No, #0
  631. func_paraval:
  632. call function_paraval_beep
  633. mov Temp5, #5 ; Wait is 5x 200ms
  634. func_paraval_wait:
  635. mov Temp6, New_Rcp ; Load RC pulse
  636. call wait200ms
  637. clr C
  638. mov A, Temp6
  639. subb A, New_Rcp ; Is RC pulse stable? (Avoid issues from 3in1 interference)
  640. jnz func_paraval_wait ; No - branch
  641. clr C
  642. mov A, New_Rcp ; Load new RC pulse value
  643. subb A, #RCP_STOP ; Below stop?
  644. jc func_paraval_store ; Yes - branch
  645. clr C
  646. mov A, New_Rcp ; Load new RC pulse value
  647. subb A, #RCP_MAX ; Below max?
  648. jc function_next ; Yes - branch
  649. ljmp func_paraval_cont_wait ; No - branch
  650. func_paraval_store:
  651. call store_new_value_in_ram ; Yes - store new value in RAM
  652. call erase_and_store_all_in_eeprom ; Store all values in EEPROM
  653. call success_beep ; Beep success
  654. clr EA ; Disable all interrupts
  655. IF ONE_S_CAPABLE == 0
  656. mov RSTSRC, #12h ; Generate hardware reset and set VDD monitor
  657. ELSE
  658. mov RSTSRC, #10h ; Generate hardware reset and disable VDD monitor
  659. ENDIF
  660. call wait1s
  661. func_paraval_cont_wait:
  662. djnz Temp5, func_paraval_wait
  663. inc Tx_Pgm_Beep_No ; Check number of beeps
  664. clr C
  665. mov A, Tx_Pgm_Beep_No
  666. subb A, #3 ; Three beeps done?
  667. jnc paraval_next ; Yes - Next parameter value
  668. jmp func_paraval ; No - go back
  669. paraval_next:
  670. call wait1s
  671. inc Tx_Pgm_Paraval_No ; Parameter value no
  672. IF MODE == 0
  673. mov A, Tx_Pgm_Func_No ; Decode number of parameters
  674. dec A
  675. mov DPTR, #TX_PGM_PARAMS_MAIN
  676. movc A, @A+DPTR
  677. mov Temp1, A
  678. ENDIF
  679. IF MODE == 1
  680. mov A, Tx_Pgm_Func_No ; Decode number of parameters
  681. dec A
  682. mov DPTR, #TX_PGM_PARAMS_TAIL
  683. movc A, @A+DPTR
  684. mov Temp1, A
  685. ENDIF
  686. IF MODE == 2
  687. mov A, Tx_Pgm_Func_No ; Decode number of parameters
  688. dec A
  689. mov DPTR, #TX_PGM_PARAMS_MULTI
  690. movc A, @A+DPTR
  691. mov Temp1, A
  692. ENDIF
  693. inc Temp1
  694. clr C
  695. mov A, Tx_Pgm_Paraval_No
  696. subb A, Temp1
  697. jnc function_next ; Last parameter value?
  698. jmp beep_no_entry ; No - go back
  699. function_next: ; Yes - Next function value
  700. call wait1s
  701. call wait1s
  702. inc Tx_Pgm_Func_No ; Function value no
  703. IF MODE == 0
  704. clr C
  705. mov A, Tx_Pgm_Func_No
  706. subb A, #12 ; Main has 11 functions
  707. ENDIF
  708. IF MODE == 1
  709. clr C
  710. mov A, Tx_Pgm_Func_No
  711. subb A, #9 ; Tail has 8 functions
  712. ENDIF
  713. IF MODE == 2
  714. clr C
  715. mov A, Tx_Pgm_Func_No
  716. subb A, #12 ; Multi has 11 functions
  717. ENDIF
  718. jnc program_by_tx_exit ; Last function value?
  719. jmp paraval_no_entry ; No - go back
  720. program_by_tx_exit:
  721. call set_default_parameters ; Load all defaults
  722. call erase_and_store_all_in_eeprom ; Erase flash and program
  723. clr EA ; Disable all interrupts
  724. IF ONE_S_CAPABLE == 0
  725. mov RSTSRC, #12h ; Generate hardware reset and set VDD monitor
  726. ELSE
  727. mov RSTSRC, #10h ; Generate hardware reset and disable VDD monitor
  728. ENDIF
  729. call wait1s
  730. */