initial ci (to continue work on compaq, nothing working by now!)
[my-code/atmel.git] / beginners / light_control.asm
1 ;
2 ; control the light connected to the pwm output pins
3 ;
4 ; author: hackbard@hackdaworld.org
5 ;
6
7 ; specify device
8 .include "../include/2313def.inc"
9
10 ; ------------------
11 ; interrupt vectors:
12 ; ------------------
13
14 ; reset
15 rjmp RESET
16 ; int0
17 reti
18 ; int1
19 reti
20 ; timer 1 capture
21 reti
22 ; timer 1 compare
23 reti
24 ; timer 1 overflow
25 reti
26 ; timer 0 overflow
27 reti
28 ; usart rx complete
29 rjmp UART_RX
30 ; usart data register empty
31 reti
32 ; usart tx complete
33 reti
34 ; analog comperator
35 reti
36 ; pin change interrupt
37 reti
38 ; timer/counter 1 compare match b
39 reti
40 ; timer/counter 0 compare match a
41 reti
42 ; timer/counter 0 compare match b
43 reti
44 ; usi start condition
45 reti
46 ; usi overflow
47 reti
48 ; eeprom ready
49 reti
50 ; watchdog timer overflow
51 reti
52
53 ; -----
54 ; code:
55 ; -----
56
57 RESET:
58         ; set stackpointer
59         ldi r16,low(RAMEND)     ; write top of ramend (lowbyte)
60         out SPL,r16             ; to stackpointer
61
62         ; rs232 init
63         ldi r16,12      ; "38.4k bps @ 8 mhz" in r16
64         out UBRR,r16    ; write to uart baudrate register
65         ldi r16,(1<<RXEN)|(1<<TXEN)|(1<<RXCIE)  ; enable rx/tx + rx interrupt
66         out UCSRB,r16   ; write to uart control register
67
68         ; pwm (OC0A=PB2 OC0B=PD5)
69         ; set as output
70         ldi r16,(1<<DDB2)
71         out DDRB,r16
72         ldi r16,(1<<DDD5)
73         out DDRD,r16
74         ; output 0
75         ldi r16,(1<<PINB2)
76         subi r16,0xff
77         out PORTB,r16
78         ldi r16,(1<<PIND5)|(1<<PIND6)
79         subi r16,0xff
80         out PORTD,r16
81         ; toggle OC0A/B on compare match / fast pwm
82         ldi r16,(1<<COM0A0)|(1<<COM0B0)|(1<<WGM00)|(1<<WGM01)
83         out TCCR0A,r16
84         ; top in OCR0A / no clock prescaling
85         ldi r16,(1<<WGM02)|(1<<CS00)
86         ; overflow interrupt enable
87         
88         ; initial pwm value 0x7f
89         ldi r16,0x7f
90         out OCR0A,r16
91         out OCR0B,r16
92
93         ; global interrupt enable
94         sei
95
96 MAIN:
97         rjmp MAIN
98
99 UART_RX:
100         reti