.def tmp1 = r16
.def tmp2 = r17
.def uart_rxtx = r18
+.def hc595_sink = r19
+.def hc595_source = r20
;
; interrupts
rjmp T0_OVF
; UART RX
-rjmp UART_RX
+rjmp UART_RECEIVE
; UART UDRE
reti
; WDT OVF
reti
-
-; include control defines
-.include "ctrl.def"
+;
+; init and main code
+;
RESET:
INIT:
rcall PORT_INIT
; timer init
- rcall TIMER_INIT
+ ;rcall TIMER_INIT
; uart init
rcall UART_INIT
;sei
; signal ready output
- ldi uart_rxtx,0x23
+ ldi uart_rxtx,0x68
+ rcall UART_TX
+
+ ; testing ... DO NOT CONNECT LEDS BY NOW !!!
+ ldi hc595_sink,0xff
+ ldi hc595_source,0xff
+ rcall SET_HC595
+ ldi uart_rxtx,0x61
rcall UART_TX
MAIN:
T0_OVF:
reti
-UART_RX:
+UART_RECEIVE:
reti
out DDRB,tmp1
; g, rck, sck -> low / scl -> high
- cbi PORTB,(1<<0)|(1<<1)|(1<<2)
- sbi PORTB,(1<<3)
+ ldi tmp1,0x07
+ out PORTB,tmp1
+ sbi PORTB,3
; port d 6 -> output
- ldi tmp1,(1<<6)
- out DDRD,tmp1
+ sbi DDRD,6
; ser -> low
- cbi PORTD,(1<<6)
+ cbi PORTD,6
ret
+SET_HC595:
+
+ ; storage clock -> low
+ cbi PORTD,1
+
+ ; source driver
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_source,7
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_source,6
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_source,5
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_source,4
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_source,3
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_source,2
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_source,1
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_source,0
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; sink driver
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_sink,7
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_sink,6
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_sink,5
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_sink,4
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_sink,3
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_sink,2
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_sink,1
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; clock -> low
+ cbi PORTB,2
+ ; set ser line
+ cbi PORTD,6
+ sbrc hc595_sink,0
+ sbi PORTD,6
+ ; clock -> high
+ sbi PORTB,2
+
+ ; store to storage register
+ sbi PORTB,1
+
+ ret
--- /dev/null
+; timer functions
+
; baudrate
ldi tmp1,UART_BR_H
- sts UBRR0H,tmp1
+ out UBRRH,tmp1
ldi tmp1,UART_BR_L
- out UBRR0L,tmp1
+ out UBRRL,tmp1
; enable
ldi tmp1,(1<<RXEN)|(1<<TXEN)
- out UCSR0B,tmp1
+ out UCSRB,tmp1
; frame format -> 8n1
- ldi tmp1,(1<<UCSZ00)|(1<<UCSZ01)
- sts UCSR0C,tmp1
+ ldi tmp1,(1<<UCSZ0)|(1<<UCSZ1)
+ out UCSRC,tmp1
ret
UART_INT_RX_INIT:
- in tmp1,UCSR0B
- sbr tmp1,(1<<RXCIE0)
- out UCSR0B,tmp1
+ in tmp1,UCSRB
+ sbr tmp1,(1<<RXCIE)
+ out UCSRB,tmp1
ret
UART_INT_TX_INIT:
- in tmp1,UCSR0B
- sbr tmp1,(1<<TXCIE0)
- out UCSR0B,tmp1
+ in tmp1,UCSRB
+ sbr tmp1,(1<<TXCIE)
+ out UCSRB,tmp1
ret
UART_RX:
; get/store received byte
- sbis UCSR0A,RXC0
+ sbis UCSRA,RXC
rjmp UART_RX
- in uart_rxtx,UDR0
+ in uart_rxtx,UDR
ret
UART_TX:
; transmit content of uart_rxtx
- sbis UCSR0A,UDRE
+ sbis UCSRA,UDRE
rjmp UART_TX
- out UDR0,uart_rxtx
+ out UDR,uart_rxtx
ret