Forum: Mikrocontroller und Digitale Elektronik RC5 mit Assembler


von M. Н. (Gast)


Lesenswert?

Hallo Leute.

Ich habe mir mal ein paar Projekte mit RC5-Dekodierung im Internet 
angeschaut. Habe mir jetzt mal folgenden Code für den atmega 8515 
zusammegebastelt. Aber es funktioniert nicht. Die fertige routine von 
Atmel liefert immer 0xFF zurück (Fehler)

Was mache ich falsch??

Gruß M.H.

Der Code:
1
.include <m8515def.inc>
2
3
4
.equ  INPUT    =0  ;PD2
5
.equ  SYS_ADDR  =0  ;The system address
6
7
8
.def  S  =R0
9
.def  inttemp  =R1
10
.def  ref1  =R2
11
.def  ref2  =R3
12
13
.def  temp  =R16
14
15
.def  timerL  =R17
16
.def  timerH  =R16
17
18
.def  system  =R19
19
.def  command  =R20
20
21
.def  bitcnt  =R21
22
23
.cseg
24
.org $00
25
rjmp reset
26
.org OVF0addr
27
TIM0_OVF:  in  S,sreg
28
    inc  timerL    ;Updated every 64us
29
    inc  inttemp
30
    brne  TIM0_OVF_exit
31
    inc  timerH
32
33
TIM0_OVF_exit:  out  sreg,S
34
    reti
35
36
37
reset:    
38
ldi r16, low(RAMEND)
39
ldi r17, high(RAMEND)
40
out spl, r16
41
out sph, r17
42
;ldi    temp,low(RAMEND)  ;Initialize stackpointer
43
    ;out  SPL,temp      
44
    ;ldi    temp,high(RAMEND)  ; Commented out since 1200 does not hae SRAM
45
    ;out  SPH,temp
46
  
47
    ldi  temp,1    ;Timer/Counter 0 clocked at CK
48
    out  TCCR0,temp
49
50
    ldi  temp,(1<<TOIE0)  ;Enable Timer0 overflow interrupt
51
    out  TIMSK,temp
52
53
  
54
    ldi temp, 0
55
    out ddrd, temp
56
  ldi r16, 255
57
  out ddrb, r16
58
out portd, r16
59
    sei  
60
        ;Enable gobal interrupt
61
    ; ============================= 
62
63
64
65
66
start:
67
68
rcall detect
69
and command, system
70
cpi command, 0xff
71
breq o
72
sbi portb, 0
73
rjmp start
74
o:
75
cbi portb, 0
76
rjmp start
77
78
detect:    
79
80
clr  inttemp
81
    clr  timerH
82
83
detect1:  clr  timerL
84
85
detect2:  cpi  timerH,8  ;If line not idle within 131ms
86
    brlo  dl1
87
    rjmp  fault    ;  then exit
88
89
dl1:    cpi  timerL,55  ;If line low for 3.5ms
90
    brge  start1    ;   then wait for start bit
91
92
    sbis  PIND,INPUT  ;If line is
93
    rjmp  detect1    ;   low  - jump to detect1
94
    rjmp  detect2    ;   high - jump to detect2
95
96
97
start1:    cpi  timerH,8  ;If no start bit detected
98
    brge  fault    ;within 130ms then exit
99
100
    sbic  PIND,INPUT  ;Wait for start bit
101
    rjmp  start1
102
103
104
    clr  timerL    ;Measure length of start bit
105
    
106
start2:    cpi  timerL,17  ;If startbit longer than 1.1ms,
107
    brge  fault    ;   exit
108
109
    sbis  PIND,INPUT
110
    rjmp  start2
111
          ;Positive edge of 1st start bit
112
113
    mov  temp,timerL  ;timer is 1/2 bit time
114
    clr  timerL
115
116
    mov  ref1,temp
117
    lsr  ref1
118
    mov  ref2,ref1
119
    add  ref1,temp  ;ref1 = 3/4 bit time
120
    lsl  temp
121
    add  ref2,temp  ;ref2 = 5/4 bit time
122
123
124
start3:    cp  timerL,ref1  ;If high periode St2 > 3/4 bit time
125
    brge  fault    ;   exit
126
127
    sbic  PIND,INPUT  ;Wait for falling edge start bit 2
128
    rjmp  start3
129
130
    clr  timerL
131
    ldi  bitcnt,12  ;Receive 12 bits
132
    clr  command
133
    clr  system
134
135
136
sample:    cp  timerL,ref1  ;Sample INPUT at 1/4 bit time
137
    brlo  sample
138
139
    sbic  PIND,INPUT
140
    rjmp  bit_is_a_1  ;Jump if line high
141
142
143
bit_is_a_0:  clc      ;Store a '0'
144
    rol  command
145
    rol  system
146
147
          ;Synchronize timing
148
bit_is_a_0a:  cp  timerL,ref2  ;If no edge within 3/4 bit time
149
    brge  fault    ;   exit
150
    sbis  PIND,INPUT  ;Wait for rising edge
151
    rjmp  bit_is_a_0a  ;in the middle of the bit
152
153
    clr  timerL
154
    rjmp  nextbit
155
156
bit_is_a_1:  sec      ;Store a '1'
157
    rol  command
158
    rol  system
159
          ;Synchronize timing
160
bit_is_a_1a:  cp  timerL,ref2  ;If no edge within 3/4 bit time
161
    brge  fault    ;   exit
162
    sbic  PIND,INPUT  ;Wait for falling edge
163
    rjmp  bit_is_a_1a  ;in the middle of the bit
164
165
    clr  timerL
166
167
nextbit:  dec  bitcnt    ;If bitcnt > 0
168
    brne  sample    ;   get next bit
169
170
171
;All bits sucessfully received!
172
    mov  temp,command  ;Place system bits in "system"
173
    rol  temp
174
    rol  system
175
    rol  temp
176
    rol  system
177
178
    bst  system,5  ;Move toggle bit
179
    bld  command,6  ;to "command"
180
181
          ;Clear remaining bits
182
    andi  command,0b01111111
183
    andi  system,0x1F
184
185
    ret
186
187
fault:    ser  command    ;Both "command" and "system"
188
    ser  system    ;0xFF indicates failure
189
    
190
    ret
191
.exit

von Stulle (Gast)


Lesenswert?

Die MCU in der  Atmel App. läuft mit 4Mhz Taktfrequenz !
also alle 64µsec. ein Interupt , nochmal alles überprf.
oder deine Fernbedienung ist keine RC5
mfg

von Spess53 (Gast)


Lesenswert?

Hi

Und dein Controller läuft auch mit 4MHz?

MfG Spess

von M. Н. (Gast)


Lesenswert?

Sorry:
Ich hab vergessen zu sagen, dass er mit 4 MHz ext. quarz läuft.

Hab mehrere Fernbedienungen versucht.

ach, noch was: wenn kein signal reinkommt, liegt der Output vom 
empfänger auf high. Ist das normal?

Gruß M.H.

von Stefan B. (stefan) Benutzerseite


Lesenswert?

M. H. schrieb:

> ach, noch was: wenn kein signal reinkommt, liegt der Output vom
> empfänger auf high. Ist das normal?

Als ich das damals mit dem TSOP1736 auf dem Pollin-Funk-Board in C 
(Artikelsammlung) gemacht hatte, war es so. Dein Programmcode mit 
eingeschaltetem Pullup-Widerstand an PD2 deutet auch darauf hin. Um 
deine Frage exakt zu beantworten, müsste man wissen, welchen Empfänger 
du benutzt und wie der angeschlossen ist.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.