1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
| .nolist
.include "M2560DEF.INC"
.list
.def temp = R17
.def leds = R18
.def RS = R22
.cseg
.org 0
;Time Delay 2s
;Time Delay 2s
tick_MAX: .dw $127A ; int(0.5 + (Base_Clock/Prescaler) * Delay) --> int(0.5 * (1.000.000/64 * 2) == 31.250 ($7A12) Prescaler Used: 64
;Loading data from Program Memory (Flash - .cseg)
ldi ZH, high(tick_MAX*2)
ldi ZL, low(tick_MAX*2)
lpm R19, Z+
lpm R20, Z
;Defining 16-bits TOP value to compare
STS OCR1AH, R19
STS OCR1AL, R20
/* Setting WGM Mode (CTC) & Prescaler (1024)
==================================================================================================================
TCCR1A – Timer/Counter 1 Control Register A
Bit 7 6 5 4 3 2 1 0
(0x80) COM1A1 COM1A0 COM1B1 COM1B0 COM1C1 COM1C0 WGM11 WGM10 --> (TCCR1A)
==================================================================================================================
TCCR1B – Timer/Counter 1 Control Register B
Bit 7 6 5 4 3 2 1 0
(0x81) ICNC1 ICES1 – WGM13 WGM12 CS12 CS11 CS10 --> (TCCR1B)
==================================================================================================================
CTC Mode (0100): WGMn3 WGMn2 WGMn1 WGMn0 (WGMn3 & WGMn2 -> TCCR1B) (WGMn1 & WGMn0 -> TCCR1A)
Prescaler (011) : CS12 CS11 CS10 (CS12 CS11 CS10 -> TCCR1B)
*/
ldi temp, 0b00000000
STS TCCR1A, temp
ldi temp, 0b00001011
STS TCCR1B, temp
;Data Direction OUTPUT (DDRB - Output DDRC - Input)
LDI temp, 0b00000011
OUT DDRB, temp
LDI temp, 0b00000000
OUT DDRC, temp
;Setting Initial Condition S --> HIGH // R --> LOW
ldi RS, 0b00000010
OUT PORTB,RS
CALL delay_loop
;+++++++++++++++++++++++++++ Wait Pess a Button +++++++++++++++++++
waitpress:
in temp, PINC
cpi temp, 0b00000000 ;0x00 means none pressed
breq waitpress
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ldi RS, 0b00000001
OUT PORTB,RS
;+++++++++++++++++++++++++++ Wait Release +++++++++++++++++++++++++
waitrelease:
in temp, PINC
cpi temp, 0b00000001 ;0xFF means none pressed
breq waitrelease
CALL delay_loop
rjmp PC
;++++++++++++++++++++++++ Delay Loop ++++++++++++++++++++++
delay_loop:
in temp, TIFR1
cpi temp, 0b00000000
breq delay_loop
ldi temp, 1<<OCF1A
out TIFR1, temp
;After Loop S --> HIGH // R --> HIGH
ldi RS, 0b00000011
OUT PORTB,RS
ret
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |