ATTiny22 Software ändern

Gast #1500043
Lesenswert?

Hallo, ich habe ein kleines Problem ich habe im Internet eine 
Bauanleitung für eine IR-Einschalter gefunden den ich momentan nachbaue. 
Ich habe aber erst jetzt gemerkt das der IR-Einschalter das Relai nur 
ca.3 Sekunden schaltet und dann wieder ausschaltet. Gibt es eine 
Möglichkeit die .ASM Datei so abzuändern das das Relai solange schaltet 
bis man es ausschaltet. Sprich der gleiche IR-Befehl soll bewirken das 
das Relai schaltet oder wenn es schaltet es ausgeschaltet wird. Hier ist 
die .ASM Datei und der Link zu der Seite wo ich diese runter geladen 
habe http://home.arcor.de/desmo123/IREin.zip. Ich hoffe mir kann jemand 
helfen. Ich habe leider noch keine Ahnung von Controller Programmierung 
aber ich will mich jetzt etwas mehr damit beschäftigen. Ich habe zwar 
Erfahrung im Programmieren aber leider nur in C++. Danke.

1
;**** T I T L E    R C 5 T I N Y L A M P    ***************************************
2

3
;*
4

5
;* Title    :RC5TinyLamp 
6

7
;* Version    :1.0
8

9
;* Date      :00.05.31
10

11
;* Last updated    :00.08.19
12

13
;* Target    :ATTiny22 
14

15
;* Crystal frequency  :1Mhz intern oscillator
16

17
;*
18

19
;* Support    :J.v.Boxtel
20

21
;* Support E-mail  :boxteldoelen@hetnet.nl
22

23
;*
24

25
;* Code Size    :149 words 
26

27
;* Low Register Usage  :5 
28

29
;* High Register Usage  :11 
30

31
;* Interrupt Usage  :
32

33
;* Based on     :avr410 rc5, avr100 EEprom access, RC5Lamp
34

35
;*
36

37
;* DESCRIPTION
38

39
;* This Application switch a lamp on/off with RC5 if
40

41
;* system and lamp_nr are correct
42

43
;* system and lamp_nr are can be change with the "learn_button"
44

45
;* pB2 (pin7) is IRinput, pB3 (pin2) is learn button, pB0 (pin5) is output
46

47
;* pB3 learbutton open=normal groud=learn
48

49
;* pB1 (pin6) ext interrupt 
50

51
;***************************************************************************
52

53

54

55
.include "c:\avrtools\appnotes\tn22def.inc"
56

57

58

59
  .equ INPUT    =2   ;PB2 input for ir reciever
60

61

62

63
  .def S      =R0   ;Storage for the Status Register
64

65
  .def inttemp     =R1   ;Temporary variable for ISR
66

67
  .def ref1   =R2   ;Reference for timing
68

69
  .def ref2   =R3    ;Reference for timing
70

71
  .def EEdrd       =R4   ;read data byte from EEprom
72

73
  .def temp   =R16   ;Temporary variable
74

75
  .def timerL   =R17   ;Timing variable updated every 14 us
76

77
  .def timerH   =R18   ;Timing variable updated every 16 ms
78

79
  .def system   =R19   ;Address data received
80

81
  .def command   =R20   ;Command received
82

83
  .def bitcnt   =R21   ;Counter
84

85
  .def SYS_ADDR   =R22   ;Systen addres to respond on
86

87
  .def LAMP_NR   =R23   ;Lamp number to respond on
88

89
  .def EEard       =R24   ;address to read from
90

91
  .def EEdwr   =R25   ;data byte to write to EEPROM
92

93
  .def EEawr   =R26   ;address byte to write to
94

95
  .def tim1   =R27
96

97
  .def tim2   =R28
98

99
  .equ zeit   =255
100

101

102

103
.cseg
104

105
.org 0
106

107

108

109
  rjmp reset
110

111

112

113
;********************************************************************
114

115
;* "TIM0_OVF" - Timer/counter overflow interrupt handler
116

117
;*
118

119
;* The overflow interrupt increments the "timerL" and "timerH"
120

121
;* every 64us and 16,384us.
122

123
;*
124

125
;* Crystal Frequency is 1 MHz
126

127
;*
128

129
;* Number of words:
130

131
;* Number of cycles:6 + reti
132

133
;* Low registers used:1
134

135
;* High registers used: 3
136

137
;* Pointers used:0
138

139
;********************************************************************
140

141
.org OVF0addr
142

143
TIM0_OVF:
144

145
  in S,sreg     ; Store SREG
146

147
  inc timerL     ; Updated every 64us
148

