.DEF A = R17 .DEF B = R16 .EQU XAML = $0124 ; Last "opened" location Low .EQU XAMH = $0125 ; Last "opened" location High .EQU STL = $0126 ; Store address Low .EQU STH = $0127 ; Store address High .EQU L = $0128 ; Hex value parsing Low .EQU H = $0129 ; Hex value parsing High .EQU YSAV = $012A ; Used to see if hex value is given .EQU MODE = $012B ; $00=XAM, $7F=STOR, $AE=BLOCK XAM .EQU LINEND= $0A ; sets the end of line character $0D = CR, $0A = LF .DSEG .ORG $0100 ;XAML: .BYTE 1 ;XAMH: .BYTE ;MODE: .BYTE 1 .ORG $0200 INBUFFER: .BYTE 128 .CSEG .ORG 0 JMP RESET ;interupt service routine vector setup JMP INT0_ISR JMP INT1_ISR JMP PCINT0_ISR JMP PCINT1_ISR JMP PCINT2_ISR JMP WDT_ISR JMP TIMER2_COMPA_ISR JMP TIMER2_COMPB_ISR JMP TIMER2_OVF_ISR JMP TIMER1_CAPT_ISR JMP TIMER1_COMPA_ISR JMP TIMER1_COMPB_ISR JMP TIMER1_OVF_ISR JMP TIMER0_COMPA_ISR JMP TIMER0_COMPB_ISR JMP TIMER0_OVF_ISR JMP SPI_ISR JMP USART_RX_ISR JMP USART_DATA_EMPTY_ISR JMP USART_TX_ISR JMP ADC_DONE_ISR JMP EE_READY_ISR JMP ANALOG_COMP_ISR JMP TWI_ISR JMP SPM_READY_ISR .ORG 0x34 RESET: ;setup serial, send esc CLR R24 STS UCSR0A, R24 ;clear UCSR0A register STS UBRR0H, R24 ;clear UBRR0H register LDI R24, 103 ;& store in UBRR0L 103 value STS UBRR0L, R24 ;to set baud rate 9600 LDI R24, 1<L STS H, XL ;0->H STS YSAV, YL ;save y NEXTHEX: LD A, Y ;get char for hex test LDI B, $30 ;map digits EOR A, B CPI A, $0A ;is digit? BRLO DIG ;if true jump LDI B, $89 ;map A-F ADD A, B ;p CPI A, $FA ;is hex letter? BRLO NOTHEX ;if not then jump here DIG: LSL A LSL A LSL A LSL A LDI XL, $04 ;shift count HEXSHIFT: LSL A ;hex digit left msb to carry LDS B, L ;rotate into LSD ROL B STS L, B LDS B, H ;rotate into MSD ROL B STS H, B DEC XL ;done four shifts? BRNE HEXSHIFT ;if not loop INC YL ;incriment text index BRNE NEXTHEX ;check next char NOTHEX: LDS B, YSAV ;check if L, H empty (no hex) CP YL, B BRNE NOTESC RJMP ESCAPE ;If true generate ESC sequence NOTESC: LDS B, MODE ;test b6 of MODE byte BST B, 6 ;SBRS B, 6 BRTC NOTSTOR ;if b6=0 (STOR), jump to notstor LDS A, L ;load LSD hex ;LDI ZL, LOW(STL) ;store current store index ;LDI ZH, $01 ; LDS ZL, STL LDS ZH, STH ;ADD ZL, XL ; ;LDI B, $00 ; ;ADC ZH, B ; ST Z, A ; LDS B, STL ;incriment store index INC B STS STL,B BRNE TONEXTITEM ;get next item LDS B, STH ;add carry to 'store index' high byte INC B STS STH,B TONEXTITEM: RJMP NEXTITEM ;get next command line RUN: LDS ZH, XAMH ;run at current XAM index LDS ZL, XAML IJMP NOTSTOR: BST B, 7 BRTS XAMNEXT ;B7 = 0 for XAM, 1 for BLOCK XAM. LDI XL, $02 ;byte count SETADR: LDI ZH, $01 ;copy hexdata to 'store index' and 'XAM index' MOV ZL, XL LDD A, Z+LOW(L-1) STD Z+LOW(STL-1),A STD Z+LOW(XAML-1),A DEC XL ;next of two bytes BRNE SETADR ;loop if x!=0 NXTPRNT: BRNE PRDATA ;if no address to print got prdata LDI A, LINEND ;CR RCALL ECHO ;output CR LDS A, XAMH ;examine index high byte RCALL PRBYTE ;output as hex LDS A, XAML ;examine index low byte RCALL PRBYTE ;output as hex LDI A, $3A ;':' RCALL ECHO ;output ':' PRDATA: LDI A, $20 RCALL ECHO ;LDI ZL, LOW(XAML) ;Get data byte at examine index ;LDI ZH, $01 ;ADD ZL, XL ;LDI B, $0 ;ADC ZL, B ;LD A, Z LDS ZL, XAML LDS ZH, XAMH LD A, Z RCALL PRBYTE ;output byte as hex XAMNEXT: STS MODE,XL ;store x to mode LDS A, XAML ; LDS B, L CP A, B LDS A, XAMH LDS B, H SBC A, B BRSH TONEXTITEM LDS B, XAML INC B STS XAML,B BRNE MOD8CHK LDS B, XAMH INC B STS XAMH,B MOD8CHK: LDS A, XAML ANDI A, $07 RJMP NXTPRNT PRBYTE: PUSH A LSR A LSR A LSR A LSR A RCALL PRHEX POP A PRHEX: ANDI A, $0F ORI A, $30 CPI A, $3A BRLO ECHO LDI B, $07 ADD A, B ECHO: PUSH A STS UDR0,A ;LDI A, $FF TXDELAY: LDS A, UCSR0A ANDI A, 0b01000000;DEC A BREQ TXDELAY STS UCSR0A, A POP A RET ;interupt service routines ;can be moved INT0_ISR: RETI INT1_ISR: RETI PCINT0_ISR: RETI PCINT1_ISR: RETI PCINT2_ISR: RETI WDT_ISR: RETI TIMER2_COMPA_ISR: RETI TIMER2_COMPB_ISR: RETI TIMER2_OVF_ISR: RETI TIMER1_CAPT_ISR: RETI TIMER1_COMPA_ISR: RETI TIMER1_COMPB_ISR: RETI TIMER1_OVF_ISR: RETI TIMER0_COMPA_ISR: RETI TIMER0_COMPB_ISR: RETI TIMER0_OVF_ISR: RETI SPI_ISR: RETI USART_RX_ISR: RETI USART_DATA_EMPTY_ISR: RETI USART_TX_ISR: RETI ADC_DONE_ISR: RETI EE_READY_ISR: RETI ANALOG_COMP_ISR: RETI TWI_ISR: RETI SPM_READY_ISR: RETI