| ??? 10/19/99 08:02 Read: times |
#873 - 8052 program hangs after 150 cycles of loop. |
Dear Guys,
I've written a program for the Atmel 8052 chip that would run a stepper motor. However I keep finding that my program freezes-up after may be 100 - 120 cycles ( the program runs in a loop, depending on the task that the motor must perform). I use some 'sjmp' and 'ljmp' command, thus don't know what could be the problem. Sample Program : BaudLoad equ -36 ;9600 at 18.432MHz Smod equ 0 DIR equ P1.0 CONTROL bit P1.1 ENABLE bit P1.2 ;FULL bit P1.3 V5 bit P1.3 I3 bit p1.4 I2 bit P1.5 I1 bit p1.6 I4 bit P1.7 HIGH_CURRENT bit P2.0 EN_245 bit P0.0 RESET bit P0.1 FULL bit P0.2 HOME bit P0.3 CLK bit P0.4 DIR_245 bit P0.5 V36 bit P0.6 org 00h ljmp start ; org 03h ; ljmp ISR0 ; org 013h ; ljmp ISR1 org 30h start: acall init_ports acall request_print sjmp start mov r3,#0h ;Main Section ;Displays > and waits for 3 types of command namely '.','5','7'. If Restart: L1: mov r5,#0h setb high_current acall init1 mov a,#'>' ; Command prompt acall send command: acall init2 acall receive cjne a,#'.',not_dot ; Request to Power Down acall pwr_off not_dot: cjne a,#05h,not_06 acall Initialize_Motor ; Request to Initialize Motor not_06: cjne a,#35h,not_05 ; Request to Print acall Request_Print not_05: sjmp L1 ; mov IE,#81h ; setb it1 ; Level Activate for Interupts ;----------------------------------------------------------------------------- ; Initialize Motor to Ref. sensor location ; Acc = Motor Speed ; I4 = Ref. Position ; I3 = Max. Position ;----------------------------------------------------------------------------- Initialize_Motor: acall pwr_on ; Move the board clr high_current ; High speed switch clr full ; Req. for Half step mode clr dir ; set a direction mov a,#50 ; Move motor speed mov r1,#0 muharam: mov r2,#13 shawal: mov r3,#200 ramadan: jnb i4,i4_slow jnb i3,i3_slow setb clk acall clock clr clk acall clock djnz r3,ramadan djnz r2,shawal djnz r1,muharam acall init1 mov r6,#02 ; Cannot Initialize ljmp error_dump i3_slow: setb dir ; Cpl direction clr reset acall mdelay acall mdelay setb reset acall mdelay acall mdelay mov r7,#10 ; Move out of sensor slightly i3_slow1: setb clk acall clock clr clk acall clock djnz r7,i3_slow1 sjmp ramadan i4_slow: clr dir vikna: acall init1 mov a,#06h ; Initialization OK, Motor = Min. acall send sjmp L1 ;----------------------------------------------------------------------------- ;Request to Print ; ; ;----------------------------------------------------------------------------- Request_Print: acall pwr_on ; Move the board clr full ; Req. for Half step mode clr dir ; set a direction jnb I4,min_pos jnb I3,max_pos mov r6,#54 acall error_dump ; Cannot Print, Head out of position min_pos: mov R6,#06h acall dump_host mov R6,#2Fh acall dump_host clr dir sjmp cont_hitam max_pos: mov R6,#06h acall dump_host mov R6,#2Bh acall dump_host setb dir cont_hitam: acall init2 acall receive cjne a,#'.',not_quit acall pwr_off not_quit: cjne a,#'t',not_print print: acall init2 acall receive clr high_current mov r7,a mov r0,#20 Yanty: setb clk acall clock clr clk acall clock djnz r0,yanty mov r0,#15 Abdul_Karim: mov r1,#200 Sharril: setb clk acall clock clr clk acall clock jnb i3,i3_found ; is mAX sensor activated jnb i4,i4_found djnz r1,sharril djnz r0,abdul_karim mov r6,#'3' ljmp error_dump i4_found: i3_found: mov R6,#06h acall dump_host clr reset acall mdelay acall mdelay acall mdelay setb reset not_print: ljmp restart error1: mov r6,#49 sjmp error_dump error_dump: acall init1 mov a,#15h ; NACK acall send dump_error: mov a,R6 ; Error 3 acall send ljmp pwr_off sjmp dump_error dump_host: acall init1 mov a,R6 acall send ret init1: mov pcon,#80h mov scon,#40h ;send mode clr tr1 ;stop baudrate generator mov tmod,#20h ;n - 8 - 1 mov tl1,#0fdh ;preload autoreload registers on 4800 bps = 0fah mov th1,#0fdh ;preload autoreload registers on 4800 bps = 0fah setb tr1 ;start baudrate generator ret INIT2: mov pcon,#80h mov scon,#50h ;receive mode clr tr1 ;idem mov tmod,#20h mov tcon,#41h mov tl1,#0fdh mov th1,#0fdh setb tr1 ;idem ret ;return from isr INIT_PORTS: mov p0,#11000000b mov p1,#11111000b setb p3.2 setb p3.3 setb control setb enable clr full setb reset clr dir ; setb high_current ret SEND: trans: mov sbuf,a ;load sbuf with char from acc loop1: jnb ti,loop1 ;flush char - if ti==1 then char is flushed clr ti ;reset ti ret ajmp truncate ;go to receive routine truncate: ajmp receive RECEIVE: acall flushsbuf loop2: jnb ri,$ ;$-sign means address of current label 'loop' mov a,sbuf clr ri ;reset ri-flag ret flushsbuf: mov a,sbuf ;preserve sbuf in acc ret ;return from isr not_rite: ajmp loop2 ISR0: push psw push acc acall init1 mov a,#'F' ; Denote V5_AUX shutdown acall send pop acc pop psw reti PWR_ON: clr V5 acall mdelay acall mdelay clr V36 acall mdelay acall mdelay setb enable ; mov r2,#100 ;shammil: acall mdelay acall mdelay ; djnz r2,shammil jb I1,thermal ret Thermal: mov r6,#'1' ljmp error_dump PWR_OFF: mov IE,#0h clr Enable acall mdelay setb V36 acall mdelay setb V5 acall mdelay setb high_current ljmp restart MDELAY: push acc mov a, #0a6h md_olp: inc a nop nop nop nop nop nop nop nop jnz md_olp nop pop acc ret sdelay: push acc mov a, #91h sd_olp: inc a acall mdelay acall mdelay acall mdelay acall mdelay acall mdelay acall mdelay acall mdelay acall mdelay acall mdelay nop nop nop nop nop jnz sd_olp mov a, #33h sd_ilp: djnz acc, sd_ilp pop acc ret clock: push acc clock1: dec a nop nop nop nop nop nop nop nop jnz clock1 nop pop acc ret END ;pseudo code for end of assembly file |
| Topic | Author | Date |
| 8052 program hangs after 150 cycles of loop. | 01/01/70 00:00 | |
| RE: 8052 program hangs after 150 cycles of loop. | 01/01/70 00:00 | |
| RE: 8052 program hangs after 150 cycles of loop. | 01/01/70 00:00 | |
RE: 8052 program hangs after 150 cycles of loop. | 01/01/70 00:00 |



