X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=beginners%2Fseason_junior.asm;h=e6a46067d459aaf6c6aa0bd249c0921370a2f84a;hb=d33a33e018bbcaa09907be8fa03b965fe411a974;hp=703b29fbe203ed2bcd020c27a2e256022968822b;hpb=db9964b83523d6892548d2e55cbfede35c33d473;p=my-code%2Fatmel.git diff --git a/beginners/season_junior.asm b/beginners/season_junior.asm index 703b29f..e6a4606 100644 --- a/beginners/season_junior.asm +++ b/beginners/season_junior.asm @@ -6,6 +6,7 @@ ; at90s2313 ; setup: +; ; vcc card --- atmel vcc ; vcc cam --- ; rst cam --- atmel int0 (pd2) @@ -19,19 +20,6 @@ .include "../include/2313def.inc" -; functions by now: -; -; stupid mode only by now. just see what cam/card do and redirect -; this to card/cam. -; -; next implementation: -; -; try to read one byte of card/cam communication and output via uart. -; output time information in some way. -; -; future: -; -; buffer/parse whole strings and decide whether to send to card or not. ; ####### ; defines @@ -46,22 +34,27 @@ .define etu_h 312 .define baudrate 5 ; UBRR value for 76800 bits/s (8mhz clock) +; sizes +.define uart_data_len 4 + ; names for registers -.define tmp r16 -.define bitcount r17 -.define tmp1 r18 -.define tmp2 r19 -.define byte r20 -.define overflow_counter r21 -.define counter_l r22 -.define counter_h r23 -.define state r24 -.define state_m r25 -.define mode r26 -.define counter_l_tmp r27 -.define counter_h_tmp r28 -.define one r1 -.define zero r0 +.def tmp = r16 +.def bitcount = r17 +.def tmp1 = r18 +.def tmp2 = r19 +.def byte = r20 +.def overflow_counter = r21 +.def counter_l = r22 +.def counter_h = r23 +.def state = r24 +.def state_m = r25 +.def mode = r26 +.def counter_l_tmp = r27 +.def counter_h_tmp = r28 +.def address_h = r31 +.def address_l = r30 +.def one = r1 +.def zero = r0 ; state .define LOW (1<<0) @@ -107,7 +100,7 @@ rjmp REC_CARD reti ; timer/counter overflow 1 -rjmp CLK_OVERFLOW +rjmp T1_OVERFLOW ; timer/counter overflow 0 reti @@ -130,6 +123,10 @@ reti INIT: +; output low on rst to card while init +sbi DDRD,DDD4 +cbi PORTD,PD4 + ; set stackpointer ldi tmp,low(RAMEND) out SPL,tmp @@ -142,7 +139,7 @@ ldi tmp,((1< calc delta, store to counter_l_tmp, counter_h_tmp +rcall CALC_DELTA_CLOCK ; send time and state via uart sbrc mode,COOL_F -rcall SEND_TO_UART ; -> prepare date & enable uart dre interrupt (sbi UCR,UDRIE) +rcall PREPARE_UART ; return reti +; ------------------------ +; calc_delta_clock routine +; ------------------------ + +CALC_DELTA_CLOCK: + +; store counters +mov counter_l_tmp,counter_l +mov counter_h_tmp,counter_h + +; get new ones +in counter_l,ICR1L +in counter_h,ICR1H + +; delta calc on host software by now + +; return +ret + ; ------------------------ ; toggle_icp_sense routine ; ------------------------ @@ -224,9 +243,11 @@ reti TOGGLE_ICP_SENSE: ; toggle according to state -cbi TCCR1B,ICES1 -sbrs state,HIGH -sbi TCCR1B,ICES1 +in tmp,TCCR1B +cbr tmp,ICES1 +sbrs state,HIGH ; maybe toggle according to TCCR1B? +sbr tmp,ICES1 +out TCCR1B,tmp ; return ret @@ -235,105 +256,191 @@ ret ; fwd_to_cam routine ; ------------------ +FWD_TO_CAM: + +; disable external interrupt 1 while toggling edge +in tmp,GIMSK +cbr tmp,INT1 +out GIMSK,tmp + ; output state on port to cam -mov tmp,state -andi tmp,HIGH -lsl tmp ; as we have to set pd3 (dirty, shorter way?) +in tmp1,PORTD +sbr tmp1,PD3 +sbrs state,HIGH_F +cbr tmp1,PD3 + +; configure as output and push-pull low/high sbi DDRD,DDD3 -out PORTD,tmp ; <- hunz: low or high if pd3 bit is set ? +out PORTD,tmp1; + +; reenable external interrupt 1 +sbr tmp,INT1 +out GIMSK,tmp ; return ret +; -------------------- +; prepare_uart routine +; -------------------- -; zzZZzZzZZZ .... hier gehts weiter !!! +PREPARE_UART: + +; write transfer data to sram +ldi address_l,0x60 +st address_l+,counter_l +st address_l+,counter_h +st address_l+,overflow_counter +st address_l+,state + +; enable uart data register empty interrupt +sbi UCR,UDRIE + +; return +ret -; -; rec_cam routines -; + +; --------------- +; rec_cam routine +; --------------- REC_CAM: -; decide what to do -sbic PORTD,PD3 -rjmp REC_CAM_HIGH -rjmp REC_CAM_LOW +; first thing - pullup on +cbi DDRD,DDD3 +sbi DDRD,PD3 -REC_CAM_HIGH: +; toggle state +eor state,state_m -; output high on port to card -sbi PORTD,PD6 +; toggle int sense +rcall TOGGLE_INT_SENSE + +; fwd to card if in stupid mode +sbrc mode,STUPID_F +rcall FWD_TO_CARD -; toggle int1 sense -in r16,MCUCR -cbr r16,ISC10 -out MCUCR,r16 +; calculate delta clocks if in cool mode +sbrc mode,COOL_F +rcall CALC_DELTA_CLOCK +; return reti -REC_CAM_LOW: +; ------------------------ +; toggle_int_sense routine +; ------------------------ + +TOGGLE_INT_SENSE: -; output low on port to card -cbi PORTD,PD6 +in tmp,MCUCR +cbr tmp,ISC10 +sbrs state,HIGH_F +sbr tmp,ISC10 +out MCUCR,tmp + +; return +ret -; toggle int 1 sense -in r16,MCUCR -sbr r16,ISC10 -out MCUCR,r16 +; ------------------- +; fwd_to_card routine +; ------------------- -reti +FWD_TO_CARD: -; +; disable icp interrupt while toggling edge +in tmp,TIMSK +cbr tmp,TICIE +out TIMSK,tmp + +; output state on port to card +in tmp1,PORTD +sbr tmp1,PD6 +sbrs state,HIGH_F +cbr tmp1,PD6 + +; configure as output and push-pull low/high +sbi DDRD,DDD6 +out PORTD,tmp1; + +; reenable icp interrupt +sbr tmp,TICIE +out TIMSK,tmp + +; return +ret + +; ------------------- ; t1_overflow routine -; +; ------------------- T1_OVERFLOW: -add r22,r1 ; inc counter overflow register +; increment counter overflow +add overflow_counter,one +; return reti -; +; --------------- ; rst_cam routine -; +; --------------- RST_CAM: -; decide what to do -sbic PORTD,PD2 -rjmp RST_CAM_HIGH -rjmp RST_CAM_LOW +; by now just jump to init +rjmp INIT -RST_CAM_HIGH: +; ---------------- +; uart_out routine +; ---------------- -; output high on rst port to card -sbi PORTD,PD4 +UART_OUT: + +; disable uart data register empty interrupt +cbi UCR,UDRIE + +; init counter(s) +mov address_l,zero +mov tmp,zero -; toggle int0 sense -in r16,MCUCR -cbr r16,ISC00 -out MCUCR,r16 +; send the data +rcall UART_SEND +; return reti -RST_CAM_LOW: +; ----------------- +; uart_send routine +; ----------------- -; output low on rst port to cam -cbi PORTD,PD4 +UART_SEND: -; toggle int0 sense -in r16,MCUCR -sbr r16,ISC00 -out MCUCR,r16 +; read next byte from memmory and transfer via uart +sbic USR,UDRE +rcall UART_GS -reti +; return if everything was sent +cpi tmp,uart_data_len +brne UART_SEND +ret -; -; uart_out routines -; +; --------------- +; uart_gs routine +; --------------- -UART_OUT: +UART_GS: +; +; wie macht man load mit autoinc richtig? ; -; hier weiter ... -; + +; read byte from memory and write via uart +ld tmp1,address_l+ +out UDR,tmp1 + +; increment counter (maybe needed later) +add tmp,one + +; return +ret