149
  inc inttemp    ;   4 MHz clock
150

151
  inc timerL     ; Updated every 64us
152

153
  inc inttemp    ;   3 MHz clock
154

155
  inc timerL     ; Updated every 64us
156

157
  inc inttemp    ;   2 MHz clock
158

159
  inc timerL     ; Updated every 64us
160

161
  inc inttemp    ;   1 MHz clock
162

163
  brne TIM0_OVF_exit
164

165

166

167
  inc timerH     ; if 256th int inc timer
168

169

170

171
     TIM0_OVF_exit:
172

173
  out sreg,S     ; Restore SREG
174

175
  reti
176

177

178

179
reset:
180

181
  ldi temp,1     ;Timer/Counter 0 clocked at CK
182

183
  out TCCR0,temp    ;  Timer counter 0 prescaler
184

185
  ldi temp,1<<TOIE0   ;Enable Timer0 overflow interrupt
186

187
  out TIMSK,temp    ;  set timer interrupt mask
188

189
  ldi temp,0x01     ;PORTB 0 as output
190

191
  out DDRb,temp    ;  set direction
192

193
  ldi temp,15    ;load 15 for init pullup on pB1,pB2;pB3 
194

195
  out portb,temp    ;  and set defaul lamp off after reset
196

197
  
198

199
  ldi temp,ramend    ;init stack pointer
200

201
  out spl,temp    ;  ram_end to spl
202

203
  
204

205
  sei       ;Enable global interrupt
206

207
        cbi $18,0
208

209

210

211
main:  
212

213
  rcall detect    ;Call RC5 detect routine
214

215
  
216

217
  cpi command,0xFF  ;If no or wrong code return to main
218

219
  breq main
220

221
  
222

223
  in temp,pinb    ;learbutton test
224

225
  andi temp,$08    ;  test pb3 only (learnbutton)
226

227
  cpi temp,$08    ;  high then main1
228

229
  breq main1    
230

231
    
232

233
          
234

235
  mov  EEdwr,system  ;store new system addres in EEprom
236

237
  ldi  EEawr,$00  ;  at addres 00
238

239
  rcall  EEWrite    ;  store system in EEPROM location $0000
240

241

242

243
  andi command,0x3F  ;remove toggle bit
244

245
  mov  EEdwr,command  ;store new command in EEprom
246

247
  ldi  EEawr,$01  ;  at addres $0001
248

249
  rcall  EEWrite    ;  store command in EEPROM location $0001
250

251
    
252

253
    main1:  
254

255
  rcall readin    ;readin the system-addres and lamp_nr
256

257
  
258

259
  cp system,sys_addr  ;correct addres? else return to main
260

261
  brne main
262

263
  
264

265
  andi command,0x3F  ;remove toggle bit
266

267
  cp command,lamp_nr  ;correct lamp nr? else return to main
268

269
  brne main
270

271
invert:
272

273
  brts invert1    ;if T bit is 0 then lamp on
274

275
  set      ;set t bit (lamp on code)
276

277
  cbi $18,0    ;port pin low =lamp on
278

279
  rjmp wait     
280

281
     invert1:      ;if t bit is 1 then lamp off
282

283
        sbi $18,0    ;set pin high
284

285
  rcall pause    ;Pause
286

287
        rcall pause    ;Pause
288

289
  cbi $18,0    ;set pin low
290

291
     wait:
292

293
  rcall detect    ;Call RC5 detect routine and
294

295
  cpi command,0xFF  ;   wait until button is released
296

297
  brne wait    ;
298

299
    rjmp main    ;
300

301
  
302

303
readin:
304

305
  ldi  EEard,$00  ;load addres
306

307
  rcall  EERead    ;read address $00 (System addres)
308

309
  mov  sys_addr,EEdrd  ;load system addres
310

311
  
312

313
  ldi  EEard,$01  ;load addres
314

315
  rcall  EERead    ;read address $01 (command number)
316

317
  mov  lamp_nr,EEdrd  ;command mumber is lamp number
318

319
  
320

321
  ret
322

323
  
324

325
;***************************************************************************
326

327
;* 
328

329
;* EERead
330

331
;*
332

333
;* This subroutine waits until the EEPROM is ready to be programmed, then
334

335
;* reads the register variable "EEdrd" from address "EEardh:EEard"
336

337
;*
338

339
;* Number of words  :1200 ; 5 + return
340

341
;*      :8515 ; 6 + return
342

343
;* Number of cycles  :1200 ; 8 + return (if EEPROM is ready)
344

345
;*      :8515 ; 9 + return (if EEPROM is ready)
346

347
;* Low Registers used  :1 (EEdrd)
348

