/****************************************************************************** * * ToggleDIOs.Asm * * This is the source code to recreate the command extensions block that came * with MIRTOS Version 2.00, occupying the range from 0x3000 to 0x3033. * This is the source file to recreate six (6) subroutines which came as part * of MIRTOS Version 2.00. Each one toggles one of the DIOs. It occupies * the range from 0x3300 to 0x3033. * * Command sequence to create the (.ELF, .HEX, .DMP, .RDE, .SYM, .PTR) files: * * AVR-AS ToggleDIOs.Asm -mmcu=atmega328p -o ToggleDIOs.Elf * If ErrorLevel 1 GoTo :Exit * If NOT Exist ToggleDIOs.Elf GoTo :Exit * AVR-ObjCopy -j .text -j .data -O ihex ToggleDIOs.Elf ToggleDIOs.Hex * If ErrorLevel 1 GoTo :Exit * If NOT Exist ToggleDIOs.Hex GoTo :Exit * AVR-ObjDump -d ToggleDIOs.Elf > ToggleDIOs.Dmp * If ErrorLevel 1 GoTo :Exit * If NOT Exist ToggleDIOs.Dmp GoTo :Exit * AVR-ReadELF -a ToggleDIOs.Elf > ToggleDIOs.RdE * If ErrorLevel 1 GoTo :Exit * If NOT Exist ToggleDIOs.RdE GoTo :Exit * AVR-ReadELF -s ToggleDIOs.Elf > ToggleDIOs.Sym * If ErrorLevel 1 GoTo :Exit * If NOT Exist ToggleDIOs.Sym GoTo :Exit * MakePTRFile /Q ToggleDIOs.Sym ToggleDIOs.Ptr * * :Exit * * General register usage and rules: * R0 a temporay "scratch" register; assume any called routine may change it * R1 should always contain the value 0 (may be used and restored, however) * R2 through R17, R28, R29 Called routine must save and restore these * R18 through R27, R30, R31 May be used without saving and restoring * "T" is a temporary "scratch" FLAG in the SREG byte (use BLD and BST) * ******************************************************************************/ ; All INCLUDE files should be in the same directory as this .ASM source code: .INCLUDE "CommonDefs.Def" ; TRUE, FALSE, YES, NO, BIT_PV_*, et.al. ; .INCLUDE "BinDefs.Def" ; All the B0 to B11111111 definitions ; .INCLUDE "IOM328P.Def" ; All register definitions for the ATmega328P ; .INCLUDE "SystemEEPROM.Def" ; .INCLUDE "SystemFLASH.Def" ; .INCLUDE "SystemSRAM.Def" ; .INCLUDE "nRF24L01.Def" .INCLUDE "Addresses.Def" ; All 128 system routines' Jump Table addresses .INCLUDE "Indices.Def" ; All 128 indirectly-accessed system jump indices .INCLUDE "ToggleDIOs.Ptr" ; Generated by the SSG MakePTRFile program /****************************************************************************** * * Code begins * ******************************************************************************/ SoftVector: ; SoftVector resides at address 0x0000 and is used to JMP AIndexedJump ; access the library routine, like old DOS INT 21 ;----------------------- .ORG 0x3000 ; ; Pass: R24 byte ¯ PORT (PPPP) and PIN (ppp) selection (format: PPPP0ppp) ; R22 byte ¯ (for "DiscreteOutput" only) zero/nonzero value to write ; Ret.: R24 byte ¯ (for "DiscreteInput" only) zero/nonzero value read Toggle_DO_0: LDI R24, 0x20 RJMP AToggle_DO_Common Toggle_DO_1: LDI R24, 0x21 RJMP AToggle_DO_Common Toggle_DO_2: LDI R24, 0x22 RJMP AToggle_DO_Common Toggle_DO_3: LDI R24, 0x23 RJMP AToggle_DO_Common Toggle_DO_4: LDI R24, 0x24 RJMP AToggle_DO_Common Toggle_DO_5: LDI R24, 0x25 Toggle_DO_Common: MOV R18, R24 ; Save the selector parameter value LDI R30, I_DiscreteInput ; Read the discrete input specified CALL 0 ; Direct FAR CALL with constant address LDI R30, I_DumpRegisters ; CALL ASoftVector ; Direct FAR CALL with named address MOV R22, R24 ; Transfer the ON/OFF state to R22 SUBI R22, 1 ; Subtract 1; if it was 1, it will become MOV R24, R18 ; 0 and if was 0 it will become 0xFF = -1 LDI R30, I_DumpRegisters RCALL AToggle_DO_SoftVector ; LDI R30, I_DiscreteOutput Toggle_DO_SoftVector: JMP ASoftVector /****************************************************************************** * * The resulting iHex output for this block is: * :1030000080E209C081E207C082E205C083E203C01A * :1030100084E201C085E2282FE4E70E940000EDE78A * :103020000E940000682F6150822FEDE701D0E5E794 * :043030000C940000FC * :00000001FF * ******************************************************************************/