本帖最后由 逗倪豌儿 于 2016-10-24 09:33 编辑
# 默认参数加载函数 -- set_default_parameters #
----------
说明 :
从_Pgm_Gov_P_Gain 地址开始 每一个字节存一个变量
参数地址 默认参数 参数意义
_Pgm_Gov_P_Gain 0FFh P 参数
_Pgm_Gov_P_Gain + 1 0FFh I 参数
_Pgm_Gov_P_Gain + 2 0FFh Governor mode 调节模式
_Pgm_Gov_P_Gain + 3 0FFh Low voltage limit 低压限制值
_Pgm_Gov_P_Gain + 4 0FFh Multi gain
_Pgm_Gov_P_Gain + 5 0FFh 保留
_Pgm_Gov_P_Gain + 6 DEFAULT_PGM_STARTUP_PWR
_Pgm_Gov_P_Gain + 7 0FFh Pwm freq PWM频率
_Pgm_Gov_P_Gain + 8 DEFAULT_PGM_DIRECTION
从 Pgm_Enable_TX_Program 地址开始 每一个字节存一个变量
参数地址 默认参数 参数意义
Pgm_Enable_TX_Program DEFAULT_PGM_ENABLE_TX_PROGRAM
Pgm_Enable_TX_Program + 1 0FFh Main rearm start
Pgm_Enable_TX_Program + 2 0FFh Governor setup target
Pgm_Enable_TX_Program + 3 0FFh Startup rpm
Pgm_Enable_TX_Program + 4 0FFh Startup accel
Pgm_Enable_TX_Program + 5 0FFh Voltage comp
Pgm_Enable_TX_Program + 6 DEFAULT_PGM_COMM_TIMING
Pgm_Enable_TX_Program + 7 0FFh Damping force
Pgm_Enable_TX_Program + 8 0FFh Governor range
Pgm_Enable_TX_Program + 9 0FFh Startup method
Pgm_Enable_TX_Program + A DEFAULT_PGM_MIN_THROTTLE
Pgm_Enable_TX_Program + B DEFAULT_PGM_MAX_THROTTLE
Pgm_Enable_TX_Program + C DEFAULT_PGM_BEEP_STRENGTH
Pgm_Enable_TX_Program + D DEFAULT_PGM_BEACON_STRENGTH
Pgm_Enable_TX_Program + E DEFAULT_PGM_BEACON_DELAY
Pgm_Enable_TX_Program + F 0FFh Throttle rate
Pgm_Enable_TX_Program + 10h DEFAULT_PGM_DEMAG_COMP
Pgm_Enable_TX_Program + 11h 0FFh Bec voltage high
Pgm_Enable_TX_Program + 12h DEFAULT_PGM_CENTER_THROTTLE
Pgm_Enable_TX_Program + 13h 0FFh 保留
Pgm_Enable_TX_Program + 14h DEFAULT_PGM_ENABLE_TEMP_PROT
Pgm_Enable_TX_Program + 15h DEFAULT_PGM_ENABLE_POWER_PROT
Pgm_Enable_TX_Program + 16h 0FFh Enable pwm input
Pgm_Enable_TX_Program + 17h 0FFh Pwm dither
Pgm_Enable_TX_Program + 18h DEFAULT_PGM_BRAKE_ON_STOP
Pgm_Enable_TX_Program + 19h DEFAULT_PGM_LED_CONTROL
# 读取全部eeprom函数: read_all_eeprom_parameters #
执行过程 :
从 Eep_Initialized_L 所代表的地址中读取数据dataL放到 Bit_Access所代表的地址中 ,
如果 读到数据dataL == 055h
把 Eep_Initialized_L +1 所代表的地址中的数据读取出来dataH,放到 Bit_Access所代表的地址中,此时
如果 dataH ==0AAh 则调用read_eeprom_read函数,读取 eeprom中的数据;
如果 dataH != 0AAh 则调用 read_eeprom_store_defaults函数 ,读取默认的eeprom中的数据
如果 读到数据dataL != 055h
则调用 read_eeprom_store_defaults函数 ,读取默认的eeprom中的数据
总结 :如果 [Eep_Initialized_L] = 055h 且 [Eep_Initialized_L +1] = 0AAh 才能调用read_eeprom_read函数,读取 eeprom中的数据;否则会调用 read_eeprom_store_defaults函数 ,读取默认的eeprom中的数据,
# 延时函数#
----------
执行一次是 42.7us 内环是 23 * 42.7 us = 982.1us = 1ms
所以 Temp2的值决定着 要延时多少ms eg : wait30ms中 要把 Temp2 = 30
- ;**** **** **** **** **** **** **** **** **** **** **** **** ****
- ;
- ; Wait xms ~(x*4*250) (Different entry points)
- ;
- ; No assumptions
- ;
- ;**** **** **** **** **** **** **** **** **** **** **** **** ****
- wait1ms:
- mov Temp2, #1
- jmp waitxms_o
- wait3ms:
- mov Temp2, #3
- jmp waitxms_o
- wait10ms:
- mov Temp2, #10
- jmp waitxms_o
- wait30ms:
- mov Temp2, #30
- jmp waitxms_o
- wait100ms:
- mov Temp2, #100
- jmp waitxms_o
- wait200ms:
- mov Temp2, #200
- jmp waitxms_o
- waitxms_o: ; Outer loop
- mov Temp1, #23
- waitxms_m: ; Middle loop
- clr A
- djnz ACC, [ DISCUZ_CODE_0 ]nbsp; ; Inner loop (42.7us - 1024 cycles)
- djnz Temp1, waitxms_m
- djnz Temp2, waitxms_o
- ret
复制代码
# pgm_start 函数 #
1. 初始化 Flash_Key_1和Flash_Key_2为 0
2. 禁能看门口
3. 初始化栈大小
4. 使能VDD电压监视器
5. 如果 是1s电池 不把VDD电压监视器设置为系统复位源,否则设置为系统复位源
6. 选择内部震荡器为系统时钟源
7. 关闭所有的MOS管和PWM输出
8. 初始化 所有IO
9. 初始化交叉开关
10. 再次关闭所有的MOS管和PWM输出
11. 清除RAM
12. 执行设置默认参数到内存中
13. 执行从eeprom中读取参数
14. 取出Pgm_Beep_Strength地址中的数据 放到Beep_Strength中
15. 把 Initial_Arm位置1
16. 禁能所有中断,
17. 发声处理
18. 执行led控制
代码如下 :
- pgm_start:
- ; Initialize flash keys to invalid values
- mov Flash_Key_1, #0
- mov Flash_Key_2, #0
- ; Disable the WDT.
- mov WDTCN, #0DEh ; Disable watchdog
- mov WDTCN, #0ADh
- ; Initialize stack
- mov SP, #0c0h ; Stack = 64 upper bytes of RAM
- ; Initialize VDD monitor
- orl VDM0CN, #080h ; Enable the VDD monitor
- IF ONE_S_CAPABLE == 0
- mov RSTSRC, #06h ; Set missing clock and VDD monitor as a reset source if not 1S capable
- ELSE
- mov RSTSRC, #04h ; Do not set VDD monitor as a reset source for 1S ESCSs, in order to avoid resets due to it
- ENDIF
- ; Set clock frequency
- mov CLKSEL, #00h ; Set clock divider to 1
- ; Switch power off
- call switch_power_off
- ; Ports initialization
- mov P0, #P0_INIT
- mov P0MDIN, #P0_DIGITAL
- mov P0MDOUT, #P0_PUSHPULL
- mov P0, #P0_INIT
- mov P0SKIP, #P0_SKIP
- mov P1, #P1_INIT
- mov P1MDIN, #P1_DIGITAL
- mov P1MDOUT, #P1_PUSHPULL
- mov P1, #P1_INIT
- mov P1SKIP, #P1_SKIP
- mov P2MDOUT, #P2_PUSHPULL
- ; Initialize the XBAR and related functionality
- Initialize_Xbar
- ; Switch power off again, after initializing ports
- call switch_power_off
- ; Clear RAM
- clr A ; Clear accumulator
- mov Temp1, A ; Clear Temp1
- clear_ram:
- mov @Temp1, A ; Clear RAM
- djnz Temp1, clear_ram ; Is A not zero? - jump
- ; Set default programmed parameters
- call set_default_parameters
- ; Read all programmed parameters
- call read_all_eeprom_parameters
- ; Set beep strength
- mov Temp1, #Pgm_Beep_Strength
- mov Beep_Strength, @Temp1
- ; Set initial arm variable
- mov Initial_Arm, #1
- ; Initializing beep
- clr IE_EA ; Disable interrupts explicitly
- call wait200ms
- call beep_f1
- call wait30ms
- call beep_f2
- call wait30ms
- call beep_f3
- call wait30ms
- call led_control
复制代码
|