349
;* High Registers used:  :2 (EEard,EEardh)
350

351
;*
352

353
;***************************************************************************
354

355

356

357

358

359
EERead:
360

361
  sbic  EECR,EEWE  ;if EEWE not clear
362

363
  rjmp  EERead    ;    wait more
364

365
  out  EEAR,EEard  ;output address for 1200
366

367

368

369

370

371
  sbi  EECR,EERE  ;set EEPROM Read strobe
372

373
        ;This instruction takes 4 clock cycles since
374

375
        ;it halts the CPU for two clock cycles
376

377
  in  EEdrd,EEDR  ;get data
378

379
  ret
380

381

382

383
EEWrite:
384

385
  sbic  EECR,EEWE  ;if EEWE not clear
386

387
  rjmp  EEWrite    ;    wait more
388

389

390

391
  out  EEARL,EEawr  ;output address low 
392

393

394

395
  out  EEDR,EEdwr  ;output data
396

397
  sbi   EECR,EEMWE  ;  set master write enable
398

399
  sbi  EECR,EEWE  ;  set EEPROM Write strobe
400

401
        ;  This instruction takes 4 clock cycles since
402

403
        ;  it halts the CPU for two clock cycles
404

405
  ret
406

407

408

409
pause1:
410

411
  ldi tim2,zeit    ;Lade Wert in Register
412

413
  s2:
414

415
  dec  tim2    ;tim2 - 1
416

417
  brne  s2    ;Wenn tim2 > 0 dann springe nach s1
418

419
  ret
420

421

422

423
pause:
424

425
  ldi tim1,zeit    ;Lade Wert in Register
426

427
  s1:
428

429
  rcall pause1    ;Rufe Schleife1 auf
430

431
  dec  tim1    ;tim1 - 1
432

433
  brne  s1    ;Wenn tim1 > 0 dann springe nach s1
434

435
  ret
436

437

438

439
;********************************************************************
440

441
;* "detect" - RC5 decode routine
442

443
;*
444

445
;* This subroutine decodes the RC5 bit stream applied on PORTB
446

447
;* pin "INPUT".
448

449
;*
450

451
;* If success: The command and system address are
452

453
;* returned in "command" and "system".
454

455
;* Bit 6 of "command" holds the toggle bit.
456

457
;*
458

459
;* If failed: $FF in both "system" and "command"
460

461
;*
462

463
;* Crystal frequency is 4MHz
464

465
;*
466

467
;* Number of words:72
468

469
;* Low registers used: 3
470

471
;* High registers used: 6
472

473
;* Pointers used: 0
474

475
;********************************************************************
476

477
detect0:      ;only for test
478

479
  ldi command,0x7
480

481
  ldi system,0x05
482

483
  ret
484

485
  
486

487
detect:
488

489
  clr inttemp     ; Init Counters
490

491
  clr timerH
492

493
     detect1:
494

495
  clr timerL
496

497
     detect2:
498

499
  cpi timerH,8    ;If line not idle within 131ms
500

501
  brlo dl1
502

503
  rjmp fault     ;then exit
504

505
     dl1:
506

507
  cpi timerL,55    ;If line low for 3.5ms
508

509
  brge start1     ;then wait for start bit
510

511
  sbis PINB,INPUT   ;If line is
512

513
  rjmp detect1     ;low - jump to detect1
514

515
  rjmp detect2     ;high - jump to detect2
516

517
     start1:
518

519
  cpi timerH,8     ;If no start bit detected
520

521
  brge fault     ;within 130ms then exit
522

523
  sbic PINB,INPUT   ;Wait for start bit
524

525
  rjmp start1
526

527
  clr timerL     ;Measure length of start bit
528

529
     start2:
530

531
  cpi timerL,17     ;If startbit longer than 1.1ms,
532

533
  brge fault     ;exit
534

535
  sbis PINB,INPUT
536

537
  rjmp start2     ;Positive edge of 1st start bit
538

539
  mov temp,timerL   ;timer is 1/2 bit time.
540

541

542

543
  clr timerL
544

545
  mov ref1,temp
546

547
  lsr ref1
548

549
  mov ref2,ref1
550

551
  add ref1,temp     ;ref1 = 3/4 bit time
552

553
  lsl temp
554

555
  add ref2,temp     ;ref2 = 5/4 bit time
556

557
     start3:
558

559
  cp timerL,ref1     ;If high period St2 > 3/4 bit time
560

561
  brge fault     ;exit
562

563
  sbic PINB,INPUT   ;Wait for falling edge start bit 2
564

565
  rjmp start3
566

567
  clr timerL
568

