; this program steps a 3-winding variable reluctance motor from hard-coded data. .equ esc, 0x003E ;Check for ESC key .equ port_e, 0xF901 ;access port E .equ port_def_pgm, 0xF903 ;configure in/out of all three ports .equ cout, 0x0030 ;Send Acc to serial port .equ phex, 0x0034 ;Print Hex value of Acc .equ pstr, 0x0038 ;Print string pointed to by DPTR, ;must be terminated by 0 or a high bit set ;pressing ESC will stop the printing .equ ghex, 0x003A ;Get Hex input into Acc ;Carry set if ESC has been pressed .org 0x2000 ljmp begin .org 0x200B ljmp timer0_isr begin: mov dptr, #port_def_pgm mov a, #128 movx @dptr, a ;make all D-E-F port pins outputs ; get the delay mov dptr,#start_string lcall pstr lcall ghex mov r1,a ; set up timer mov ie, #0 ;turn off all interrupts clr tr0 ;make sure timer 0 is stopped clr tf0 ;clear the overflow flag anl tmod, #0xF0 ;set to mode 0 (without touching timer 1) mov th0, #0 ;clear the timer 0 value mov tl0, #0 setb tr0 ;start the timing mov ip, #0 ;set interrupt priorities (all low) mov ie, #0x82 ;enable timer0 interrupt ; set up the program variables mov r6, #1 mov r0,a main_loop: lcall esc jc abort sjmp main_loop abort: mov a, #255 mov dptr, #port_e movx @dptr, a ljmp 0 timer0_isr: djnz r0,isr_end ; push acc push dph push dpl mov a,r6 ; get the current value mov dptr, #port_e movx @dptr, a lcall phex ; increment the position cjne r6,#8,inc_position mov r6,#1 sjmp clean_up inc_position: mov a,r6 mov b,#2 mul ab mov r6,a ; inc r6 clean_up: pop dpl pop dph ; pop acc mov a,r1 mov r0,a isr_end: nop reti start_string: .db "Please enter the delay value in hex format:",13,10,0