; this program steps a 2-winding unipolar motor from hard-coded data. ; Register uses: ; R0 - The current number of elapsed skipped steps. Reset to the value of r1 when it overflows ; R1 - Delay (number of timer iterations to skip per step) ; R2 - Current value on the port ; R3 - unused ; R4 - unused ; R5 - unused ; R6 - unused ; R7 - unused .equ esc, 0x003E ;Check for ESC key .equ portE, 0xF901 ;access port E .equ portF, 0xF902 ;access port F .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 ;clear timer 0 settings (without touching timer 1) orl tmod, #0x02 ;make it an auto-reload timer (without touching timer 1) ; setb t0m1 ; set timer 0 to mode 2 (auto-reload) mov th0, #255 ; set the reload value mov tl0, #0 ;clear the timer 0 value 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 r2, #1 mov r0,a main_loop: lcall esc jc abort sjmp main_loop abort: mov a, #255 mov dptr, #portE movx @dptr, a mov a, #0 mov dptr, #portF movx @dptr, a ljmp 0 timer0_isr: djnz r0,isr_end ; push acc push dph push dpl mov a,r2 ; get the current value mov dptr, #portE movx @dptr, a mov dptr, #portF movx @dptr, a ; lcall phex ; increment the position cjne r2,#8,inc_position mov r2,#1 sjmp clean_up inc_position: mov a,r2 mov b,#2 mul ab mov r2,a clean_up: pop dpl pop dph ; pop acc mov a,r1 mov r0,a isr_end: nop reti start_string: .db "Please enter the number of timer cycles to skip in hex format: ",13,10,0