569
  ldi bitcnt,12     ;Receive 12 bits
570

571
  clr command
572

573
  clr system
574

575
     sample:
576

577
  cp timerL,ref1     ;Sample INPUT at 1/4 bit time
578

579
  brlo sample
580

581
  sbic PINB,INPUT
582

583
  rjmp bit_is_a_1   ;Jump if line high
584

585
     bit_is_a_0:
586

587
  clc       ;Store a ’0’
588

589
  rol command
590

591
  rol system
592

593
        ;Synchronize timing
594

595
     bit_is_a_0a:
596

597
  cp timerL,ref2     ;If no edge within 3/4 bit time
598

599
  brge fault     ;exit
600

601
  sbis PINB,INPUT   ;Wait for rising edge
602

603
  rjmp bit_is_a_0a   ;in the middle of the bit
604

605
  clr timerL
606

607
  rjmp nextbit
608

609
     bit_is_a_1:
610

611
  sec       ;Store a ’1’
612

613
  rol command
614

615
  rol system
616

617
        ;Synchronize timing
618

619
     bit_is_a_1a:
620

621
  cp timerL,ref2     ;If no edge within 3/4 bit time
622

623
  brge fault     ;exit
624

625
  sbic PINB,INPUT   ;Wait for falling edge
626

627
  rjmp bit_is_a_1a   ;in the middle of the bit.
628

629
  clr timerL
630

631
     nextbit:
632

633
  dec bitcnt     ;If bitcnt > 0
634

635
  brne sample     ;get next bit
636

637
        ;All bits sucessfully received!
638

639
  mov temp,command   ;Place system bits in "system"
640

641
  rol temp
642

643
  rol system
644

645
  rol temp
646

647
  rol system
648

649

650

651
  andi command,0b01111111
652

653
  andi system,0x1F
654

655
  ret
656

657

658

659
     fault:
660

661
  ser command     ;Both "command" and "system"
662

663
  ser system     ;0xFF indicates failure
664

665
  ret
666

667

668

669
  .eseg
670

671
  .org 0
672

673
table:
674

675
  .db $00,$04  ;KTV1, button 4 default settings
Moderator (Firma: Titel) Persönliche Seite #1500051
Lesenswert?

Das ist mir zu unübersichtlich...  :-/
1
Wichtige Regeln - erst lesen, dann posten!
2
    * Längeren Sourcecode nicht im Text einfügen, sondern als Dateianhang
Ein Quelltext wird nichtlesbarer, wenn jedesmal eine Leerzeile eingefügt 
ist.


> Gibt es eine Möglichkeit die .ASM Datei so abzuändern das das Relai
> solange schaltet bis man es ausschaltet.
Ja, sicher...
Gast #1500146
Lesenswert?

Hi

Ich würde diesen Teil:

>invert:
>    brts invert1    ;if T bit is 0 then lamp on
>    set      ;set t bit (lamp on code)
>    cbi $18,0    ;port pin low =lamp on
>    rjmp wait
>invert1:      ;if t bit is 1 then lamp off
>    sbi $18,0    ;set pin high
>    rcall pause    ;Pause
>    rcall pause    ;Pause
>    cbi $18,0    ;set pin low

durch:

invert:
     in temp; PortB
     ldi r29,1<<PB0
     eor temp,r29
     out PortB,temp

ersetzen. Damit sollte, wenn ich nichts grundlegendes übersehen habe, 
die Lampe bei jedem erkannten richtigen Code umgeschaltet werden.

MfG Spess
Gast #1508894
Lesenswert?

Ich habe jetzt noch ein kleines Problem bei dem mir sicher jemand helfen 
kann. Das Problem ist wie wandele ich das .ASM File in ein .HEX File um. 
Wie ich weiter oben schon geschrieben habe habe ich den Code nicht 
selber geschrieben. Ich habe das umwandeln schon mit AVR-Studio versucht 
aber da bekomme ich immer mehrere Fehlermeldungen.
Gast #1508907
Lesenswert?

Das sind diese 3 Fehlermeldungen:

C:\Dokumente und Einstellungen\Markus\Eigene Dateien\d.asm(28): error: 
Cannot find include file: c:\avrtools\appnotes\tn22def.inc
C:\Dokumente und Einstellungen\Markus\Eigene Dateien\d.asm(71): error: 
Use of undefined or forward referenced symbol 'OVF0addr' in .org
C:\Dokumente und Einstellungen\Markus\Eigene Dateien\d.asm(73): error: 
Overlap in .cseg: addr=0x0 conflicts with 0x0:0x1

Assembly failed, 3 errors, 0 warnings

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren