-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfirmware.asm
138 lines (121 loc) · 2.26 KB
/
firmware.asm
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
p5_5 equ 0cdh
p5m0 equ 0cah
rb0r0 equ 0
rb0r1 equ 1
rb0r2 equ 2
rb0r3 equ 3
rb0r4 equ 4
rb0r5 equ 5
rb0r6 equ 6
rb0r7 equ 7
rb1r0 equ 8
org 0
ljmp reset
set_rx:
clr txd
setb rxd
ret
org 0bh
ljmp on_timer0
on_timer0:
push acc
push b
push dph
push dpl
push psw
mov psw, #0
push rb0r0
push rb0r1
push rb0r2
push rb0r3
push rb0r4
push rb0r5
push rb0r6
push rb0r7
jb int1, on_timer0_exit
mov r7, #32h
mov r6, #0
lcall delay ; delay(50)
jb int1, on_timer0_exit
setb p5_5
lcall set_rx
sjmp $ ; while(1);
on_timer0_exit:
pop rb0r7
pop rb0r6
pop rb0r5
pop rb0r4
pop rb0r3
pop rb0r2
pop rb0r1
pop rb0r0
pop psw
pop dpl
pop dph
pop b
pop acc
reti
main:
mov p5m0, #0ffh
lcall init
lcall init_interrupts
main_loop:
jnb int0, main_loop_on
main_loop_off:
jnb p5_5, main_loop_continue
clr p5_5 ; turn on 230v
lcall set_tx
ljmp main_loop_continue
main_loop_on:
jb p5_5, main_loop_continue
setb p5_5 ; turn off 230v
lcall set_rx
main_loop_continue:
mov r7, #0b8h ; delay(3000)
mov r6, #0bh
lcall delay
sjmp main_loop
delay:
mov a, r7
dec r7
jnz delay_0
dec r6
delay_0:
dec a
orl a, r6
jz delay_exit
nop
nop
nop
mov r5, #0bh
mov r4, #0beh
delay_loop:
djnz r4, delay_loop
djnz r5, delay_loop
sjmp delay
delay_exit:
ret
reset:
mov r0, #7fh
clr a
memset_loop:
mov @r0, a
djnz r0, memset_loop
mov sp, #8
ljmp main
init:
clr p5_5
clr rxd
clr txd
setb int0
ljmp set_tx
init_interrupts:
mov rb1r0, #1
setb it1 ; falling edge of INT1
setb ea ; enable interrupts
setb ex1 ; enable INT1 interrupt which is weird as we need timer0 ?!
ret
set_tx:
clr rxd
setb txd
ret