;**** **** **** **** ****
;
; BLHeli program for controlling brushless motors in helicopters
;
; Copyright 2011, 2012 Steffen Skaug
; This program is distributed under the terms of the GNU General Public License
;
; This file is part of BLHeli.
;
; BLHeli is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; BLHeli is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with BLHeli. If not, see .
;
;**** **** **** **** ****
;
; BLHeliTxPgm Atmel
;
;**** **** **** **** ****
;**** **** **** **** **** **** **** **** **** **** **** **** ****
;
; Read eeprom byte routine
;
; Assumes data in Temp1 and address in X
; Also assumes address high byte to be zero
;
;**** **** **** **** **** **** **** **** **** **** **** **** ****
read_eeprom_byte:
; Wait for completion of previous write
Check_Eeprom_Ready
rjmp read_eeprom_byte
; Set up address in address register
Set_Eeprom_Address Temp2, Temp3
; Start eeprom read
sbi EECR, EERE
in Temp1, EEDR
ret
;**** **** **** **** **** **** **** **** **** **** **** **** ****
;
; Write eeprom byte routine
;
; Assumes data in Temp1 and address in Temp2/Temp3
; Also assumes address high byte to be zero
;
;**** **** **** **** **** **** **** **** **** **** **** **** ****
write_eeprom_byte:
; Wait for completion of previous write
Check_Eeprom_Ready
rjmp write_eeprom_byte
; Set up address in address register
out EEDR, Temp1
Set_Eeprom_Address Temp2, Temp3
; Set write enables and start writing
cli ; Disable interrupts
Start_Eeprom_Write
sei ; Enable interrupts
ret
;**** **** **** **** **** **** **** **** **** **** **** **** ****
;
; Clear eeprom signature routine
;
; No assumptions
;
;**** **** **** **** **** **** **** **** **** **** **** **** ****
clear_eeprom_signature:
ldi Temp2, low(Eep_Initialized_L)
ldi Temp3, high(Eep_Initialized_L)
ldi Temp1, 0xFF
rcall write_eeprom_byte
ldi Temp2, low(Eep_Initialized_H)
ldi Temp3, high(Eep_Initialized_H)
ldi Temp1, 0xFF
rcall write_eeprom_byte
ret
;**** **** **** **** **** **** **** **** **** **** **** **** ****
;
; Write eeprom signature routine
;
; No assumptions
;
;**** **** **** **** **** **** **** **** **** **** **** **** ****
write_eeprom_signature:
.if TAIL == 0
ldi Temp2, low(Eep_Initialized_L)
ldi Temp3, high(Eep_Initialized_L)
ldi Temp1, 0xA5
rcall write_eeprom_byte
ldi Temp2, low(Eep_Initialized_H)
ldi Temp3, high(Eep_Initialized_H)
ldi Temp1, 0x5A
rcall write_eeprom_byte
.else
ldi Temp2, low(Eep_Initialized_L)
ldi Temp3, high(Eep_Initialized_L)
ldi Temp1, 0x5A
rcall write_eeprom_byte
ldi Temp2, low(Eep_Initialized_H)
ldi Temp3, high(Eep_Initialized_H)
ldi Temp1, 0xA5
rcall write_eeprom_byte
.endif
ret
;**** **** **** **** **** **** **** **** **** **** **** **** ****
;
; Read eeprom perameters routine
;
; No assumptions
;
;**** **** **** **** **** **** **** **** **** **** **** **** ****
read_eeprom_parameters:
.if TAIL == 0
; Check initialized signature
ldi Temp2, low(Eep_Initialized_L)
ldi Temp3, high(Eep_Initialized_L)
rcall read_eeprom_byte
cpi Temp1, 0xA5
brne read_eeprom_store_defaults
ldi Temp2, low(Eep_Initialized_H)
ldi Temp3, high(Eep_Initialized_H)
rcall read_eeprom_byte
cpi Temp1, 0x5A
brne read_eeprom_store_defaults
; Read eeprom
ldi Temp2, low(Eep_Pgm_Gov_P_Gain)
ldi Temp3, high(Eep_Pgm_Gov_P_Gain)
rcall read_eeprom_byte
sts Pgm_Gov_P_Gain, Temp1
ldi Temp2, low(Eep_Pgm_Gov_I_Gain)
ldi Temp3, high(Eep_Pgm_Gov_I_Gain)
rcall read_eeprom_byte
sts Pgm_Gov_I_Gain, Temp1
ldi Temp2, low(Eep_Pgm_Gov_Mode)
ldi Temp3, high(Eep_Pgm_Gov_Mode)
rcall read_eeprom_byte
sts Pgm_Gov_Mode, Temp1
ldi Temp2, low(Eep_Pgm_Startup_Pwr)
ldi Temp3, high(Eep_Pgm_Startup_Pwr)
rcall read_eeprom_byte
sts Pgm_Startup_Pwr, Temp1
ldi Temp2, low(Eep_Pgm_Pwm_Freq)
ldi Temp3, high(Eep_Pgm_Pwm_Freq)
rcall read_eeprom_byte
sbr Flags2, (1<