;.device AT90S1200 .include "1200def.inc" ; externer quarz, 4 mhz ;***** Common Registers .def soll1pos =r01 ;soll motorposition 1 .def soll2pos =r02 ;soll motorposition 2 .def soll3pos =r03 ;soll motorposition 3 .def soll4pos =r04 ;soll motorposition 4 .def soll5pos =r05 ;soll motorposition 5 .def soll6pos =r06 ;soll motorposition 6 .def soll7pos =r07 ;soll motorposition 7 .def soll8pos =r08 ;soll motorposition 8 .def servnum =r09 ;servo number ;***** UART Global Registers .def u_buffer =r14 ;Serial buffer .def u_sr =r15 ;Status-register storage .def u_tmp =r16 ;Scratchregister .def u_bit_cnt =r17 ;Bit counter .def u_status =r18 ;Status buffer .def u_reload =r19 ;Reload-register (internal - do not use) ;***** Common Global Registers .def charct =r20 ;character counter .def temp =r21 ;erste allgemeine variable .def wait_ct =r22 ;verzoegerungs counter variable .def delay_ct =r23 ;verzoegerungs counter .def temp2 =r24 ;zweite allgemeine variable ;***** Bit positions in the Status-register .equ RDR=0 ;Receive data ready bit .equ TD=6 ;Transmitting data (internal - read-only) .equ BUSY=7 ;Busy-flag (internal - read-only) ;***** Pin Definitions ;PD0 = down taste mot1 ;PD1 = up taste mot1 ;PD2 = serial input rs232 ;PD3 = serial output rs232 ;PD4 = down taste mot2 ;PD5 = up taste mot2 ;PB0 = servo motor 1 ;PB1 = servo motor 2 ;PB2 = servo motor 3 ;PB3 = servo motor 4 ;PB4 = servo motor 5 ;PB5 = servo motor 6 ;PB6 = servo motor 7 ;PB7 = servo motor 8 ;***** Constants .equ N=52 ;9600 .equ C=8 .equ R=2 ;R=1 when C=1 (1,1; 2,8; 3,64) ;***** Reset and Interrupt Vectors .CSEG .org $00 rjmp reset ;reset handle .org INT0addr rjmp ext_int0 ;External interrupt handler .org OVF0addr rjmp tim0_ovf ;Timer0 overflow handler .org ACIaddr reti ;Analog comparator handler ;---------------------------------------------- .MACRO waitservo ; macro definition nop nop nop nop nop nop nop nop nop nop nop nop nop nop .ENDMACRO ;------------------------------ reset: ldi delay_ct,0x10 ;step delay ldi temp,0x80 mov soll1pos,temp mov soll2pos,temp mov soll3pos,temp mov soll4pos,temp mov soll5pos,temp mov soll6pos,temp mov soll7pos,temp mov soll8pos,temp ldi u_tmp,0xff out DDRB,u_tmp ;pb as output ldi u_tmp,0x00 out PORTB,u_tmp ;set all outputs = l ldi u_tmp,0x48 out DDRD,u_tmp ;pd3 as output ldi u_tmp,0xff out PORTD,u_tmp ;set all outputs = h ldi u_tmp,R out TCCR0,u_tmp ;Start timer and set clock source ldi u_tmp,0x40 out GIMSK,u_tmp ;Enable external interrupt 0 ;ldi u_tmp,0x02 ;inv rs232 (using max232) ldi u_tmp,0x03 ;not inv. rs232 out MCUCR,u_tmp ;On falling edges clr u_status ;Erase status-byte sei ;Enable interrupts loop: sbis PIND,0 ;is increase switch pressed? inc soll1pos ;yes sbis PIND,1 ;is decrease switch pressed? dec soll1pos ;yes sbis PIND,4 ;is increase switch pressed? inc soll2pos ;yes sbis PIND,5 ;is decrease switch pressed? dec soll2pos ;yes rcall waitstep ;wait a time sbi PORTB,0 rcall wdefin mov temp,soll1pos rcall wmot cbi PORTB,0 sbi PORTB,1 rcall wdefin mov temp,soll2pos rcall wmot cbi PORTB,1 sbi PORTB,2 rcall wdefin mov temp,soll3pos rcall wmot cbi PORTB,2 sbi PORTB,3 rcall wdefin mov temp,soll4pos rcall wmot cbi PORTB,3 sbi PORTB,4 rcall wdefin mov temp,soll5pos rcall wmot cbi PORTB,4 sbi PORTB,5 rcall wdefin mov temp,soll6pos rcall wmot cbi PORTB,5 sbi PORTB,6 rcall wdefin mov temp,soll7pos rcall wmot cbi PORTB,6 sbi PORTB,7 rcall wdefin mov temp,soll8pos rcall wmot cbi PORTB,7 rjmp loop ;again ;------------------------------ wmot: waitservo dec temp cpi temp,0x00 brne wmot ret ;------------------------------ wdefin: ldi temp,0 w_def: nop nop nop nop nop nop nop dec temp cpi temp,0x00 brne w_def ret ;------------------------------ .MACRO waitpwm ; macro definition nop nop nop nop .ENDMACRO ;------------------------------ waitstep: mov wait_ct,delay_ct w_loop: ;das ist die warteschleife ldi temp,0xff wi_loop: ;das ist innere die warteschleife waitpwm dec temp cpi temp,0x00 brne wi_loop ;ende der inneren warteschleife dec wait_ct cpi wait_ct,0x00 brne w_loop ;ende der warteschleife ret ;---------------------------------------------- ext_int0: ;action on the rs232 line in u_sr,SREG ;Store Status Register ;sbic PIND,2 ;using max232 sbis PIND,2 ;get start bit rjmp endextir ;no startbit found, abort ldi u_status,1<