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.

472 lines
16 KiB

  1. ;---------------------------------------------------------------------------
  2. ;
  3. ;
  4. ;
  5. ;
  6. ; FILE NAME: C8051F330.INC
  7. ; TARGET MCUs: C8051F330, F331
  8. ; DESCRIPTION: Register/bit definitions for the C8051F330 product family.
  9. ;
  10. ; REVISION 1.0
  11. ;
  12. ;---------------------------------------------------------------------------
  13. ;REGISTER DEFINITIONS
  14. ;
  15. P0 DATA 080H ; PORT 0 LATCH
  16. SP DATA 081H ; STACK POINTER
  17. DPL DATA 082H ; DATA POINTER LOW
  18. DPH DATA 083H ; DATA POINTER HIGH
  19. PCON DATA 087H ; POWER CONTROL
  20. TCON DATA 088H ; TIMER/COUNTER CONTROL
  21. TMOD DATA 089H ; TIMER/COUNTER MODE
  22. TL0 DATA 08AH ; TIMER/COUNTER 0 LOW
  23. TL1 DATA 08BH ; TIMER/COUNTER 1 LOW
  24. TH0 DATA 08CH ; TIMER/COUNTER 0 HIGH
  25. TH1 DATA 08DH ; TIMER/COUNTER 1 HIGH
  26. CKCON DATA 08EH ; CLOCK CONTROL
  27. PSCTL DATA 08FH ; PROGRAM STORE R/W CONTROL
  28. P1 DATA 090H ; PORT 1 LATCH
  29. TMR3CN DATA 091H ; TIMER/COUNTER 3 CONTROL
  30. TMR3RLL DATA 092H ; TIMER/COUNTER 3 RELOAD LOW
  31. TMR3RLH DATA 093H ; TIMER/COUNTER 3 RELOAD HIGH
  32. TMR3L DATA 094H ; TIMER/COUNTER 3 LOW
  33. TMR3H DATA 095H ; TIMER/COUNTER 3 HIGH
  34. IDA0L DATA 096H ; CURRENT MODE DAC0 LOW
  35. IDA0H DATA 097H ; CURRENT MODE DAC0 HIGH
  36. SCON0 DATA 098H ; UART0 CONTROL
  37. SBUF0 DATA 099H ; UART0 DATA BUFFER
  38. CPT0CN DATA 09BH ; COMPARATOR0 CONTROL
  39. CPT0MD DATA 09DH ; COMPARATOR0 MODE SELECTION
  40. CPT0MX DATA 09FH ; COMPARATOR0 MUX SELECTION
  41. P2 DATA 0A0H ; PORT 2 LATCH
  42. SPI0CFG DATA 0A1H ; SPI CONFIGURATION
  43. SPI0CKR DATA 0A2H ; SPI CLOCK RATE CONTROL
  44. SPI0DAT DATA 0A3H ; SPI DATA
  45. P0MDOUT DATA 0A4H ; PORT 0 OUTPUT MODE CONFIGURATION
  46. P1MDOUT DATA 0A5H ; PORT 1 OUTPUT MODE CONFIGURATION
  47. P2MDOUT DATA 0A6H ; PORT 2 OUTPUT MODE CONFIGURATION
  48. IE DATA 0A8H ; INTERRUPT ENABLE
  49. CLKSEL DATA 0A9H ; CLOCK SELECT
  50. EMI0CN DATA 0AAH ; EXTERNAL MEMORY INTERFACE CONTROL
  51. OSCXCN DATA 0B1H ; EXTERNAL OSCILLATOR CONTROL
  52. OSCICN DATA 0B2H ; INTERNAL OSCILLATOR CONTROL
  53. OSCICL DATA 0B3H ; INTERNAL OSCILLATOR CALIBRATION
  54. FLSCL DATA 0B6H ; FLASH SCALE
  55. FLKEY DATA 0B7H ; FLASH LOCK AND KEY
  56. IP DATA 0B8H ; INTERRUPT PRIORITY
  57. IDA0CN DATA 0B9H ; CURRENT MODE DAC0 CONTROL
  58. AMX0N DATA 0BAH ; AMUX0 NEGATIVE CHANNEL SELECT
  59. AMX0P DATA 0BBH ; AMUX0 POSITIVE CHANNEL SELECT
  60. ADC0CF DATA 0BCH ; ADC0 CONFIGURATION
  61. ADC0L DATA 0BDH ; ADC0 LOW
  62. ADC0H DATA 0BEH ; ADC0 HIGH
  63. SMB0CN DATA 0C0H ; SMBUS CONTROL
  64. SMB0CF DATA 0C1H ; SMBUS CONFIGURATION
  65. SMB0DAT DATA 0C2H ; SMBUS DATA
  66. ADC0GTL DATA 0C3H ; ADC0 GREATER-THAN COMPARE LOW
  67. ADC0GTH DATA 0C4H ; ADC0 GREATER-THAN COMPARE HIGH
  68. ADC0LTL DATA 0C5H ; ADC0 LESS-THAN COMPARE WORD LOW
  69. ADC0LTH DATA 0C6H ; ADC0 LESS-THAN COMPARE WORD HIGH
  70. TMR2CN DATA 0C8H ; TIMER/COUNTER 2 CONTROL
  71. TMR2RLL DATA 0CAH ; TIMER/COUNTER 2 RELOAD LOW
  72. TMR2RLH DATA 0CBH ; TIMER/COUNTER 2 RELOAD HIGH
  73. TMR2L DATA 0CCH ; TIMER/COUNTER 2 LOW
  74. TMR2H DATA 0CDH ; TIMER/COUNTER 2 HIGH
  75. PSW DATA 0D0H ; PROGRAM STATUS WORD
  76. REF0CN DATA 0D1H ; VOLTAGE REFERENCE CONTROL
  77. P0SKIP DATA 0D4H ; PORT 0 SKIP
  78. P1SKIP DATA 0D5H ; PORT 1 SKIP
  79. PCA0CN DATA 0D8H ; PCA CONTROL
  80. PCA0MD DATA 0D9H ; PCA MODE
  81. PCA0CPM0 DATA 0DAH ; PCA MODULE 0 MODE REGISTER
  82. PCA0CPM1 DATA 0DBH ; PCA MODULE 1 MODE REGISTER
  83. PCA0CPM2 DATA 0DCH ; PCA MODULE 2 MODE REGISTER
  84. ACC DATA 0E0H ; ACCUMULATOR
  85. XBR0 DATA 0E1H ; PORT I/O CROSSBAR CONTROL 0
  86. XBR1 DATA 0E2H ; PORT I/O CROSSBAR CONTROL 1
  87. OSCLCN DATA 0E3H ; LOW-FREQUENCY OSCILLATOR CONTROL
  88. IT01CF DATA 0E4H ; INT0/INT1 CONFIGURATION
  89. EIE1 DATA 0E6H ; EXTENDED INTERRUPT ENABLE 1
  90. ADC0CN DATA 0E8H ; ADC0 CONTROL
  91. PCA0CPL1 DATA 0E9H ; PCA CAPTURE 1 LOW
  92. PCA0CPH1 DATA 0EAH ; PCA CAPTURE 1 HIGH
  93. PCA0CPL2 DATA 0EBH ; PCA CAPTURE 2 LOW
  94. PCA0CPH2 DATA 0ECH ; PCA CAPTURE 2 HIGH
  95. RSTSRC DATA 0EFH ; RESET SOURCE CONFIGURATION/STATUS
  96. B DATA 0F0H ; B REGISTER
  97. P0MDIN DATA 0F1H ; PORT 0 INPUT MODE CONFIGURATION
  98. P1MDIN DATA 0F2H ; PORT 1 INPUT MODE CONFIGURATION
  99. EIP1 DATA 0F6H ; EXTENDED INTERRUPT PRIORITY 1
  100. SPI0CN DATA 0F8H ; SPI CONTROL
  101. PCA0L DATA 0F9H ; PCA COUNTER LOW
  102. PCA0H DATA 0FAH ; PCA COUNTER HIGH
  103. PCA0CPL0 DATA 0FBH ; PCA CAPTURE 0 LOW
  104. PCA0CPH0 DATA 0FCH ; PCA CAPTURE 0 HIGH
  105. VDM0CN DATA 0FFH ; VDD MONITOR CONTROL
  106. ;
  107. ;------------------------------------------------------------------------------
  108. ;BIT DEFINITIONS
  109. ;
  110. ; TCON 088H
  111. TF1 BIT 08FH ; TIMER 1 OVERFLOW FLAG
  112. TR1 BIT 08EH ; TIMER 1 ON/OFF CONTROL
  113. TF0 BIT 08DH ; TIMER 0 OVERFLOW FLAG
  114. TR0 BIT 08CH ; TIMER 0 ON/OFF CONTROL
  115. IE1 BIT 08BH ; EXT. INTERRUPT 1 EDGE FLAG
  116. IT1 BIT 08AH ; EXT. INTERRUPT 1 TYPE
  117. IE0 BIT 089H ; EXT. INTERRUPT 0 EDGE FLAG
  118. IT0 BIT 088H ; EXT. INTERRUPT 0 TYPE
  119. ; SCON0 098H
  120. S0MODE BIT 09FH ; UART 0 MODE
  121. MCE0 BIT 09DH ; UART 0 MCE
  122. REN0 BIT 09CH ; UART 0 RX ENABLE
  123. TB80 BIT 09BH ; UART 0 TX BIT 8
  124. RB80 BIT 09AH ; UART 0 RX BIT 8
  125. TI0 BIT 099H ; UART 0 TX INTERRUPT FLAG
  126. RI0 BIT 098H ; UART 0 RX INTERRUPT FLAG
  127. ; IE 0A8H
  128. EA BIT 0AFH ; GLOBAL INTERRUPT ENABLE
  129. ESPI0 BIT 0AEH ; SPI0 INTERRUPT ENABLE
  130. ET2 BIT 0ADH ; TIMER 2 INTERRUPT ENABLE
  131. ES0 BIT 0ACH ; UART0 INTERRUPT ENABLE
  132. ET1 BIT 0ABH ; TIMER 1 INTERRUPT ENABLE
  133. EX1 BIT 0AAH ; EXTERNAL INTERRUPT 1 ENABLE
  134. ET0 BIT 0A9H ; TIMER 0 INTERRUPT ENABLE
  135. EX0 BIT 0A8H ; EXTERNAL INTERRUPT 0 ENABLE
  136. ; IP 0B8H
  137. PSPI0 BIT 0BEH ; SPI0 PRIORITY
  138. PT2 BIT 0BDH ; TIMER 2 PRIORITY
  139. PS0 BIT 0BCH ; UART0 PRIORITY
  140. PT1 BIT 0BBH ; TIMER 1 PRIORITY
  141. PX1 BIT 0BAH ; EXTERNAL INTERRUPT 1 PRIORITY
  142. PT0 BIT 0B9H ; TIMER 0 PRIORITY
  143. PX0 BIT 0B8H ; EXTERNAL INTERRUPT 0 PRIORITY
  144. ; SMB0CN 0C0H
  145. MASTER BIT 0C7H ; SMBUS 0 MASTER/SLAVE
  146. TXMODE BIT 0C6H ; SMBUS 0 TRANSMIT MODE
  147. STA BIT 0C5H ; SMBUS 0 START FLAG
  148. STO BIT 0C4H ; SMBUS 0 STOP FLAG
  149. ACKRQ BIT 0C3H ; SMBUS 0 ACKNOWLEDGE REQUEST
  150. ARBLOST BIT 0C2H ; SMBUS 0 ARBITRATION LOST
  151. ACK BIT 0C1H ; SMBUS 0 ACKNOWLEDGE FLAG
  152. SI BIT 0C0H ; SMBUS 0 INTERRUPT PENDING FLAG
  153. ; TMR2CN 0C8H
  154. TF2H BIT 0CFH ; TIMER 2 HIGH BYTE OVERFLOW FLAG
  155. TF2L BIT 0CEH ; TIMER 2 LOW BYTE OVERFLOW FLAG
  156. TF2LEN BIT 0CDH ; TIMER 2 LOW BYTE INTERRUPT ENABLE
  157. TF2CEN BIT 0CCH ; TIMER 2 LFO CAPTURE ENABLE
  158. T2SPLIT BIT 0CBH ; TIMER 2 SPLIT MODE ENABLE
  159. TR2 BIT 0CAH ; TIMER 2 ON/OFF CONTROL
  160. T2XCLK BIT 0C8H ; TIMER 2 EXTERNAL CLOCK SELECT
  161. ; PSW 0D0H
  162. CY BIT 0D7H ; CARRY FLAG
  163. AC BIT 0D6H ; AUXILIARY CARRY FLAG
  164. F0 BIT 0D5H ; USER FLAG 0
  165. RS1 BIT 0D4H ; REGISTER BANK SELECT 1
  166. RS0 BIT 0D3H ; REGISTER BANK SELECT 0
  167. OV BIT 0D2H ; OVERFLOW FLAG
  168. F1 BIT 0D1H ; USER FLAG 1
  169. P BIT 0D0H ; ACCUMULATOR PARITY FLAG
  170. ; PCA0CN 0D8H
  171. CF BIT 0DFH ; PCA 0 COUNTER OVERFLOW FLAG
  172. CR BIT 0DEH ; PCA 0 COUNTER RUN CONTROL BIT
  173. CCF2 BIT 0DAH ; PCA 0 MODULE 2 INTERRUPT FLAG
  174. CCF1 BIT 0D9H ; PCA 0 MODULE 1 INTERRUPT FLAG
  175. CCF0 BIT 0D8H ; PCA 0 MODULE 0 INTERRUPT FLAG
  176. ; ADC 0 WINDOW INTERRUPT FLAG
  177. ; ADC0CN 0E8H
  178. AD0EN BIT 0EFH ; ADC 0 ENABLE
  179. AD0TM BIT 0EEH ; ADC 0 TRACK MODE
  180. AD0INT BIT 0EDH ; ADC 0 EOC INTERRUPT FLAG
  181. AD0BUSY BIT 0ECH ; ADC 0 BUSY FLAG
  182. AD0WINT BIT 0EBH ; ADC 0 WINDOW INTERRUPT FLAG
  183. AD0CM2 BIT 0EAH ; ADC 0 CONVERT START MODE BIT 2
  184. AD0CM1 BIT 0E9H ; ADC 0 CONVERT START MODE BIT 1
  185. AD0CM0 BIT 0E8H ; ADC 0 CONVERT START MODE BIT 0
  186. ; SPI0CN 0F8H
  187. SPIF BIT 0FFH ; SPI 0 INTERRUPT FLAG
  188. WCOL BIT 0FEH ; SPI 0 WRITE COLLISION FLAG
  189. MODF BIT 0FDH ; SPI 0 MODE FAULT FLAG
  190. RXOVRN BIT 0FCH ; SPI 0 RX OVERRUN FLAG
  191. NSSMD1 BIT 0FBH ; SPI 0 SLAVE SELECT MODE 1
  192. NSSMD0 BIT 0FAH ; SPI 0 SLAVE SELECT MODE 0
  193. TXBMT BIT 0F9H ; SPI 0 TX BUFFER EMPTY FLAG
  194. SPIEN BIT 0F8H ; SPI 0 SPI ENABLE
  195. ;**** **** **** **** ****
  196. ; Uses internal calibrated oscillator set to 24Mhz
  197. ;**** **** **** **** ****
  198. ;**** **** **** **** ****
  199. ; Constant definitions
  200. ;**** **** **** **** ****
  201. CSEG AT 1A40h
  202. Eep_ESC_Layout: DB "#XP18A# " ; ESC layout tag
  203. CSEG AT 1A50h
  204. Eep_ESC_MCU: DB "#BLHELI#F330# " ; Project and MCU tag (16 Bytes)
  205. PORT3_EXIST EQU 0 ; Set to 1 if MCU has port3
  206. COMP1_USED EQU 0 ; Set to 1 if MCU has comparator 1 and it is being used
  207. DUAL_BEC_VOLTAGE EQU 0 ; Set to 1 if dual BEC voltage is supported
  208. DAMPED_MODE_ENABLE EQU 1 ; Damped mode disabled
  209. NFETON_DELAY EQU 1 ; Wait delay from pfets off to nfets on
  210. PFETON_DELAY EQU 1 ; Wait delay from nfets off to pfets on
  211. COMP_PWM_HIGH_ON_DELAY EQU 15 ; Wait delay from pwm on until comparator can be read (for high pwm frequency)
  212. COMP_PWM_HIGH_OFF_DELAY EQU 20 ; Wait delay from pwm off until comparator can be read (for high pwm frequency)
  213. COMP_PWM_LOW_ON_DELAY EQU 5 ; Wait delay from pwm on until comparator can be read (for low pwm frequency)
  214. COMP_PWM_LOW_OFF_DELAY EQU 7 ; Wait delay from pwm off until comparator can be read (for low pwm frequency)
  215. ADC_LIMIT_L EQU 80 ; 2.8V 2013.05.31
  216. ;ADC_LIMIT_L EQU 85 ; Power supply measurement ADC value for which main motor power is limited (low byte)
  217. ADC_LIMIT_H EQU 0 ; Power supply measurement ADC value for which main motor power is limited (2 MSBs)
  218. TEMP_LIMIT EQU 92 ; 2013.8.20 140120 Temperature measurement ADC value for which main motor power is limited (low byte, assuming high byte is 1)
  219. TEMP_LIMIT_STEP EQU 5 ; Temperature measurement ADC value increment for which main motor power is further limited
  220. MAIN_SPOOLUP_TIME EQU 10 ; Main motor spoolup time
  221. ;**** **** **** **** ****
  222. ; ESC specific defaults
  223. ;**** **** **** **** ****
  224. DEFAULT_PGM_MAIN_STARTUP_PWR EQU 10 ; 1=0.031 2=0.047 3=0.063 4=0.094 5=0.125 6=0.188 7=0.25 8=0.38 9=0.50 10=0.75 11=1.00 12=1.25 13=1.50
  225. DEFAULT_PGM_TAIL_STARTUP_PWR EQU 10 ; 1=0.031 2=0.047 3=0.063 4=0.094 5=0.125 6=0.188 7=0.25 8=0.38 9=0.50 10=0.75 11=1.00 12=1.25 13=1.50
  226. DEFAULT_PGM_MULTI_STARTUP_PWR EQU 10 ; 1=0.031 2=0.047 3=0.063 4=0.094 5=0.125 6=0.188 7=0.25 8=0.38 9=0.50 10=0.75 11=1.00 12=1.25 13=1.50
  227. DEFAULT_PGM_MAIN_STARTUP_METHOD EQU 2 ; 1=Stepped 2=Direct
  228. DEFAULT_PGM_TAIL_STARTUP_METHOD EQU 2 ; 1=Stepped 2=Direct
  229. DEFAULT_PGM_MULTI_STARTUP_METHOD EQU 2 ; 1=Stepped 2=Direct
  230. ;*********************
  231. ; PORT 0 definitions *
  232. ;*********************
  233. Rcp_In EQU 7 ;i
  234. Adc_Ip EQU 6 ;i
  235. Mux_A EQU 5 ;i
  236. ; EQU 4 ;i
  237. Mux_B EQU 3 ;i
  238. Comp_Com EQU 2 ;i
  239. Mux_C EQU 1 ;i
  240. Vref EQU 0 ;i
  241. P0_DIGITAL EQU NOT((1 SHL Mux_A)+(1 SHL Mux_B)+(1 SHL Mux_C)+(1 SHL Comp_Com)+(1 SHL Adc_Ip)+(1 SHL Vref))
  242. P0_INIT EQU 0FFh
  243. P0_PUSHPULL EQU 0
  244. P0_SKIP EQU NOT(1 SHL Rcp_In) AND 0FFh
  245. MACRO Read_Rcp_Int
  246. mov A, P0
  247. jnb Flags3.PGM_RCP_PWM_POL, ($+4) ; Is pwm polarity negative?
  248. cpl A ; Yes - invert
  249. ENDM
  250. MACRO Rcp_Int_Enable
  251. orl PCA0CPM0, #01h ; Interrupt enabled
  252. ENDM
  253. MACRO Rcp_Int_Disable
  254. anl PCA0CPM0, #0FEh ; Interrupt disabled
  255. ENDM
  256. MACRO Rcp_Int_First
  257. anl PCA0CPM0, #0CFh
  258. jb Flags3.PGM_RCP_PWM_POL, ($+6) ; Is pwm polarity positive?
  259. orl PCA0CPM0, #20h ; Capture rising edge
  260. jnb Flags3.PGM_RCP_PWM_POL, ($+6) ; Is pwm polarity negative?
  261. orl PCA0CPM0, #10h ; Capture falling edge
  262. ENDM
  263. MACRO Rcp_Int_Second
  264. anl PCA0CPM0, #0CFh
  265. jb Flags3.PGM_RCP_PWM_POL, ($+6) ; Is pwm polarity positive?
  266. orl PCA0CPM0, #10h ; Capture falling edge
  267. jnb Flags3.PGM_RCP_PWM_POL, ($+6) ; Is pwm polarity negative?
  268. orl PCA0CPM0, #20h ; Capture rising edge
  269. ENDM
  270. MACRO Rcp_Clear_Int_Flag
  271. clr CCF0 ; Clear interrupt flag
  272. ENDM
  273. ;*********************
  274. ; PORT 1 definitions *
  275. ;*********************
  276. DriverEn EQU 7 ;o At least on some escs. Others are hardwired
  277. ; EQU 6 ;i
  278. AnFET EQU 2 ;o "nFETs" are really the high side drivers
  279. BnFET EQU 1 ;o
  280. CnFET EQU 0 ;o
  281. ApFET EQU 5 ;o "pFETs" are really the low side drivers
  282. BpFET EQU 4 ;o
  283. CpFET EQU 3 ;o
  284. P1_DIGITAL EQU (1 SHL AnFET)+(1 SHL BnFET)+(1 SHL CnFET)+(1 SHL ApFET)+(1 SHL BpFET)+(1 SHL CpFET)+(1 SHL DriverEn)
  285. P1_INIT EQU 080h
  286. P1_PUSHPULL EQU (1 SHL AnFET)+(1 SHL BnFET)+(1 SHL CnFET)+(1 SHL ApFET)+(1 SHL BpFET)+(1 SHL CpFET)+(1 SHL DriverEn)
  287. P1_SKIP EQU 0
  288. MACRO AnFET_on
  289. mov A, Current_Pwm_Limited
  290. jz ($+12)
  291. jb Flags3.PGM_DIR_REV, ($+5)
  292. setb P1.AnFET
  293. jnb Flags3.PGM_DIR_REV, ($+5)
  294. setb P1.CnFET
  295. ENDM
  296. MACRO AnFET_off
  297. jb Flags3.PGM_DIR_REV, ($+5)
  298. clr P1.AnFET
  299. jnb Flags3.PGM_DIR_REV, ($+5)
  300. clr P1.CnFET
  301. ENDM
  302. MACRO BnFET_on
  303. mov A, Current_Pwm_Limited
  304. jz ($+4)
  305. setb P1.BnFET
  306. ENDM
  307. MACRO BnFET_off
  308. clr P1.BnFET
  309. ENDM
  310. MACRO CnFET_on
  311. mov A, Current_Pwm_Limited
  312. jz ($+12)
  313. jb Flags3.PGM_DIR_REV, ($+5)
  314. setb P1.CnFET
  315. jnb Flags3.PGM_DIR_REV, ($+5)
  316. setb P1.AnFET
  317. ENDM
  318. MACRO CnFET_off
  319. jb Flags3.PGM_DIR_REV, ($+5)
  320. clr P1.CnFET
  321. jnb Flags3.PGM_DIR_REV, ($+5)
  322. clr P1.AnFET
  323. ENDM
  324. MACRO All_nFETs_Off
  325. clr P1.AnFET
  326. clr P1.BnFET
  327. clr P1.CnFET
  328. ENDM
  329. MACRO All_nFETs_On
  330. setb P1.AnFET
  331. setb P1.BnFET
  332. setb P1.CnFET
  333. ENDM
  334. MACRO A_B_nFETs_On
  335. setb P1.AnFET
  336. setb P1.BnFET
  337. ENDM
  338. MACRO ApFET_on
  339. jb Flags3.PGM_DIR_REV, ($+5)
  340. setb P1.ApFET
  341. jnb Flags3.PGM_DIR_REV, ($+5)
  342. setb P1.CpFET
  343. ENDM
  344. MACRO ApFET_off
  345. jb Flags3.PGM_DIR_REV, ($+5)
  346. clr P1.ApFET
  347. jnb Flags3.PGM_DIR_REV, ($+5)
  348. clr P1.CpFET
  349. ENDM
  350. MACRO BpFET_on
  351. setb P1.BpFET
  352. ENDM
  353. MACRO BpFET_off
  354. clr P1.BpFET
  355. ENDM
  356. MACRO CpFET_on
  357. jb Flags3.PGM_DIR_REV, ($+5)
  358. setb P1.CpFET
  359. jnb Flags3.PGM_DIR_REV, ($+5)
  360. setb P1.ApFET
  361. ENDM
  362. MACRO CpFET_off
  363. jb Flags3.PGM_DIR_REV, ($+5)
  364. clr P1.CpFET
  365. jnb Flags3.PGM_DIR_REV, ($+5)
  366. clr P1.ApFET
  367. ENDM
  368. MACRO All_pFETs_Off
  369. clr P1.ApFET
  370. clr P1.BpFET
  371. clr P1.CpFET
  372. ENDM
  373. ;MACRO All_pFETs_On
  374. ; setb P1.ApFET
  375. ; setb P1.BpFET
  376. ; setb P1.CpFET
  377. ;ENDM
  378. MACRO Set_Comp_Phase_A
  379. jb Flags3.PGM_DIR_REV, ($+6)
  380. mov CPT0MX, #21h ; Set comparator multiplexer to phase A
  381. jnb Flags3.PGM_DIR_REV, ($+6)
  382. mov CPT0MX, #01h
  383. ENDM
  384. MACRO Set_Comp_Phase_B
  385. mov CPT0MX, #11h ; Set comparator multiplexer to phase B
  386. ENDM
  387. MACRO Set_Comp_Phase_C
  388. jb Flags3.PGM_DIR_REV, ($+6)
  389. mov CPT0MX, #01h ; Set comparator multiplexer to phase C
  390. jnb Flags3.PGM_DIR_REV, ($+6)
  391. mov CPT0MX, #21h
  392. ENDM
  393. MACRO Read_Comp_Out
  394. mov A, CPT0CN ; Read comparator output
  395. cpl A
  396. ENDM
  397. ;*********************
  398. ; PORT 2 definitions *
  399. ;*********************
  400. DebugPin EQU 0 ;o
  401. P2_PUSHPULL EQU (1 SHL DebugPin)
  402. ;**********************
  403. ; MCU specific macros *
  404. ;**********************
  405. MACRO Interrupt_Table_Definition
  406. CSEG AT 0 ; Code segment start
  407. jmp reset
  408. CSEG AT 0Bh ; Timer0 interrupt
  409. jmp t0_int
  410. CSEG AT 2Bh ; Timer2 interrupt
  411. jmp t2_int
  412. CSEG AT 5Bh ; PCA interrupt
  413. jmp pca_int
  414. CSEG AT 73h ; Timer3 interrupt
  415. jmp t3_int
  416. ENDM
  417. MACRO Initialize_Adc
  418. mov REF0CN, #0Eh ; Set vdd (3.3V) as reference. Enable temp sensor and bias
  419. mov ADC0CF, #58h ; ADC clock 2MHz
  420. mov AMX0P, #Adc_Ip ; Select positive input
  421. mov AMX0N, #11h ; Select negative input as ground
  422. mov ADC0CN, #80h ; ADC enabled
  423. ENDM
  424. MACRO Set_Adc_Ip_Volt
  425. mov AMX0P, #Adc_Ip ; Select positive input P0.6
  426. ENDM
  427. MACRO Set_Adc_Ip_Temp
  428. mov AMX0P, #10h ; Select temp sensor input
  429. ENDM
  430. MACRO Start_Adc
  431. mov ADC0CN, #90h ; ADC start
  432. ENDM
  433. MACRO Get_Adc_Status
  434. mov A, ADC0CN
  435. ENDM
  436. MACRO Read_Adc_Result
  437. mov Temp1, ADC0L
  438. mov Temp2, ADC0H
  439. ENDM
  440. MACRO Stop_Adc
  441. ENDM