Added the projects

pull/1/head
Ondřej Hruška 10 years ago
parent 9c04c8f3f3
commit 868f28bff1
  1. 21
      .gitignore
  2. 517
      ASM_OLD/DS1820/RGB teploměr krok 10/ds1820LEDk10.asm
  3. 496
      ASM_OLD/DS1820/RGB teploměr krok 20/ds1820LEDk20.asm
  4. 354
      ASM_OLD/DS1820/Univerzal OneWire/ds1820u.asm
  5. BIN
      ASM_OLD/DS1820/schema/PB250219.JPG
  6. BIN
      ASM_OLD/DS1820/schema/PB250221.JPG
  7. BIN
      ASM_OLD/DS1820/schema/PB250223.JPG
  8. BIN
      ASM_OLD/DS1820/schema/obvod.png
  9. BIN
      ASM_OLD/DS1820/schema/sensor.jpg
  10. 94
      ASM_OLD/Detektor tmy s 1 led/tma.asm
  11. 2
      ASM_OLD/EEPROM/t13-EEPROM_nahoda/AvrBuild.bat
  12. 1
      ASM_OLD/EEPROM/t13-EEPROM_nahoda/EEPROM_nahoda.aps
  13. 108
      ASM_OLD/EEPROM/t13-EEPROM_nahoda/EEPROM_nahoda.asm
  14. 2
      ASM_OLD/EEPROM/t13-EEPROM_nahoda/EEPROM_nahoda.eep
  15. 289
      ASM_OLD/EEPROM/t13-EEPROM_nahoda/EEPROM_nahoda.map
  16. 1
      ASM_OLD/EEPROM/t13-EEPROM_nahoda/eeprom_nahoda.aws
  17. 32
      ASM_OLD/EEPROM/t13-EEPROM_nahoda/labels.tmp
  18. 2
      ASM_OLD/EEPROM/t13-EEPROM_read/AvrBuild.bat
  19. 1
      ASM_OLD/EEPROM/t13-EEPROM_read/EEPROM_read.aps
  20. 49
      ASM_OLD/EEPROM/t13-EEPROM_read/EEPROM_read.asm
  21. 2
      ASM_OLD/EEPROM/t13-EEPROM_read/EEPROM_read.eep
  22. 283
      ASM_OLD/EEPROM/t13-EEPROM_read/EEPROM_read.map
  23. 1
      ASM_OLD/EEPROM/t13-EEPROM_read/eeprom_read.aws
  24. 27
      ASM_OLD/EEPROM/t13-EEPROM_read/labels.tmp
  25. 351
      ASM_OLD/HD44780/lcd_default.asm
  26. 215
      ASM_OLD/HD44780/pokusy/cocacola.asm
  27. 305
      ASM_OLD/HD44780/pokusy/geocache.asm
  28. 305
      ASM_OLD/HD44780/pokusy/krokodyl.asm
  29. 311
      ASM_OLD/HD44780/pokusy/krokodyl_real.asm
  30. 228
      ASM_OLD/HD44780/pokusy/lcd.asm
  31. 380
      ASM_OLD/HD44780/pokusy/lcd_default_4row.asm
  32. 89
      ASM_OLD/IR insect/prijimac 36kHz - modulace/rcvm.asm
  33. 66
      ASM_OLD/IR insect/prijimac 36kHz - ochrana x zakmitum - preklapeni/delic.asm
  34. 63
      ASM_OLD/IR insect/prijimac 36kHz - ochrana x zakmitum - prosty/tlac.asm
  35. 252
      ASM_OLD/IR insect/switch controlled/brouk-sw.asm
  36. 124
      ASM_OLD/IR insect/vysilac 36kHz - modulace/36kHzm.asm
  37. 70
      ASM_OLD/IR insect/vysilac 36kHz/36kHz.asm
  38. 131
      ASM_OLD/KOSTKA-nelinearni/a/dice2a.asm
  39. 146
      ASM_OLD/KOSTKA-nelinearni/dice2b.asm
  40. 150
      ASM_OLD/KOSTKA-nelinearni/dice2c.asm
  41. 111
      ASM_OLD/KOSTKA/dice.asm
  42. 2
      ASM_OLD/OBSLUHA_PORTU/m16-HAD_leze/AvrBuild.bat
  43. 1
      ASM_OLD/OBSLUHA_PORTU/m16-HAD_leze/efekty_LED.aps
  44. 87
      ASM_OLD/OBSLUHA_PORTU/m16-HAD_leze/efekty_LED.asm
  45. 621
      ASM_OLD/OBSLUHA_PORTU/m16-HAD_leze/efekty_LED.map
  46. 88
      ASM_OLD/OBSLUHA_PORTU/m16-HAD_leze/efekty_LED2
  47. 1
      ASM_OLD/OBSLUHA_PORTU/m16-HAD_leze/efekty_led.aws
  48. 33
      ASM_OLD/OBSLUHA_PORTU/m16-HAD_leze/labels.tmp
  49. 2
      ASM_OLD/OBSLUHA_PORTU/m16_LED_display/AvrBuild.bat
  50. 1
      ASM_OLD/OBSLUHA_PORTU/m16_LED_display/LED_display.aps
  51. 74
      ASM_OLD/OBSLUHA_PORTU/m16_LED_display/LED_display.asm
  52. 613
      ASM_OLD/OBSLUHA_PORTU/m16_LED_display/LED_display.map
  53. 29
      ASM_OLD/OBSLUHA_PORTU/m16_LED_display/labels.tmp
  54. 1
      ASM_OLD/OBSLUHA_PORTU/m16_LED_display/led_display.aws
  55. 53
      ASM_OLD/OBSLUHA_PORTU/t13-Navesti_vlak/pokus.asm
  56. 287
      ASM_OLD/OBSLUHA_PORTU/t13-Navesti_vlak/pokus.map
  57. 53
      ASM_OLD/OBSLUHA_PORTU/t13-Vstup_button/Vstup_button.asm
  58. 97
      ASM_OLD/ONDIS displej 8 R-G ledek/ondis01.asm
  59. 549
      ASM_OLD/SETI/01/seti.asm
  60. 597
      ASM_OLD/SETI/02/seti2.asm
  61. 605
      ASM_OLD/SETI/03/seti3.asm
  62. 630
      ASM_OLD/SETI/04/seti4.asm
  63. 175
      ASM_OLD/SETI/seti - pípač pro Punťu/punta.asm
  64. 630
      ASM_OLD/SETI/seti5.asm
  65. 151
      ASM_OLD/Světelné efekty/Blikac prolinani 5/bezici-svetlo-prol.asm
  66. 53
      ASM_OLD/Světelné efekty/Blikač 2 led/pokus.asm
  67. 287
      ASM_OLD/Světelné efekty/Blikač 2 led/pokus.map
  68. 100
      ASM_OLD/Světelné efekty/Pulzující LED/pulzovani.asm
  69. 179
      ASM_OLD/Světelné efekty/RGB LED efekty/prepinani nekolika odstinu/prepinani 12 barev/rgbdrivch12.asm
  70. 133
      ASM_OLD/Světelné efekty/RGB LED efekty/prepinani nekolika odstinu/prepinani 6 barev/rgbdrivch.asm
  71. 156
      ASM_OLD/Světelné efekty/RGB LED efekty/prepinani nekolika odstinu/prepinani 9 barev/rgbdrivch9.asm
  72. 493
      ASM_OLD/bomba/bomba.asm
  73. 233
      ASM_OLD/bomba/tmp/bomba.asm
  74. 439
      ASM_OLD/bomba/tmp/bomba2.asm
  75. 462
      ASM_OLD/bomba/tmp/bomba2b.asm
  76. 180
      ASM_OLD/bomba/tmp/bomba_mx.asm
  77. 80
      ASM_OLD/pokusy/slowdown/sldn.asm
  78. 96
      ASM_OLD/t13_PASTICKA_morse/t13_PASTICKA_morse.asm
  79. 130
      ASM_OLD/timer/citac/timer.asm
  80. 87
      ASM_OLD/utility/3-kanalova simulovana PWM/rgbdriv.asm
  81. 2
      ASM_OLD/utility/EEPROM/t13-EEPROM_nahoda/AvrBuild.bat
  82. 1
      ASM_OLD/utility/EEPROM/t13-EEPROM_nahoda/EEPROM_nahoda.aps
  83. 108
      ASM_OLD/utility/EEPROM/t13-EEPROM_nahoda/EEPROM_nahoda.asm
  84. 2
      ASM_OLD/utility/EEPROM/t13-EEPROM_nahoda/EEPROM_nahoda.eep
  85. 289
      ASM_OLD/utility/EEPROM/t13-EEPROM_nahoda/EEPROM_nahoda.map
  86. 1
      ASM_OLD/utility/EEPROM/t13-EEPROM_nahoda/eeprom_nahoda.aws
  87. 32
      ASM_OLD/utility/EEPROM/t13-EEPROM_nahoda/labels.tmp
  88. 2
      ASM_OLD/utility/EEPROM/t13-EEPROM_read/AvrBuild.bat
  89. 1
      ASM_OLD/utility/EEPROM/t13-EEPROM_read/EEPROM_read.aps
  90. 49
      ASM_OLD/utility/EEPROM/t13-EEPROM_read/EEPROM_read.asm
  91. 2
      ASM_OLD/utility/EEPROM/t13-EEPROM_read/EEPROM_read.eep
  92. 283
      ASM_OLD/utility/EEPROM/t13-EEPROM_read/EEPROM_read.map
  93. 1
      ASM_OLD/utility/EEPROM/t13-EEPROM_read/eeprom_read.aws
  94. 27
      ASM_OLD/utility/EEPROM/t13-EEPROM_read/labels.tmp
  95. 130
      ASM_OLD/utility/citac/timer.asm
  96. 53
      ASM_OLD/utility/osetreni zakmitu tlacitek/Vstup_button.asm
  97. 5
      README.md
  98. 437
      bomb-countdown/main.c
  99. 74
      bomb-countdown/makefile
  100. 69
      dice/Makefile
  101. Some files were not shown because too many files have changed in this diff Show More

21
.gitignore vendored

@ -1,29 +1,14 @@
# Object files
*.o
*.ko
*.obj
*.elf
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lst
*~
*.bak
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

@ -0,0 +1,517 @@
.DEVICE ATtiny13
.LIST
.LISTMAC
;běží na 9.6MHz, ckdiv8=0 (zapnuto)
;avrdude příkaz pro FUSEs: -U lfuse:w:0x6a:m -U hfuse:w:0xff:m
;LFUSE: 0x6A
;HFUSE: 0xFF
;aliasy pointerů
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
.def ARG = r20 ;registr pro předání hodnoty rutinám
;počátek paměti SRAM pro uložení přečtené teploty (9 bajtů)
.equ SRAM_t_H = 0x00
.equ SRAM_t_L = 0x00
;komunikační kanál pro ds1820
.equ PORTn = PORTB
.equ PINn = PINB
.equ DDRn = DDRB
.equ n = 0 ;pin pro komunikaci s DS1820
; Č A S O V Á N Í
;délka 1 cyklu = T = 1/f
; tXXXu = [XXX / (4*T)] - 2
; (ldi, rcall a ret zabere 8 cyklů)
; nejnižší hodnota je 1 ... 12T čekání
; attiny13@9.6MHz+CKDIV8...T=0.83333us
.equ t480u = 142
.equ t410u = 120
.equ t70u = 19
.equ t64u = 17
.equ t60u = 16
.equ t54u = 14
.equ t10u = 1
;registry pro CRC rutinu
.def rChar = r19
.def rCount = r18 ;počet bajtů
.def rBitCount = r17
.def rTemp = r16
.def rCRC8 = r21 ;výsledek (musí být jiný než ARG)
.def R = r4
.def G = r5
.def B = r6
.def tL = r2
.def tH = r3
;6us je obvykle moc málo pro volání DELAY
.MACRO t6uDELAY
ldi r16,2 ;pro attiny13@9.6MHz+CKDIV8 je to 2 x 4T = 8T = 8 x 0.83333us = 6us čekání
t6u: nop ;pozor! některé překladače labely v makrech nepodporují!
dec r16
brne t6u
.ENDMACRO
;ovládání sběrnice
.MACRO BUS_L
cbi PORTn,n
sbi DDRn,n ;pin n výstupní, výstup 0
.ENDMACRO
.MACRO BUS_H
sbi PORTn,n
cbi DDRn,n ;pin n vstupní, pullup zapnutý (+ doporučeno 4.7k externí pullup)
.ENDMACRO
.MACRO RGB_OFF
cbi PORTB,1
cbi PORTB,2
cbi PORTB,3
.ENDMACRO
.MACRO RGB_ON
sbi PORTB,1
sbi PORTB,2
sbi PORTB,3
.ENDMACRO
.MACRO PWM_CYCLE
ldi r17,@0 ;1
PWM0: RGB_OFF ; 6
ldi r16,40 ; 1
PWM1: cp r16,R ; 1
brne PWM2 ; 1/2
sbi PORTB,1 ; 2
PWM2: cp r16,G ; 1
brne PWM3 ; 1/2
sbi PORTB,2 ; 2
PWM3: cp r16,B ; 1
brne PWM4 ; 1/2
sbi PORTB,3 ; 2
PWM4: dec r16 ; 1
brne PWM1 ; 1/2 (805)*r17+6
dec r17 ; 1
brne PWM0 ; 1/2
RGB_OFF ;6
.ENDMACRO
; Z A C A T E K P R O G R A M U
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
; začátek kódu
.org 0x0010
RESET: ldi r16,low(RAMEND) ;nastaví stack pointer
out SPL,r16
ldi r16,0b00011111 ;směr portu B - vše na výstup. Směr pinu n se bude měnit za chodu
out DDRB,r16
ldi r16,0b00000000 ;RGB=0b000, ledka zhasnuta
out PORTB,r16
;tělo programu
clr R
clr G
clr B
MainLoop:
rcall GET_T ;teplota do SRAM 0x00-0x08
cpi ARG, 0
brne MainLoop
;výpočet barvy
ldi ZH,SRAM_t_H ;počátek řetězce přijatých bajtů do Z
ldi ZL,SRAM_t_L
ld tL,Z+ ;načíst teplotu z paměti
ld tH,Z
ldi r16,40
mov R,r16 ;defaultní barva - bílá, 40 40 40
mov G,r16
mov B,r16
ldi r16,0
cpse tH,r16 ;pokud tH != 0x00, skoč na mínus
rjmp MINUS
;PLUS nebo NULA
ldi r16,21 ;tL >= 10.5? --> c10_20
cp tL,r16
brge c10_20
;0-blue,10-white
clr R
clr G
mov r16,tL
lsl r16
mov R,r16
mov G,r16
rjmp C_DONE
c10_20: ;10-white,20-yellow
ldi r16,41 ;tL >= 20.5? --> c20_30
cp tL,r16
brge c20_30
mov r16,tL
subi r16,20
lsl r16
sub B,r16
rjmp C_DONE
c20_30: ;20-yellow,30-red
ldi r16,61 ;tL >= 30.5? --> c30_40
cp tL,r16
brge c30_40
clr B
mov r16,tL
subi r16,40
lsl r16
sub G, r16
rjmp C_DONE
c30_40: ;30-red, 40-purple
ldi r16,81 ;tL >= 40.5? --> c40_50
cp tL,r16
brge c40_50
clr B
clr G
mov r16,tL
subi r16,60
lsl r16
add B, r16
rjmp C_DONE
c40_50: ;40-purple, 50-"UV"
ldi r16,101 ;tL >= 50.5? --> c50_hi
cp tL,r16
brge c50_hi
clr G
mov r16,tL
subi r16,80
sub R, r16
rjmp C_DONE
c50_hi:
clr G
ldi r16,20
mov R,r16
rjmp C_DONE
MINUS:
neg tL
ldi r16,21 ;-tL >= 10.5? --> cm10_20
cp tL,r16
brge cm10_20
mov r16,tL
lsl r16
clr R
clr G
add G,r16
rjmp C_DONE
cm10_20:
ldi r16,41 ;-tL >= 20? --> cm20_lo
cp tL,r16
brge cm20_lo
clr R
mov r16,tL
subi r16,20
lsl r16
sub B,r16
rjmp C_DONE
cm20_lo:
clr R ;-tL >= 20? --> cm40_lo
clr B
rjmp C_DONE
C_DONE:
; mov r16,R
; ldi r17,11
; rcall EEwrite
; mov r16,G
; ldi r17,12
; rcall EEwrite
; mov r16,B
; ldi r17,13
; rcall EEwrite
; ldi ZH, SRAM_t_H
; ldi ZL, SRAM_t_L
;NextEE: ld r16,Z
; mov r17, ZL
; rcall EEwrite
; inc ZL
; cpi ZL,2
; brlo NextEE
PWM_CYCLE 255
rjmp MainLoop
;G E T T E M P E R A T U R E
;Přečte 9 bajtů z teplotního čidla na pinu n (PINn, PORTn, DDRn) a uloží je do SRAM na adresu 0x00 až 0x08.
;status je uložen do ARG (ARG == 0 -> CRC se shoduje, OK; ARG != 0 -> CRC se neshoduje, chyba přenosu)
;
;SRAM po vykonání procedury GET_T:
; 0x00 temperature low byte - unit: 0.5°C
; 0x01 temperature high byte (sign, 0x00 = positive, 0xff = negative)
; 0x02 "user byte 1"
; 0x03 "user byte 2"
; 0x04 reserved, 0xFF
; 0x05 reserved, 0xFF
; 0x06 count remain (default 0x0C)
; 0x07 count per °C (fixed to 0x10)
; 0x08 CRC
;celá čtecí rutina trvá obvykle asi 550ms, max je asi 750ms. Během rutiny "W4C" může být prováděno něco jiného s pevnou délkou 700ms.
GET_T:
push r17 ;ulož používané registry do STACKu
rcall TxRESET ;RESET
ldi ARG,0xCC ;SKIP_ROM
rcall TxBYTE
ldi ARG,0x44 ;CONVERT_T
rcall TxBYTE
rcall W4C ;čekej na konverzi teploty
rcall TxRESET ;RESET
ldi ARG,0xCC ;SKIP_ROM
rcall TxBYTE
ldi ARG,0xBE ;READ_SCRATCHPAD
rcall TxBYTE
;přijmout 9 bajtů, uložit na 0x00 až 0x09 v SRAM
ldi ZH, SRAM_t_H
ldi ZL, SRAM_t_L
NEXT_B: rcall RxBYTE ;přijmi 1 bajt -> ARG
N_B3: st Z+,ARG ;do SRAM na adresu Z ulož výsledek. Z++
cpi ZL,9 ;je Z == 9?
brlo NEXT_B ;je-li menší, čti další bajt
;vypočítat CRC, pokud se shoduje s přečtenou hodnotou, r16=1, jinak r16=0
ldi XH,SRAM_t_H
ldi XL,SRAM_t_L
ldi rCount,9
rcall CRC8
mov ARG,rCRC8
pop r17
ret ;návrat, ARG==0 .. ok, ARG!=0 .. error
;D E L A Y
; r16 = d = poček čtyřkloků zmenšený o 2 (dva čtyřkloly se vykonají při nastavení r16 pomocí LDI (1T), RCALL (3T) a RET (4T))
DELAY: nop
dec r16
brne DELAY
nop
ret ; po návratu je r16 = 0
;R E S E T P U L S E
TxRESET:
BUS_L ;stáhni sběrnici
PWM_CYCLE 1
;ldi r16,t480u
;rcall DELAY ;480us čekání
BUS_H ;uvolni sběrnici
ldi r16,t70u
rcall DELAY ;70us čekání
sbic PINn,n
rjmp TxRESET ;není-li presence pulse, zopakuj TxRESET
;ldi r16,t410u
;rcall DELAY ;410T čekání
PWM_CYCLE 1
ret ;návrat
;T R A N S M I T B Y T E
; odešlou se data z ARG
TxBYTE: ldi r17,8 ;čítač bytů = 8
;nový bit
TxNB: lsr ARG ;nový bit; rotovat ARG: ARG.0 -> C
brcs Tx1 ;jednička - skok na Tx1, jinak pokračuj
;-- Odeslání 0 --
BUS_L ;stáhni sběrnici
ldi r16,t60u
rcall DELAY ;60us čekání
BUS_H ;uvolni sběrnici
ldi r16,t10u
rcall DELAY ;10us čekání
rjmp TxLOOP ;skok na konec rutiny
;-- Odeslání 1 --
Tx1: BUS_L ;stáhni sběrnici
t6uDELAY ;6us čekání
BUS_H ;uvolni sběrnici
ldi r16,t64u
rcall DELAY ;64us čekání
TxLOOP: dec r17 ;odečti 1 od čítače bitů
brne TxNB ;zbývají bity? ano -> TxNB
ret ;návrat
;R E C E I V E B Y T E
; do ARG se uloží přečtený byte
RxBYTE: ldi r17,8 ;čítač bitů
clr ARG ;vymaž ARG
;nový bit
RxNB: rcall RxBIT
ror ARG ;rotuj ARG C[=PINB.n] -> ARG.7, ARG.0 -> C
dec r17 ;odečti 1 od čítače bitů
brne RxNB ;zbývají bity? ano -> RxNB
ret ;návrat
;R E C E I V E S I N G L E B I T
RxBIT: BUS_L ;stáhni sběrnici
t6uDELAY ;6us čekání
BUS_H ;uvolni sběrnici
ldi r16,t10u
rcall DELAY ;10us čekání
sbic PINn,n ;PINB.n -> C
sec
sbis PINn,n
clc
ldi r16,t54u
rcall DELAY ;54us čekání
ret ;návrat
;Č E K Á N Í N A D O K O N Č E N Í K O N V E R Z E
;čekání na dokončení konverze teploty (nelze použít v parazitním režimu, v tom je třeba čekat 700ms.)
W4C: BUS_H
;až 700ms dlouhá čekací smyčka
W4C0: ldi r18,5
W4C1: PWM_CYCLE 200
dec r18
brne W4C1
rcall RxBIT ;přijmi bit do C.
brcc W4C0 ;C=0 -> čekej dál
ret ;návrat
;V Ý P O Č E T C R C
;XH,XL,rCount --> rCRC8
CRC8: push XH ;save XH
push XL ;save XL
push rChar ;save rChar
push rCount ;save rCount
push rBitCount ;save rBitCount
push rTemp ;save rTemp
clr rCRC8 ;start with a zero CRC-8
;begin loop to do each byte in the string
CRC8BYT:
ld rChar,X+ ;fetch next string byte and bump pointer
ldi rBitCount,8 ;load the bit-counter for this byte
;begin loop to do each bit in the byte
CRC8BIT:
mov rTemp,rChar ;get a temporary copy of current data
eor rTemp,rCRC8 ;XOR the data byte with the current CRC
lsr rCRC8 ;position to the new CRC
lsr rChar ;position to next bit of this byte
lsr rTemp ;get low bit of old result into c-bit
brcc CRC8NA ;br if low bit was clear (no adjustment)
ldi rTemp,$8C ;magical value needed for CRC-8s
eor rCRC8,rTemp ;fold in the magic CRC8 value
CRC8NA:
dec rBitCount ;count the previous bit done
brne CRC8BIT ;br if not done all bits in this byte
;end loop to do each bit in the byte
dec rCount ;count this byte done
brne CRC8BYT ;br if not done all bytes in the string
;end loop to do each byte in the string
pop rTemp ;restore rTemp
pop rBitCount ;restore rBitCount
pop rCount ;restore rCount
pop rChar ;restore rChar
pop XL ;restore XL
pop XH ;restore XH
ret ;return to caller
;
;END OF SUBROUTINE CRC8
;cteni z EEPROM, v [r17 je ADRESA], v (r16 se objeví DATA)
;EEread:
; sbic EECR,1
; rjmp EEread ;cekani dokud neni EEPROM ready
;
; out EEARL, r17 ;ulozit adresu z r17
; sbi EECR,0 ;nastavenim EERE zacina cteni
; in r16,EEDR ;cteni dat z EEDR do r16
;
; ret
;zapis do EEPROM, v [R17 je ADRESA], v [R16 jsou DATA]
EEwrite:
sbic EECR,EEPE
rjmp EEwrite ;cekani dokud neni EEPROM ready
cbi EECR,EEPM1 ;nastavit programovaci mod
cbi EECR,EEPM0
out EEARL, r17 ;dej adresu z r17 do EEARL
out EEDR, r16 ;dej data z r16 do EEDR
sbi EECR,EEMPE ;master program enable
sbi EECR,EEPE ;program enable
ret

@ -0,0 +1,496 @@
.DEVICE ATtiny13
.LIST
.LISTMAC
;běží na 9.6MHz, ckdiv8=0 (zapnuto)
;avrdude příkaz pro FUSEs: -U lfuse:w:0x6a:m -U hfuse:w:0xff:m
;LFUSE: 0x6A
;HFUSE: 0xFF
;aliasy pointerů
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
.def ARG = r20 ;registr pro předání hodnoty rutinám
;počátek paměti SRAM pro uložení přečtené teploty (9 bajtů)
.equ SRAM_t_H = 0x00
.equ SRAM_t_L = 0x00
;komunikační kanál pro ds1820
.equ PORTn = PORTB
.equ PINn = PINB
.equ DDRn = DDRB
.equ n = 0 ;pin pro komunikaci s DS1820
; Č A S O V Á N Í
;délka 1 cyklu = T = 1/f
; tXXXu = [XXX / (4*T)] - 2
; (ldi, rcall a ret zabere 8 cyklů)
; nejnižší hodnota je 1 ... 12T čekání
; attiny13@9.6MHz+CKDIV8...T=0.83333us
.equ t480u = 142
.equ t410u = 120
.equ t70u = 19
.equ t64u = 17
.equ t60u = 16
.equ t54u = 14
.equ t10u = 1
;registry pro CRC rutinu
.def rChar = r19
.def rCount = r18 ;počet bajtů
.def rBitCount = r17
.def rTemp = r16
.def rCRC8 = r21 ;výsledek (musí být jiný než ARG)
.def R = r4
.def G = r5
.def B = r6
.def tL = r2
.def tH = r3
;6us je obvykle moc málo pro volání DELAY
.MACRO t6uDELAY
ldi r16,2 ;pro attiny13@9.6MHz+CKDIV8 je to 2 x 4T = 8T = 8 x 0.83333us = 6us čekání
t6u: nop ;pozor! některé překladače labely v makrech nepodporují!
dec r16
brne t6u
.ENDMACRO
;ovládání sběrnice
.MACRO BUS_L
cbi PORTn,n
sbi DDRn,n ;pin n výstupní, výstup 0
.ENDMACRO
.MACRO BUS_H
sbi PORTn,n
cbi DDRn,n ;pin n vstupní, pullup zapnutý (+ doporučeno 4.7k externí pullup)
.ENDMACRO
.MACRO RGB_OFF
cbi PORTB,1
cbi PORTB,2
cbi PORTB,3
.ENDMACRO
.MACRO RGB_ON
sbi PORTB,1
sbi PORTB,2
sbi PORTB,3
.ENDMACRO
.MACRO PWM_CYCLE
ldi r17,@0 ;1
PWM0: RGB_OFF ; 6
ldi r16,40 ; 1
PWM1: cp r16,R ; 1
brne PWM2 ; 1/2
sbi PORTB,1 ; 2
PWM2: cp r16,G ; 1
brne PWM3 ; 1/2
sbi PORTB,2 ; 2
PWM3: cp r16,B ; 1
brne PWM4 ; 1/2
sbi PORTB,3 ; 2
PWM4: dec r16 ; 1
brne PWM1 ; 1/2 (805)*r17+6
dec r17 ; 1
brne PWM0 ; 1/2
RGB_OFF ;6
.ENDMACRO
; Z A C A T E K P R O G R A M U
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
; začátek kódu
.org 0x0010
RESET: ldi r16,low(RAMEND) ;nastaví stack pointer
out SPL,r16
ldi r16,0b00011111 ;směr portu B - vše na výstup. Směr pinu n se bude měnit za chodu
out DDRB,r16
ldi r16,0b00000000 ;RGB=0b000, ledka zhasnuta
out PORTB,r16
;tělo programu
clr R
clr G
clr B
MainLoop:
rcall GET_T ;teplota do SRAM 0x00-0x08
cpi ARG, 0
brne MainLoop
; ldi ZH, SRAM_t_H
; ldi ZL, SRAM_t_L
;NextEE: ld r16,Z
; mov r17, ZL
; rcall EEwrite
; inc ZL
; cpi ZL,2
; brlo NextEE
;výpočet barvy
ldi ZH,SRAM_t_H ;počátek řetězce přijatých bajtů do Z
ldi ZL,SRAM_t_L
ld tL,Z+ ;načíst teplotu z paměti
ld tH,Z
ldi r16,40
mov R,r16 ;defaultní barva - bílá, 40 40 40
mov G,r16
mov B,r16
ldi r16,0
cpse tH,r16 ;pokud tH != 0x00, skoč na mínus
rjmp MINUS
;PLUS nebo NULA
ldi r16,41 ;tL >= 20.5? --> c20_40
cp tL,r16
brge c20_40
sub B,tL
rjmp C_DONE
c20_40:
ldi r16,81 ;tL >= 40.5? --> c40_60
cp tL,r16
brge c40_60
clr B
mov r16,tL
subi r16,40
sub G,r16
rjmp C_DONE
c40_60:
ldi r16,121 ;tL >= 60.5? --> c60_hi
cp tL,r16
brge c60_hi
clr G
clr B
mov r16,tL
subi r16,80
add B, r16
rjmp C_DONE
c60_hi:
clr G
rjmp C_DONE
MINUS:
neg tL
ldi r16,21 ;-tL >= 10.5? --> cm10_20
cp tL,r16
brge cm10_20
mov r16,tL
lsl r16
sub R,r16
sub G,r16
rjmp C_DONE
cm10_20:
ldi r16,41 ;-tL >= 20? --> cm20_40
cp tL,r16
brge cm20_40
clr R
mov r16,tL
subi r16,20
lsl r16
mov G,r16
rjmp C_DONE
cm20_40:
ldi r16,81 ;-tL >= 20? --> cm40_lo
cp tL,r16
brge cm40_lo
clr R
mov r16,tL
subi r16,40
sub B,r16
rjmp C_DONE
cm40_lo:
clr R
clr B
rjmp C_DONE
C_DONE:
; mov r16,R
; ldi r17,11
; rcall EEwrite
; mov r16,G
; ldi r17,12
; rcall EEwrite
; mov r16,B
; ldi r17,13
; rcall EEwrite
PWM_CYCLE 255
rjmp MainLoop
;G E T T E M P E R A T U R E
;Přečte 9 bajtů z teplotního čidla na pinu n (PINn, PORTn, DDRn) a uloží je do SRAM na adresu 0x00 až 0x08.
;status je uložen do ARG (ARG == 0 -> CRC se shoduje, OK; ARG != 0 -> CRC se neshoduje, chyba přenosu)
;
;SRAM po vykonání procedury GET_T:
; 0x00 temperature low byte - unit: 0.5°C
; 0x01 temperature high byte (sign, 0x00 = positive, 0xff = negative)
; 0x02 "user byte 1"
; 0x03 "user byte 2"
; 0x04 reserved, 0xFF
; 0x05 reserved, 0xFF
; 0x06 count remain (default 0x0C)
; 0x07 count per °C (fixed to 0x10)
; 0x08 CRC
;celá čtecí rutina trvá obvykle asi 550ms, max je asi 750ms. Během rutiny "W4C" může být prováděno něco jiného s pevnou délkou 700ms.
GET_T:
push r17 ;ulož používané registry do STACKu
rcall TxRESET ;RESET
ldi ARG,0xCC ;SKIP_ROM
rcall TxBYTE
ldi ARG,0x44 ;CONVERT_T
rcall TxBYTE
rcall W4C ;čekej na konverzi teploty
rcall TxRESET ;RESET
ldi ARG,0xCC ;SKIP_ROM
rcall TxBYTE
ldi ARG,0xBE ;READ_SCRATCHPAD
rcall TxBYTE
;přijmout 9 bajtů, uložit na 0x00 až 0x09 v SRAM
ldi ZH, SRAM_t_H
ldi ZL, SRAM_t_L
NEXT_B: rcall RxBYTE ;přijmi 1 bajt -> ARG
N_B3: st Z+,ARG ;do SRAM na adresu Z ulož výsledek. Z++
cpi ZL,9 ;je Z == 9?
brlo NEXT_B ;je-li menší, čti další bajt
;vypočítat CRC, pokud se shoduje s přečtenou hodnotou, r16=1, jinak r16=0
ldi XH,SRAM_t_H
ldi XL,SRAM_t_L
ldi rCount,9
rcall CRC8
mov ARG,rCRC8
pop r17
ret ;návrat, ARG==0 .. ok, ARG!=0 .. error
;D E L A Y
; r16 = d = poček čtyřkloků zmenšený o 2 (dva čtyřkloly se vykonají při nastavení r16 pomocí LDI (1T), RCALL (3T) a RET (4T))
DELAY: nop
dec r16
brne DELAY
nop
ret ; po návratu je r16 = 0
;R E S E T P U L S E
TxRESET:
BUS_L ;stáhni sběrnici
PWM_CYCLE 1
;ldi r16,t480u
;rcall DELAY ;480us čekání
BUS_H ;uvolni sběrnici
ldi r16,t70u
rcall DELAY ;70us čekání
sbic PINn,n
rjmp TxRESET ;není-li presence pulse, zopakuj TxRESET
;ldi r16,t410u
;rcall DELAY ;410T čekání
PWM_CYCLE 1
ret ;návrat
;T R A N S M I T B Y T E
; odešlou se data z ARG
TxBYTE: ldi r17,8 ;čítač bytů = 8
;nový bit
TxNB: lsr ARG ;nový bit; rotovat ARG: ARG.0 -> C
brcs Tx1 ;jednička - skok na Tx1, jinak pokračuj
;-- Odeslání 0 --
BUS_L ;stáhni sběrnici
ldi r16,t60u
rcall DELAY ;60us čekání
BUS_H ;uvolni sběrnici
ldi r16,t10u
rcall DELAY ;10us čekání
rjmp TxLOOP ;skok na konec rutiny
;-- Odeslání 1 --
Tx1: BUS_L ;stáhni sběrnici
t6uDELAY ;6us čekání
BUS_H ;uvolni sběrnici
ldi r16,t64u
rcall DELAY ;64us čekání
TxLOOP: dec r17 ;odečti 1 od čítače bitů
brne TxNB ;zbývají bity? ano -> TxNB
ret ;návrat
;R E C E I V E B Y T E
; do ARG se uloží přečtený byte
RxBYTE: ldi r17,8 ;čítač bitů
clr ARG ;vymaž ARG
;nový bit
RxNB: rcall RxBIT
ror ARG ;rotuj ARG C[=PINB.n] -> ARG.7, ARG.0 -> C
dec r17 ;odečti 1 od čítače bitů
brne RxNB ;zbývají bity? ano -> RxNB
ret ;návrat
;R E C E I V E S I N G L E B I T
RxBIT: BUS_L ;stáhni sběrnici
t6uDELAY ;6us čekání
BUS_H ;uvolni sběrnici
ldi r16,t10u
rcall DELAY ;10us čekání
sbic PINn,n ;PINB.n -> C
sec
sbis PINn,n
clc
ldi r16,t54u
rcall DELAY ;54us čekání
ret ;návrat
;Č E K Á N Í N A D O K O N Č E N Í K O N V E R Z E
;čekání na dokončení konverze teploty (nelze použít v parazitním režimu, v tom je třeba čekat 700ms.)
W4C: BUS_H
;až 700ms dlouhá čekací smyčka
W4C0: ldi r18,5
W4C1: PWM_CYCLE 200
dec r18
brne W4C1
rcall RxBIT ;přijmi bit do C.
brcc W4C0 ;C=0 -> čekej dál
ret ;návrat
;V Ý P O Č E T C R C
;XH,XL,rCount --> rCRC8
CRC8: push XH ;save XH
push XL ;save XL
push rChar ;save rChar
push rCount ;save rCount
push rBitCount ;save rBitCount
push rTemp ;save rTemp
clr rCRC8 ;start with a zero CRC-8
;begin loop to do each byte in the string
CRC8BYT:
ld rChar,X+ ;fetch next string byte and bump pointer
ldi rBitCount,8 ;load the bit-counter for this byte
;begin loop to do each bit in the byte
CRC8BIT:
mov rTemp,rChar ;get a temporary copy of current data
eor rTemp,rCRC8 ;XOR the data byte with the current CRC
lsr rCRC8 ;position to the new CRC
lsr rChar ;position to next bit of this byte
lsr rTemp ;get low bit of old result into c-bit
brcc CRC8NA ;br if low bit was clear (no adjustment)
ldi rTemp,$8C ;magical value needed for CRC-8s
eor rCRC8,rTemp ;fold in the magic CRC8 value
CRC8NA:
dec rBitCount ;count the previous bit done
brne CRC8BIT ;br if not done all bits in this byte
;end loop to do each bit in the byte
dec rCount ;count this byte done
brne CRC8BYT ;br if not done all bytes in the string
;end loop to do each byte in the string
pop rTemp ;restore rTemp
pop rBitCount ;restore rBitCount
pop rCount ;restore rCount
pop rChar ;restore rChar
pop XL ;restore XL
pop XH ;restore XH
ret ;return to caller
;
;END OF SUBROUTINE CRC8
;cteni z EEPROM, v [r17 je ADRESA], v (r16 se objeví DATA)
;EEread:
; sbic EECR,1
; rjmp EEread ;cekani dokud neni EEPROM ready
;
; out EEARL, r17 ;ulozit adresu z r17
; sbi EECR,0 ;nastavenim EERE zacina cteni
; in r16,EEDR ;cteni dat z EEDR do r16
;
; ret
;zapis do EEPROM, v [R17 je ADRESA], v [R16 jsou DATA]
EEwrite:
sbic EECR,EEPE
rjmp EEwrite ;cekani dokud neni EEPROM ready
cbi EECR,EEPM1 ;nastavit programovaci mod
cbi EECR,EEPM0
out EEARL, r17 ;dej adresu z r17 do EEARL
out EEDR, r16 ;dej data z r16 do EEDR
sbi EECR,EEMPE ;master program enable
sbi EECR,EEPE ;program enable
ret

@ -0,0 +1,354 @@
.DEVICE ATtiny13
.LIST
.LISTMAC
;běží na 9.6MHz, ckdiv8=0 (zapnuto)
;avrdude příkaz pro FUSEs: -U lfuse:w:0x6a:m -U hfuse:w:0xff:m
;LFUSE: 0x6A
;HFUSE: 0xFF
;aliasy pointerů
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
.def ARG = r20 ;registr pro předání hodnoty rutinám
;počátek paměti SRAM pro uložení přečtené teploty (9 bajtů)
.equ SRAM_t_H = 0x00
.equ SRAM_t_L = 0x00
;komunikační kanál pro ds1820
.equ PORTn = PORTB
.equ PINn = PINB
.equ DDRn = DDRB
.equ n = 0 ;pin pro komunikaci s DS1820
; Č A S O V Á N Í
;délka 1 cyklu = T = 1/f
; tXXXu = [XXX / (4*T)] - 2
; (ldi, rcall a ret zabere 8 cyklů)
; nejnižší hodnota je 1 ... 12T čekání
; attiny13@9.6MHz+CKDIV8...T=0.83333us
.equ t480u = 142
.equ t410u = 120
.equ t70u = 19
.equ t64u = 17
.equ t60u = 16
.equ t54u = 14
.equ t10u = 1
;registry pro CRC rutinu
.def rChar = r19
.def rCount = r18 ;počet bajtů
.def rBitCount = r17
.def rTemp = r16
.def rCRC8 = r21 ;výsledek
;6us je obvykle moc málo pro volání DELAY
.MACRO t6uDELAY
ldi r16,2 ;pro attiny13@9.6MHz+CKDIV8 je to 2 x 4T = 8T = 8 x 0.83333us = 6us čekání
t6u: nop ;pozor! některé překladače labely v makrech nepodporují!
dec r16
brne t6u
.ENDMACRO
;ovládání sběrnice
.MACRO BUS_L
cbi PORTn,n
sbi DDRn,n ;pin n výstupní, výstup 0
.ENDMACRO
.MACRO BUS_H
sbi PORTn,n
cbi DDRn,n ;pin n vstupní, pullup zapnutý (+ doporučeno 4.7k externí pullup)
.ENDMACRO
; Z A C A T E K P R O G R A M U
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
; začátek kódu
.org 0x0010
RESET: ldi r16,low(RAMEND) ;nastaví stack pointer
out SPL,r16
;tělo programu
rcall GET_T ;teplota do SRAM 0x00-0x08
;uložit status testu teploty z ARG do eeprom na pozici 11 (12. bajt)
mov r16,ARG
ldi r17,11
rcall EEwrite
;důkaz, že to funguje
;uložit SRAM SRAM_t_H:SRAM_t_L až SRAM_t_H:SRAM_t_L + 9 do EEPROM na tutéž adresu
ldi ZH, SRAM_t_H
ldi ZL, SRAM_t_L
NextEE: ld r16,Z
mov r17, ZL
rcall EEwrite
inc ZL
cpi ZL,9
brlo NextEE
;věčná smyčka
F_LOOP: rjmp F_LOOP
;G E T T E M P E R A T U R E
;Přečte 9 bajtů z teplotního čidla na pinu n (PINn, PORTn, DDRn) a uloží je do SRAM na adresu 0x00 až 0x08.
;status je uložen do ARG (ARG == 0 -> CRC se shoduje, OK; ARG != 0 -> CRC se neshoduje, chyba přenosu)
;
;SRAM po vykonání procedury GET_T:
; 0x00 temperature low byte - unit: 0.5°C
; 0x01 temperature high byte (sign, 0x00 = positive, 0xff = negative)
; 0x02 "user byte 1"
; 0x03 "user byte 2"
; 0x04 reserved, 0xFF
; 0x05 reserved, 0xFF
; 0x06 count remain (default 0x0C)
; 0x07 count per °C (fixed to 0x10)
; 0x08 CRC
;celá čtecí rutina trvá obvykle asi 550ms, max je asi 750ms. Během rutiny "W4C" může být prováděno něco jiného s pevnou délkou 700ms.
GET_T:
push r17 ;ulož používané registry do STACKu
cli ;zakázat přerušení
rcall TxRESET ;RESET
ldi ARG,0xCC ;SKIP_ROM
rcall TxBYTE
ldi ARG,0x44 ;CONVERT_T
rcall TxBYTE
rcall W4C ;čekej na konverzi teploty
rcall TxRESET ;RESET
ldi ARG,0xCC ;SKIP_ROM
rcall TxBYTE
ldi ARG,0xBE ;READ_SCRATCHPAD
rcall TxBYTE
;přijmout 9 bajtů, uložit na 0x00 až 0x09 v SRAM
ldi ZH, SRAM_t_H
ldi ZL, SRAM_t_L
NEXT_B: rcall RxBYTE ;přijmi 1 bajt -> ARG
N_B3: st Z+,ARG ;do SRAM na adresu Z ulož výsledek. Z++
cpi ZL,9 ;je Z == 9?
brlo NEXT_B ;je-li menší, čti další bajt
;vypočítat CRC, pokud se shoduje s přečtenou hodnotou, r16=1, jinak r16=0
ldi XH, SRAM_t_H ;do Z pointer na uložená data
ldi XL, SRAM_t_L
ldi rCount,9 ;9 bajtů, včetně CRC
rcall CRC8
mov ARG,rCRC8 ;pokud je nový CRC == 0, byl přenos v pořádku. CRC --> ARG
sei ;povolit přerušení
pop r17
ret ;návrat, ARG==0 .. ok, ARG!=0 .. error
;D E L A Y
; r16 = d = poček čtyřkloků zmenšený o 2 (dva čtyřkloly se vykonají při nastavení r16 pomocí LDI (1T), RCALL (3T) a RET (4T))
DELAY: nop
dec r16
brne DELAY
nop
ret ; po návratu je r16 = 0
;R E S E T P U L S E
TxRESET:
BUS_L ;stáhni sběrnici
ldi r16,t480u
rcall DELAY ;480us čekání
BUS_H ;uvolni sběrnici
ldi r16,t70u
rcall DELAY ;70us čekání
sbic PINn,n
rjmp TxRESET ;není-li presence pulse, zopakuj TxRESET
ldi r16,t410u
rcall DELAY ;410T čekání
ret ;návrat
;T R A N S M I T B Y T E
; odešlou se data z ARG
TxBYTE: ldi r17,8 ;čítač bytů = 8
;nový bit
TxNB: lsr ARG ;nový bit; rotovat ARG: ARG.0 -> C
brcs Tx1 ;jednička - skok na Tx1, jinak pokračuj
;-- Odeslání 0 --
BUS_L ;stáhni sběrnici
ldi r16,t60u
rcall DELAY ;60us čekání
BUS_H ;uvolni sběrnici
ldi r16,t10u
rcall DELAY ;10us čekání
rjmp TxLOOP ;skok na konec rutiny
;-- Odeslání 1 --
Tx1: BUS_L ;stáhni sběrnici
t6uDELAY ;6us čekání
BUS_H ;uvolni sběrnici
ldi r16,t64u
rcall DELAY ;64us čekání
TxLOOP: dec r17 ;odečti 1 od čítače bitů
brne TxNB ;zbývají bity? ano -> TxNB
ret ;návrat
;R E C E I V E B Y T E
; do ARG se uloží přečtený byte
RxBYTE: ldi r17,8 ;čítač bitů
clr ARG ;vymaž ARG
;nový bit
RxNB: rcall RxBIT
ror ARG ;rotuj ARG C[=PINB.n] -> ARG.7, ARG.0 -> C
dec r17 ;odečti 1 od čítače bitů
brne RxNB ;zbývají bity? ano -> RxNB
ret ;návrat
;R E C E I V E S I N G L E B I T
RxBIT: BUS_L ;stáhni sběrnici
t6uDELAY ;6us čekání
BUS_H ;uvolni sběrnici
ldi r16,t10u
rcall DELAY ;10us čekání
sbic PINn,n ;PINB.n -> C
sec
sbis PINn,n
clc
ldi r16,t54u
rcall DELAY ;54us čekání
ret ;návrat
;Č E K Á N Í N A D O K O N Č E N Í K O N V E R Z E
;čekání na dokončení konverze teploty (nelze použít v parazitním režimu, v tom je třeba čekat 700ms.)
W4C: BUS_H
;až 700ms dlouhá čekací smyčka
W4C1: rcall RxBIT ;přijmi bit do C.
brcc W4C1 ;C=0 -> čekej dál
ret ;návrat
;V Ý P O Č E T C R C
;XH,XL,rCount --> rCRC8
CRC8: push XH ;save XH
push XL ;save XL
push rChar ;save rChar
push rCount ;save rCount
push rBitCount ;save rBitCount
push rTemp ;save rTemp
clr rCRC8 ;start with a zero CRC-8
;begin loop to do each byte in the string
CRC8BYT:
ld rChar,X+ ;fetch next string byte and bump pointer
ldi rBitCount,8 ;load the bit-counter for this byte
;begin loop to do each bit in the byte
CRC8BIT:
mov rTemp,rChar ;get a temporary copy of current data
eor rTemp,rCRC8 ;XOR the data byte with the current CRC
lsr rCRC8 ;position to the new CRC
lsr rChar ;position to next bit of this byte
lsr rTemp ;get low bit of old result into c-bit
brcc CRC8NA ;br if low bit was clear (no adjustment)
ldi rTemp,$8C ;magical value needed for CRC-8s
eor rCRC8,rTemp ;fold in the magic CRC8 value
CRC8NA:
dec rBitCount ;count the previous bit done
brne CRC8BIT ;br if not done all bits in this byte
;end loop to do each bit in the byte
dec rCount ;count this byte done
brne CRC8BYT ;br if not done all bytes in the string
;end loop to do each byte in the string
pop rTemp ;restore rTemp
pop rBitCount ;restore rBitCount
pop rCount ;restore rCount
pop rChar ;restore rChar
pop XL ;restore XL
pop XH ;restore XH
ret ;return to caller
;
;END OF SUBROUTINE CRC8
;cteni z EEPROM, v [r17 je ADRESA], v (r16 se objeví DATA)
;EEread:
; sbic EECR,1
; rjmp EEread ;cekani dokud neni EEPROM ready
;
; out EEARL, r17 ;ulozit adresu z r17
; sbi EECR,0 ;nastavenim EERE zacina cteni
; in r16,EEDR ;cteni dat z EEDR do r16
;
; ret
;zapis do EEPROM, v [R17 je ADRESA], v [R16 jsou DATA]
EEwrite:
sbic EECR,EEPE
rjmp EEwrite ;cekani dokud neni EEPROM ready
cbi EECR,EEPM1 ;nastavit programovaci mod
cbi EECR,EEPM0
out EEARL, r17 ;dej adresu z r17 do EEARL
out EEDR, r16 ;dej data z r16 do EEDR
sbi EECR,EEMPE ;master program enable
sbi EECR,EEPE ;program enable
ret

Binary file not shown.

After

Width:  |  Height:  |  Size: 604 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 589 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

@ -0,0 +1,94 @@
;pracuje jako 5-ti bitovy binarni citac
;vystupy 3 a 4 jsou prohozene kvuli desce
.device attiny13
.def i=r20 ;prvni citac, cita jen pro zpomaleni
.def j=r21 ;druhy citac, cita az do TOP, pak se oba vynulujou
.def cnt=r22 ;maximalni hodnota pro citac j -> vynulovani a dalsi faze
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow A
rjmp CASOVAC
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b11111111 ;smer pinu
out DDRB,r16
ldi r16,0b00000000 ;PullUpy
out PORTB,r16
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/64=75000Hz
ldi r16,(1<<WGM01) ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,75 ;Compare Match 0 A je 75
out OCR0A,r16 ;75000/75=1000Hz interrupt
in r16, TIMSK0 ;povolit interrupt od preteceni
ori r16, (1<<OCIE0A)
out timsk0,r16
in r16, MCUCR
ori r16, (1<<PUD)
out MCUCR, r16 ;pull-ups disabled
clr i ;nastavime pocatecni hodnoty
clr j
sei ;Global Interrupt Enable
LOOP:
rjmp LOOP
CASOVAC:
inc i
cpi i,100 ;je i=100? ne->ceka se na dalsi interrupt
brne CASEND
clr i
inc j
cpi j,10
brne CASEND ;je j=10 (delay=1s)? ne -> ceka se dal
clr cnt
clr i
clr j
ldi r16,0b00000011 ;outputy
out DDRB,r16
ldi r16,0b00000010 ;obracene pripojeni led
out PORTB,r16
ldi r16,0b00000001 ;input na PB1
out DDRB,r16
cekani: in r16,PINB ;kdyz je pinb1 zapnuty dele nez 150 cyklu tak je svetlo
sbrs r16,1
rjmp tma
inc cnt
cpi cnt, 250
brne cekani
ldi r16,0b00000011 ;svetlo -> zhasiname
out DDRB,r16
ldi r16,0b00000000 ;led nesviti
out PORTB,r16
rjmp casend
tma: ldi r16,0b00000011 ;tma -> sekundu bude svitit
out DDRB,r16
ldi r16,0b00000001 ;led sviti
out PORTB,r16
CASEND:
reti

@ -0,0 +1,2 @@
@ECHO OFF
"C:\Program Files\Atmel\AVR Tools\AvrAssembler2\avrasm2.exe" -S "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\labels.tmp" -fI -W+ie -o "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.hex" -d "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.obj" -e "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.eep" -m "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.map" "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm"

@ -0,0 +1 @@
<AVRStudio><MANAGEMENT><ProjectName>EEPROM_nahoda</ProjectName><Created>14-Sep-2007 21:26:15</Created><LastEdit>14-Sep-2007 21:30:30</LastEdit><ICON>208</ICON><ProjectType>0</ProjectType><Created>14-Sep-2007 21:26:15</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>Atmel AVR Assembler</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>EEPROM_nahoda.obj</ObjectFile><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_nahoda\EEPROM_nahoda.asm</EntryFile><SaveFolder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_nahoda\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATtiny13.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AvrAssembler><Folder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_nahoda\</Folder><RelPath>EEPROM_nahoda.asm</RelPath><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_nahoda\EEPROM_nahoda.asm</EntryFile><IncludePath>C:\Program Files\Atmel\AVR Tools\AvrAssembler\Appnotes</IncludePath><V2IncludePath></V2IncludePath><V2Parameters></V2Parameters><FileType>I</FileType><ObjectName>EEPROM_nahoda</ObjectName><Wrap>0</Wrap><ErrorAsWarning>0</ErrorAsWarning><MapFile>1</MapFile><ListFile>0</ListFile><Version1>0</Version1><PreCompile></PreCompile><PostCompile></PostCompile><SourceFiles>,</SourceFiles></AvrAssembler><ProjectIncludeDirs><Dirs><Dir>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</Dir></Dirs></ProjectIncludeDirs><ProjectFiles><Files><Name>\EEPROM_nahoda.asm</Name></Files></ProjectFiles><IOView><usergroups/></IOView><Files><File00000><FileId>00000</FileId><FileName>EEPROM_nahoda.asm</FileName><Status>1</Status></File00000></Files><Workspace><File00000><Position>197 71 1026 566</Position><LineCol>108 0</LineCol><State>Maximized</State></File00000></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

@ -0,0 +1,108 @@
;EEPROM_nahoda
;pokud je stisknuto tlacitko PB0,
;hrozne rychle se z EEPROM ctou hodnoty na adresach 0-3
;a davaji se na PORTB
;Vypada to pak, jako by se pri drzeni tlacitka rozsvitily obe ledky PB1 a PB2,
;ale po pusteni tlacitka na nich zustane 'nahodna' kombinace 1 a 0.
.include "tn13def.inc"
.def CNT=r20
.cseg
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010 ;zacatek vlastniho programu
RESET:
LDI r16,low(RAMEND) ;nastavi stack pointer
OUT SPL,r16
LDI r16,0b00000110 ;nastavi I/O nohy
OUT DDRB,r16
LOOP:
RCALL cekani ;zavolej cekani pro zpomaleni celeho programu
IN r16,PINB ;Porovnej stav PB0 s 1 a pokud neni rovno, jdi na LOOP
ANDI r16,0b00000001
CPI r16,0b00000001
BRNE LOOP
MOV r17,CNT ;do r17 (adresovy registr) dej CNT
RCALL EEread ;zavolej cteni z EEPROM - adresa je r17, do r16 se ulozi data.
OUT PORTB,r16 ;posli data z r16 ven
INC CNT ;inkrementuj CNT
CPI CNT,4 ;pokud je mensi nez 4, jdi na loop
BRLT LOOP
CLR CNT ;jinak vynuluj CNT
RJMP LOOP ;a jdi na LOOP
;
;EEread je funkce pro cteni z EEPROM
;do r17 se ulozi adresa,
;zavola se EEread
;a v r16 se objevi hodnota, ktera je na adrese.
EEread:
SBIC EECR,1
RJMP EEread ;cekani dokud neni EEPROM ready
OUT EEARL, r17 ;ulozit adresu z r17
SBI EECR,0 ;nastavenim EERE zacina cteni
IN r16,EEDR ;cteni dat z EEDR do r16
RET
;zapis do EEPROM, v R17 je ADRESA, v R16 jsou DATA
EEwrite:
SBIC EECR,EEPE
RJMP EEwrite ;cekani dokud neni EEPROM ready
LDI r16, 0 ;nastavit programovaci mod
OUT EECR, r16
OUT EEARL, r17 ;dej adresu z r17 do EEARL
OUT EEDR, r16 ;dej data z r16 do EEDR
SBI EECR,EEMPE ;master program enable
SBI EECR,EEPE ;program enable
RET
;cekaci cyklus
CEKANI:
PUSH r18 ;ulozit pouzivane registry do STACKU
PUSH r17
PUSH r16
LDI r16, 3
L1: DEC r16 ;cekaci smycka vnejsi - zacatek
LDI r17, 3
L2: DEC r17 ; cekaci smycka stredni - zacatek
LDI r18, 3
L3: DEC r18 ; cekaci smycka vnitrni - zacatek
CPI r18, 0
BRNE L3 ; cekaci smycka vnitrni - konec
CPI r17, 0
BRNE L2 ; cekaci smycka stredni - konec
CPI r16, 0
BRNE L1 ;cekaci smycka vnejsi - konec
POP r16 ;nacist puvodni obsah registru ze STACKU
POP r17
POP r18
RET ;navrat do hlavniho programu
.eseg ;zacatek ESEGu
.org 0x00 ;adresa 0
.DB 0b00000000 ;tady se definujou byty postupne podle adres.
.DB 0b00000010
.DB 0b00000100
.DB 0b00000110

@ -0,0 +1,2 @@
:0400000000020406F0
:00000001FF

@ -0,0 +1,289 @@
AVRASM ver. 2.1.12 C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm Fri Sep 14 21:26:55 2007
EQU SIGNATURE_000 0000001e
EQU SIGNATURE_001 00000090
EQU SIGNATURE_002 00000007
EQU SREG 0000003f
EQU SPL 0000003d
EQU GIMSK 0000003b
EQU GIFR 0000003a
EQU TIMSK0 00000039
EQU TIFR0 00000038
EQU SPMCSR 00000037
EQU OCR0A 00000036
EQU MCUCR 00000035
EQU MCUSR 00000034
EQU TCCR0B 00000033
EQU TCNT0 00000032
EQU OSCCAL 00000031
EQU TCCR0A 0000002f
EQU DWDR 0000002e
EQU OCR0B 00000029
EQU GTCCR 00000028
EQU CLKPR 00000026
EQU WDTCR 00000021
EQU EEAR 0000001e
EQU EEDR 0000001d
EQU EECR 0000001c
EQU PORTB 00000018
EQU DDRB 00000017
EQU PINB 00000016
EQU PCMSK 00000015
EQU DIDR0 00000014
EQU ACSR 00000008
EQU ADMUX 00000007
EQU ADCSRA 00000006
EQU ADCH 00000005
EQU ADCL 00000004
EQU ADCSRB 00000003
EQU MUX0 00000000
EQU MUX1 00000001
EQU ADLAR 00000005
EQU REFS0 00000006
EQU ADPS0 00000000
EQU ADPS1 00000001
EQU ADPS2 00000002
EQU ADIE 00000003
EQU ADIF 00000004
EQU ADATE 00000005
EQU ADSC 00000006
EQU ADEN 00000007
EQU ADCH0 00000000
EQU ADCH1 00000001
EQU ADCH2 00000002
EQU ADCH3 00000003
EQU ADCH4 00000004
EQU ADCH5 00000005
EQU ADCH6 00000006
EQU ADCH7 00000007
EQU ADCL0 00000000
EQU ADCL1 00000001
EQU ADCL2 00000002
EQU ADCL3 00000003
EQU ADCL4 00000004
EQU ADCL5 00000005
EQU ADCL6 00000006
EQU ADCL7 00000007
EQU ADTS0 00000000
EQU ADTS1 00000001
EQU ADTS2 00000002
EQU ADC1D 00000002
EQU ADC3D 00000003
EQU ADC2D 00000004
EQU ADC0D 00000005
EQU ACME 00000006
EQU ACIS0 00000000
EQU ACIS1 00000001
EQU ACIE 00000003
EQU ACI 00000004
EQU ACO 00000005
EQU ACBG 00000006
EQU AINBG 00000006
EQU ACD 00000007
EQU AIN0D 00000000
EQU AIN1D 00000001
EQU EEARL 0000001e
EQU EEAR0 00000000
EQU EEAR1 00000001
EQU EEAR2 00000002
EQU EEAR3 00000003
EQU EEAR4 00000004
EQU EEAR5 00000005
EQU EEDR0 00000000
EQU EEDR1 00000001
EQU EEDR2 00000002
EQU EEDR3 00000003
EQU EEDR4 00000004
EQU EEDR5 00000005
EQU EEDR6 00000006
EQU EEDR7 00000007
EQU EERE 00000000
EQU EEWE 00000001
EQU EEPE 00000001
EQU EEMWE 00000002
EQU EEMPE 00000002
EQU EERIE 00000003
EQU EEPM0 00000004
EQU EEPM1 00000005
EQU SREG_C 00000000
EQU SREG_Z 00000001
EQU SREG_N 00000002
EQU SREG_V 00000003
EQU SREG_S 00000004
EQU SREG_H 00000005
EQU SREG_T 00000006
EQU SREG_I 00000007
EQU SP0 00000000
EQU SP1 00000001
EQU SP2 00000002
EQU SP3 00000003
EQU SP4 00000004
EQU SP5 00000005
EQU SP6 00000006
EQU SP7 00000007
EQU ISC00 00000000
EQU ISC01 00000001
EQU SM0 00000003
EQU SM1 00000004
EQU SE 00000005
EQU PUD 00000006
EQU PORF 00000000
EQU EXTRF 00000001
EQU BORF 00000002
EQU WDRF 00000003
EQU CAL0 00000000
EQU CAL1 00000001
EQU CAL2 00000002
EQU CAL3 00000003
EQU CAL4 00000004
EQU CAL5 00000005
EQU CAL6 00000006
EQU CLKPS0 00000000
EQU CLKPS1 00000001
EQU CLKPS2 00000002
EQU CLKPS3 00000003
EQU CLKPCE 00000007
EQU DWDR0 00000000
EQU DWDR1 00000001
EQU DWDR2 00000002
EQU DWDR3 00000003
EQU DWDR4 00000004
EQU DWDR5 00000005
EQU DWDR6 00000006
EQU DWDR7 00000007
EQU SPMEN 00000000
EQU PGERS 00000001
EQU PGWRT 00000002
EQU RFLB 00000003
EQU CTPB 00000004
EQU PORTB0 00000000
EQU PB0 00000000
EQU PORTB1 00000001
EQU PB1 00000001
EQU PORTB2 00000002
EQU PB2 00000002
EQU PORTB3 00000003
EQU PB3 00000003
EQU PORTB4 00000004
EQU PB4 00000004
EQU PORTB5 00000005
EQU PB5 00000005
EQU DDB0 00000000
EQU DDB1 00000001
EQU DDB2 00000002
EQU DDB3 00000003
EQU DDB4 00000004
EQU DDB5 00000005
EQU PINB0 00000000
EQU PINB1 00000001
EQU PINB2 00000002
EQU PINB3 00000003
EQU PINB4 00000004
EQU PINB5 00000005
EQU GICR 0000003b
EQU PCIE 00000005
EQU INT0 00000006
EQU PCIF 00000005
EQU INTF0 00000006
EQU PCINT0 00000000
EQU PCINT1 00000001
EQU PCINT2 00000002
EQU PCINT3 00000003
EQU PCINT4 00000004
EQU PCINT5 00000005
EQU TOIE0 00000001
EQU OCIE0A 00000002
EQU OCIE0B 00000003
EQU TOV0 00000001
EQU OCF0A 00000002
EQU OCF0B 00000003
EQU OCR0_0 00000000
EQU OCR0_1 00000001
EQU OCR0_2 00000002
EQU OCR0_3 00000003
EQU OCR0_4 00000004
EQU OCR0_5 00000005
EQU OCR0_6 00000006
EQU OCR0_7 00000007
EQU WGM00 00000000
EQU WGM01 00000001
EQU COM0B0 00000004
EQU COM0B1 00000005
EQU COM0A0 00000006
EQU COM0A1 00000007
EQU TCNT0_0 00000000
EQU TCNT0_1 00000001
EQU TCNT0_2 00000002
EQU TCNT0_3 00000003
EQU TCNT0_4 00000004
EQU TCNT0_5 00000005
EQU TCNT0_6 00000006
EQU TCNT0_7 00000007
EQU CS00 00000000
EQU CS01 00000001
EQU CS02 00000002
EQU WGM02 00000003
EQU FOC0B 00000006
EQU FOC0A 00000007
EQU PSR10 00000000
EQU TSM 00000007
EQU WDP0 00000000
EQU WDP1 00000001
EQU WDP2 00000002
EQU WDE 00000003
EQU WDCE 00000004
EQU WDP3 00000005
EQU WDTIE 00000006
EQU WDTIF 00000007
EQU LB1 00000000
EQU LB2 00000001
EQU CKSEL0 00000000
EQU CKSEL1 00000001
EQU SUT0 00000002
EQU SUT1 00000003
EQU CKDIV8 00000004
EQU WDTON 00000005
EQU EESAVE 00000006
EQU SPIEN 00000007
EQU RSTDISBL 00000000
EQU BODLEVEL0 00000001
EQU BODLEVEL1 00000002
EQU DWEN 00000003
EQU SELFPRGEN 00000004
DEF XH r27
DEF XL r26
DEF YH r29
DEF YL r28
DEF ZH r31
DEF ZL r30
EQU FLASHEND 000001ff
EQU IOEND 0000003f
EQU SRAM_START 00000060
EQU SRAM_SIZE 00000040
EQU RAMEND 0000009f
EQU XRAMEND 00000000
EQU E2END 0000003f
EQU EEPROMEND 0000003f
EQU EEADRBITS 00000006
EQU PAGESIZE 00000010
EQU INT0addr 00000001
EQU PCI0addr 00000002
EQU OVF0addr 00000003
EQU ERDYaddr 00000004
EQU ACIaddr 00000005
EQU OC0Aaddr 00000006
EQU OC0Baddr 00000007
EQU WDTaddr 00000008
EQU ADCCaddr 00000009
EQU INT_VECTORS_SIZE 0000000a
DEF CNT r20
CSEG RESET 00000010
CSEG LOOP 00000014
CSEG cekani 00000030
CSEG EEread 00000021
CSEG EEwrite 00000027
CSEG L1 00000034
CSEG L2 00000036
CSEG L3 00000038

@ -0,0 +1 @@
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATTINY13"/><Files><File00000 Name="C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_nahoda\EEPROM_nahoda.asm" Position="197 71 1026 566" LineCol="48 12" State="Maximized"/></Files></AVRWorkspace>

@ -0,0 +1,32 @@
<ASSEMBLER_INFO>
<VERSION>2.1.12</VERSION>
<DEVICE>ATtiny13</DEVICE>
<WORKING_DIR>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda</WORKING_DIR>
<INCLUDE_PATH>
<DIR>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</DIR>
</INCLUDE_PATH>
<SOURCE_FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</SOURCE_FILE>
<INCLUDED_FILES>
<FILE>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\tn13def.inc</FILE>
</INCLUDED_FILES>
<OBJECT_FILES>
<FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.obj</FILE>
</OBJECT_FILES>
<HEX_FILES>
<FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.hex</FILE>
<FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.eep</FILE>
</HEX_FILES>
<OUTPUT_FILES>
<FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.map</FILE>
</OUTPUT_FILES>
<LABELS>
<RESET><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>19</LINE></RESET>
<LOOP><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>26</LINE></LOOP>
<cekani><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>73</LINE></cekani>
<EEread><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>48</LINE></EEread>
<EEwrite><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>58</LINE></EEwrite>
<L1><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>79</LINE></L1>
<L2><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>81</LINE></L2>
<L3><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>83</LINE></L3>
</LABELS>
</ASSEMBLER_INFO>

@ -0,0 +1,2 @@
@ECHO OFF
"C:\Program Files\Atmel\AVR Tools\AvrAssembler2\avrasm2.exe" -S "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\labels.tmp" -fI -W+ie -o "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.hex" -d "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.obj" -e "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.eep" -m "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.map" "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm"

@ -0,0 +1 @@
<AVRStudio><MANAGEMENT><Created>06-Sep-2007 20:57:13</Created><LastEdit>13-Sep-2007 21:45:27</LastEdit><ProjectType>0</ProjectType><Created>06-Sep-2007 20:57:13</Created><Version>4</Version><Build>4, 13, 0, 528</Build><Created>08-Sep-2007 21:57:32</Created><LastEdit>08-Sep-2007 21:57:32</LastEdit><ProjectType>0</ProjectType><Created>08-Sep-2007 21:57:32</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>Atmel AVR Assembler</ProjectTypeName><ICON>208</ICON><ProjectName>EEPROM_access</ProjectName><Created>10-Sep-2007 21:52:01</Created><LastEdit>10-Sep-2007 21:52:01</LastEdit><ICON>208</ICON><ProjectType>0</ProjectType><Created>10-Sep-2007 21:52:01</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>Atmel AVR Assembler</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>EEPROM_access.obj</ObjectFile><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</EntryFile><ObjectFile></ObjectFile><EntryFile></EntryFile><ObjectFile></ObjectFile><EntryFile></EntryFile><SaveFolder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_PART>ATtiny13</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><CURRENT_PART>ATmega16.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND></IO_EXPAND><REGISTERNAMES></REGISTERNAMES><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATtiny13.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND></IO_EXPAND><REGISTERNAMES></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><modules><module></module></modules><Triggers></Triggers></Debugger><AvrAssembler><Folder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\</Folder><RelPath>EEPROM_access.asm</RelPath><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</EntryFile><IncludePath>C:\Program Files\Atmel\AVR Tools\AvrAssembler\Appnotes</IncludePath><V2IncludePath></V2IncludePath><V2Parameters></V2Parameters><FileType>I</FileType><ObjectName>EEPROM_access</ObjectName><Wrap>0</Wrap><ErrorAsWarning>0</ErrorAsWarning><MapFile>1</MapFile><ListFile>0</ListFile><Version1>0</Version1><PreCompile></PreCompile><PostCompile></PostCompile><SourceFiles>,</SourceFiles></AvrAssembler><ProjectIncludeDirs><Dirs><Dir>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</Dir></Dirs></ProjectIncludeDirs><ProjectFiles><Files><Name>\EEPROM_access.asm</Name></Files></ProjectFiles><IOView><usergroups/></IOView><Files><File00000><FileId>00000</FileId><FileName>EEPROM_access.asm</FileName><Status>257</Status></File00000></Files><Workspace><File00000><Position>197 71 1026 566</Position><LineCol>100 0</LineCol><State>Maximized</State></File00000></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

@ -0,0 +1,49 @@
;program cyklicky nacita z EEPROM adresy:0x00 hodnotu (0b00000101) a dava ji do PORTB.
.include "tn13def.inc"
.cseg
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010 ;zacatek vlastniho programu
RESET:
LDI r16,low(RAMEND) ;nastavi stack pointer
OUT SPL,r16
LDI r16,0b00000111
OUT DDRB,r16
LOOP:
LDI r17,0
RCALL EEread
OUT PORTB,r16
RJMP LOOP
;
;EEread je funkce pro cteni z EEPROM
;do r17 se ulozi adresa,
;zavola se EEread
;a v r16 se objevi hodnota, ktera je na adrese.
EEread:
SBIC EECR,1
RJMP EEread ;cekani dokud neni EEPROM ready
OUT EEARL, r17 ;ulozit adresu z r17
SBI EECR,0 ;nastavenim EERE zacina cteni
IN r16,EEDR ;cteni dat z EEDR do r16
RET
.eseg
.org 0x00
.DB 0b00000101

@ -0,0 +1,2 @@
:0100000005FA
:00000001FF

@ -0,0 +1,283 @@
AVRASM ver. 2.1.12 C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm Thu Sep 13 21:48:45 2007
EQU SIGNATURE_000 0000001e
EQU SIGNATURE_001 00000090
EQU SIGNATURE_002 00000007
EQU SREG 0000003f
EQU SPL 0000003d
EQU GIMSK 0000003b
EQU GIFR 0000003a
EQU TIMSK0 00000039
EQU TIFR0 00000038
EQU SPMCSR 00000037
EQU OCR0A 00000036
EQU MCUCR 00000035
EQU MCUSR 00000034
EQU TCCR0B 00000033
EQU TCNT0 00000032
EQU OSCCAL 00000031
EQU TCCR0A 0000002f
EQU DWDR 0000002e
EQU OCR0B 00000029
EQU GTCCR 00000028
EQU CLKPR 00000026
EQU WDTCR 00000021
EQU EEAR 0000001e
EQU EEDR 0000001d
EQU EECR 0000001c
EQU PORTB 00000018
EQU DDRB 00000017
EQU PINB 00000016
EQU PCMSK 00000015
EQU DIDR0 00000014
EQU ACSR 00000008
EQU ADMUX 00000007
EQU ADCSRA 00000006
EQU ADCH 00000005
EQU ADCL 00000004
EQU ADCSRB 00000003
EQU MUX0 00000000
EQU MUX1 00000001
EQU ADLAR 00000005
EQU REFS0 00000006
EQU ADPS0 00000000
EQU ADPS1 00000001
EQU ADPS2 00000002
EQU ADIE 00000003
EQU ADIF 00000004
EQU ADATE 00000005
EQU ADSC 00000006
EQU ADEN 00000007
EQU ADCH0 00000000
EQU ADCH1 00000001
EQU ADCH2 00000002
EQU ADCH3 00000003
EQU ADCH4 00000004
EQU ADCH5 00000005
EQU ADCH6 00000006
EQU ADCH7 00000007
EQU ADCL0 00000000
EQU ADCL1 00000001
EQU ADCL2 00000002
EQU ADCL3 00000003
EQU ADCL4 00000004
EQU ADCL5 00000005
EQU ADCL6 00000006
EQU ADCL7 00000007
EQU ADTS0 00000000
EQU ADTS1 00000001
EQU ADTS2 00000002
EQU ADC1D 00000002
EQU ADC3D 00000003
EQU ADC2D 00000004
EQU ADC0D 00000005
EQU ACME 00000006
EQU ACIS0 00000000
EQU ACIS1 00000001
EQU ACIE 00000003
EQU ACI 00000004
EQU ACO 00000005
EQU ACBG 00000006
EQU AINBG 00000006
EQU ACD 00000007
EQU AIN0D 00000000
EQU AIN1D 00000001
EQU EEARL 0000001e
EQU EEAR0 00000000
EQU EEAR1 00000001
EQU EEAR2 00000002
EQU EEAR3 00000003
EQU EEAR4 00000004
EQU EEAR5 00000005
EQU EEDR0 00000000
EQU EEDR1 00000001
EQU EEDR2 00000002
EQU EEDR3 00000003
EQU EEDR4 00000004
EQU EEDR5 00000005
EQU EEDR6 00000006
EQU EEDR7 00000007
EQU EERE 00000000
EQU EEWE 00000001
EQU EEPE 00000001
EQU EEMWE 00000002
EQU EEMPE 00000002
EQU EERIE 00000003
EQU EEPM0 00000004
EQU EEPM1 00000005
EQU SREG_C 00000000
EQU SREG_Z 00000001
EQU SREG_N 00000002
EQU SREG_V 00000003
EQU SREG_S 00000004
EQU SREG_H 00000005
EQU SREG_T 00000006
EQU SREG_I 00000007
EQU SP0 00000000
EQU SP1 00000001
EQU SP2 00000002
EQU SP3 00000003
EQU SP4 00000004
EQU SP5 00000005
EQU SP6 00000006
EQU SP7 00000007
EQU ISC00 00000000
EQU ISC01 00000001
EQU SM0 00000003
EQU SM1 00000004
EQU SE 00000005
EQU PUD 00000006
EQU PORF 00000000
EQU EXTRF 00000001
EQU BORF 00000002
EQU WDRF 00000003
EQU CAL0 00000000
EQU CAL1 00000001
EQU CAL2 00000002
EQU CAL3 00000003
EQU CAL4 00000004
EQU CAL5 00000005
EQU CAL6 00000006
EQU CLKPS0 00000000
EQU CLKPS1 00000001
EQU CLKPS2 00000002
EQU CLKPS3 00000003
EQU CLKPCE 00000007
EQU DWDR0 00000000
EQU DWDR1 00000001
EQU DWDR2 00000002
EQU DWDR3 00000003
EQU DWDR4 00000004
EQU DWDR5 00000005
EQU DWDR6 00000006
EQU DWDR7 00000007
EQU SPMEN 00000000
EQU PGERS 00000001
EQU PGWRT 00000002
EQU RFLB 00000003
EQU CTPB 00000004
EQU PORTB0 00000000
EQU PB0 00000000
EQU PORTB1 00000001
EQU PB1 00000001
EQU PORTB2 00000002
EQU PB2 00000002
EQU PORTB3 00000003
EQU PB3 00000003
EQU PORTB4 00000004
EQU PB4 00000004
EQU PORTB5 00000005
EQU PB5 00000005
EQU DDB0 00000000
EQU DDB1 00000001
EQU DDB2 00000002
EQU DDB3 00000003
EQU DDB4 00000004
EQU DDB5 00000005
EQU PINB0 00000000
EQU PINB1 00000001
EQU PINB2 00000002
EQU PINB3 00000003
EQU PINB4 00000004
EQU PINB5 00000005
EQU GICR 0000003b
EQU PCIE 00000005
EQU INT0 00000006
EQU PCIF 00000005
EQU INTF0 00000006
EQU PCINT0 00000000
EQU PCINT1 00000001
EQU PCINT2 00000002
EQU PCINT3 00000003
EQU PCINT4 00000004
EQU PCINT5 00000005
EQU TOIE0 00000001
EQU OCIE0A 00000002
EQU OCIE0B 00000003
EQU TOV0 00000001
EQU OCF0A 00000002
EQU OCF0B 00000003
EQU OCR0_0 00000000
EQU OCR0_1 00000001
EQU OCR0_2 00000002
EQU OCR0_3 00000003
EQU OCR0_4 00000004
EQU OCR0_5 00000005
EQU OCR0_6 00000006
EQU OCR0_7 00000007
EQU WGM00 00000000
EQU WGM01 00000001
EQU COM0B0 00000004
EQU COM0B1 00000005
EQU COM0A0 00000006
EQU COM0A1 00000007
EQU TCNT0_0 00000000
EQU TCNT0_1 00000001
EQU TCNT0_2 00000002
EQU TCNT0_3 00000003
EQU TCNT0_4 00000004
EQU TCNT0_5 00000005
EQU TCNT0_6 00000006
EQU TCNT0_7 00000007
EQU CS00 00000000
EQU CS01 00000001
EQU CS02 00000002
EQU WGM02 00000003
EQU FOC0B 00000006
EQU FOC0A 00000007
EQU PSR10 00000000
EQU TSM 00000007
EQU WDP0 00000000
EQU WDP1 00000001
EQU WDP2 00000002
EQU WDE 00000003
EQU WDCE 00000004
EQU WDP3 00000005
EQU WDTIE 00000006
EQU WDTIF 00000007
EQU LB1 00000000
EQU LB2 00000001
EQU CKSEL0 00000000
EQU CKSEL1 00000001
EQU SUT0 00000002
EQU SUT1 00000003
EQU CKDIV8 00000004
EQU WDTON 00000005
EQU EESAVE 00000006
EQU SPIEN 00000007
EQU RSTDISBL 00000000
EQU BODLEVEL0 00000001
EQU BODLEVEL1 00000002
EQU DWEN 00000003
EQU SELFPRGEN 00000004
DEF XH r27
DEF XL r26
DEF YH r29
DEF YL r28
DEF ZH r31
DEF ZL r30
EQU FLASHEND 000001ff
EQU IOEND 0000003f
EQU SRAM_START 00000060
EQU SRAM_SIZE 00000040
EQU RAMEND 0000009f
EQU XRAMEND 00000000
EQU E2END 0000003f
EQU EEPROMEND 0000003f
EQU EEADRBITS 00000006
EQU PAGESIZE 00000010
EQU INT0addr 00000001
EQU PCI0addr 00000002
EQU OVF0addr 00000003
EQU ERDYaddr 00000004
EQU ACIaddr 00000005
EQU OC0Aaddr 00000006
EQU OC0Baddr 00000007
EQU WDTaddr 00000008
EQU ADCCaddr 00000009
EQU INT_VECTORS_SIZE 0000000a
CSEG RESET 00000010
CSEG LOOP 00000014
CSEG EEread 00000018

@ -0,0 +1 @@
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATTINY13"/><Files><File00000 Name="C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm" Position="197 71 1026 566" LineCol="28 47" State="Maximized"/></Files></AVRWorkspace>

@ -0,0 +1,27 @@
<ASSEMBLER_INFO>
<VERSION>2.1.12</VERSION>
<DEVICE>ATtiny13</DEVICE>
<WORKING_DIR>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access</WORKING_DIR>
<INCLUDE_PATH>
<DIR>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</DIR>
</INCLUDE_PATH>
<SOURCE_FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</SOURCE_FILE>
<INCLUDED_FILES>
<FILE>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\tn13def.inc</FILE>
</INCLUDED_FILES>
<OBJECT_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.obj</FILE>
</OBJECT_FILES>
<HEX_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.hex</FILE>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.eep</FILE>
</HEX_FILES>
<OUTPUT_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.map</FILE>
</OUTPUT_FILES>
<LABELS>
<RESET><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</FILE><LINE>12</LINE></RESET>
<LOOP><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</FILE><LINE>19</LINE></LOOP>
<EEread><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</FILE><LINE>30</LINE></EEread>
</LABELS>
</ASSEMBLER_INFO>

@ -0,0 +1,351 @@
; Zapojeni (Připojen DMC-50399 v 4-bitovem modu):
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; --+ PD0 PB7 +-- RS (0=instr W, BF+addr R; 1=data W/R)
; --+ PD1 PB6 +-- R/W (1=read,0=write)
; --+ PA1 PB5 +-- E (clock, active falling edge)
; --+ PA0 PB4 +--
; --+ PD2 PB3 +-- DATA 7
; --+ PD3 PB2 +-- DATA 6
; --+ PD4 PB1 +-- DATA 5
; --+ PD5 PB0 +-- DATA 4
; GND --+ GND PD6 +--
; +-------------+
;DMC-50399:
; 1 - GND
; 2 - +5V
; 3 - 0V (lcd driver)
; 4 - RS
; 5 - R/W
; 6 - E
; 7 - DATA 0
; 8 - DATA 1
;...
;14 - DATA 7
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;250x16=1ms=1000us
;LFUSE: 0xE2 -U lfuse:w:0xE2:m
;HFUSE: 0xDF -U hfuse:w:0xDF:m
;K O N S T A N T Y + P R E Z D I V K Y P O R T U A P I N U
.equ LCDPORT = PORTB
.equ LCDPIN = PINB
.equ LCDDDR = DDRB
.equ RS = 7
.equ RW = 6
.equ E = 5
.equ LCD_CLEAR = 0b00000001
.equ LCD_HOME = 0b00000010
.equ LCD_MODE_INC_NOSHIFT = 0b00000110
.equ LCD_MODE_INC_SHIFT = 0b00000111
.equ LCD_MODE_DEC_NOSHIFT = 0b00000100
.equ LCD_MODE_DEC_SHIFT = 0b00000101
.equ LCD_DISPLAY_DISABLED = 0b00001000
.equ LCD_DISPLAY_NOCURSOR = 0b00001100
.equ LCD_DISPLAY_CURSOR = 0b00001110
.equ LCD_DISPLAY_ALTER = 0b00001101
.equ LCD_DISPLAY_CURSOR_ALTER = 0b00001111
.equ LCD_CURSOR_LEFT = 0b00010000
.equ LCD_CURSOR_RIGHT = 0b00010100
.equ LCD_SHIFT_LEFT = 0b00011000
.equ LCD_SHIFT_RIGHT = 0b00011100
;5x7 font, 1-line
.equ LCD_MODE_4BIT_1LINE = 0b00100000
;.equ LCD_MODE_8BIT_1LINE = 0b00110000
;5x7 font, 2-line
.equ LCD_MODE_4BIT_2LINE = 0b00101000
;.equ LCD_MODE_8BIT_2LINE = 0b00111000
.equ ROW1_ADDR = 0x00
.equ ROW2_ADDR = 0x40
.equ ROW3_ADDR = 0x14
.equ ROW4_ADDR = 0x54
;aliases
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0013
;nastaveni po resetu
.DB "HD44780 INTERFACE" ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
;PORTB = LCDPORT
ldi r16,0b11111111 ;smer portu B
out LCDDDR,r16
ldi r16,0b00000000 ;vypnout B
out LCDPORT,r16
sei ;Global Interrupt Enable
; == display init ==
rcall LCD_INIT
ldi r17,LCD_MODE_INC_NOSHIFT
rcall TX_INSTR
ldi r17,LCD_DISPLAY_NOCURSOR
rcall TX_INSTR
; == load user-defined characters to CGRAM == (default, array label named MYCHARS, end-mark=0xFE)
ldi r17,0
rcall CGRAM_SET_ADDR
ldi ZH,high(MYCHARS*2)
ldi ZL,low(MYCHARS*2)
CGRAM_loop:
lpm r17,Z+
cpi r17,0xFE
breq CGRAM_loop_end
rcall TX_DATA
rjmp CGRAM_loop
CGRAM_loop_end:
; == pgm body ==
;load text to DDRAM
ldi r17,ROW1_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT1*2)
ldi ZL,low(MYTEXT1*2)
DDRAM_loop:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM_loop_end
rcall TX_DATA
rjmp DDRAM_loop
DDRAM_loop_end:
;load text to DDRAM
ldi r17,ROW2_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT2*2)
ldi ZL,low(MYTEXT2*2)
DDRAM2_loop:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM2_loop_end
rcall TX_DATA
rjmp DDRAM2_loop
DDRAM2_loop_end:
;direct write to X,Y - example
ldi r16,3 ;Y, zacina 0 a roste smerem dolu
ldi r17,5 ;X, zacina nulou a roste smerem doprava
rcall LCD_CURSOR_XY
ldi r17,"%"
rcall TX_DATA
ldi r17,"%"
rcall TX_DATA
ldi r17,"%"
rcall TX_DATA
;infinite loop
loop: rjmp loop
MYTEXT1:
.DB 0,0,0," POKUSNY TEXT ",0,0,0,0xFE
MYTEXT2:
.DB "Opravdu pekny text!",0xFE
; == USER-DEFINED CHARS ==
MYCHARS:
; 5x8, first 3 bits are not used
;end of mychars
.DB 0xe,0x1f,0x15,0x1f,0x1f,0x1f,0x15 ;smajlik
;konec
.DB 0xFE
;r16=Y
;r17=X
LCD_CURSOR_XY:
cpi r16,0
brne test1
fail: ldi r16,ROW1_ADDR
rjmp addrdone
test1:
cpi r16,1
brne test2
ldi r16,ROW2_ADDR
rjmp addrdone
test2:
cpi r16,2
brne test3
ldi r16,ROW3_ADDR
rjmp addrdone
test3:
cpi r16,3
brne fail
ldi r16,ROW4_ADDR
addrdone:
add r17,r16
rcall DDRAM_SET_ADDR
ret
;r16=počet ms (cca)
delay:
push r17 ;2
push r18 ;2
d1:
ldi r17,250 ;1
d2:
ldi r18,14 ;1
d3:
dec r18 ;1
nop
brne d3 ;2 (1
dec r17 ; +1)
brne d2 ;2 (1
dec r16 ; +1)
brne d1 ;2 (1)
pop r18 ;2
pop r17 ;2
ret
LCD_INIT:
ldi r16,16
rcall delay
ldi r16,0b00000010 ;4bit
out PORTB,r16
rcall LCD_CLK
ldi r16,5
rcall delay
ldi r17,LCD_MODE_4BIT_2LINE ;set 4-bit mode
rcall TX_INSTR
ret
;r17
TX_INSTR:
swap r17 ;send high nibble
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
swap r17 ;send low nibble
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
ret
;r17
TX_DATA:
swap r17 ;send high nibble
mov r16,r17
andi r16,0b00001111
sbr r16,(1<<RS)
out LCDPORT,r16
rcall LCD_CLK
swap r17 ;send low nibble
mov r16,r17
andi r16,0b00001111
sbr r16,(1<<RS)
out LCDPORT,r16
rcall LCD_CLK
ret
;r17 disabled to reduce code size
;RX_DATA:
; ;input
; ldi r16,0b11110000 ;LCDPORT dirrection (RS RW E n.c.) output, (D7 D6 D5 D4) input
; out LCDDDR,r16
; ldi r16,0b00001111 ;pullups to data pins enabled
; out LCDPORT,r16
;
; clr r17
; ldi r16,(1<<RW)|(1<<RS)
; out LCDPORT,r16 ;set LCD to read mode, for data
;
; rcall LCD_CLK ;receive high nibble
; in r16,LCDPIN
; andi r16,0b00001111
; or r17,r16
; swap r17 ;store high nibble
;
; rcall LCD_CLK ;receive low nibble
; in r16,LCDPIN
; andi r16,0b00001111
; or r17,r16 ;store low nibble
;
; ;output
; ldi r16,0b11111111 ;LCDPORT as output (RS RW E n.c. D7 D6 D5 D4)
; out LCDDDR,r16
; ldi r16,0b00000000 ;LCDPORT off
; out LCDPORT,r16
;
; ;r17=received value (D7 D6 D5 D4 D3 D2 D1 D0)
; ret
LCD_CLK:
sbi LCDPORT,E ;EXECUTE on
nop
nop
nop
cbi LCDPORT,E ;EXECUTE off
ldi r16,150 ;pause: 100 for 4MHZ
clkw:
dec r16
brne clkw
ret
;r17
;7 bitu (1.radek zacina 00,druhej 40)
DDRAM_SET_ADDR:
clr r16
sbr r16,0b10000000
or r17,r16
rcall TX_INSTR
ret
;r17
;6 bitu (5,4,3 = znak, 2,1,0 = radek - shora)
CGRAM_SET_ADDR:
clr r16
sbr r16,0b01000000
or r17,r16
rcall TX_INSTR
ret

@ -0,0 +1,215 @@
; Zapojeni (Připojen DMC-50399 v 4-bitovem modu):
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; --+ PD0 PB7 +-- RS (0=instr W, BF+addr R; 1=data W/R)
; --+ PD1 PB6 +-- R/W (1=read,0=write)
; --+ PA1 PB5 +-- E (strobe)
; --+ PA0 PB4 +--
; --+ PD2 PB3 +-- DATA 7
; --+ PD3 PB2 +-- DATA 6
; --+ PD4 PB1 +-- DATA 5
; --+ PD5 PB0 +-- DATA 4
; GND --+ GND PD6 +--
; +-------------+
;DMC-50399:
; 1 - GND
; 2 - +5V
; 3 - 0V (lcd driver)
; 4 - RS
; 5 - R/W
; 6 - E
; 7 - DATA 0
; 8 - DATA 1
;...
;14 - DATA 7
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;250x16=1ms=1000us
;LFUSE: 0xE2
;HFUSE: 0xDF
;K O N S T A N T Y + P R E Z D I V K Y P O U R T U A P I N U
;PORTB
.equ LCDPORT = PORTB
.equ LCDPIN = PINB
.equ LCDDDR = DDRB
.equ RS = 7
.equ RW = 6
.equ E = 5
.equ LCD_CLEAR = 0b00000001
.equ LCD_HOME = 0b00000010
.equ LCD_MODE_INC_NOSHIFT = 0b00000110
.equ LCD_MODE_INC_SHIFT = 0b00000111
.equ LCD_MODE_DEC_NOSHIFT = 0b00000100
.equ LCD_MODE_DEC_SHIFT = 0b00000101
.equ LCD_DISPLAY_DISABLED = 0b00001000
.equ LCD_DISPLAY_NOCURSOR = 0b00001100
.equ LCD_DISPLAY_CURSOR = 0b00001110
.equ LCD_DISPLAY_BLINK = 0b00001101
.equ LCD_DISPLAY_ALTER = 0b00001111
;4bit,5x7,2line
.equ LCD_MODE_4BIT = 0b00101000
.equ LCD_MODE_8BIT = 0b00111000
.equ ROW1_ADDR = 0x00
.equ ROW2_ADDR = 0x40
;aliasy pointerů
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0013
;nastaveni po resetu
.DB "DMC-50399 TEST" ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
;PORTB = LCDPORT
ldi r16,0b11111111 ;smer portu B
out LCDDDR,r16
ldi r16,0b00000000 ;vypnout B
out LCDPORT,r16
sei ;Global Interrupt Enable
rcall LCD_INIT
ldi r17,LCD_MODE_INC_SHIFT
rcall TX_INSTR
ldi r17,LCD_DISPLAY_NOCURSOR
rcall TX_INSTR
ldi r17,20
rcall DDRAM_SET_ADDR
colastart:
ldi ZH,high(ROW1*2)
ldi ZL,low(ROW1*2)
read1: lpm r17,Z+
cpi r17,0
breq colastart
rcall TX_DATA
ldi r16,60
rcall delay
rjmp read1
loop: rjmp loop
;r16=počet ms (cca)
delay:
push r17 ;2
push r18 ;2
d1:
ldi r17,250 ;1
d2:
ldi r18,14 ;1
d3:
dec r18 ;1
nop
brne d3 ;2 (1
dec r17 ; +1)
brne d2 ;2 (1
dec r16 ; +1)
brne d1 ;2 (1)
pop r18 ;2
pop r17 ;2
ret
LCD_INIT:
ldi r16,16
rcall delay
ldi r16,0b00000010 ;4bit
out PORTB,r16
rcall LCD_CLK
ldi r16,5
rcall delay
ldi r17,LCD_MODE_4BIT
rcall TX_INSTR
ret
;r17
TX_INSTR:
swap r17
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
swap r17
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
ret
;r17
TX_DATA:
swap r17
mov r16,r17
andi r16,0b00001111
sbr r16,0b10000000
out LCDPORT,r16
rcall LCD_CLK
swap r17
mov r16,r17
andi r16,0b00001111
sbr r16,0b10000000
out LCDPORT,r16
rcall LCD_CLK
ret
LCD_CLK:
sbi LCDPORT,E
nop
nop
nop
cbi LCDPORT,E
ldi r16,100 ;100 funguje na 4MHZ
clkw1:
dec r16
brne clkw1
; ldi r16,1
; rcall delay
ret
;7 bitu (1.radek zacina 00,druhej 40)
DDRAM_SET_ADDR:
clr r16
sbr r16,0b10000000
or r17,r16
rcall TX_INSTR
ret
;6 bitu (5,4,3 = znak, 2,1,0 = radek - shora)
CGRAM_SET_ADDR:
clr r16
sbr r16,0b01000000
or r17,r16
rcall TX_INSTR
ret
ROW1:
.DB "*** Ice cold CocaCola sold here! *** ",0

@ -0,0 +1,305 @@
; Zapojeni (Připojen DMC-50399 v 4-bitovem modu):
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; --+ PD0 PB7 +-- RS (0=instr W, BF+addr R; 1=data W/R)
; --+ PD1 PB6 +-- R/W (1=read,0=write)
; --+ PA1 PB5 +-- E (clock, active falling edge)
; --+ PA0 PB4 +--
; --+ PD2 PB3 +-- DATA 7
; --+ PD3 PB2 +-- DATA 6
; --+ PD4 PB1 +-- DATA 5
; --+ PD5 PB0 +-- DATA 4
; GND --+ GND PD6 +--
; +-------------+
;DMC-50399:
; 1 - GND
; 2 - +5V
; 3 - 0V (lcd driver)
; 4 - RS
; 5 - R/W
; 6 - E
; 7 - DATA 0
; 8 - DATA 1
;...
;14 - DATA 7
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;250x16=1ms=1000us
;LFUSE: 0xE2
;HFUSE: 0xDF
;K O N S T A N T Y + P R E Z D I V K Y P O R T U A P I N U
.equ LCDPORT = PORTB
.equ LCDPIN = PINB
.equ LCDDDR = DDRB
.equ RS = 7
.equ RW = 6
.equ E = 5
.equ LCD_CLEAR = 0b00000001
.equ LCD_HOME = 0b00000010
.equ LCD_MODE_INC_NOSHIFT = 0b00000110
.equ LCD_MODE_INC_SHIFT = 0b00000111
.equ LCD_MODE_DEC_NOSHIFT = 0b00000100
.equ LCD_MODE_DEC_SHIFT = 0b00000101
.equ LCD_DISPLAY_DISABLED = 0b00001000
.equ LCD_DISPLAY_NOCURSOR = 0b00001100
.equ LCD_DISPLAY_CURSOR = 0b00001110
.equ LCD_DISPLAY_ALTER = 0b00001101
.equ LCD_DISPLAY_CURSOR_ALTER = 0b00001111
.equ LCD_CURSOR_LEFT = 0b00010000
.equ LCD_CURSOR_RIGHT = 0b00010100
.equ LCD_SHIFT_LEFT = 0b00011000
.equ LCD_SHIFT_RIGHT = 0b00011100
;5x7 font, 1-line
.equ LCD_MODE_4BIT_1LINE = 0b00100000
;.equ LCD_MODE_8BIT_1LINE = 0b00110000
;5x7 font, 2-line
.equ LCD_MODE_4BIT_2LINE = 0b00101000
;.equ LCD_MODE_8BIT_2LINE = 0b00111000
.equ ROW1_ADDR = 0x00
.equ ROW2_ADDR = 0x40
;aliases
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0013
;nastaveni po resetu
.DB "HD44780 INTERFACE" ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
;PORTB = LCDPORT
ldi r16,0b11111111 ;smer portu B
out LCDDDR,r16
ldi r16,0b00000000 ;vypnout B
out LCDPORT,r16
sei ;Global Interrupt Enable
rcall LCD_INIT
ldi r17,LCD_MODE_INC_NOSHIFT
rcall TX_INSTR
ldi r17,LCD_DISPLAY_NOCURSOR
rcall TX_INSTR
;load user-defined characters to CGRAM
ldi r17,0
rcall CGRAM_SET_ADDR
ldi ZH,high(MYCHARS*2)
ldi ZL,low(MYCHARS*2)
CGRAM_loop:
lpm r17,Z+
cpi r17,0xFE
breq CGRAM_loop_end
rcall TX_DATA
rjmp CGRAM_loop
CGRAM_loop_end:
;load text to DDRAM
ldi r17,ROW1_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT1*2)
ldi ZL,low(MYTEXT1*2)
DDRAM_loop:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM_loop_end
rcall TX_DATA
rjmp DDRAM_loop
DDRAM_loop_end:
;load text to DDRAM
ldi r17,ROW2_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT2*2)
ldi ZL,low(MYTEXT2*2)
DDRAM_loop2:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM_loop2_end
rcall TX_DATA
rjmp DDRAM_loop2
DDRAM_loop2_end:
loop: rjmp loop
MYTEXT1:
.DB 0,3," This is GEOCACHE",0xFE
MYTEXT2:
.DB 1,2," ", 4, " geocaching.com",0xFE
MYCHARS:
; 5x8, first 3 bits are not used
;end of mychars
.DB 0x0,0x15,0xe,0x6,0xe,0x1b,0x18
.DB 0x18,0x1c,0xa,0x7,0x3,0x0,0x0
.DB 0x8,0xc,0xe,0xc,0x8,0x8,0x8 ;0x8,0xe,0xf,0x4,0x4,0x2,0x0
.DB 0x0,0x0,0x18,0x1c,0xa,0x7,0x3
.DB 0x0,0x4,0x2,0x1f,0x2,0x4,0x0
.DB 0xFE
;r16=počet ms (cca)
delay:
push r17 ;2
push r18 ;2
d1:
ldi r17,250 ;1
d2:
ldi r18,14 ;1
d3:
dec r18 ;1
nop
brne d3 ;2 (1
dec r17 ; +1)
brne d2 ;2 (1
dec r16 ; +1)
brne d1 ;2 (1)
pop r18 ;2
pop r17 ;2
ret
LCD_INIT:
ldi r16,16
rcall delay
ldi r16,0b00000010 ;4bit
out PORTB,r16
rcall LCD_CLK
ldi r16,5
rcall delay
ldi r17,LCD_MODE_4BIT_2LINE ;set 4-bit mode
rcall TX_INSTR
ret
;r17
TX_INSTR:
swap r17 ;send high nibble
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
swap r17 ;send low nibble
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
ret
;r17
TX_DATA:
swap r17 ;send high nibble
mov r16,r17
andi r16,0b00001111
sbr r16,(1<<RS)
out LCDPORT,r16
rcall LCD_CLK
swap r17 ;send low nibble
mov r16,r17
andi r16,0b00001111
sbr r16,(1<<RS)
out LCDPORT,r16
rcall LCD_CLK
ret
;r17
RX_DATA:
;input
ldi r16,0b11110000 ;LCDPORT dirrection (RS RW E n.c.) output, (D7 D6 D5 D4) input
out LCDDDR,r16
ldi r16,0b00001111 ;pullups to data pins enabled
out LCDPORT,r16
clr r17
ldi r16,(1<<RW)|(1<<RS)
out LCDPORT,r16 ;set LCD to read mode, for data
rcall LCD_CLK ;receive high nibble
in r16,LCDPIN
andi r16,0b00001111
or r17,r16
swap r17 ;store high nibble
rcall LCD_CLK ;receive low nibble
in r16,LCDPIN
andi r16,0b00001111
or r17,r16 ;store low nibble
;output
ldi r16,0b11111111 ;LCDPORT as output (RS RW E n.c. D7 D6 D5 D4)
out LCDDDR,r16
ldi r16,0b00000000 ;LCDPORT off
out LCDPORT,r16
;r17=received value (D7 D6 D5 D4 D3 D2 D1 D0)
ret
LCD_CLK:
sbi LCDPORT,E ;EXECUTE on
nop
nop
nop
cbi LCDPORT,E ;EXECUTE off
ldi r16,100 ;pause: 100 for 4MHZ
clkw:
dec r16
brne clkw
ret
;r17
;7 bitu (1.radek zacina 00,druhej 40)
DDRAM_SET_ADDR:
clr r16
sbr r16,0b10000000
or r17,r16
rcall TX_INSTR
ret
;r17
;6 bitu (5,4,3 = znak, 2,1,0 = radek - shora)
CGRAM_SET_ADDR:
clr r16
sbr r16,0b01000000
or r17,r16
rcall TX_INSTR
ret

@ -0,0 +1,305 @@
; Zapojeni (Připojen DMC-50399 v 4-bitovem modu):
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; --+ PD0 PB7 +-- RS (0=instr W, BF+addr R; 1=data W/R)
; --+ PD1 PB6 +-- R/W (1=read,0=write)
; --+ PA1 PB5 +-- E (clock, active falling edge)
; --+ PA0 PB4 +--
; --+ PD2 PB3 +-- DATA 7
; --+ PD3 PB2 +-- DATA 6
; --+ PD4 PB1 +-- DATA 5
; --+ PD5 PB0 +-- DATA 4
; GND --+ GND PD6 +--
; +-------------+
;DMC-50399:
; 1 - GND
; 2 - +5V
; 3 - 0V (lcd driver)
; 4 - RS
; 5 - R/W
; 6 - E
; 7 - DATA 0
; 8 - DATA 1
;...
;14 - DATA 7
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;250x16=1ms=1000us
;LFUSE: 0xE2
;HFUSE: 0xDF
;K O N S T A N T Y + P R E Z D I V K Y P O R T U A P I N U
.equ LCDPORT = PORTB
.equ LCDPIN = PINB
.equ LCDDDR = DDRB
.equ RS = 7
.equ RW = 6
.equ E = 5
.equ LCD_CLEAR = 0b00000001
.equ LCD_HOME = 0b00000010
.equ LCD_MODE_INC_NOSHIFT = 0b00000110
.equ LCD_MODE_INC_SHIFT = 0b00000111
.equ LCD_MODE_DEC_NOSHIFT = 0b00000100
.equ LCD_MODE_DEC_SHIFT = 0b00000101
.equ LCD_DISPLAY_DISABLED = 0b00001000
.equ LCD_DISPLAY_NOCURSOR = 0b00001100
.equ LCD_DISPLAY_CURSOR = 0b00001110
.equ LCD_DISPLAY_ALTER = 0b00001101
.equ LCD_DISPLAY_CURSOR_ALTER = 0b00001111
.equ LCD_CURSOR_LEFT = 0b00010000
.equ LCD_CURSOR_RIGHT = 0b00010100
.equ LCD_SHIFT_LEFT = 0b00011000
.equ LCD_SHIFT_RIGHT = 0b00011100
;5x7 font, 1-line
.equ LCD_MODE_4BIT_1LINE = 0b00100000
;.equ LCD_MODE_8BIT_1LINE = 0b00110000
;5x7 font, 2-line
.equ LCD_MODE_4BIT_2LINE = 0b00101000
;.equ LCD_MODE_8BIT_2LINE = 0b00111000
.equ ROW1_ADDR = 0x00
.equ ROW2_ADDR = 0x40
;aliases
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0013
;nastaveni po resetu
.DB "HD44780 INTERFACE" ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
;PORTB = LCDPORT
ldi r16,0b11111111 ;smer portu B
out LCDDDR,r16
ldi r16,0b00000000 ;vypnout B
out LCDPORT,r16
sei ;Global Interrupt Enable
rcall LCD_INIT
ldi r17,LCD_MODE_INC_NOSHIFT
rcall TX_INSTR
ldi r17,LCD_DISPLAY_NOCURSOR
rcall TX_INSTR
;load user-defined characters to CGRAM
ldi r17,0
rcall CGRAM_SET_ADDR
ldi ZH,high(MYCHARS*2)
ldi ZL,low(MYCHARS*2)
CGRAM_loop:
lpm r17,Z+
cpi r17,0xFE
breq CGRAM_loop_end
rcall TX_DATA
rjmp CGRAM_loop
CGRAM_loop_end:
;load text to DDRAM
ldi r17,ROW1_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT1*2)
ldi ZL,low(MYTEXT1*2)
DDRAM_loop:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM_loop_end
rcall TX_DATA
rjmp DDRAM_loop
DDRAM_loop_end:
;load text to DDRAM
ldi r17,ROW2_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT2*2)
ldi ZL,low(MYTEXT2*2)
DDRAM_loop2:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM_loop2_end
rcall TX_DATA
rjmp DDRAM_loop2
DDRAM_loop2_end:
loop: rjmp loop
MYTEXT1:
.DB 0,3," This is GEOCACHE",0xFE
MYTEXT2:
.DB 1,2, 4, "geocaching.com",0xFE
MYCHARS:
; 5x8, first 3 bits are not used
;end of mychars
.DB 0x0,0x15,0xe,0x6,0xe,0x1b,0x18
.DB 0x18,0x1c,0xa,0x7,0x3,0x0,0x0
.DB 0x8,0xe,0xf,0x4,0x4,0x2,0x0
.DB 0x0,0x0,0x18,0x1c,0xa,0x7,0x3
.DB 0x0,0x4,0x2,0x1f,0x2,0x4,0x0
.DB 0xFE
;r16=počet ms (cca)
delay:
push r17 ;2
push r18 ;2
d1:
ldi r17,250 ;1
d2:
ldi r18,14 ;1
d3:
dec r18 ;1
nop
brne d3 ;2 (1
dec r17 ; +1)
brne d2 ;2 (1
dec r16 ; +1)
brne d1 ;2 (1)
pop r18 ;2
pop r17 ;2
ret
LCD_INIT:
ldi r16,16
rcall delay
ldi r16,0b00000010 ;4bit
out PORTB,r16
rcall LCD_CLK
ldi r16,5
rcall delay
ldi r17,LCD_MODE_4BIT_2LINE ;set 4-bit mode
rcall TX_INSTR
ret
;r17
TX_INSTR:
swap r17 ;send high nibble
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
swap r17 ;send low nibble
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
ret
;r17
TX_DATA:
swap r17 ;send high nibble
mov r16,r17
andi r16,0b00001111
sbr r16,(1<<RS)
out LCDPORT,r16
rcall LCD_CLK
swap r17 ;send low nibble
mov r16,r17
andi r16,0b00001111
sbr r16,(1<<RS)
out LCDPORT,r16
rcall LCD_CLK
ret
;r17
RX_DATA:
;input
ldi r16,0b11110000 ;LCDPORT dirrection (RS RW E n.c.) output, (D7 D6 D5 D4) input
out LCDDDR,r16
ldi r16,0b00001111 ;pullups to data pins enabled
out LCDPORT,r16
clr r17
ldi r16,(1<<RW)|(1<<RS)
out LCDPORT,r16 ;set LCD to read mode, for data
rcall LCD_CLK ;receive high nibble
in r16,LCDPIN
andi r16,0b00001111
or r17,r16
swap r17 ;store high nibble
rcall LCD_CLK ;receive low nibble
in r16,LCDPIN
andi r16,0b00001111
or r17,r16 ;store low nibble
;output
ldi r16,0b11111111 ;LCDPORT as output (RS RW E n.c. D7 D6 D5 D4)
out LCDDDR,r16
ldi r16,0b00000000 ;LCDPORT off
out LCDPORT,r16
;r17=received value (D7 D6 D5 D4 D3 D2 D1 D0)
ret
LCD_CLK:
sbi LCDPORT,E ;EXECUTE on
nop
nop
nop
cbi LCDPORT,E ;EXECUTE off
ldi r16,100 ;pause: 100 for 4MHZ
clkw:
dec r16
brne clkw
ret
;r17
;7 bitu (1.radek zacina 00,druhej 40)
DDRAM_SET_ADDR:
clr r16
sbr r16,0b10000000
or r17,r16
rcall TX_INSTR
ret
;r17
;6 bitu (5,4,3 = znak, 2,1,0 = radek - shora)
CGRAM_SET_ADDR:
clr r16
sbr r16,0b01000000
or r17,r16
rcall TX_INSTR
ret

@ -0,0 +1,311 @@
; Zapojeni (Připojen DMC-50399 v 4-bitovem modu):
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; --+ PD0 PB7 +-- RS (0=instr W, BF+addr R; 1=data W/R)
; --+ PD1 PB6 +-- R/W (1=read,0=write)
; --+ PA1 PB5 +-- E (clock, active falling edge)
; --+ PA0 PB4 +--
; --+ PD2 PB3 +-- DATA 7
; --+ PD3 PB2 +-- DATA 6
; --+ PD4 PB1 +-- DATA 5
; --+ PD5 PB0 +-- DATA 4
; GND --+ GND PD6 +--
; +-------------+
;DMC-50399:
; 1 - GND
; 2 - +5V
; 3 - 0V (lcd driver)
; 4 - RS
; 5 - R/W
; 6 - E
; 7 - DATA 0
; 8 - DATA 1
;...
;14 - DATA 7
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;250x16=1ms=1000us
;LFUSE: 0xE2
;HFUSE: 0xDF
;K O N S T A N T Y + P R E Z D I V K Y P O R T U A P I N U
.equ LCDPORT = PORTB
.equ LCDPIN = PINB
.equ LCDDDR = DDRB
.equ RS = 7
.equ RW = 6
.equ E = 5
.equ LCD_CLEAR = 0b00000001
.equ LCD_HOME = 0b00000010
.equ LCD_MODE_INC_NOSHIFT = 0b00000110
.equ LCD_MODE_INC_SHIFT = 0b00000111
.equ LCD_MODE_DEC_NOSHIFT = 0b00000100
.equ LCD_MODE_DEC_SHIFT = 0b00000101
.equ LCD_DISPLAY_DISABLED = 0b00001000
.equ LCD_DISPLAY_NOCURSOR = 0b00001100
.equ LCD_DISPLAY_CURSOR = 0b00001110
.equ LCD_DISPLAY_ALTER = 0b00001101
.equ LCD_DISPLAY_CURSOR_ALTER = 0b00001111
.equ LCD_CURSOR_LEFT = 0b00010000
.equ LCD_CURSOR_RIGHT = 0b00010100
.equ LCD_SHIFT_LEFT = 0b00011000
.equ LCD_SHIFT_RIGHT = 0b00011100
;5x7 font, 1-line
.equ LCD_MODE_4BIT_1LINE = 0b00100000
;.equ LCD_MODE_8BIT_1LINE = 0b00110000
;5x7 font, 2-line
.equ LCD_MODE_4BIT_2LINE = 0b00101000
;.equ LCD_MODE_8BIT_2LINE = 0b00111000
.equ ROW1_ADDR = 0x00
.equ ROW2_ADDR = 0x40
;aliases
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0013
;nastaveni po resetu
.DB "HD44780 INTERFACE" ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
;PORTB = LCDPORT
ldi r16,0b11111111 ;smer portu B
out LCDDDR,r16
ldi r16,0b00000000 ;vypnout B
out LCDPORT,r16
sei ;Global Interrupt Enable
rcall LCD_INIT
ldi r17,LCD_MODE_INC_NOSHIFT
rcall TX_INSTR
ldi r17,LCD_DISPLAY_NOCURSOR
rcall TX_INSTR
;load user-defined characters to CGRAM
ldi r17,0
rcall CGRAM_SET_ADDR
ldi ZH,high(MYCHARS*2)
ldi ZL,low(MYCHARS*2)
CGRAM_loop:
lpm r17,Z+
cpi r17,0xFE
breq CGRAM_loop_end
rcall TX_DATA
rjmp CGRAM_loop
CGRAM_loop_end:
;load text to DDRAM
ldi r17,ROW1_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT1*2)
ldi ZL,low(MYTEXT1*2)
DDRAM_loop:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM_loop_end
rcall TX_DATA
rjmp DDRAM_loop
DDRAM_loop_end:
;load text to DDRAM
ldi r17,ROW2_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT2*2)
ldi ZL,low(MYTEXT2*2)
DDRAM_loop2:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM_loop2_end
rcall TX_DATA
rjmp DDRAM_loop2
DDRAM_loop2_end:
loop: rjmp loop
MYTEXT1:
.DB " ",0,1,1,1,1,1,2,4,4,4,4,5,6,6,6,6,6,7," ",0xFE
MYTEXT2:
.DB "Straslivy krokodyl!",0xFE
MYCHARS:
; 5x8, first 3 bits are not used
;end of mychars
.DB 0x0,0x3,0x0,0x0,0x0,0x1,0x3 ;konec huby 0
.DB 0x0,0x1f,0xe,0x4,0x10,0x19,0x1f ;zuby1
.DB 0x2,0x15,0x1f,0x1f,0x1f,0x1f,0x10 ;hlava 2
.DB 0xe,0x1f,0x15,0x1f,0x1f,0x1f,0x15 ;smajlik 3
.DB 0x0,0x1f,0x1f,0x1f,0x1f,0x1,0x3 ;noha4
.DB 0x0,0x10,0x1c,0x1f,0x1f,0x0,0x0 ;do ocasu5
.DB 0x0,0x4,0xe,0x1f,0x1f,0x0,0x0
.DB 0x0,0x0,0x0,0x0,0x10,0x0,0x0 ;konec ocasu7
.DB 0xFE
;r16=počet ms (cca)
delay:
push r17 ;2
push r18 ;2
d1:
ldi r17,250 ;1
d2:
ldi r18,14 ;1
d3:
dec r18 ;1
nop
brne d3 ;2 (1
dec r17 ; +1)
brne d2 ;2 (1
dec r16 ; +1)
brne d1 ;2 (1)
pop r18 ;2
pop r17 ;2
ret
LCD_INIT:
ldi r16,16
rcall delay
ldi r16,0b00000010 ;4bit
out PORTB,r16
rcall LCD_CLK
ldi r16,5
rcall delay
ldi r17,LCD_MODE_4BIT_2LINE ;set 4-bit mode
rcall TX_INSTR
ret
;r17
TX_INSTR:
swap r17 ;send high nibble
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
swap r17 ;send low nibble
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
ret
;r17
TX_DATA:
swap r17 ;send high nibble
mov r16,r17
andi r16,0b00001111
sbr r16,(1<<RS)
out LCDPORT,r16
rcall LCD_CLK
swap r17 ;send low nibble
mov r16,r17
andi r16,0b00001111
sbr r16,(1<<RS)
out LCDPORT,r16
rcall LCD_CLK
ret
;r17
RX_DATA:
;input
ldi r16,0b11110000 ;LCDPORT dirrection (RS RW E n.c.) output, (D7 D6 D5 D4) input
out LCDDDR,r16
ldi r16,0b00001111 ;pullups to data pins enabled
out LCDPORT,r16
clr r17
ldi r16,(1<<RW)|(1<<RS)
out LCDPORT,r16 ;set LCD to read mode, for data
rcall LCD_CLK ;receive high nibble
in r16,LCDPIN
andi r16,0b00001111
or r17,r16
swap r17 ;store high nibble
rcall LCD_CLK ;receive low nibble
in r16,LCDPIN
andi r16,0b00001111
or r17,r16 ;store low nibble
;output
ldi r16,0b11111111 ;LCDPORT as output (RS RW E n.c. D7 D6 D5 D4)
out LCDDDR,r16
ldi r16,0b00000000 ;LCDPORT off
out LCDPORT,r16
;r17=received value (D7 D6 D5 D4 D3 D2 D1 D0)
ret
LCD_CLK:
sbi LCDPORT,E ;EXECUTE on
nop
nop
nop
cbi LCDPORT,E ;EXECUTE off
ldi r16,100 ;pause: 100 for 4MHZ
clkw:
dec r16
brne clkw
ret
;r17
;7 bitu (1.radek zacina 00,druhej 40)
DDRAM_SET_ADDR:
clr r16
sbr r16,0b10000000
or r17,r16
rcall TX_INSTR
ret
;r17
;6 bitu (5,4,3 = znak, 2,1,0 = radek - shora)
CGRAM_SET_ADDR:
clr r16
sbr r16,0b01000000
or r17,r16
rcall TX_INSTR
ret

@ -0,0 +1,228 @@
; Zapojeni (Připojen DMC-50399 v 4-bitovem modu):
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; --+ PD0 PB7 +-- RS (0=instr W, BF+addr R; 1=data W/R)
; --+ PD1 PB6 +-- R/W (1=read,0=write)
; --+ PA1 PB5 +-- E (strobe)
; --+ PA0 PB4 +--
; --+ PD2 PB3 +-- DATA 7
; --+ PD3 PB2 +-- DATA 6
; --+ PD4 PB1 +-- DATA 5
; --+ PD5 PB0 +-- DATA 4
; GND --+ GND PD6 +--
; +-------------+
;DMC-50399:
; 1 - GND
; 2 - +5V
; 3 - 0V (lcd driver)
; 4 - RS
; 5 - R/W
; 6 - E
; 7 - DATA 0
; 8 - DATA 1
;...
;14 - DATA 7
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;250x16=1ms=1000us
;LFUSE: 0xE2
;HFUSE: 0xDF
;K O N S T A N T Y + P R E Z D I V K Y P O U R T U A P I N U
;PORTB
.equ LCDPORT = PORTB
.equ LCDPIN = PINB
.equ LCDDDR = DDRB
.equ RS = 7
.equ RW = 6
.equ E = 5
.equ LCD_CLEAR = 0b00000001
.equ LCD_HOME = 0b00000010
.equ LCD_MODE_INC_NOSH = 0b00000110
.equ LCD_MODE_INC_SH = 0b00000111
.equ LCD_MODE_DEC_NOSH = 0b00000100
.equ LCD_MODE_DEC_SH = 0b00000101
.equ LCD_DISPLAY_DISABLED = 0b00001000
.equ LCD_DISPLAY_NOCURSOR = 0b00001100
.equ LCD_DISPLAY_CURSOR = 0b00001110
.equ LCD_DISPLAY_BLINK = 0b00001101
.equ LCD_DISPLAY_ALTER = 0b00001111
;4bit,5x7,2line
.equ LCD_MODE_4BIT = 0b00101000
.equ LCD_MODE_8BIT = 0b00111000
.equ ROW1_ADDR = 0x00
.equ ROW2_ADDR = 0x40
;aliasy pointerů
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0013
;nastaveni po resetu
.DB "DMC-50399 TEST" ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
;PORTB = LCDPORT
ldi r16,0b11111111 ;smer portu B
out LCDDDR,r16
ldi r16,0b00000000 ;vypnout B
out LCDPORT,r16
sei ;Global Interrupt Enable
rcall LCD_INIT
ldi r17,LCD_DISPLAY_DISABLED
rcall TX_INSTR
ldi r17,ROW1_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(ROW1*2)
ldi ZL,low(ROW1*2)
read1: lpm r17,Z+
cpi r17,0
breq text2
rcall TX_DATA
rjmp read1
text2:
ldi r17,ROW2_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(ROW2*2)
ldi ZL,low(ROW2*2)
read2: lpm r17,Z+
cpi r17,0
breq loop
rcall TX_DATA
rjmp read2
ldi r17,LCD_DISPLAY_CURSOR
rcall TX_INSTR
loop: rjmp loop
;r16=počet ms (cca)
delay:
push r17 ;2
push r18 ;2
d1:
ldi r17,250 ;1
d2:
ldi r18,14 ;1
d3:
dec r18 ;1
nop
brne d3 ;2 (1
dec r17 ; +1)
brne d2 ;2 (1
dec r16 ; +1)
brne d1 ;2 (1)
pop r18 ;2
pop r17 ;2
ret
LCD_INIT:
ldi r16,16
rcall delay
ldi r16,0b00000010 ;4bit
out PORTB,r16
rcall LCD_CLK
ldi r16,5
rcall delay
ldi r17,LCD_MODE_4BIT
rcall TX_INSTR
ldi r17,LCD_MODE_INC_NOSH
rcall TX_INSTR
ret
;r17
TX_INSTR:
swap r17
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
swap r17
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
ret
;r17
TX_DATA:
swap r17
mov r16,r17
andi r16,0b00001111
sbr r16,0b10000000
out LCDPORT,r16
rcall LCD_CLK
swap r17
mov r16,r17
andi r16,0b00001111
sbr r16,0b10000000
out LCDPORT,r16
rcall LCD_CLK
ret
LCD_CLK:
sbi LCDPORT,E
nop
nop
nop
cbi LCDPORT,E
ldi r16,100 ;100 funguje na 4MHZ
clkw1:
dec r16
brne clkw1
; ldi r16,1
; rcall delay
ret
;7 bitu (1.radek zacina 00,druhej 40)
DDRAM_SET_ADDR:
clr r16
sbr r16,0b10000000
or r17,r16
rcall TX_INSTR
ret
;6 bitu (5,4,3 = znak, 2,1,0 = radek - shora)
CGRAM_SET_ADDR:
clr r16
sbr r16,0b01000000
or r17,r16
rcall TX_INSTR
ret
ROW1:
.DB "ATTINY2313 & HD44780",0
ROW2:
.DB "* www.ondrovo.com *",0

@ -0,0 +1,380 @@
; Zapojeni (Připojen DMC-50399 v 4-bitovem modu):
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; --+ PD0 PB7 +-- RS (0=instr W, BF+addr R; 1=data W/R)
; --+ PD1 PB6 +-- R/W (1=read,0=write)
; --+ PA1 PB5 +-- E (clock, active falling edge)
; --+ PA0 PB4 +--
; --+ PD2 PB3 +-- DATA 7
; --+ PD3 PB2 +-- DATA 6
; --+ PD4 PB1 +-- DATA 5
; --+ PD5 PB0 +-- DATA 4
; GND --+ GND PD6 +--
; +-------------+
;DMC-50399:
; 1 - GND
; 2 - +5V
; 3 - 0V (lcd driver)
; 4 - RS
; 5 - R/W
; 6 - E
; 7 - DATA 0
; 8 - DATA 1
;...
;14 - DATA 7
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;250x16=1ms=1000us
;LFUSE: 0xE2
;HFUSE: 0xDF
;K O N S T A N T Y + P R E Z D I V K Y P O R T U A P I N U
.equ LCDPORT = PORTB
.equ LCDPIN = PINB
.equ LCDDDR = DDRB
.equ RS = 7
.equ RW = 6
.equ E = 5
.equ LCD_CLEAR = 0b00000001
.equ LCD_HOME = 0b00000010
.equ LCD_MODE_INC_NOSHIFT = 0b00000110
.equ LCD_MODE_INC_SHIFT = 0b00000111
.equ LCD_MODE_DEC_NOSHIFT = 0b00000100
.equ LCD_MODE_DEC_SHIFT = 0b00000101
.equ LCD_DISPLAY_DISABLED = 0b00001000
.equ LCD_DISPLAY_NOCURSOR = 0b00001100
.equ LCD_DISPLAY_CURSOR = 0b00001110
.equ LCD_DISPLAY_ALTER = 0b00001101
.equ LCD_DISPLAY_CURSOR_ALTER = 0b00001111
.equ LCD_CURSOR_LEFT = 0b00010000
.equ LCD_CURSOR_RIGHT = 0b00010100
.equ LCD_SHIFT_LEFT = 0b00011000
.equ LCD_SHIFT_RIGHT = 0b00011100
;5x7 font, 1-line
.equ LCD_MODE_4BIT_1LINE = 0b00100000
;.equ LCD_MODE_8BIT_1LINE = 0b00110000
;5x7 font, 2-line
.equ LCD_MODE_4BIT_2LINE = 0b00101000
;.equ LCD_MODE_8BIT_2LINE = 0b00111000
.equ ROW1_ADDR = 0x00
.equ ROW2_ADDR = 0x40
.equ ROW3_ADDR = 0x14
.equ ROW4_ADDR = 0x54
;aliases
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0013
;nastaveni po resetu
.DB "HD44780 INTERFACE" ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
;PORTB = LCDPORT
ldi r16,0b11111111 ;smer portu B
out LCDDDR,r16
ldi r16,0b00000000 ;vypnout B
out LCDPORT,r16
sei ;Global Interrupt Enable
rcall LCD_INIT
ldi r17,LCD_MODE_INC_NOSHIFT
rcall TX_INSTR
ldi r17,LCD_DISPLAY_NOCURSOR
rcall TX_INSTR
;load user-defined characters to CGRAM
ldi r17,0
rcall CGRAM_SET_ADDR
ldi ZH,high(MYCHARS*2)
ldi ZL,low(MYCHARS*2)
CGRAM_loop:
lpm r17,Z+
cpi r17,0xFE
breq CGRAM_loop_end
rcall TX_DATA
rjmp CGRAM_loop
CGRAM_loop_end:
;load text to DDRAM
ldi r17,ROW1_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT1*2)
ldi ZL,low(MYTEXT1*2)
DDRAM_loop:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM_loop_end
rcall TX_DATA
rjmp DDRAM_loop
DDRAM_loop_end:
;load text to DDRAM
ldi r17,ROW2_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT2*2)
ldi ZL,low(MYTEXT2*2)
DDRAM2_loop:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM2_loop_end
rcall TX_DATA
rjmp DDRAM2_loop
DDRAM2_loop_end:
;load text to DDRAM
ldi r17,ROW3_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT3*2)
ldi ZL,low(MYTEXT3*2)
DDRAM3_loop:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM3_loop_end
rcall TX_DATA
rjmp DDRAM3_loop
DDRAM3_loop_end:
;load text to DDRAM
ldi r17,ROW4_ADDR
rcall DDRAM_SET_ADDR
ldi ZH,high(MYTEXT4*2)
ldi ZL,low(MYTEXT4*2)
DDRAM4_loop:
lpm r17,Z+
cpi r17,0xFE
breq DDRAM4_loop_end
rcall TX_DATA
rjmp DDRAM4_loop
DDRAM4_loop_end:
ldi r16,2 ;Y (0,1,2,3)
ldi r17,7 ;X (0,1,2,...19,20,....)
rcall LCD_CURSOR_XY
ldi r17,255
rcall TX_DATA
loop: rjmp loop
MYTEXT1:
.DB 0,"PRVNI RADEK=======*",0xFE
MYTEXT2:
.DB 0,0,"DRUHY RADEK======*",0xFE
MYTEXT3:
.DB 0,0,0,"TRETI RADEK=====*",0xFE
MYTEXT4:
.DB 0,0,0,0,"CTVRTY RADEK===*",0xFE
MYCHARS:
; 5x8, first 3 bits are not used
;end of mychars
.DB 0xe,0x1f,0x15,0x1f,0x1f,0x1f,0x15 ;smajlik
;konec
.DB 0xFE
;r16=počet ms (cca)
delay:
push r17 ;2
push r18 ;2
d1:
ldi r17,250 ;1
d2:
ldi r18,14 ;1
d3:
dec r18 ;1
nop
brne d3 ;2 (1
dec r17 ; +1)
brne d2 ;2 (1
dec r16 ; +1)
brne d1 ;2 (1)
pop r18 ;2
pop r17 ;2
ret
;r16=Y
;r17=X
LCD_CURSOR_XY:
cpi r16,0
brne test1
fail: ldi r16,ROW1_ADDR
rjmp addrdone
test1:
cpi r16,1
brne test2
ldi r16,ROW2_ADDR
rjmp addrdone
test2:
cpi r16,2
brne test3
ldi r16,ROW3_ADDR
rjmp addrdone
test3:
cpi r16,3
brne fail
ldi r16,ROW4_ADDR
addrdone:
add r17,r16
rcall DDRAM_SET_ADDR
ret
LCD_INIT:
ldi r16,16
rcall delay
ldi r16,0b00000010 ;4bit
out PORTB,r16
rcall LCD_CLK
ldi r16,5
rcall delay
ldi r17,LCD_MODE_4BIT_2LINE ;set 4-bit mode
rcall TX_INSTR
ret
;r17
TX_INSTR:
swap r17 ;send high nibble
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
swap r17 ;send low nibble
mov r16,r17
andi r16,0b00001111
out LCDPORT,r16
rcall LCD_CLK
ret
;r17
TX_DATA:
swap r17 ;send high nibble
mov r16,r17
andi r16,0b00001111
sbr r16,(1<<RS)
out LCDPORT,r16
rcall LCD_CLK
swap r17 ;send low nibble
mov r16,r17
andi r16,0b00001111
sbr r16,(1<<RS)
out LCDPORT,r16
rcall LCD_CLK
ret
;r17
;RX_DATA:
; ;input
; ldi r16,0b11110000 ;LCDPORT dirrection (RS RW E n.c.) output, (D7 D6 D5 D4) input
; out LCDDDR,r16
; ldi r16,0b00001111 ;pullups to data pins enabled
; out LCDPORT,r16
;
; clr r17
; ldi r16,(1<<RW)|(1<<RS)
; out LCDPORT,r16 ;set LCD to read mode, for data
;
; rcall LCD_CLK ;receive high nibble
; in r16,LCDPIN
; andi r16,0b00001111
; or r17,r16
; swap r17 ;store high nibble
;
; rcall LCD_CLK ;receive low nibble
; in r16,LCDPIN
; andi r16,0b00001111
; or r17,r16 ;store low nibble
;
; ;output
; ldi r16,0b11111111 ;LCDPORT as output (RS RW E n.c. D7 D6 D5 D4)
; out LCDDDR,r16
; ldi r16,0b00000000 ;LCDPORT off
; out LCDPORT,r16
;
; ;r17=received value (D7 D6 D5 D4 D3 D2 D1 D0)
; ret
LCD_CLK:
sbi LCDPORT,E ;EXECUTE on
nop
nop
nop
cbi LCDPORT,E ;EXECUTE off
ldi r16,150 ;pause: 100 for 4MHZ
clkw:
dec r16
brne clkw
ret
;r17
;7 bitu (1.radek zacina 00,druhej 40)
DDRAM_SET_ADDR:
clr r16
sbr r16,0b10000000
or r17,r16
rcall TX_INSTR
ret
;r17
;6 bitu (5,4,3 = znak, 2,1,0 = radek - shora)
CGRAM_SET_ADDR:
clr r16
sbr r16,0b01000000
or r17,r16
rcall TX_INSTR
ret

@ -0,0 +1,89 @@
.device attiny13
.def cnt=r22
.def i=r18
.def j=r19
.def pom=r16
.def dat=r20
.equ clks=200 ;100 kloknuti (36kHz) na 1 bit (200 preklopeni)
.equ clksh=100
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazeme preruseni
ldi r16,0b00011110 ;smer portu
out DDRB,r16
clr pom
clr i
clr j
clr cnt
sei ;povolime preruseni
NIC: clr i
clr dat
W0: in pom,PINB ;1 [10+56 =66 cyklu *clksh celkani]
sbrc pom,0 ;2 /
rjmp NIC ;(1)
rcall sclk ;3
inc i ;1
cpi i,clksh ;1
brne W0 ;2 10 kloku + 56 kloku z sclk = 66 kloku
;bylo 100 kloku 0
ldi j,8 ;1 -> bude se cist osm bitu
BREAD: dec j ;1
breq ENDB ;1
clr i ;1
W1: nop ;1 -> cekaci smycka 1klok
nop ;1
nop ;1
rcall sclk ;3
inc i ;1
cpi i,clks ;1
brne W1 ;2
in pom,PINB ;1 zanedbatelne zpozdeni - netreba zohlednovat
sbrs pom,0 ;2 (1) precte se PINB0 a invertovany se zapise do bufferu
sbr dat,0 ;(+1)
lsl dat ;1
rjmp BREAD ;2
ENDB:
;skoncil byte, ted bude stopbit - netreba cist
cpi dat,0b00111100
breq toogle
clr dat
clr cnt
clr i
clr j
rjmp NIC
toogle: sbi PORTB,1
;sbi pinb,1
rjmp NIC
sclk: ;presne nastavena doba jednoho kloku - 200 kloku == 1bit
ldi r16,6 ;1
cB:
nop ; [48
nop ; -
nop ; -
nop ; -
nop ; -
dec r16 ; -
brne cB ; -
nop ; ]
nop ;3
nop ;
nop ;
ret ;4 celkem: 56

@ -0,0 +1,66 @@
;tohle ceka az bude na PB0 dlouho jednicka a pak invertuje PB1 a ceka na nulu na PB0
.device attiny13
.def cnt=r19
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b00011110 ;smer portu
out DDRB,r16
ldi r16,0
out PORTB,r16
clr r16
clr r17
clr r18
clr cnt
sei ;Global Interrupt Enable
LOOP: ;cekam na 0
in r16,PINB
sbrs r16,0
rjmp pinset
rjmp LOOP
pinset: ;cekej, az bude hodne cyklu po sobe 0 na PB0
clr cnt
pinset2:
clr r20
pinset2b:
clr r21
pinset2c:
in r16,PINB
sbrc r16,0
rjmp loop
inc r21
cpi r21,2
brne pinset2c
inc r20
cpi r20,255
brne pinset2b
inc cnt
cpi cnt,255
brne pinset2
sbi PINB,1 ;invertuj to co je na PB1
odrus0: ;cekam na 1
in r16,PINB
sbrc r16,0
rjmp w2
rjmp odrus0
w2: ;cekani pro odruseni zakmitu
inc cnt
cpi cnt,255
brne w2
rjmp LOOP ;skok na loop

@ -0,0 +1,63 @@
;tohle ceka az bude na PB0 dlouho jednicka a pak invertuje PB1 a ceka na nulu na PB0
.device attiny13
.def cnt=r19
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b00011110 ;smer portu
out DDRB,r16
ldi r16,0
out PORTB,r16
clr r16
clr r17
clr r18
clr cnt
sei ;Global Interrupt Enable
LOOP: ;cekam na nulu
in r16,PINB
sbrs r16,0
rjmp pinset
rjmp LOOP
pinset: ;cekej, az bude hodne cyklu po sobe 0 na PB0
clr cnt
pinset2:
clr r20
pinset2b:
inc r20
in r16,PINB
sbrc r16,0
rjmp loop
cpi r20,255
brne pinset2b
inc cnt
cpi cnt,255
brne pinset2
sbi PORTB,1 ;zapni pb1
odrus0: ;cekam na 1
in r16,PINB
sbrc r16,0
rjmp w2
rjmp odrus0
w2: ;cekani pro odruseni zakmitu
inc cnt
cpi cnt,255
brne w2
cbi PORTB,1
rjmp LOOP ;skok na loop

@ -0,0 +1,252 @@
.device attiny13
.def a=r16
.def b=r17
.def i=r18
.def j=r19
.def k=r20
.def secs=r21
.DEF mins=r22
;běží na 4.8MHz
.MACRO cvrk1
sbi portb,3
.ENDMACRO
.MACRO cvrk0
cbi portb,3
.ENDMACRO
.MACRO osc1
in a, TIMSK0
ORI a, 0b00000100
out timsk0,a
.ENDMACRO
.MACRO osc0
clr a
out timsk0,a
.ENDMACRO
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow
RJMP TIMER
.org 0x0010
RESET:
ldi a,low(RAMEND) ;nastavi stack pointer
out SPL,a
cli ;zakazat vsechna preruseni
ldi a,0b00001000 ;smer portu
out DDRB,a
ldi a,0 ;vymazat port
out PORTB,a
clr a
clr b
clr i
clr j
clr k
clr secs
clr mins
ldi r16,0b00000011 ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/64=75000Hz
ldi r16,0b00000010 ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,75 ;Compare Match 0 A je 75
out OCR0A,r16 ;75000/75=1000Hz interrupt
osc0 ;zakazeme interrupt
in a,MCUCR ;zapne se vnitrni pullup
ori a,0b01000000
out MCUCR,a
sei ;Global Interrupt Enable
in a,PINB
andi a,0b00000111
;volba programu podle nastaveni prepinacu
cpi a,0
breq prog0
cpi a,1
breq prog1
cpi a,2
breq prog2
cpi a,3
breq prog3
cpi a,4
breq prog4
cpi a,5
breq prog5
cpi a,6
breq prog6
rjmp prog7
prog0: ;5 min, (3 cvrky / 1 min pauza) x5, sleep
ldi mins,5 ;pauza úvod
rcall minuty
ldi k,5 ;počet opakování
pd00:
rcall scvrk
rcall scvrk
rcall scvrk
ldi mins,1 ;minuty pauza
rcall minuty
dec k
brne pd00
rjmp usni
prog1: ;2 min, (2 cvrk / 2 min pauza) x5, sleep
ldi mins,2 ;pauza úvod
rcall minuty
ldi k,6 ;počet opakování
pd01:
rcall scvrk
rcall scvrk
ldi mins,2 ;minuty pauza
rcall minuty
dec k
brne pd01
rjmp usni
prog2: ;40 min, (2 cvrky / 20 sec pauza) x13, sleep
ldi mins,40 ;pauza úvod
rcall minuty
ldi k,13 ;počet opakování
pd02:
rcall scvrk
rcall scvrk
ldi secs,20 ;sekundy pauza
rcall sekundy
dec k
brne pd02
rjmp usni
prog3: ;5 min, (2 cvrk / 5 min pauza) x8, sleep
ldi mins,5 ;pauza úvod
rcall minuty
ldi k,9 ;počet opakování
pd03:
rcall scvrk
rcall scvrk
rcall scvrk
rcall scvrk
ldi mins,5 ;minuty pauza
rcall minuty
dec k
brne pd03
rjmp usni
prog4: ;10 min, (4 cvrk / 10 min pauza) x5, sleep
ldi mins,10 ;pauza úvod
rcall minuty
ldi k,5 ;počet opakování
pd04:
rcall scvrk
rcall scvrk
rcall scvrk
rcall scvrk
ldi mins,10 ;minuty pauza
rcall minuty
dec k
brne pd04
rjmp usni
prog5: ;20 min, (4 cvrk / 10 min pauza) x1, sleep
ldi mins,20 ;pauza úvod
rcall minuty
rcall scvrk
rcall scvrk
rcall scvrk
rcall scvrk
rjmp usni
prog6: ;0, (2 cvrk / 10s) x inf
rcall scvrk
rcall scvrk
ldi secs,10 ;minuty pauza
rcall sekundy
rjmp prog6
prog7: ;trvale
cvrk1
infloop:
rjmp infloop
usni:
in a,MCUCR
ori a,0b00110000
andi a,0b01110111
out MCUCR,a
sleep
rjmp usni ;kdyby se probudil tak zase usne
TIMER: ;pracuje se s prerusenim 1000x za sekundu
inc i
cpi i,100
brne endcas
clr i
inc j
endcas:
reti
scvrk:
clr i
clr j
cvrk1
osc1
del01: cpi j,20 ;konstanta pro dobu jednoho cvrku v desetinach sekundy
brne del01
osc0
cvrk0
ret
sekundy:
clr i
clr j
osc1
del02: cpi j,10 ;konstanta pro dobu 1 sekundy
brne del02
dec secs
breq endsecs
clr i
clr j
rjmp del02
endsecs:
osc0
ret
minuty:
ldi secs,60 ;minuta ma 60 sekund -> secs=60
rcall sekundy ;a vykoname cekani secs sekund
dec mins
breq endmins
rjmp minuty
endmins:
ret

@ -0,0 +1,124 @@
.device attiny13
.def cnt=r19
.equ clks=200 ;100 kloknuti (36kHz) na 1 bit (200 preklopeni)
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b00011110 ;smer portu
out DDRB,r16
ldi r16,0 ;vypnout PullUp
out PORTB,r16
clr r16
clr r17
clr r18
clr cnt
sei ;Global Interrupt Enable
LOOP:
in r16,PINB
sbrc r16,0
rjmp pinset
rjmp LOOP
pinset: ;cekej, az bude 200 cyklu po sobe 1 na PB0
clr cnt
pinset2:
in r16,PINB
sbrs r16,0
rjmp loop
inc cnt
cpi cnt,200
brne pinset2
rcall blik
rcall nblik
rcall nblik
rcall blik
rcall blik
rcall blik
rcall blik
rcall nblik
rcall nblik
rcall blik
rcall nblik
rcall nblik
rcall nblik
rcall nblik
rcall nblik
rcall nblik
rcall nblik
rcall nblik
rcall nblik
pinset0: ;cekej, az bude 200 cyklu po sobe 0 na PB0
;clr cnt
pinset3:
;in r16,PINB
;sbrc r16,0
;rjmp pinset0
;inc cnt
;cpi cnt,200
;brne pinset3
rjmp LOOP ;skok na loop
blik:
ldi r17,clks
A:
ldi r16,7 ;1
B:
nop ;1
nop ;1
nop ;1
nop ;1
nop ;1
dec r16 ;1
brne B ;2 (1 +
nop ;1)
sbi PINB,1 ;2 -> toogle portb1
nop ;1
nop ;1
dec r17 ;1
breq endblik ;1 (2 -> preruseno, nedulezite)
rjmp A ;2
endblik:
cbi PORTB,1 ;2
ret ;4
nblik:
ldi r17,clks
nA:
ldi r16,7 ;1
nB:
nop ;1
nop ;1
nop ;1
nop ;1
nop ;1
dec r16 ;1
brne nB ;2 (1 +
nop ;1)
nop ;1
nop ;1
nop ;1
nop ;1
dec r17 ;1
breq endnblik ;1 (2 -> preruseno, nedulezite)
rjmp nA ;2
endnblik:
cbi PORTB,1 ;2
ret ;4

@ -0,0 +1,70 @@
.device attiny13
.def cnt=r19
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b00011110 ;smer portu
out DDRB,r16
ldi r16,0 ;vypnout PullUp
out PORTB,r16
clr r16
clr r17
clr r18
clr cnt
sei ;Global Interrupt Enable
LOOP:
in r16,PINB
sbrc r16,0
rjmp pinset
rjmp LOOP
pinset: ;cekej, az bude 100 cyklu po sobe 1 na PB0
clr cnt
pinset2:
in r16,PINB
sbrs r16,0
rjmp loop
inc cnt
cpi cnt,200
brne pinset2
rcall blik
w2: ;cekani pro odruseni zakmitu - 40 cyklu
inc cnt
cpi cnt,200
brne w2
rjmp LOOP ;skok na loop
blik:
A:
ldi r16,7 ;1
B:
nop ;1
nop ;1
nop ;1
nop ;1
nop ;1
dec r16 ;1
brne B ;2 (1 +
nop ;1)
sbi PINB,1 ;2 -> toogle portb1
nop ;1
nop ;1
in r17,pinb ;1
sbrc r17,0 ;1 (2 -> preruseno, nedulezite)
rjmp A ;2
cbi PORTB,1 ;2
ret ;4

@ -0,0 +1,131 @@
;Kostka pro attiny13
;sestupna hrana impulzu na PB0 spousti kostku, vzestupna hrana spousti zpomalovani
;kostka se zastavi na nahodnem cisle.
;segmenty:
; PB2 PB3
; PB4 PB1 PB4
; PB3 PB2
; diody na spolecne noze maji kazda svuj odpor. muze byt pole odporu
.device attiny13
.def i=r20 ;prvni citac, cita jen pro zpomaleni
.def j=r21 ;druhy citac, cita az do TOP, pak se oba vynulujou
.def top=r22 ;maximalni hodnota pro citac j -> vynulovani a dalsi faze
.def faze=r23 ;faze kostky. jsou zde cisla 0-5
.def plus=r24 ;prirustek v dobe cekani na timer overflow - vzdy se inkrementuje
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow A
rjmp CASOVAC
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b11111110 ;smer pinu
out DDRB,r16
ldi r16,1 ;PullUpy
out PORTB,r16
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/64=75000Hz
ldi r16,(1<<WGM01) ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,75 ;Compare Match 0 A je 75
out OCR0A,r16 ;75000/75=1000Hz interrupt
in r16, TIMSK0 ;povolit interrupt od preteceni
ori r16, (1<<OCIE0A)
out timsk0,r16
clr i ;nastavime pocatecni hodnoty
clr j
ldi top,2
ldi faze,0
ldi plus,1
sei ;Global Interrupt Enable
LOOP:
in r16,PINB ;kontrola jestli je PINB0 vypnutej (stisknuto)
andi r16, 1
sbrc r16, 0
rjmp LOOP ;NE -> jdi na loop
ldi top,1 ;ANO -> nastavit top na 1 a vymazat citace
ldi plus,1
clr i
clr j
CEKANI:
ldi top,3 ;cekame na uvolneni, zatim se prepina s top=2
ldi plus,1
in r16,PINB ;kontrola jestli je PINB0 zapnutej (pusteny tlacitko)
andi r16, 1
sbrs r16, 0
rjmp CEKANI
ldi top,1
ldi plus,1
clr i
clr j
rjmp LOOP ;skok na loop
CASOVAC:
cpi top,50 ;porovnam top s 50, kdyz vetsi nebo rovno
brge CASEND ;tak se dal nepocita - preskok na konec
inc i ;i++
cpi i,8 ;je i == 8 ?
brne CASEND ; ne -> konec, citam dal
clr i ;i=0
inc j ;j++
cp j,top ;je j == top?
brne CASEND ; ne -> konec, citam dal
add top,plus ;k top prictu plus
inc plus ;a plus zvysim o 1
clr i ;vymazu pomocne
clr j
inc faze ;dalsi faze kostky
cpi faze,6 ;je faze 6?
brne VYBER ; neni -> skok na VYBER
ldi faze,0 ; je -> nuluju fazi
VYBER: cpi faze,0 ;podminene se vybere, co se ma zobrazit
breq F0
cpi faze,1
breq F1
cpi faze,2
breq F2
cpi faze,3
breq F3
cpi faze,4
breq F4
cpi faze,5
breq F5
F0: ldi r16,0b00000011
out PORTB,r16
rjmp CASEND
F1: ldi r16,0b00000101
out PORTB,r16
rjmp CASEND
F2: ldi r16,0b00001011
out PORTB,r16
rjmp CASEND
F3: ldi r16,0b00001101
out PORTB,r16
rjmp CASEND
F4: ldi r16,0b00001111
out PORTB,r16
rjmp CASEND
F5: ldi r16,0b00011101
out PORTB,r16
CASEND: ;navrat z preruseni
reti

@ -0,0 +1,146 @@
;Kostka pro attiny13
;sestupna hrana impulzu na PB0 spousti kostku, vzestupna hrana spousti zpomalovani
;kostka se zastavi na nahodnem cisle.
;segmenty:
; PB2 PB3
; PB4 PB1 PB4
; PB3 PB2
; diody na spolecne noze maji kazda svuj odpor. muze byt pole odporu
.device attiny13
.def i=r20 ;prvni citac, cita jen pro zpomaleni
.def j=r21 ;druhy citac, cita az do TOP, pak se oba vynulujou
.def top=r22 ;maximalni hodnota pro citac j -> vynulovani a dalsi faze
.def faze=r23 ;faze kostky. jsou zde cisla 0-5
.def plus=r24 ;prirustek v dobe cekani na timer overflow - vzdy se inkrementuje
.def fx=r25
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow A
rjmp CASOVAC
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b11111110 ;smer pinu
out DDRB,r16
ldi r16,1 ;PullUpy
out PORTB,r16
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/64=75000Hz
ldi r16,(1<<WGM01) ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,75 ;Compare Match 0 A je 75
out OCR0A,r16 ;75000/75=1000Hz interrupt
in r16, TIMSK0 ;povolit interrupt od preteceni
ori r16, (1<<OCIE0A)
out timsk0,r16
clr i ;nastavime pocatecni hodnoty
clr j
ldi top,2
ldi fx,5
ldi faze,0
ldi plus,1
sei ;Global Interrupt Enable
LOOP:
inc fx
cpi fx,6
brne fxok
ldi fx, 0
fxok:
in r16,PINB ;kontrola jestli je PINB0 vypnutej (stisknuto)
andi r16, 1
sbrc r16, 0
rjmp LOOP ;NE -> jdi na loop
mov faze, fx
ldi top,1 ;ANO -> nastavit top na 1 a vymazat citace
ldi plus,1
clr i
clr j
CEKANI:
ldi top,2 ;cekame na uvolneni, zatim se prepina s top=2
ldi plus,1
inc fx
cpi fx,6
brne fxok2
ldi fx, 0
fxok2:
in r16,PINB ;kontrola jestli je PINB0 zapnutej (pusteny tlacitko)
andi r16, 1
sbrs r16, 0
rjmp CEKANI
mov faze, fx
ldi top,1
ldi plus,1
clr i
clr j
rjmp LOOP ;skok na loop
CASOVAC:
cpi top,50 ;porovnam top s 50, kdyz vetsi nebo rovno
brge CASEND ;tak se dal nepocita - preskok na konec
inc i ;i++
cpi i,8 ;je i == 8 ?
brne CASEND ; ne -> konec, citam dal
clr i ;i=0
inc j ;j++
cp j,top ;je j == top?
brne CASEND ; ne -> konec, citam dal
add top,plus ;k top prictu plus
inc plus ;a plus zvysim o 1
clr i ;vymazu pomocne
clr j
inc faze ;dalsi faze kostky
cpi faze,6 ;je faze 6?
brne VYBER ; neni -> skok na VYBER
ldi faze,0 ; je -> nuluju fazi
VYBER: cpi faze,0 ;podminene se vybere, co se ma zobrazit
breq F0
cpi faze,1
breq F1
cpi faze,2
breq F2
cpi faze,3
breq F3
cpi faze,4
breq F4
cpi faze,5
breq F5
F0: ldi r16,0b00000011
out PORTB,r16
rjmp CASEND
F1: ldi r16,0b00000101
out PORTB,r16
rjmp CASEND
F2: ldi r16,0b00001011
out PORTB,r16
rjmp CASEND
F3: ldi r16,0b00001101
out PORTB,r16
rjmp CASEND
F4: ldi r16,0b00001111
out PORTB,r16
rjmp CASEND
F5: ldi r16,0b00011101
out PORTB,r16
CASEND: ;navrat z preruseni
reti

@ -0,0 +1,150 @@
;Kostka pro attiny13
;sestupna hrana impulzu na PB0 spousti kostku, vzestupna hrana spousti zpomalovani
;kostka se zastavi na nahodnem cisle.
;segmenty:
; PB2 PB3
; PB4 PB1 PB4
; PB3 PB2
; diody na spolecne noze maji kazda svuj odpor. muze byt pole odporu
.device attiny13
.def i=r20 ;prvni citac, cita jen pro zpomaleni
.def j=r21 ;druhy citac, cita az do TOP, pak se oba vynulujou
.def top=r22 ;maximalni hodnota pro citac j -> vynulovani a dalsi faze
.def faze=r23 ;faze kostky. jsou zde cisla 0-5
.def plus=r24 ;prirustek v dobe cekani na timer overflow - vzdy se inkrementuje
.def fx=r25
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow A
rjmp CASOVAC
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b11111110 ;smer pinu
out DDRB,r16
ldi r16,1 ;PullUpy
out PORTB,r16
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/64=75000Hz
ldi r16,(1<<WGM01) ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,75 ;Compare Match 0 A je 75
out OCR0A,r16 ;75000/75=1000Hz interrupt
in r16, TIMSK0 ;povolit interrupt od preteceni
ori r16, (1<<OCIE0A)
out timsk0,r16
clr i ;nastavime pocatecni hodnoty
clr j
ldi top,2
ldi fx,5
ldi faze,0
ldi plus,1
sei ;Global Interrupt Enable
LOOP:
inc fx
cpi fx,6
brne fxok
ldi fx, 0
fxok:
in r16,PINB ;kontrola jestli je PINB0 vypnutej (stisknuto)
andi r16, 1
sbrc r16, 0
rjmp LOOP ;NE -> jdi na loop
mov faze, fx
cli
ldi top,1 ;ANO -> nastavit top na 1 a vymazat citace
ldi plus,1
clr i
clr j
sei
CEKANI:
ldi top,2 ;cekame na uvolneni, zatim se prepina s top=2
ldi plus,1
inc fx
cpi fx,6
brne fxok2
ldi fx, 0
fxok2:
in r16,PINB ;kontrola jestli je PINB0 zapnutej (pusteny tlacitko)
andi r16, 1
sbrs r16, 0
rjmp CEKANI
cli
mov faze, fx
ldi top,1
ldi plus,1
clr i
clr j
sei
rjmp LOOP ;skok na loop
CASOVAC:
cpi top,50 ;porovnam top s 50, kdyz vetsi nebo rovno
brge CASEND ;tak se dal nepocita - preskok na konec
inc i ;i++
cpi i,8 ;je i == 8 ?
brne CASEND ; ne -> konec, citam dal
clr i ;i=0
inc j ;j++
cp j,top ;je j == top?
brne CASEND ; ne -> konec, citam dal
add top,plus ;k top prictu plus
inc plus ;a plus zvysim o 1
clr i ;vymazu pomocne
clr j
inc faze ;dalsi faze kostky
cpi faze,6 ;je faze 6?
brne VYBER ; neni -> skok na VYBER
ldi faze,0 ; je -> nuluju fazi
VYBER: cpi faze,0 ;podminene se vybere, co se ma zobrazit
breq F0
cpi faze,1
breq F1
cpi faze,2
breq F2
cpi faze,3
breq F3
cpi faze,4
breq F4
cpi faze,5
breq F5
F0: ldi r16,0b00000011
out PORTB,r16
rjmp CASEND
F1: ldi r16,0b00000101
out PORTB,r16
rjmp CASEND
F2: ldi r16,0b00001011
out PORTB,r16
rjmp CASEND
F3: ldi r16,0b00001101
out PORTB,r16
rjmp CASEND
F4: ldi r16,0b00001111
out PORTB,r16
rjmp CASEND
F5: ldi r16,0b00011101
out PORTB,r16
CASEND: ;navrat z preruseni
reti

@ -0,0 +1,111 @@
;pracuje jako 5-ti bitovy binarni citac
;vystupy 3 a 4 jsou prohozene kvuli desce
.device attiny13
.def i=r20 ;prvni citac, cita jen pro zpomaleni
.def j=r21 ;druhy citac, cita az do TOP, pak se oba vynulujou
.def top=r22 ;maximalni hodnota pro citac j -> vynulovani a dalsi faze
.def faze=r23
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow A
rjmp CASOVAC
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b11111110 ;smer pinu
out DDRB,r16
ldi r16,0 ;PullUpy
out PORTB,r16
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/64=75000Hz
ldi r16,(1<<WGM01) ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,75 ;Compare Match 0 A je 75
out OCR0A,r16 ;75000/75=1000Hz interrupt
in r16, TIMSK0 ;povolit interrupt od preteceni
ori r16, (1<<OCIE0A)
out timsk0,r16
clr i ;nastavime pocatecni hodnoty
clr j
ldi top,2
ldi faze,0
sei ;Global Interrupt Enable
LOOP:
in r16,PINB ;kontrola jestli je PINB0 zapnutej
sbrs r16, 0
rjmp LOOP ;NE -> jdi na loop
ldi top,1 ;ANO -> nastavit top na 1 a vymazat citace
clr i
clr j
CEKANI:
ldi top,2 ;cekame na uvolneni, zatim se prepina s top=2
in r16,PINB ;kontrola jestli je PINB0 vypnutej
sbrc r16, 0
rjmp CEKANI
rjmp LOOP ;skok na loop
CASOVAC:
cpi top,40
breq CASEND
inc i
cpi i,10
brne CASEND
clr i
inc j
cp j,top
brne CASEND
inc top
clr i
clr j
inc faze ;PODMINENY VYBER VYSTUPNIHO SYMBOLU
cpi faze,6
brne VYBER
ldi faze,0
VYBER: cpi faze,0
breq F0
cpi faze,1
breq F1
cpi faze,2
breq F2
cpi faze,3
breq F3
cpi faze,4
breq F4
cpi faze,5
breq F5
F0: ldi r16,0b00000010
out PORTB,r16
rjmp CASEND
F1: ldi r16,0b00000100
out PORTB,r16
rjmp CASEND
F2: ldi r16,0b00001010
out PORTB,r16
rjmp CASEND
F3: ldi r16,0b00001100
out PORTB,r16
rjmp CASEND
F4: ldi r16,0b00001110
out PORTB,r16
rjmp CASEND
F5: ldi r16,0b00011100
out PORTB,r16
CASEND:
reti

@ -0,0 +1,2 @@
@ECHO OFF
"C:\Program Files\Atmel\AVR Tools\AvrAssembler2\avrasm2.exe" -S "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\labels.tmp" -fI -W+ie -o "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.hex" -d "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.obj" -e "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.eep" -m "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.map" "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm"

@ -0,0 +1 @@
<AVRStudio><MANAGEMENT><ProjectName>efekty_LED</ProjectName><Created>06-Sep-2007 20:57:13</Created><LastEdit>08-Sep-2007 21:56:18</LastEdit><ICON>208</ICON><ProjectType>0</ProjectType><Created>06-Sep-2007 20:57:13</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>Atmel AVR Assembler</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>efekty_LED.obj</ObjectFile><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</EntryFile><SaveFolder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega16</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><modules><module></module></modules><Triggers></Triggers></Debugger><AvrAssembler><Folder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\</Folder><RelPath>efekty_LED.asm</RelPath><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</EntryFile><IncludePath>C:\Program Files\Atmel\AVR Tools\AvrAssembler\Appnotes</IncludePath><V2IncludePath></V2IncludePath><V2Parameters></V2Parameters><FileType>I</FileType><ObjectName>efekty_LED</ObjectName><Wrap>0</Wrap><ErrorAsWarning>0</ErrorAsWarning><MapFile>1</MapFile><ListFile>0</ListFile><Version1>0</Version1><PreCompile></PreCompile><PostCompile></PostCompile><SourceFiles>,</SourceFiles></AvrAssembler><ProjectIncludeDirs><Dirs><Dir>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</Dir></Dirs></ProjectIncludeDirs><ProjectFiles><Files><Name>\efekty_LED.asm</Name><Name>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m16def.inc</Name></Files></ProjectFiles><IOView><usergroups/></IOView><Files><File00000><FileId>00000</FileId><FileName>efekty_LED2</FileName><Status>1</Status></File00000><File00001><FileId>00001</FileId><FileName>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\tn13def.inc</FileName><Status>1</Status></File00001><File00002><FileId>00002</FileId><FileName>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\tn2313def.inc</FileName><Status>1</Status></File00002><File00003><FileId>00003</FileId><FileName>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m16def.inc</FileName><Status>257</Status></File00003><File00004><FileId>00004</FileId><FileName>efekty_LED.asm</FileName><Status>257</Status></File00004><File00005><FileId>00005</FileId><FileName>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\_cekani.inc</FileName><Status>259</Status></File00005></Files><Workspace><File00000><Position>193 71 1022 718</Position><LineCol>0 0</LineCol></File00000><File00001><Position>14 146 677 456</Position><LineCol>0 0</LineCol></File00001><File00002><Position>235 132 898 442</Position><LineCol>0 0</LineCol></File00002><File00003><Position>191 67 1020 722</Position><LineCol>0 0</LineCol></File00003><File00004><Position>197 71 1026 566</Position><LineCol>78 6</LineCol><State>Maximized</State></File00004><File00005><Position>311 204 978 518</Position><LineCol>12 15</LineCol></File00005></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

@ -0,0 +1,87 @@
;pokus
.include "m16def.inc"
.def POM=r16
.def A=r17
.def B=r18
.def C=r19
.def D=r20
.cseg
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010 ;zacatek vlastniho programu
RESET:
LDI R16,0x5F ;nastavi stack pointer na 0x045F
OUT SPL,R16 ;coz je konec SRAM u ATmegy16
LDI R16,0x04
OUT SPH,R16
LDI POM,0xFF ;nastavi vsechny porty jako vystupni
OUT DDRA,POM
OUT DDRB,POM
OUT DDRC,POM
OUT DDRD,POM
LDI A,0b01110000 ;hodnoty portu A az D
LDI B,0b10001000
LDI C,0b10001000
LDI D,0b00000111
LOOP:
CLC
ROL A ;preroluj A registr
BRCC ACC ;pokud je C=0, skoc na ACC (A Carry Clear)
SBR A,0b00000001 ;nastav prvni bit v A na 1
ACC: OUT PORTA,A ;output A do PORTA
CLC
ROL B ;preroluj B registr - totez co u A reg.
BRCC BCC
SBR B,0b00000001
BCC: OUT PORTB,B
CLC
ROL C ;preroluj C registr - totez co u A reg.
BRCC CCC
SBR C,0b00000001
CCC: OUT PORTC,C
CLC
ROL D ;preroluj D registr - totez co u A reg.
BRCC DCC
SBR D,0b00000001
DCC: OUT PORTD,D
RCALL CEKANI
RJMP LOOP ;jdi na LOOP
CEKANI:
PUSH r18 ;ulozit pouzivane registry do STACKU
PUSH r17
PUSH r16
LDI r16, 40
L1: DEC r16
LDI r17, 40
L2: DEC r17
LDI r18, 40
L3: DEC r18
CPI r18, 0
BRNE L3
CPI r17, 0
BRNE L2
CPI r16, 0
BRNE L1
POP r16 ;nacist puvodni obsah registru ze STACKU
POP r17
POP r18
RET ;navrat do hlavniho programu

@ -0,0 +1,621 @@
AVRASM ver. 2.1.12 C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm Sat Sep 08 21:56:17 2007
EQU SIGNATURE_000 0000001e
EQU SIGNATURE_001 00000094
EQU SIGNATURE_002 00000003
EQU SREG 0000003f
EQU SPL 0000003d
EQU SPH 0000003e
EQU OCR0 0000003c
EQU GICR 0000003b
EQU GIFR 0000003a
EQU TIMSK 00000039
EQU TIFR 00000038
EQU SPMCSR 00000037
EQU TWCR 00000036
EQU MCUCR 00000035
EQU MCUCSR 00000034
EQU TCCR0 00000033
EQU TCNT0 00000032
EQU OSCCAL 00000031
EQU OCDR 00000031
EQU SFIOR 00000030
EQU TCCR1A 0000002f
EQU TCCR1B 0000002e
EQU TCNT1L 0000002c
EQU TCNT1H 0000002d
EQU OCR1AL 0000002a
EQU OCR1AH 0000002b
EQU OCR1BL 00000028
EQU OCR1BH 00000029
EQU ICR1L 00000026
EQU ICR1H 00000027
EQU TCCR2 00000025
EQU TCNT2 00000024
EQU OCR2 00000023
EQU ASSR 00000022
EQU WDTCR 00000021
EQU UBRRH 00000020
EQU UCSRC 00000020
EQU EEARL 0000001e
EQU EEARH 0000001f
EQU EEDR 0000001d
EQU EECR 0000001c
EQU PORTA 0000001b
EQU DDRA 0000001a
EQU PINA 00000019
EQU PORTB 00000018
EQU DDRB 00000017
EQU PINB 00000016
EQU PORTC 00000015
EQU DDRC 00000014
EQU PINC 00000013
EQU PORTD 00000012
EQU DDRD 00000011
EQU PIND 00000010
EQU SPDR 0000000f
EQU SPSR 0000000e
EQU SPCR 0000000d
EQU UDR 0000000c
EQU UCSRA 0000000b
EQU UCSRB 0000000a
EQU UBRRL 00000009
EQU ACSR 00000008
EQU ADMUX 00000007
EQU ADCSRA 00000006
EQU ADCH 00000005
EQU ADCL 00000004
EQU TWDR 00000003
EQU TWAR 00000002
EQU TWSR 00000001
EQU TWBR 00000000
EQU CS00 00000000
EQU CS01 00000001
EQU CS02 00000002
EQU WGM01 00000003
EQU CTC0 00000003
EQU COM00 00000004
EQU COM01 00000005
EQU WGM00 00000006
EQU PWM0 00000006
EQU FOC0 00000007
EQU TCNT0_0 00000000
EQU TCNT0_1 00000001
EQU TCNT0_2 00000002
EQU TCNT0_3 00000003
EQU TCNT0_4 00000004
EQU TCNT0_5 00000005
EQU TCNT0_6 00000006
EQU TCNT0_7 00000007
EQU OCR0_0 00000000
EQU OCR0_1 00000001
EQU OCR0_2 00000002
EQU OCR0_3 00000003
EQU OCR0_4 00000004
EQU OCR0_5 00000005
EQU OCR0_6 00000006
EQU OCR0_7 00000007
EQU TOIE0 00000000
EQU OCIE0 00000001
EQU TOV0 00000000
EQU OCF0 00000001
EQU PSR10 00000000
EQU TOIE1 00000002
EQU OCIE1B 00000003
EQU OCIE1A 00000004
EQU TICIE1 00000005
EQU TOV1 00000002
EQU OCF1B 00000003
EQU OCF1A 00000004
EQU ICF1 00000005
EQU WGM10 00000000
EQU PWM10 00000000
EQU WGM11 00000001
EQU PWM11 00000001
EQU FOC1B 00000002
EQU FOC1A 00000003
EQU COM1B0 00000004
EQU COM1B1 00000005
EQU COM1A0 00000006
EQU COM1A1 00000007
EQU CS10 00000000
EQU CS11 00000001
EQU CS12 00000002
EQU WGM12 00000003
EQU CTC10 00000003
EQU CTC1 00000003
EQU WGM13 00000004
EQU CTC11 00000004
EQU ICES1 00000006
EQU ICNC1 00000007
EQU GIMSK 0000003b
EQU IVCE 00000000
EQU IVSEL 00000001
EQU INT2 00000005
EQU INT0 00000006
EQU INT1 00000007
EQU INTF2 00000005
EQU INTF0 00000006
EQU INTF1 00000007
EQU ISC00 00000000
EQU ISC01 00000001
EQU ISC10 00000002
EQU ISC11 00000003
EQU ISC2 00000006
EQU EEDR0 00000000
EQU EEDR1 00000001
EQU EEDR2 00000002
EQU EEDR3 00000003
EQU EEDR4 00000004
EQU EEDR5 00000005
EQU EEDR6 00000006
EQU EEDR7 00000007
EQU EERE 00000000
EQU EEWE 00000001
EQU EEMWE 00000002
EQU EEWEE 00000002
EQU EERIE 00000003
EQU SREG_C 00000000
EQU SREG_Z 00000001
EQU SREG_N 00000002
EQU SREG_V 00000003
EQU SREG_S 00000004
EQU SREG_H 00000005
EQU SREG_T 00000006
EQU SREG_I 00000007
EQU SM0 00000004
EQU SM1 00000005
EQU SE 00000006
EQU SM2 00000007
EQU MCUSR 00000034
EQU PORF 00000000
EQU EXTRF 00000001
EQU EXTREF 00000001
EQU BORF 00000002
EQU WDRF 00000003
EQU JTRF 00000004
EQU JTD 00000007
EQU CAL0 00000000
EQU CAL1 00000001
EQU CAL2 00000002
EQU CAL3 00000003
EQU CAL4 00000004
EQU CAL5 00000005
EQU CAL6 00000006
EQU CAL7 00000007
EQU PSR2 00000001
EQU PUD 00000002
EQU TOIE2 00000006
EQU OCIE2 00000007
EQU TOV2 00000006
EQU OCF2 00000007
EQU CS20 00000000
EQU CS21 00000001
EQU CS22 00000002
EQU WGM21 00000003
EQU CTC2 00000003
EQU COM20 00000004
EQU COM21 00000005
EQU WGM20 00000006
EQU PWM2 00000006
EQU FOC2 00000007
EQU TCNT2_0 00000000
EQU TCNT2_1 00000001
EQU TCNT2_2 00000002
EQU TCNT2_3 00000003
EQU TCNT2_4 00000004
EQU TCNT2_5 00000005
EQU TCNT2_6 00000006
EQU TCNT2_7 00000007
EQU OCR2_0 00000000
EQU OCR2_1 00000001
EQU OCR2_2 00000002
EQU OCR2_3 00000003
EQU OCR2_4 00000004
EQU OCR2_5 00000005
EQU OCR2_6 00000006
EQU OCR2_7 00000007
EQU TCR2UB 00000000
EQU OCR2UB 00000001
EQU TCN2UB 00000002
EQU AS2 00000003
EQU SPDR0 00000000
EQU SPDR1 00000001
EQU SPDR2 00000002
EQU SPDR3 00000003
EQU SPDR4 00000004
EQU SPDR5 00000005
EQU SPDR6 00000006
EQU SPDR7 00000007
EQU SPI2X 00000000
EQU WCOL 00000006
EQU SPIF 00000007
EQU SPR0 00000000
EQU SPR1 00000001
EQU CPHA 00000002
EQU CPOL 00000003
EQU MSTR 00000004
EQU DORD 00000005
EQU SPE 00000006
EQU SPIE 00000007
EQU UDR0 00000000
EQU UDR1 00000001
EQU UDR2 00000002
EQU UDR3 00000003
EQU UDR4 00000004
EQU UDR5 00000005
EQU UDR6 00000006
EQU UDR7 00000007
EQU USR 0000000b
EQU MPCM 00000000
EQU U2X 00000001
EQU UPE 00000002
EQU PE 00000002
EQU DOR 00000003
EQU FE 00000004
EQU UDRE 00000005
EQU TXC 00000006
EQU RXC 00000007
EQU UCR 0000000a
EQU TXB8 00000000
EQU RXB8 00000001
EQU UCSZ2 00000002
EQU CHR9 00000002
EQU TXEN 00000003
EQU RXEN 00000004
EQU UDRIE 00000005
EQU TXCIE 00000006
EQU RXCIE 00000007
EQU UCPOL 00000000
EQU UCSZ0 00000001
EQU UCSZ1 00000002
EQU USBS 00000003
EQU UPM0 00000004
EQU UPM1 00000005
EQU UMSEL 00000006
EQU URSEL 00000007
EQU UBRRHI 00000020
EQU I2BR 00000000
EQU TWBR0 00000000
EQU TWBR1 00000001
EQU TWBR2 00000002
EQU TWBR3 00000003
EQU TWBR4 00000004
EQU TWBR5 00000005
EQU TWBR6 00000006
EQU TWBR7 00000007
EQU I2CR 00000036
EQU TWIE 00000000
EQU I2IE 00000000
EQU TWEN 00000002
EQU I2EN 00000002
EQU ENI2C 00000002
EQU TWWC 00000003
EQU I2WC 00000003
EQU TWSTO 00000004
EQU I2STO 00000004
EQU TWSTA 00000005
EQU I2STA 00000005
EQU TWEA 00000006
EQU I2EA 00000006
EQU TWINT 00000007
EQU I2INT 00000007
EQU I2SR 00000001
EQU TWPS0 00000000
EQU TWS0 00000000
EQU I2GCE 00000000
EQU TWPS1 00000001
EQU TWS1 00000001
EQU TWS3 00000003
EQU I2S3 00000003
EQU TWS4 00000004
EQU I2S4 00000004
EQU TWS5 00000005
EQU I2S5 00000005
EQU TWS6 00000006
EQU I2S6 00000006
EQU TWS7 00000007
EQU I2S7 00000007
EQU I2DR 00000003
EQU TWD0 00000000
EQU TWD1 00000001
EQU TWD2 00000002
EQU TWD3 00000003
EQU TWD4 00000004
EQU TWD5 00000005
EQU TWD6 00000006
EQU TWD7 00000007
EQU I2AR 00000002
EQU TWGCE 00000000
EQU TWA0 00000001
EQU TWA1 00000002
EQU TWA2 00000003
EQU TWA3 00000004
EQU TWA4 00000005
EQU TWA5 00000006
EQU TWA6 00000007
EQU ACME 00000003
EQU ACIS0 00000000
EQU ACIS1 00000001
EQU ACIC 00000002
EQU ACIE 00000003
EQU ACI 00000004
EQU ACO 00000005
EQU ACBG 00000006
EQU ACD 00000007
EQU MUX0 00000000
EQU MUX1 00000001
EQU MUX2 00000002
EQU MUX3 00000003
EQU MUX4 00000004
EQU ADLAR 00000005
EQU REFS0 00000006
EQU REFS1 00000007
EQU ADCSR 00000006
EQU ADPS0 00000000
EQU ADPS1 00000001
EQU ADPS2 00000002
EQU ADIE 00000003
EQU ADIF 00000004
EQU ADATE 00000005
EQU ADFR 00000005
EQU ADSC 00000006
EQU ADEN 00000007
EQU ADCH0 00000000
EQU ADCH1 00000001
EQU ADCH2 00000002
EQU ADCH3 00000003
EQU ADCH4 00000004
EQU ADCH5 00000005
EQU ADCH6 00000006
EQU ADCH7 00000007
EQU ADCL0 00000000
EQU ADCL1 00000001
EQU ADCL2 00000002
EQU ADCL3 00000003
EQU ADCL4 00000004
EQU ADCL5 00000005
EQU ADCL6 00000006
EQU ADCL7 00000007
EQU ADTS0 00000005
EQU ADTS1 00000006
EQU ADTS2 00000007
EQU OCDR0 00000000
EQU OCDR1 00000001
EQU OCDR2 00000002
EQU OCDR3 00000003
EQU OCDR4 00000004
EQU OCDR5 00000005
EQU OCDR6 00000006
EQU OCDR7 00000007
EQU IDRD 00000007
EQU SPMCR 00000037
EQU SPMEN 00000000
EQU PGERS 00000001
EQU PGWRT 00000002
EQU BLBSET 00000003
EQU RWWSRE 00000004
EQU ASRE 00000004
EQU RWWSB 00000006
EQU ASB 00000006
EQU SPMIE 00000007
EQU PORTA0 00000000
EQU PA0 00000000
EQU PORTA1 00000001
EQU PA1 00000001
EQU PORTA2 00000002
EQU PA2 00000002
EQU PORTA3 00000003
EQU PA3 00000003
EQU PORTA4 00000004
EQU PA4 00000004
EQU PORTA5 00000005
EQU PA5 00000005
EQU PORTA6 00000006
EQU PA6 00000006
EQU PORTA7 00000007
EQU PA7 00000007
EQU DDA0 00000000
EQU DDA1 00000001
EQU DDA2 00000002
EQU DDA3 00000003
EQU DDA4 00000004
EQU DDA5 00000005
EQU DDA6 00000006
EQU DDA7 00000007
EQU PINA0 00000000
EQU PINA1 00000001
EQU PINA2 00000002
EQU PINA3 00000003
EQU PINA4 00000004
EQU PINA5 00000005
EQU PINA6 00000006
EQU PINA7 00000007
EQU PORTB0 00000000
EQU PB0 00000000
EQU PORTB1 00000001
EQU PB1 00000001
EQU PORTB2 00000002
EQU PB2 00000002
EQU PORTB3 00000003
EQU PB3 00000003
EQU PORTB4 00000004
EQU PB4 00000004
EQU PORTB5 00000005
EQU PB5 00000005
EQU PORTB6 00000006
EQU PB6 00000006
EQU PORTB7 00000007
EQU PB7 00000007
EQU DDB0 00000000
EQU DDB1 00000001
EQU DDB2 00000002
EQU DDB3 00000003
EQU DDB4 00000004
EQU DDB5 00000005
EQU DDB6 00000006
EQU DDB7 00000007
EQU PINB0 00000000
EQU PINB1 00000001
EQU PINB2 00000002
EQU PINB3 00000003
EQU PINB4 00000004
EQU PINB5 00000005
EQU PINB6 00000006
EQU PINB7 00000007
EQU PORTC0 00000000
EQU PC0 00000000
EQU PORTC1 00000001
EQU PC1 00000001
EQU PORTC2 00000002
EQU PC2 00000002
EQU PORTC3 00000003
EQU PC3 00000003
EQU PORTC4 00000004
EQU PC4 00000004
EQU PORTC5 00000005
EQU PC5 00000005
EQU PORTC6 00000006
EQU PC6 00000006
EQU PORTC7 00000007
EQU PC7 00000007
EQU DDC0 00000000
EQU DDC1 00000001
EQU DDC2 00000002
EQU DDC3 00000003
EQU DDC4 00000004
EQU DDC5 00000005
EQU DDC6 00000006
EQU DDC7 00000007
EQU PINC0 00000000
EQU PINC1 00000001
EQU PINC2 00000002
EQU PINC3 00000003
EQU PINC4 00000004
EQU PINC5 00000005
EQU PINC6 00000006
EQU PINC7 00000007
EQU PORTD0 00000000
EQU PD0 00000000
EQU PORTD1 00000001
EQU PD1 00000001
EQU PORTD2 00000002
EQU PD2 00000002
EQU PORTD3 00000003
EQU PD3 00000003
EQU PORTD4 00000004
EQU PD4 00000004
EQU PORTD5 00000005
EQU PD5 00000005
EQU PORTD6 00000006
EQU PD6 00000006
EQU PORTD7 00000007
EQU PD7 00000007
EQU DDD0 00000000
EQU DDD1 00000001
EQU DDD2 00000002
EQU DDD3 00000003
EQU DDD4 00000004
EQU DDD5 00000005
EQU DDD6 00000006
EQU DDD7 00000007
EQU PIND0 00000000
EQU PIND1 00000001
EQU PIND2 00000002
EQU PIND3 00000003
EQU PIND4 00000004
EQU PIND5 00000005
EQU PIND6 00000006
EQU PIND7 00000007
EQU WDP0 00000000
EQU WDP1 00000001
EQU WDP2 00000002
EQU WDE 00000003
EQU WDTOE 00000004
EQU WDDE 00000004
EQU LB1 00000000
EQU LB2 00000001
EQU BLB01 00000002
EQU BLB02 00000003
EQU BLB11 00000004
EQU BLB12 00000005
EQU CKSEL0 00000000
EQU CKSEL1 00000001
EQU CKSEL2 00000002
EQU CKSEL3 00000003
EQU SUT0 00000004
EQU SUT1 00000005
EQU BODEN 00000006
EQU BODLEVEL 00000007
EQU BOOTRST 00000000
EQU BOOTSZ0 00000001
EQU BOOTSZ1 00000002
EQU EESAVE 00000003
EQU CKOPT 00000004
EQU SPIEN 00000005
EQU JTAGEN 00000006
EQU OCDEN 00000007
DEF XH r27
DEF XL r26
DEF YH r29
DEF YL r28
DEF ZH r31
DEF ZL r30
EQU FLASHEND 00001fff
EQU IOEND 0000003f
EQU SRAM_START 00000060
EQU SRAM_SIZE 00000400
EQU RAMEND 0000045f
EQU XRAMEND 00000000
EQU E2END 000001ff
EQU EEPROMEND 000001ff
EQU EEADRBITS 00000009
EQU NRWW_START_ADDR 00001c00
EQU NRWW_STOP_ADDR 00001fff
EQU RWW_START_ADDR 00000000
EQU RWW_STOP_ADDR 00001bff
EQU PAGESIZE 00000040
EQU FIRSTBOOTSTART 00001f80
EQU SECONDBOOTSTART 00001f00
EQU THIRDBOOTSTART 00001e00
EQU FOURTHBOOTSTART 00001c00
EQU SMALLBOOTSTART 00001f80
EQU LARGEBOOTSTART 00001c00
EQU INT0addr 00000002
EQU INT1addr 00000004
EQU OC2addr 00000006
EQU OVF2addr 00000008
EQU ICP1addr 0000000a
EQU OC1Aaddr 0000000c
EQU OC1Baddr 0000000e
EQU OVF1addr 00000010
EQU OVF0addr 00000012
EQU SPIaddr 00000014
EQU URXCaddr 00000016
EQU UDREaddr 00000018
EQU UTXCaddr 0000001a
EQU ADCCaddr 0000001c
EQU ERDYaddr 0000001e
EQU ACIaddr 00000020
EQU TWIaddr 00000022
EQU INT2addr 00000024
EQU OC0addr 00000026
EQU SPMRaddr 00000028
EQU INT_VECTORS_SIZE 0000002a
DEF POM r16
DEF A r17
DEF B r18
DEF C r19
DEF D r20
CSEG RESET 00000010
CSEG LOOP 0000001d
CSEG ACC 00000021
CSEG BCC 00000026
CSEG CCC 0000002b
CSEG DCC 00000030
CSEG CEKANI 00000033
CSEG L1 00000037
CSEG L2 00000039
CSEG L3 0000003b

@ -0,0 +1,88 @@
;pokus
.include "m16def.inc"
.def POM=r16
.def A=r17
.def B=r18
.def C=r19
.def D=r20
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010 ;zacatek vlastniho programu
RESET:
LDI R16,0x5F ;nastavi stack pointer na 0x045F
OUT SPL,R16 ;coz je konec SRAM u ATmegy16
LDI R16,0x04
OUT SPH,R16
LDI POM,0xFF ;nastavi vsechny porty jako vystupni
OUT DDRA,POM
OUT DDRB,POM
OUT DDRC,POM
OUT DDRD,POM
LDI A,0b01110000 ;hodnoty portu A az D
LDI B,0b10001000
LDI C,0b10001000
LDI D,0b00000111
LOOP:
CLC
ROL A ;preroluj A registr
BRCC ACC ;pokud je C=0, skoc na ACC (A Carry Clear)
SBR A,0b00000001 ;nastav prvni bit v A na 1
ACC: OUT PORTA,A ;output A do PORTA
CLC
ROL B ;preroluj B registr - totez co u A reg.
BRCC BCC
SBR B,0b00000001
BCC: OUT PORTB,B
CLC
ROL C ;preroluj C registr - totez co u A reg.
BRCC CCC
SBR C,0b00000001
CCC: OUT PORTC,C
CLC
ROL D ;preroluj D registr - totez co u A reg.
BRCC DCC
SBR D,0b00000001
DCC: OUT PORTD,D
RCALL CEKANI
RJMP LOOP ;znovu na navesti LOOP
CEKANI:
PUSH r18 ;ulozit pouzivane registry do STACKU
PUSH r17
PUSH r16
LDI r16, 40
L1: DEC r16
LDI r17, 40
L2: DEC r17
LDI r18, 40
L3: DEC r18
CPI r18, 0
BRNE L3
CPI r17, 0
BRNE L2
CPI r16, 0
BRNE L1
POP r16 ;nacist puvodni obsah registru ze STACKU
POP r17
POP r18
RET ;navrat do hlavniho programu

@ -0,0 +1 @@
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATmega16"/><Files><File00000 Name="C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED2" Position="197 71 1026 566" LineCol="0 0" State="Maximized"/></Files></AVRWorkspace>

@ -0,0 +1,33 @@
<ASSEMBLER_INFO>
<VERSION>2.1.12</VERSION>
<DEVICE>ATmega16</DEVICE>
<WORKING_DIR>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze</WORKING_DIR>
<INCLUDE_PATH>
<DIR>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</DIR>
</INCLUDE_PATH>
<SOURCE_FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</SOURCE_FILE>
<INCLUDED_FILES>
<FILE>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m16def.inc</FILE>
</INCLUDED_FILES>
<OBJECT_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.obj</FILE>
</OBJECT_FILES>
<HEX_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.hex</FILE>
</HEX_FILES>
<OUTPUT_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.map</FILE>
</OUTPUT_FILES>
<LABELS>
<RESET><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</FILE><LINE>18</LINE></RESET>
<LOOP><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</FILE><LINE>36</LINE></LOOP>
<ACC><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</FILE><LINE>41</LINE></ACC>
<BCC><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</FILE><LINE>47</LINE></BCC>
<CCC><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</FILE><LINE>53</LINE></CCC>
<DCC><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</FILE><LINE>59</LINE></DCC>
<CEKANI><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</FILE><LINE>63</LINE></CEKANI>
<L1><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</FILE><LINE>69</LINE></L1>
<L2><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</FILE><LINE>71</LINE></L2>
<L3><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\HAD_leze\efekty_LED.asm</FILE><LINE>73</LINE></L3>
</LABELS>
</ASSEMBLER_INFO>

@ -0,0 +1,2 @@
@ECHO OFF
"C:\Program Files\Atmel\AVR Tools\AvrAssembler2\avrasm2.exe" -S "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\labels.tmp" -fI -W+ie -o "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.hex" -d "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.obj" -e "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.eep" -m "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.map" "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm"

@ -0,0 +1 @@
<AVRStudio><MANAGEMENT><Created>06-Sep-2007 20:57:13</Created><LastEdit>10-Sep-2007 21:51:09</LastEdit><ProjectType>0</ProjectType><Created>06-Sep-2007 20:57:13</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>Atmel AVR Assembler</ProjectTypeName><ICON>208</ICON><ProjectName>LED_display</ProjectName><Created>08-Sep-2007 21:57:32</Created><LastEdit>08-Sep-2007 21:57:32</LastEdit><ICON>208</ICON><ProjectType>0</ProjectType><Created>08-Sep-2007 21:57:32</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>Atmel AVR Assembler</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>LED_display.obj</ObjectFile><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm</EntryFile><ObjectFile></ObjectFile><EntryFile></EntryFile><SaveFolder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_PART>ATmega16</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega16.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND></IO_EXPAND><REGISTERNAMES></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><modules><module></module></modules><Triggers></Triggers></Debugger><AvrAssembler><Folder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\</Folder><RelPath>LED_display.asm</RelPath><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm</EntryFile><IncludePath>C:\Program Files\Atmel\AVR Tools\AvrAssembler\Appnotes</IncludePath><V2IncludePath></V2IncludePath><V2Parameters></V2Parameters><FileType>I</FileType><ObjectName>LED_display</ObjectName><Wrap>0</Wrap><ErrorAsWarning>0</ErrorAsWarning><MapFile>1</MapFile><ListFile>0</ListFile><Version1>0</Version1><PreCompile></PreCompile><PostCompile></PostCompile><SourceFiles>,</SourceFiles></AvrAssembler><ProjectIncludeDirs><Dirs><Dir>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</Dir></Dirs></ProjectIncludeDirs><ProjectFiles><Files><Name>\LED_display.asm</Name><Name>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m16def.inc</Name></Files></ProjectFiles><IOView><usergroups/></IOView><Files><File00000><FileId>00000</FileId><FileName>LED_display.asm</FileName><Status>1</Status></File00000></Files><Workspace><File00000><Position>197 71 1026 566</Position><LineCol>59 11</LineCol><State>Maximized</State></File00000></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

@ -0,0 +1,74 @@
;pokus
.include "m16def.inc"
.def POM=r16
.cseg
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010 ;zacatek vlastniho programu
RESET:
LDI R16,0x5F ;nastavi stack pointer na 0x045F
OUT SPL,R16 ;coz je konec SRAM u ATmegy16
LDI R16,0x04
OUT SPH,R16
LDI POM,0xFF ;nastavi vsechny potrebne porty jako vystupni
OUT DDRA,POM
OUT DDRB,POM
LOOP:
LDI r16,0b01110111 ;display 3 abcef
LDI r17,0b00001000
OUT PORTA,r16
OUT PORTB,r17
RCALL cekani
LDI r16,0b01110110 ;display 2
LDI r17,0b00000100
OUT PORTA,r16
OUT PORTB,r17
RCALL cekani
LDI r16,0b00111111 ;display 1
LDI r17,0b00000010
OUT PORTA,r16
OUT PORTB,r17
RCALL cekani
LDI r16,0b00011110 ;display 0
LDI r17,0b00000001
OUT PORTA,r16
OUT PORTB,r17
RCALL cekani
RJMP LOOP ;jdi na LOOP
CEKANI:
PUSH r18 ;ulozit pouzivane registry do STACKU
PUSH r17
PUSH r16
LDI r16, 2
L1: DEC r16
LDI r17, 2
L2: DEC r17
LDI r18, 2
L3: DEC r18
CPI r18, 0
BRNE L3
CPI r17, 0
BRNE L2
CPI r16, 0
BRNE L1
POP r16 ;nacist puvodni obsah registru ze STACKU
POP r17
POP r18
RET ;navrat do hlavniho programu

@ -0,0 +1,613 @@
AVRASM ver. 2.1.12 C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm Mon Sep 10 21:42:09 2007
EQU SIGNATURE_000 0000001e
EQU SIGNATURE_001 00000094
EQU SIGNATURE_002 00000003
EQU SREG 0000003f
EQU SPL 0000003d
EQU SPH 0000003e
EQU OCR0 0000003c
EQU GICR 0000003b
EQU GIFR 0000003a
EQU TIMSK 00000039
EQU TIFR 00000038
EQU SPMCSR 00000037
EQU TWCR 00000036
EQU MCUCR 00000035
EQU MCUCSR 00000034
EQU TCCR0 00000033
EQU TCNT0 00000032
EQU OSCCAL 00000031
EQU OCDR 00000031
EQU SFIOR 00000030
EQU TCCR1A 0000002f
EQU TCCR1B 0000002e
EQU TCNT1L 0000002c
EQU TCNT1H 0000002d
EQU OCR1AL 0000002a
EQU OCR1AH 0000002b
EQU OCR1BL 00000028
EQU OCR1BH 00000029
EQU ICR1L 00000026
EQU ICR1H 00000027
EQU TCCR2 00000025
EQU TCNT2 00000024
EQU OCR2 00000023
EQU ASSR 00000022
EQU WDTCR 00000021
EQU UBRRH 00000020
EQU UCSRC 00000020
EQU EEARL 0000001e
EQU EEARH 0000001f
EQU EEDR 0000001d
EQU EECR 0000001c
EQU PORTA 0000001b
EQU DDRA 0000001a
EQU PINA 00000019
EQU PORTB 00000018
EQU DDRB 00000017
EQU PINB 00000016
EQU PORTC 00000015
EQU DDRC 00000014
EQU PINC 00000013
EQU PORTD 00000012
EQU DDRD 00000011
EQU PIND 00000010
EQU SPDR 0000000f
EQU SPSR 0000000e
EQU SPCR 0000000d
EQU UDR 0000000c
EQU UCSRA 0000000b
EQU UCSRB 0000000a
EQU UBRRL 00000009
EQU ACSR 00000008
EQU ADMUX 00000007
EQU ADCSRA 00000006
EQU ADCH 00000005
EQU ADCL 00000004
EQU TWDR 00000003
EQU TWAR 00000002
EQU TWSR 00000001
EQU TWBR 00000000
EQU CS00 00000000
EQU CS01 00000001
EQU CS02 00000002
EQU WGM01 00000003
EQU CTC0 00000003
EQU COM00 00000004
EQU COM01 00000005
EQU WGM00 00000006
EQU PWM0 00000006
EQU FOC0 00000007
EQU TCNT0_0 00000000
EQU TCNT0_1 00000001
EQU TCNT0_2 00000002
EQU TCNT0_3 00000003
EQU TCNT0_4 00000004
EQU TCNT0_5 00000005
EQU TCNT0_6 00000006
EQU TCNT0_7 00000007
EQU OCR0_0 00000000
EQU OCR0_1 00000001
EQU OCR0_2 00000002
EQU OCR0_3 00000003
EQU OCR0_4 00000004
EQU OCR0_5 00000005
EQU OCR0_6 00000006
EQU OCR0_7 00000007
EQU TOIE0 00000000
EQU OCIE0 00000001
EQU TOV0 00000000
EQU OCF0 00000001
EQU PSR10 00000000
EQU TOIE1 00000002
EQU OCIE1B 00000003
EQU OCIE1A 00000004
EQU TICIE1 00000005
EQU TOV1 00000002
EQU OCF1B 00000003
EQU OCF1A 00000004
EQU ICF1 00000005
EQU WGM10 00000000
EQU PWM10 00000000
EQU WGM11 00000001
EQU PWM11 00000001
EQU FOC1B 00000002
EQU FOC1A 00000003
EQU COM1B0 00000004
EQU COM1B1 00000005
EQU COM1A0 00000006
EQU COM1A1 00000007
EQU CS10 00000000
EQU CS11 00000001
EQU CS12 00000002
EQU WGM12 00000003
EQU CTC10 00000003
EQU CTC1 00000003
EQU WGM13 00000004
EQU CTC11 00000004
EQU ICES1 00000006
EQU ICNC1 00000007
EQU GIMSK 0000003b
EQU IVCE 00000000
EQU IVSEL 00000001
EQU INT2 00000005
EQU INT0 00000006
EQU INT1 00000007
EQU INTF2 00000005
EQU INTF0 00000006
EQU INTF1 00000007
EQU ISC00 00000000
EQU ISC01 00000001
EQU ISC10 00000002
EQU ISC11 00000003
EQU ISC2 00000006
EQU EEDR0 00000000
EQU EEDR1 00000001
EQU EEDR2 00000002
EQU EEDR3 00000003
EQU EEDR4 00000004
EQU EEDR5 00000005
EQU EEDR6 00000006
EQU EEDR7 00000007
EQU EERE 00000000
EQU EEWE 00000001
EQU EEMWE 00000002
EQU EEWEE 00000002
EQU EERIE 00000003
EQU SREG_C 00000000
EQU SREG_Z 00000001
EQU SREG_N 00000002
EQU SREG_V 00000003
EQU SREG_S 00000004
EQU SREG_H 00000005
EQU SREG_T 00000006
EQU SREG_I 00000007
EQU SM0 00000004
EQU SM1 00000005
EQU SE 00000006
EQU SM2 00000007
EQU MCUSR 00000034
EQU PORF 00000000
EQU EXTRF 00000001
EQU EXTREF 00000001
EQU BORF 00000002
EQU WDRF 00000003
EQU JTRF 00000004
EQU JTD 00000007
EQU CAL0 00000000
EQU CAL1 00000001
EQU CAL2 00000002
EQU CAL3 00000003
EQU CAL4 00000004
EQU CAL5 00000005
EQU CAL6 00000006
EQU CAL7 00000007
EQU PSR2 00000001
EQU PUD 00000002
EQU TOIE2 00000006
EQU OCIE2 00000007
EQU TOV2 00000006
EQU OCF2 00000007
EQU CS20 00000000
EQU CS21 00000001
EQU CS22 00000002
EQU WGM21 00000003
EQU CTC2 00000003
EQU COM20 00000004
EQU COM21 00000005
EQU WGM20 00000006
EQU PWM2 00000006
EQU FOC2 00000007
EQU TCNT2_0 00000000
EQU TCNT2_1 00000001
EQU TCNT2_2 00000002
EQU TCNT2_3 00000003
EQU TCNT2_4 00000004
EQU TCNT2_5 00000005
EQU TCNT2_6 00000006
EQU TCNT2_7 00000007
EQU OCR2_0 00000000
EQU OCR2_1 00000001
EQU OCR2_2 00000002
EQU OCR2_3 00000003
EQU OCR2_4 00000004
EQU OCR2_5 00000005
EQU OCR2_6 00000006
EQU OCR2_7 00000007
EQU TCR2UB 00000000
EQU OCR2UB 00000001
EQU TCN2UB 00000002
EQU AS2 00000003
EQU SPDR0 00000000
EQU SPDR1 00000001
EQU SPDR2 00000002
EQU SPDR3 00000003
EQU SPDR4 00000004
EQU SPDR5 00000005
EQU SPDR6 00000006
EQU SPDR7 00000007
EQU SPI2X 00000000
EQU WCOL 00000006
EQU SPIF 00000007
EQU SPR0 00000000
EQU SPR1 00000001
EQU CPHA 00000002
EQU CPOL 00000003
EQU MSTR 00000004
EQU DORD 00000005
EQU SPE 00000006
EQU SPIE 00000007
EQU UDR0 00000000
EQU UDR1 00000001
EQU UDR2 00000002
EQU UDR3 00000003
EQU UDR4 00000004
EQU UDR5 00000005
EQU UDR6 00000006
EQU UDR7 00000007
EQU USR 0000000b
EQU MPCM 00000000
EQU U2X 00000001
EQU UPE 00000002
EQU PE 00000002
EQU DOR 00000003
EQU FE 00000004
EQU UDRE 00000005
EQU TXC 00000006
EQU RXC 00000007
EQU UCR 0000000a
EQU TXB8 00000000
EQU RXB8 00000001
EQU UCSZ2 00000002
EQU CHR9 00000002
EQU TXEN 00000003
EQU RXEN 00000004
EQU UDRIE 00000005
EQU TXCIE 00000006
EQU RXCIE 00000007
EQU UCPOL 00000000
EQU UCSZ0 00000001
EQU UCSZ1 00000002
EQU USBS 00000003
EQU UPM0 00000004
EQU UPM1 00000005
EQU UMSEL 00000006
EQU URSEL 00000007
EQU UBRRHI 00000020
EQU I2BR 00000000
EQU TWBR0 00000000
EQU TWBR1 00000001
EQU TWBR2 00000002
EQU TWBR3 00000003
EQU TWBR4 00000004
EQU TWBR5 00000005
EQU TWBR6 00000006
EQU TWBR7 00000007
EQU I2CR 00000036
EQU TWIE 00000000
EQU I2IE 00000000
EQU TWEN 00000002
EQU I2EN 00000002
EQU ENI2C 00000002
EQU TWWC 00000003
EQU I2WC 00000003
EQU TWSTO 00000004
EQU I2STO 00000004
EQU TWSTA 00000005
EQU I2STA 00000005
EQU TWEA 00000006
EQU I2EA 00000006
EQU TWINT 00000007
EQU I2INT 00000007
EQU I2SR 00000001
EQU TWPS0 00000000
EQU TWS0 00000000
EQU I2GCE 00000000
EQU TWPS1 00000001
EQU TWS1 00000001
EQU TWS3 00000003
EQU I2S3 00000003
EQU TWS4 00000004
EQU I2S4 00000004
EQU TWS5 00000005
EQU I2S5 00000005
EQU TWS6 00000006
EQU I2S6 00000006
EQU TWS7 00000007
EQU I2S7 00000007
EQU I2DR 00000003
EQU TWD0 00000000
EQU TWD1 00000001
EQU TWD2 00000002
EQU TWD3 00000003
EQU TWD4 00000004
EQU TWD5 00000005
EQU TWD6 00000006
EQU TWD7 00000007
EQU I2AR 00000002
EQU TWGCE 00000000
EQU TWA0 00000001
EQU TWA1 00000002
EQU TWA2 00000003
EQU TWA3 00000004
EQU TWA4 00000005
EQU TWA5 00000006
EQU TWA6 00000007
EQU ACME 00000003
EQU ACIS0 00000000
EQU ACIS1 00000001
EQU ACIC 00000002
EQU ACIE 00000003
EQU ACI 00000004
EQU ACO 00000005
EQU ACBG 00000006
EQU ACD 00000007
EQU MUX0 00000000
EQU MUX1 00000001
EQU MUX2 00000002
EQU MUX3 00000003
EQU MUX4 00000004
EQU ADLAR 00000005
EQU REFS0 00000006
EQU REFS1 00000007
EQU ADCSR 00000006
EQU ADPS0 00000000
EQU ADPS1 00000001
EQU ADPS2 00000002
EQU ADIE 00000003
EQU ADIF 00000004
EQU ADATE 00000005
EQU ADFR 00000005
EQU ADSC 00000006
EQU ADEN 00000007
EQU ADCH0 00000000
EQU ADCH1 00000001
EQU ADCH2 00000002
EQU ADCH3 00000003
EQU ADCH4 00000004
EQU ADCH5 00000005
EQU ADCH6 00000006
EQU ADCH7 00000007
EQU ADCL0 00000000
EQU ADCL1 00000001
EQU ADCL2 00000002
EQU ADCL3 00000003
EQU ADCL4 00000004
EQU ADCL5 00000005
EQU ADCL6 00000006
EQU ADCL7 00000007
EQU ADTS0 00000005
EQU ADTS1 00000006
EQU ADTS2 00000007
EQU OCDR0 00000000
EQU OCDR1 00000001
EQU OCDR2 00000002
EQU OCDR3 00000003
EQU OCDR4 00000004
EQU OCDR5 00000005
EQU OCDR6 00000006
EQU OCDR7 00000007
EQU IDRD 00000007
EQU SPMCR 00000037
EQU SPMEN 00000000
EQU PGERS 00000001
EQU PGWRT 00000002
EQU BLBSET 00000003
EQU RWWSRE 00000004
EQU ASRE 00000004
EQU RWWSB 00000006
EQU ASB 00000006
EQU SPMIE 00000007
EQU PORTA0 00000000
EQU PA0 00000000
EQU PORTA1 00000001
EQU PA1 00000001
EQU PORTA2 00000002
EQU PA2 00000002
EQU PORTA3 00000003
EQU PA3 00000003
EQU PORTA4 00000004
EQU PA4 00000004
EQU PORTA5 00000005
EQU PA5 00000005
EQU PORTA6 00000006
EQU PA6 00000006
EQU PORTA7 00000007
EQU PA7 00000007
EQU DDA0 00000000
EQU DDA1 00000001
EQU DDA2 00000002
EQU DDA3 00000003
EQU DDA4 00000004
EQU DDA5 00000005
EQU DDA6 00000006
EQU DDA7 00000007
EQU PINA0 00000000
EQU PINA1 00000001
EQU PINA2 00000002
EQU PINA3 00000003
EQU PINA4 00000004
EQU PINA5 00000005
EQU PINA6 00000006
EQU PINA7 00000007
EQU PORTB0 00000000
EQU PB0 00000000
EQU PORTB1 00000001
EQU PB1 00000001
EQU PORTB2 00000002
EQU PB2 00000002
EQU PORTB3 00000003
EQU PB3 00000003
EQU PORTB4 00000004
EQU PB4 00000004
EQU PORTB5 00000005
EQU PB5 00000005
EQU PORTB6 00000006
EQU PB6 00000006
EQU PORTB7 00000007
EQU PB7 00000007
EQU DDB0 00000000
EQU DDB1 00000001
EQU DDB2 00000002
EQU DDB3 00000003
EQU DDB4 00000004
EQU DDB5 00000005
EQU DDB6 00000006
EQU DDB7 00000007
EQU PINB0 00000000
EQU PINB1 00000001
EQU PINB2 00000002
EQU PINB3 00000003
EQU PINB4 00000004
EQU PINB5 00000005
EQU PINB6 00000006
EQU PINB7 00000007
EQU PORTC0 00000000
EQU PC0 00000000
EQU PORTC1 00000001
EQU PC1 00000001
EQU PORTC2 00000002
EQU PC2 00000002
EQU PORTC3 00000003
EQU PC3 00000003
EQU PORTC4 00000004
EQU PC4 00000004
EQU PORTC5 00000005
EQU PC5 00000005
EQU PORTC6 00000006
EQU PC6 00000006
EQU PORTC7 00000007
EQU PC7 00000007
EQU DDC0 00000000
EQU DDC1 00000001
EQU DDC2 00000002
EQU DDC3 00000003
EQU DDC4 00000004
EQU DDC5 00000005
EQU DDC6 00000006
EQU DDC7 00000007
EQU PINC0 00000000
EQU PINC1 00000001
EQU PINC2 00000002
EQU PINC3 00000003
EQU PINC4 00000004
EQU PINC5 00000005
EQU PINC6 00000006
EQU PINC7 00000007
EQU PORTD0 00000000
EQU PD0 00000000
EQU PORTD1 00000001
EQU PD1 00000001
EQU PORTD2 00000002
EQU PD2 00000002
EQU PORTD3 00000003
EQU PD3 00000003
EQU PORTD4 00000004
EQU PD4 00000004
EQU PORTD5 00000005
EQU PD5 00000005
EQU PORTD6 00000006
EQU PD6 00000006
EQU PORTD7 00000007
EQU PD7 00000007
EQU DDD0 00000000
EQU DDD1 00000001
EQU DDD2 00000002
EQU DDD3 00000003
EQU DDD4 00000004
EQU DDD5 00000005
EQU DDD6 00000006
EQU DDD7 00000007
EQU PIND0 00000000
EQU PIND1 00000001
EQU PIND2 00000002
EQU PIND3 00000003
EQU PIND4 00000004
EQU PIND5 00000005
EQU PIND6 00000006
EQU PIND7 00000007
EQU WDP0 00000000
EQU WDP1 00000001
EQU WDP2 00000002
EQU WDE 00000003
EQU WDTOE 00000004
EQU WDDE 00000004
EQU LB1 00000000
EQU LB2 00000001
EQU BLB01 00000002
EQU BLB02 00000003
EQU BLB11 00000004
EQU BLB12 00000005
EQU CKSEL0 00000000
EQU CKSEL1 00000001
EQU CKSEL2 00000002
EQU CKSEL3 00000003
EQU SUT0 00000004
EQU SUT1 00000005
EQU BODEN 00000006
EQU BODLEVEL 00000007
EQU BOOTRST 00000000
EQU BOOTSZ0 00000001
EQU BOOTSZ1 00000002
EQU EESAVE 00000003
EQU CKOPT 00000004
EQU SPIEN 00000005
EQU JTAGEN 00000006
EQU OCDEN 00000007
DEF XH r27
DEF XL r26
DEF YH r29
DEF YL r28
DEF ZH r31
DEF ZL r30
EQU FLASHEND 00001fff
EQU IOEND 0000003f
EQU SRAM_START 00000060
EQU SRAM_SIZE 00000400
EQU RAMEND 0000045f
EQU XRAMEND 00000000
EQU E2END 000001ff
EQU EEPROMEND 000001ff
EQU EEADRBITS 00000009
EQU NRWW_START_ADDR 00001c00
EQU NRWW_STOP_ADDR 00001fff
EQU RWW_START_ADDR 00000000
EQU RWW_STOP_ADDR 00001bff
EQU PAGESIZE 00000040
EQU FIRSTBOOTSTART 00001f80
EQU SECONDBOOTSTART 00001f00
EQU THIRDBOOTSTART 00001e00
EQU FOURTHBOOTSTART 00001c00
EQU SMALLBOOTSTART 00001f80
EQU LARGEBOOTSTART 00001c00
EQU INT0addr 00000002
EQU INT1addr 00000004
EQU OC2addr 00000006
EQU OVF2addr 00000008
EQU ICP1addr 0000000a
EQU OC1Aaddr 0000000c
EQU OC1Baddr 0000000e
EQU OVF1addr 00000010
EQU OVF0addr 00000012
EQU SPIaddr 00000014
EQU URXCaddr 00000016
EQU UDREaddr 00000018
EQU UTXCaddr 0000001a
EQU ADCCaddr 0000001c
EQU ERDYaddr 0000001e
EQU ACIaddr 00000020
EQU TWIaddr 00000022
EQU INT2addr 00000024
EQU OC0addr 00000026
EQU SPMRaddr 00000028
EQU INT_VECTORS_SIZE 0000002a
DEF POM r16
CSEG RESET 00000010
CSEG LOOP 00000017
CSEG cekani 0000002c
CSEG L1 00000030
CSEG L2 00000032
CSEG L3 00000034

@ -0,0 +1,29 @@
<ASSEMBLER_INFO>
<VERSION>2.1.12</VERSION>
<DEVICE>ATmega16</DEVICE>
<WORKING_DIR>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display</WORKING_DIR>
<INCLUDE_PATH>
<DIR>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</DIR>
</INCLUDE_PATH>
<SOURCE_FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm</SOURCE_FILE>
<INCLUDED_FILES>
<FILE>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\m16def.inc</FILE>
</INCLUDED_FILES>
<OBJECT_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.obj</FILE>
</OBJECT_FILES>
<HEX_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.hex</FILE>
</HEX_FILES>
<OUTPUT_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.map</FILE>
</OUTPUT_FILES>
<LABELS>
<RESET><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm</FILE><LINE>14</LINE></RESET>
<LOOP><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm</FILE><LINE>24</LINE></LOOP>
<cekani><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm</FILE><LINE>51</LINE></cekani>
<L1><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm</FILE><LINE>57</LINE></L1>
<L2><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm</FILE><LINE>59</LINE></L2>
<L3><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm</FILE><LINE>61</LINE></L3>
</LABELS>
</ASSEMBLER_INFO>

@ -0,0 +1 @@
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA16"/><Files><File00000 Name="C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\LED_display\LED_display.asm" Position="197 71 1026 566" LineCol="59 11" State="Maximized"/></Files></AVRWorkspace>

@ -0,0 +1,53 @@
;pokus
.include "tn13def.inc"
.def POM=r16
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010 ;zacatek vlastniho programu
RESET:
LDI POM,low(RAMEND) ;nastavi stack pointer
OUT SPL,POM
LDI POM,0B00000011 ;nastavi vystupni piny
OUT DDRB,POM
LOOP:
SBI PORTB,0 ;PB0=0, PB1=1
CBI PORTB,1
RCALL CEKANI ;CEKACI SUB
CBI PORTB,0 ;PB0=1, PB1=0
SBI PORTB,1
RCALL CEKANI ;CEKACI SUB
RJMP LOOP ;znovu na navesti LOOP
CEKANI:
PUSH r18 ;ulozit pouzivane registry do STACKU
PUSH r17
PUSH r16
LDI r16, 100
L1: DEC r16
LDI r17, 100
L2: DEC r17
LDI r18, 125
L3: DEC r18
CPI r18, 0
BRNE L3
CPI r17, 0
BRNE L2
CPI r16, 0
BRNE L1
POP r16 ;nacist puvodni obsah registru ze STACKU
POP r17
POP r18
RET ;navrat do hlavniho programu

@ -0,0 +1,287 @@
AVRASM ver. 2.1.12 C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\pokus\pokus.asm Tue Sep 04 20:36:18 2007
EQU SIGNATURE_000 0000001e
EQU SIGNATURE_001 00000090
EQU SIGNATURE_002 00000007
EQU SREG 0000003f
EQU SPL 0000003d
EQU GIMSK 0000003b
EQU GIFR 0000003a
EQU TIMSK0 00000039
EQU TIFR0 00000038
EQU SPMCSR 00000037
EQU OCR0A 00000036
EQU MCUCR 00000035
EQU MCUSR 00000034
EQU TCCR0B 00000033
EQU TCNT0 00000032
EQU OSCCAL 00000031
EQU TCCR0A 0000002f
EQU DWDR 0000002e
EQU OCR0B 00000029
EQU GTCCR 00000028
EQU CLKPR 00000026
EQU WDTCR 00000021
EQU EEAR 0000001e
EQU EEDR 0000001d
EQU EECR 0000001c
EQU PORTB 00000018
EQU DDRB 00000017
EQU PINB 00000016
EQU PCMSK 00000015
EQU DIDR0 00000014
EQU ACSR 00000008
EQU ADMUX 00000007
EQU ADCSRA 00000006
EQU ADCH 00000005
EQU ADCL 00000004
EQU ADCSRB 00000003
EQU MUX0 00000000
EQU MUX1 00000001
EQU ADLAR 00000005
EQU REFS0 00000006
EQU ADPS0 00000000
EQU ADPS1 00000001
EQU ADPS2 00000002
EQU ADIE 00000003
EQU ADIF 00000004
EQU ADATE 00000005
EQU ADSC 00000006
EQU ADEN 00000007
EQU ADCH0 00000000
EQU ADCH1 00000001
EQU ADCH2 00000002
EQU ADCH3 00000003
EQU ADCH4 00000004
EQU ADCH5 00000005
EQU ADCH6 00000006
EQU ADCH7 00000007
EQU ADCL0 00000000
EQU ADCL1 00000001
EQU ADCL2 00000002
EQU ADCL3 00000003
EQU ADCL4 00000004
EQU ADCL5 00000005
EQU ADCL6 00000006
EQU ADCL7 00000007
EQU ADTS0 00000000
EQU ADTS1 00000001
EQU ADTS2 00000002
EQU ADC1D 00000002
EQU ADC3D 00000003
EQU ADC2D 00000004
EQU ADC0D 00000005
EQU ACME 00000006
EQU ACIS0 00000000
EQU ACIS1 00000001
EQU ACIE 00000003
EQU ACI 00000004
EQU ACO 00000005
EQU ACBG 00000006
EQU AINBG 00000006
EQU ACD 00000007
EQU AIN0D 00000000
EQU AIN1D 00000001
EQU EEARL 0000001e
EQU EEAR0 00000000
EQU EEAR1 00000001
EQU EEAR2 00000002
EQU EEAR3 00000003
EQU EEAR4 00000004
EQU EEAR5 00000005
EQU EEDR0 00000000
EQU EEDR1 00000001
EQU EEDR2 00000002
EQU EEDR3 00000003
EQU EEDR4 00000004
EQU EEDR5 00000005
EQU EEDR6 00000006
EQU EEDR7 00000007
EQU EERE 00000000
EQU EEWE 00000001
EQU EEPE 00000001
EQU EEMWE 00000002
EQU EEMPE 00000002
EQU EERIE 00000003
EQU EEPM0 00000004
EQU EEPM1 00000005
EQU SREG_C 00000000
EQU SREG_Z 00000001
EQU SREG_N 00000002
EQU SREG_V 00000003
EQU SREG_S 00000004
EQU SREG_H 00000005
EQU SREG_T 00000006
EQU SREG_I 00000007
EQU SP0 00000000
EQU SP1 00000001
EQU SP2 00000002
EQU SP3 00000003
EQU SP4 00000004
EQU SP5 00000005
EQU SP6 00000006
EQU SP7 00000007
EQU ISC00 00000000
EQU ISC01 00000001
EQU SM0 00000003
EQU SM1 00000004
EQU SE 00000005
EQU PUD 00000006
EQU PORF 00000000
EQU EXTRF 00000001
EQU BORF 00000002
EQU WDRF 00000003
EQU CAL0 00000000
EQU CAL1 00000001
EQU CAL2 00000002
EQU CAL3 00000003
EQU CAL4 00000004
EQU CAL5 00000005
EQU CAL6 00000006
EQU CLKPS0 00000000
EQU CLKPS1 00000001
EQU CLKPS2 00000002
EQU CLKPS3 00000003
EQU CLKPCE 00000007
EQU DWDR0 00000000
EQU DWDR1 00000001
EQU DWDR2 00000002
EQU DWDR3 00000003
EQU DWDR4 00000004
EQU DWDR5 00000005
EQU DWDR6 00000006
EQU DWDR7 00000007
EQU SPMEN 00000000
EQU PGERS 00000001
EQU PGWRT 00000002
EQU RFLB 00000003
EQU CTPB 00000004
EQU PORTB0 00000000
EQU PB0 00000000
EQU PORTB1 00000001
EQU PB1 00000001
EQU PORTB2 00000002
EQU PB2 00000002
EQU PORTB3 00000003
EQU PB3 00000003
EQU PORTB4 00000004
EQU PB4 00000004
EQU PORTB5 00000005
EQU PB5 00000005
EQU DDB0 00000000
EQU DDB1 00000001
EQU DDB2 00000002
EQU DDB3 00000003
EQU DDB4 00000004
EQU DDB5 00000005
EQU PINB0 00000000
EQU PINB1 00000001
EQU PINB2 00000002
EQU PINB3 00000003
EQU PINB4 00000004
EQU PINB5 00000005
EQU GICR 0000003b
EQU PCIE 00000005
EQU INT0 00000006
EQU PCIF 00000005
EQU INTF0 00000006
EQU PCINT0 00000000
EQU PCINT1 00000001
EQU PCINT2 00000002
EQU PCINT3 00000003
EQU PCINT4 00000004
EQU PCINT5 00000005
EQU TOIE0 00000001
EQU OCIE0A 00000002
EQU OCIE0B 00000003
EQU TOV0 00000001
EQU OCF0A 00000002
EQU OCF0B 00000003
EQU OCR0_0 00000000
EQU OCR0_1 00000001
EQU OCR0_2 00000002
EQU OCR0_3 00000003
EQU OCR0_4 00000004
EQU OCR0_5 00000005
EQU OCR0_6 00000006
EQU OCR0_7 00000007
EQU WGM00 00000000
EQU WGM01 00000001
EQU COM0B0 00000004
EQU COM0B1 00000005
EQU COM0A0 00000006
EQU COM0A1 00000007
EQU TCNT0_0 00000000
EQU TCNT0_1 00000001
EQU TCNT0_2 00000002
EQU TCNT0_3 00000003
EQU TCNT0_4 00000004
EQU TCNT0_5 00000005
EQU TCNT0_6 00000006
EQU TCNT0_7 00000007
EQU CS00 00000000
EQU CS01 00000001
EQU CS02 00000002
EQU WGM02 00000003
EQU FOC0B 00000006
EQU FOC0A 00000007
EQU PSR10 00000000
EQU TSM 00000007
EQU WDP0 00000000
EQU WDP1 00000001
EQU WDP2 00000002
EQU WDE 00000003
EQU WDCE 00000004
EQU WDP3 00000005
EQU WDTIE 00000006
EQU WDTIF 00000007
EQU LB1 00000000
EQU LB2 00000001
EQU CKSEL0 00000000
EQU CKSEL1 00000001
EQU SUT0 00000002
EQU SUT1 00000003
EQU CKDIV8 00000004
EQU WDTON 00000005
EQU EESAVE 00000006
EQU SPIEN 00000007
EQU RSTDISBL 00000000
EQU BODLEVEL0 00000001
EQU BODLEVEL1 00000002
EQU DWEN 00000003
EQU SELFPRGEN 00000004
DEF XH r27
DEF XL r26
DEF YH r29
DEF YL r28
DEF ZH r31
DEF ZL r30
EQU FLASHEND 000001ff
EQU IOEND 0000003f
EQU SRAM_START 00000060
EQU SRAM_SIZE 00000040
EQU RAMEND 0000009f
EQU XRAMEND 00000000
EQU E2END 0000003f
EQU EEPROMEND 0000003f
EQU EEADRBITS 00000006
EQU PAGESIZE 00000010
EQU INT0addr 00000001
EQU PCI0addr 00000002
EQU OVF0addr 00000003
EQU ERDYaddr 00000004
EQU ACIaddr 00000005
EQU OC0Aaddr 00000006
EQU OC0Baddr 00000007
EQU WDTaddr 00000008
EQU ADCCaddr 00000009
EQU INT_VECTORS_SIZE 0000000a
DEF POM r16
CSEG RESET 00000010
CSEG LOOP 00000014
CSEG CEKANI 0000001b
CSEG L1 0000001f
CSEG L2 00000021
CSEG L3 00000023

@ -0,0 +1,53 @@
.device attiny13
.def CNT=r25
.def LED=r24
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010
RESET:
LDI r16,low(RAMEND) ;nastavi stack pointer
OUT SPL,r16
CLI ;zakazat vsechna preruseni
LDI LED,0
LDI r16,0b11111110 ;PB2 je vystupni, PB0 vstupni
OUT DDRB,r16
LDI r16,0 ;vypnout PullUp
OUT PORTB,r16
LOOP:
IN r16,PINB ;dej do r16 stav PINB
ANDI r16,0b00000001
CPI r16,1 ;neni-li to 1, jdi na STORNO
BRNE STORNO
INC CNT ;CNT+1
CPI CNT,50 ;neni-li CNT=100, jdi na LOOP
BRNE LOOP
IN r16,PORTB ;r16=PORTB (vystupni port)
LDI r17,0b00000100 ;vyxoruj r16 s 0b00000100
EOR r16,R17
OUT PORTB,R16 ;a vysledek dej na PORTB
KONEC:
IN r16,PINB ;cekani na vstup nuly do PINB0
ANDI r16,0b00000001
CPI r16,0
BRNE KONEC ;neni-li r16=0, jdi na KONEC
RJMP LOOP ;jdi na LOOP
STORNO:
LDI CNT,0 ;do CNT dej 0
RJMP LOOP ;jdi na LOOP

@ -0,0 +1,97 @@
.DEVICE ATtiny13
.LIST
.LISTMAC
;běží na 9.6MHz, ckdiv8=0 (zapnuto)
;avrdude příkaz pro FUSEs: -U lfuse:w:0x6a:m -U hfuse:w:0xff:m
;LFUSE: 0x6A
;HFUSE: 0xFF
;aliasy pointerů
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
.def A2 = r25
.def A1 = r24
; Z A C A T E K P R O G R A M U
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
; začátek kódu
.org 0x0010
RESET: ldi r16,low(RAMEND) ;nastaví stack pointer
out SPL,r16
;tělo programu
;věčná smyčka
F_LOOP: rjmp F_LOOP
SHOW:
;A1,A2 obsahují bajty k zobrazení
ldi r16,8
NextB: ror A1
brcs A1on
cbi PORTB,PB0
rjmp A2proc
A1on: sbi PORTB,PB0
A2proc: ror A2
brcs A2on
cbi PORTB,PB1
rjmp shift
A1on: sbi PORTB,PB1
shift: sbi PORTB,PB2
nop
cbi PORTB,PB2
dec r16
brne NextB
sbi PORTB,PB3
nop
cbi PORTB,PB3
ret
CharTbl:
; GR GR GR GR
; GR GR GR GR
.db 0b00000000, 0b00000000
;cteni z EEPROM, v [r17 je ADRESA], v (r16 se objeví DATA)
;EEread:
; sbic EECR,1
; rjmp EEread ;cekani dokud neni EEPROM ready
;
; out EEARL, r17 ;ulozit adresu z r17
; sbi EECR,0 ;nastavenim EERE zacina cteni
; in r16,EEDR ;cteni dat z EEDR do r16
;
; ret
;zapis do EEPROM, v [R17 je ADRESA], v [R16 jsou DATA]
;EEwrite:
; sbic EECR,EEPE
; rjmp EEwrite ;cekani dokud neni EEPROM ready
;
; cbi EECR,EEPM1 ;nastavit programovaci mod
; cbi EECR,EEPM0
;
; out EEARL, r17 ;dej adresu z r17 do EEARL
; out EEDR, r16 ;dej data z r16 do EEDR
; sbi EECR,EEMPE ;master program enable
; sbi EECR,EEPE ;program enable
;
; ret

@ -0,0 +1,549 @@
;SETI navigation module of extraterrestrial spaceship BY Ondrej Hruska (c) 2011
;-------------------------------------------------
; Zapojeni:
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; SW0 G --+ PD0 PB7 +-- wakepin
; SW1 G --+ PD1 PB6 +-- LED MAIN K
; --+ PA1 PB5 +-- LED 5 K
; speaker --+ PA0 PB4 +-- LED 4 K
; SW2 G --+ PD2 PB3 +-- LED 3 K
; SW3 G --+ PD3 PB2 +-- LED 2 K
; SW4 G --+ PD4 PB1 +-- LED 1 K
; SW5 G --+ PD5 PB0 +-- LED 0 K
; GND --+ GND PD6 +--
; +-------------+
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;LFUSE: 0xE2
;HFUSE: 0xDF
;N A S T A V E N I V Y S I L A N E M O R S E O V K Y
.equ DelkaTecky = 5 ;delka tecky v desetinach
.equ DelkaCarky = 15 ;3x delka tecky = delka carky
.equ MezeraMorspart = 5 ;mezera mezi teckami/carkami v pismene
.equ MezeraZnak = 16 ;mezera za znakem (pripojena za vnitrni mezeru)
.equ FrekvenceMorse = 40 ;62500/tohle Hz
;K O N S T A N T Y + P R E Z D I V K Y P O U R T U A P I N U
;PORTA
.equ SYSPORT = PORTA
.equ SYSPIN = PINA
.equ SYSDDR = DDRA
.equ speak = 0
;PORTB
.equ LEDPORT = PORTB
.equ LEDDDR = DDRB
.equ LEDPIN = PINB
.equ led0 = 0
.equ led1 = 1
.equ led2 = 2
.equ led3 = 3
.equ led4 = 4
.equ led5 = 5
.equ ledm = 6
.equ wakepin = 7
;PORTD
.equ SWPORT = PORTD
.equ SWPIN = PIND
.equ SWDDR = DDRD
.equ sw0 = 0
.equ sw1 = 1
.equ sw2 = 2
.equ sw3 = 3
.equ sw4 = 4
.equ sw5 = 5
;A L I A S Y R E G I S T R U
.def cmatch = r19
.def louter = r18
.def linner = r17
.def curchar = r25
.def morspart = r24
;aliasy pointerů
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
; M A K R A
;Reprak (zapnuti a vypnuti pipani 1kHz)
.MACRO BuzzOn
sbi SYSPORT,speak
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 zapnut, prescaler na 64 (4000000/64=62500)
out TCCR0B,r16
.ENDMACRO
.MACRO BuzzOff
clr r16 ;TC0 vypnut (hodiny zastaveny)
out TCCR0B,r16
sbi SYSPORT,speak ;vymazat speak (aby netekl proud reprakem)
.ENDMACRO
.MACRO SetTone
out OCR0A,r16
.ENDMACRO
.MACRO DefaultTone
ldi r16,FrekvenceMorse
out OCR0A,r16
.ENDMACRO
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x000B ;pin change
reti ;hned se vrat (tohle je jen na probuzeni, nic se nevykonava)
.org 0x000D ;TC0 Compare match A
sbi SYSPIN,speak ;přepnout speak
reti ;návrat do programu (0x000E)
.org 0x0013
;nastaveni po resetu
.DB "MORSE PIPAC SETI 2011",0 ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16, (1<<SM0) ;nastavi sleep mode = power-down (nejuspornejsi)
out MCUCR, r16
; Nastaveni portu
;PORTA = SYSPORT
ldi r16,0b00000011 ;smer portu A - vse na výstup (shutdown a speak)
out SYSDDR,r16
ldi r16,0b00000001 ;shutdown=0 (continue), speak=1 (je mezi Vcc a timhle, takze skrz nej nic netece)
out SYSPORT,r16
;PORTB = LEDPORT
ldi r16,0b01111111 ;smer portu B - vystupni (ledky) - použijou se piny 0-6, 7. = wakepin
out LEDDDR,r16
ldi r16,0b11111111 ;vse v PORTB na 1 = ledky zhasnuty, wakepin pullup enabled
out LEDPORT,r16
;PORTD = SWPORT
ldi r16,0b00000000 ;smer portu D - vse na vstup (tlačítka) - použijou se jen piny 0-5, 6. zbyde
out SWDDR,r16
ldi r16,0b01111111 ;enable pullup
out SWPORT,r16
; timer0 - generator f=1kHz (pipak)
ldi r16,(1<<WGM01) ;port se neovlivnuje citacem, CTC mod
out TCCR0A,r16
ldi r16,62 ;compare match = 62 (vystupni frekvence 1kHz)
out OCR0A,r16
ldi r16,(1<<OCIE0A) ;povolit interupt z casovace (jeste nutno zapnout: makro BuzzOn)
out TIMSK,r16
;pipani aktivuje makro BuzzOn, vypne makro BuzzOff
sei ;Global Interrupt Enable
;plynule rozsviceni ledm + stoupajici ton
BuzzOn
ldi cmatch,255 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L1NEXTSTEP:
dec cmatch ;zvys jas
breq L1DONE ;je jas=255(full)? pak L1DONE
mov r16,cmatch
SetTone
ldi louter,25 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L1OUTER:
dec louter ;je konec louter? pak novy jas
breq L1NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsviť ledmain
L1INNER:
dec linner
breq L1OUTER
cp linner,cmatch ;je cmatch?
brne L1Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L1Ib:
rjmp L1INNER
L1DONE:
cbi LEDPORT, ledm ;rozsvit ledku (pro jistotu)
;plynule zhasnuti ledm + klesajici ton
ldi cmatch,0 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L2NEXTSTEP:
inc cmatch ;sniz jas
cpi cmatch,255 ;je jas=0? pak L2DONE
breq L2DONE
mov r16,cmatch
SetTone
ldi louter,20 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L2OUTER:
dec louter ;je konec louter? pak novy jas
breq L2NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsvit ledmain
L2INNER:
dec linner
breq L2OUTER
cp linner,cmatch ;je cmatch?
brne L2Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L2Ib:
rjmp L2INNER
L2DONE:
sbi LEDPORT, ledm ;zhasni ledm (pro jistotu)
ldi r16,1 ;prodleva, aby ton neznel tak uriznute
rcall delay
BuzzOff ;vypnout zvuk
;krouzeni cervenych ledek + pipani
ldi r18,24 ;celkem 24 preklopeni
ldi r17,0b11111110 ;posuvny registr - inicializace
KRUH1:
sbr r17,0b11000000 ;1 na nepouzite bity (ledky zhasnuty)
out LEDPORT, r17 ;vystup
lsr r17 ;rotuj doprava pres carry
brcs KRUH1b ;neni carry? preskoc
cbr r17,0b00100000 ;dopln mezeru na zacatek (emulace 6bitoveho posuvneho registru)
KRUH1b:
mov r16,r17 ;vypocet tonu pipnuti
com r16
lsl r16
eor r16,r18
SetTone
BuzzOn ;pipni
ldi r16,2
rcall delay
BuzzOff
dec r18
brne KRUH1 ;neni-li to posledni preklopeni, opakuj
K1DONE:
DefaultTone ;nastav normalni ton = 1kHz (pro morseovku)
;zhasni vse
ldi r16,0b11111111
out LEDPORT,r16 ;vypni ledky
ldi r16,4
rcall delay ;cekej 0.4s
;ukaz co je zapojeno (cervenymi ledkami)
in r25, SWPIN ;prijmout stav SWPORTu
andi r25,0b00111111 ;ignoruj nepouzite piny
mov r16,r25
sbr r16,0b01000000
out LEDPORT,r16 ;ukazat na LEDPORTu
;cekej 2 sekundy
ldi r16,20 ;pauza 2s
rcall delay
;spocitani zapnutych jumperu
;r25 obsahuje stav SWPINu (bity 0-5)
sbr r25,0b11000000 ;zapni i nepouzite bity
com r25 ;neguj (jumpery jsou na zem) -> aktivni budou 1
clr r24 ;priprav citac aktivnich jumperu
clr r16 ;nulovej registr pro ADC (aby procetl jen carry)
COUNTL:
lsr r25 ;(r25>>1) bit 0 do carry
adc r24,r16 ;pricti k citaci r24 carry (r16 je 0)
cpi r25,0 ;je r25 prazdny? ne -> opakuj COUNTL
brne COUNTL
;r24 obsahuje pocet zaplych bitu
COUNTDONE:
cpi r24,6 ;je 6 jumperu?
brne TEST5
ldi ZH,high(TEXT6*2)
ldi ZL,low(TEXT6*2)
rjmp TESTDONE
TEST5:
cpi r24,5 ;je 5 jumperu?
brne TEST4
ldi ZH,high(TEXT5*2)
ldi ZL,low(TEXT5*2)
rjmp TESTDONE
TEST4:
cpi r24,4 ;jsou 4 jumpery?
brne TEST3
ldi ZH,high(TEXT4*2)
ldi ZL,low(TEXT4*2)
rjmp TESTDONE
TEST3:
cpi r24,3 ;jsou 3 jumpery?
brne TEST2
ldi ZH,high(TEXT3*2)
ldi ZL,low(TEXT3*2)
rjmp TESTDONE
TEST2:
cpi r24,2 ;jsou 2 jumpery?
brne TEST1
ldi ZH,high(TEXT2*2)
ldi ZL,low(TEXT2*2)
rjmp TESTDONE
TEST1:
cpi r24,1 ;je 1 jumper?
brne TEST0
ldi ZH,high(TEXT1*2)
ldi ZL,low(TEXT1*2)
rjmp TESTDONE
TEST0:
ldi ZH,high(TEXT0*2) ;je 0 jumperu.
ldi ZL,low(TEXT0*2)
TESTDONE:
;Z obsahuje pointer na zacatek vysilaneho textu.
;Dalsi znak textu (nebo prvni)
NextCharTxt:
lpm curchar,Z+ ;do curchar nacti soucasny znak. Z je pointer na dalsi
cpi curchar,0
breq EndCom ;curchar = 0? (konec komunikace) - jdi na konec
push ZH ;uschovej Z pointer (bude pouzivan jako pointer tabulky)
push ZL
;hledani znaku v tabulce
ldi ZH,high(MORSE*2) ;zacatek MORSE tabulky do Z
ldi ZL,low(MORSE*2)
NextCharTbl:
lpm morspart,Z+ ;precti znak z tabulky
cpi morspart,0 ;je to 0? (= konec tabulky)
breq CharDone ;pak jdi na CharDone
cp morspart,curchar ;je to hledany znak?
breq CharFound ;pak jdi na CharFound
adiw ZL,7 ;jinak jdi na nasledujici znak v tabulce (1 z postincrementu + 7 dalsich bytu)
rjmp NextCharTbl
;znak nalezen v tabulce
CharFound:
lpm morspart,Z+ ;nacti MorsPart
cpi morspart,0 ;je to 0? (= konec znaku)
breq CharDone ;pak jdi na CharDone
cpi morspart,1 ;je to tecka? (=1) - zustan tady
brne CARKA ;je to carka? (=3) - jdi na CARKA
;TECKA
cbi LEDPORT, ledm ;rozsvit ledm
BuzzOn ;zacni pipnuti
ldi r16,DelkaTecky ;cekej podle DelkaTecky
rcall delay
BuzzOff ;konec pipnuti
sbi LEDPORT, ledm ;zhasni ledm
rjmp MorsPartDone ;konec morspartu -> MorsPartDone
;CARKA
CARKA:
cbi LEDPORT, ledm ;rozsvit ledm
BuzzOn ;zacni pipnuti
ldi r16,DelkaCarky ;cekej podle DelkaTecky
rcall delay
BuzzOff ;konec pipnuti
sbi LEDPORT, ledm ;zhasni ledm
;tecka/carka dokoncena
MorsPartDone: ;konec morspartu (=tecka/carka)
ldi r16,MezeraMorspart ;udelej mezeru
rcall delay
rjmp CharFound ;jdi na dalsi cast morspartu
;znak dokoncen
CharDone:
ldi r16,MezeraZnak ;mezera za znakem
rcall delay
pop ZL ;obnov pointer pro text
pop ZH
rjmp NextCharTxt ;jdi na dalsi znak textu
EndCom:
ldi r16,10
rcall delay
BuzzOn
;plynule zhasnuti ledm + klesajici ton
ldi cmatch,0 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L3NEXTSTEP:
inc cmatch ;sniz jas
cpi cmatch,255 ;je jas=0? pak L3DONE
breq L3DONE
mov r16,cmatch
lsr r16
SetTone
ldi louter,25 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L3OUTER:
dec louter ;je konec louter? pak novy jas
breq L3NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsvit ledmain
L3INNER:
dec linner
breq L3OUTER
cp linner,cmatch ;je cmatch?
brne L3Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L3Ib:
rjmp L3INNER
L3DONE:
sbi LEDPORT, ledm ;zhasni ledm (pro jistotu)
ldi r16,2 ;prodleva, aby ton neznel tak uriznute
rcall delay
BuzzOff ;vypnout zvuk
;SLEEP (a po probuzeni skok na RESET)
clr r16
out SWPORT,r16 ;vypni pullupy jumperu
sbi SYSPORT, speak ;vypni speaker (pro jistotu)
ser r16
out LEDPORT,r16 ;zhasni ledky, PB7 (ext. interrupt) pullup enabled
ldi r16,(1<<PCIE)
out GIMSK,r16 ;povol pinchange interrupt (general)
ldi r16,(1<<PCINT7)
out PCMSK,r16 ;povol pinchange interrupt pro PB7
in r16, MCUCR
ori r16, (1<<SE)
out MCUCR, r16 ;sleep enable && sleep
sleep
in r16, MCUCR
andi r16, ~(1<<SE)
out MCUCR, r16 ;sleep disable
clr r16
out GIMSK,r16 ;zakaz pinchange interrupt (general)
out PCMSK,r16 ;zakaz pinchange interrupt z PB7
;reset
rjmp RESET
;R U T I N Y
delay:
;ldi r16,#desetin
push r17
push r18
;255*225*7
d0:
ldi r17,255
d1:
ldi r18,227
d2:
nop
nop
nop
dec r18
brne d2
dec r17
brne d1
dec r16
brne d0
pop r18
pop r17
ret
; T A B U L K A Z N A K U
MORSE:
.DB "A",1,3,0,0,0,0,0 ;A
.DB "B",3,1,1,1,0,0,0 ;B
.DB "C",3,1,3,1,0,0,0 ;C
.DB "D",3,1,1,0,0,0,0 ;D
.DB "E",1,0,0,0,0,0,0 ;E
.DB "F",1,1,3,1,0,0,0 ;F
.DB "G",3,3,1,0,0,0,0 ;G
.DB "H",1,1,1,1,0,0,0 ;H
.DB "I",1,1,0,0,0,0,0 ;I
.DB "J",1,3,3,3,0,0,0 ;J
.DB "K",3,1,3,0,0,0,0 ;K
.DB "L",1,3,1,1,0,0,0 ;L
.DB "M",3,3,0,0,0,0,0 ;M
.DB "N",3,1,0,0,0,0,0 ;N
.DB "O",3,3,3,0,0,0,0 ;O
.DB "P",1,3,3,1,0,0,0 ;P
.DB "Q",3,3,1,3,0,0,0 ;Q
.DB "R",1,3,1,0,0,0,0 ;R
.DB "S",1,1,1,0,0,0,0 ;S
.DB "T",3,0,0,0,0,0,0 ;T
.DB "U",1,1,3,0,0,0,0 ;U
.DB "V",1,1,1,3,0,0,0 ;V
.DB "W",1,3,3,0,0,0,0 ;W
.DB "X",3,1,1,3,0,0,0 ;X
.DB "Y",3,1,3,3,0,0,0 ;Y
.DB "Z",3,3,1,1,0,0,0 ;Z
.DB "0",3,3,3,3,3,0,0 ;0
.DB "1",1,3,3,3,3,0,0 ;1
.DB "2",1,1,3,3,3,0,0 ;2
.DB "3",1,1,1,3,3,0,0 ;3
.DB "4",1,1,1,1,3,0,0 ;4
.DB "5",1,1,1,1,1,0,0 ;5
.DB "6",3,1,1,1,1,0,0 ;6
.DB "7",3,3,1,1,1,0,0 ;7
.DB "8",3,3,3,1,1,0,0 ;8
.DB "9",3,3,3,3,1,0,0 ;9
.DB ".",1,3,1,3,1,3,0 ;.
.DB ",",3,3,1,1,3,3,0 ;,
.DB " ",0,0,0,0,0,0,0 ;space
.DB 0,0,0,0,0,0,0,0 ;nic
;T E X T Y K O D V Y S I L A N I
TEXT0:
.db "CHYBI ANTENA BYLA ZAMERENA NA POZICI N 50S 12.345 E014S 12.345",0
TEXT1:
.db "POTREBUJI ZESILOVAC LEZI NA N 50S 12.345 E014S 12.345",0
TEXT2:
.db "SLABY SIGNAL DALSI ANTENA JE ZDE N 50S 12.345 E 14S 12.345",0
TEXT3:
.db "DOCHAZI ENERGIE ZALOZNI ZDROJ DOPADL NA N 50S 12.345 E014S 12.345",0
TEXT4:
.db "POLOHA DALSI ANTENY JE N 50S 12.345 E014S 12.345",0
TEXT5:
.db "PRESNOST ZVYSI SUPERSENZOR N 50S 12.345 E014S 12.345",0
TEXT6:
.db "ZASOBNIK LOKALIZOVAN N 50S 12.345 E014S 12.345 MUZETE SI HO NECHAT SLIZOUN JE JEDLY",0

@ -0,0 +1,597 @@
;SETI navigation module of extraterrestrial spaceship BY Ondrej Hruska (c) 2011
;-------------------------------------------------
;Co to dela:
;Po spusteni plynule rozsviti a zhasle LED MAIN, behem toho houka s promennou frekvenci
;Povoli uspani zmenou stavu pinu PB7
; Zapojeni:
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; SW0 G --+ PD0 PB7 +---[wakeswitch]--GND
; SW1 G --+ PD1 PB6 +-- LED MAIN K
; --+ PA1 PB5 +-- LED 5 K
; Vcc-[speaker]----+ PA0 PB4 +-- LED 4 K
; SW2 G --+ PD2 PB3 +-- LED 3 K
; SW3 G --+ PD3 PB2 +-- LED 2 K
; SW4 G --+ PD4 PB1 +-- LED 1 K
; SW5 G --+ PD5 PB0 +-- LED 0 K
; GND --+ GND PD6 +--
; +-------------+
;"K" = katoda (ledka zapojena mezi Vcc a timhle pinem, aktivni je 0)
;"G" = ground (spinac mezi tomhle pionem a zemi, aktivni je 0)
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;LFUSE: 0xE2
;HFUSE: 0xDF
;N A S T A V E N I V Y S I L A N E M O R S E O V K Y
.equ DelkaTecky = 4 ;delka tecky v desetinach
.equ DelkaCarky = 14 ;3x delka tecky = delka carky
.equ MezeraMorspart = 4 ;mezera mezi teckami/carkami v pismene
.equ MezeraZnak = 16 ;mezera za znakem (pripojena za vnitrni mezeru)
.equ FrekvenceMorse = 42 ;62500/tohle Hz
;K O N S T A N T Y + P R E Z D I V K Y P O U R T U A P I N U
;PORTA
.equ SYSPORT = PORTA
.equ SYSPIN = PINA
.equ SYSDDR = DDRA
.equ speak = 0
;PORTB
.equ LEDPORT = PORTB
.equ LEDDDR = DDRB
.equ LEDPIN = PINB
.equ led0 = 0
.equ led1 = 1
.equ led2 = 2
.equ led3 = 3
.equ led4 = 4
.equ led5 = 5
.equ ledm = 6
.equ wakepin = 7
.equ AFTER_SLEEP = 0b10101010 ;informace ze byl predtim sleep
;PORTD
.equ SWPORT = PORTD
.equ SWPIN = PIND
.equ SWDDR = DDRD
.equ sw0 = 0
.equ sw1 = 1
.equ sw2 = 2
.equ sw3 = 3
.equ sw4 = 4
.equ sw5 = 5
;A L I A S Y R E G I S T R U
.def cmatch = r19
.def louter = r18
.def linner = r17
.def curchar = r25
.def morspart = r24
;aliasy pointerů
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
; M A K R A
;Reprak (zapnuti a vypnuti pipani 1kHz)
.MACRO BuzzOn
sbi SYSPORT,speak
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 zapnut, prescaler na 64 (4000000/64=62500)
out TCCR0B,r16
.ENDMACRO
.MACRO BuzzOff
clr r16 ;TC0 vypnut (hodiny zastaveny)
out TCCR0B,r16
sbi SYSPORT,speak ;vymazat speak (aby netekl proud reprakem)
.ENDMACRO
.MACRO SetTone
out OCR0A,r16
.ENDMACRO
.MACRO DefaultTone
ldi r16,FrekvenceMorse
out OCR0A,r16
.ENDMACRO
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x000B ;pin change
rjmp PINCHANGE ;probuzeni nebo preruseni cinnosti
.org 0x000D ;TC0 Compare match A
sbi SYSPIN,speak ;přepnout speak
reti ;návrat do programu (0x000E)
.org 0x0013
;nastaveni po resetu
.DB "MORSE PIPAC SETI 2011",0 ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
clr r5 ;vymaz navesti ze je po probuzeni (r5=AFTER_SLEEP, ted bude 0)
ldi r16, (1<<SM0) ;nastavi sleep mode = power-down (nejuspornejsi)
out MCUCR, r16
; Nastaveni portu
;PORTA = SYSPORT
ldi r16,0b00000011 ;smer portu A - vse na výstup (shutdown a speak)
out SYSDDR,r16
ldi r16,0b00000001 ;shutdown=0 (continue), speak=1 (je mezi Vcc a timhle, takze skrz nej nic netece)
out SYSPORT,r16
;PORTB = LEDPORT
ldi r16,0b01111111 ;smer portu B - vystupni (ledky) - použijou se piny 0-6, 7. = wakepin
out LEDDDR,r16
ldi r16,0b11111111 ;vse v PORTB na 1 = ledky zhasnuty, wakepin pullup enabled
out LEDPORT,r16
;PORTD = SWPORT
ldi r16,0b00000000 ;smer portu D - vse na vstup (tlačítka) - použijou se jen piny 0-5, 6. zbyde
out SWDDR,r16
ldi r16,0b01111111 ;enable pullup
out SWPORT,r16
; timer0 - generator f=1kHz (pipak)
ldi r16,(1<<WGM01) ;port se neovlivnuje citacem, CTC mod
out TCCR0A,r16
ldi r16,62 ;compare match = 62 (vystupni frekvence 1kHz)
out OCR0A,r16
ldi r16,(1<<OCIE0A) ;povolit interupt z casovace (jeste nutno zapnout: makro BuzzOn)
out TIMSK,r16
;pipani aktivuje makro BuzzOn, vypne makro BuzzOff
;konfigurace pinchange interruptu (jeste je treba zapnout PCIE v GIMSK)
ldi r16,(1<<PCINT7)
out PCMSK,r16 ;povol pinchange interrupt pro PB7 (=wakepin)
sei ;Global Interrupt Enable
;plynule rozsviceni ledm + stoupajici ton
BuzzOn
ldi cmatch,255 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L1NEXTSTEP:
dec cmatch ;zvys jas
breq L1DONE ;je jas=255(full)? pak L1DONE
mov r16,cmatch
SetTone
ldi louter,25 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L1OUTER:
dec louter ;je konec louter? pak novy jas
breq L1NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsviť ledmain
L1INNER:
dec linner
breq L1OUTER
cp linner,cmatch ;je cmatch?
brne L1Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L1Ib:
rjmp L1INNER
L1DONE:
cbi LEDPORT, ledm ;rozsvit ledku (pro jistotu)
;plynule zhasnuti ledm + klesajici ton
ldi cmatch,0 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L2NEXTSTEP:
inc cmatch ;sniz jas
cpi cmatch,255 ;je jas=0? pak L2DONE
breq L2DONE
mov r16,cmatch
SetTone
ldi louter,20 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L2OUTER:
dec louter ;je konec louter? pak novy jas
breq L2NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsvit ledmain
L2INNER:
dec linner
breq L2OUTER
cp linner,cmatch ;je cmatch?
brne L2Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L2Ib:
rjmp L2INNER
L2DONE:
sbi LEDPORT, ledm ;zhasni ledm (pro jistotu)
ldi r16,1 ;prodleva, aby ton neznel tak uriznute
rcall delay
BuzzOff ;vypnout zvuk
;ted uz je dost douho po resetu, zepneme moznost uspani wakepinem
;vymaz zasobnik ext. preruseni
in r16,EIFR
andi r16,(1<<PCIF)
out EIFR,r16
;povol interrupt změny pinu PB7
ldi r16,(1<<PCIE)
out GIMSK,r16 ;povol pinchange interrupt (general)
;krouzeni cervenych ledek + pipani
ldi r18,24 ;celkem 24 preklopeni
ldi r17,0b11111110 ;posuvny registr - inicializace
KRUH1:
sbr r17,0b11000000 ;1 na nepouzite bity (ledky zhasnuty)
out LEDPORT, r17 ;vystup
lsr r17 ;rotuj doprava pres carry
brcs KRUH1b ;neni carry? preskoc
cbr r17,0b00100000 ;dopln mezeru na zacatek (emulace 6bitoveho posuvneho registru)
KRUH1b:
mov r16,r17 ;vypocet tonu pipnuti
com r16
lsl r16
eor r16,r18
SetTone
BuzzOn ;pipni
ldi r16,2
rcall delay
BuzzOff
dec r18
brne KRUH1 ;neni-li to posledni preklopeni, opakuj
K1DONE:
DefaultTone ;nastav normalni ton = 1kHz (pro morseovku)
;zhasni vse
ldi r16,0b11111111
out LEDPORT,r16 ;vypni ledky
ldi r16,4
rcall delay ;cekej 0.4s
;ukaz co je zapojeno (cervenymi ledkami)
in r25, SWPIN ;prijmout stav SWPORTu
andi r25,0b00111111 ;ignoruj nepouzite piny
mov r16,r25
sbr r16,0b11000000
out LEDPORT,r16 ;ukazat na LEDPORTu
;cekej 2 sekundy
ldi r16,20 ;pauza 2s
rcall delay
;spocitani zapnutych jumperu
;r25 obsahuje stav SWPINu (bity 0-5)
sbr r25,0b11000000 ;zapni i nepouzite bity
com r25 ;neguj (jumpery jsou na zem) -> aktivni budou 1
clr r24 ;priprav citac aktivnich jumperu
clr r16 ;nulovej registr pro ADC (aby procetl jen carry)
COUNTL:
lsr r25 ;(r25>>1) bit 0 do carry
adc r24,r16 ;pricti k citaci r24 carry (r16 je 0)
cpi r25,0 ;je r25 prazdny? ne -> opakuj COUNTL
brne COUNTL
;r24 obsahuje pocet zaplych bitu
COUNTDONE:
cpi r24,6 ;je 6 jumperu?
brne TEST5
ldi ZH,high(TEXT6*2)
ldi ZL,low(TEXT6*2)
rjmp TESTDONE
TEST5:
cpi r24,5 ;je 5 jumperu?
brne TEST4
ldi ZH,high(TEXT5*2)
ldi ZL,low(TEXT5*2)
rjmp TESTDONE
TEST4:
cpi r24,4 ;jsou 4 jumpery?
brne TEST3
ldi ZH,high(TEXT4*2)
ldi ZL,low(TEXT4*2)
rjmp TESTDONE
TEST3:
cpi r24,3 ;jsou 3 jumpery?
brne TEST2
ldi ZH,high(TEXT3*2)
ldi ZL,low(TEXT3*2)
rjmp TESTDONE
TEST2:
cpi r24,2 ;jsou 2 jumpery?
brne TEST1
ldi ZH,high(TEXT2*2)
ldi ZL,low(TEXT2*2)
rjmp TESTDONE
TEST1:
cpi r24,1 ;je 1 jumper?
brne TEST0
ldi ZH,high(TEXT1*2)
ldi ZL,low(TEXT1*2)
rjmp TESTDONE
TEST0:
ldi ZH,high(TEXT0*2) ;je 0 jumperu.
ldi ZL,low(TEXT0*2)
TESTDONE:
;Z obsahuje pointer na zacatek vysilaneho textu.
;Dalsi znak textu (nebo prvni)
NextCharTxt:
lpm curchar,Z+ ;do curchar nacti soucasny znak. Z je pointer na dalsi
cpi curchar,0
breq EndCom ;curchar = 0? (konec komunikace) - jdi na konec
push ZH ;uschovej Z pointer (bude pouzivan jako pointer tabulky)
push ZL
;hledani znaku v tabulce
ldi ZH,high(MORSE*2) ;zacatek MORSE tabulky do Z
ldi ZL,low(MORSE*2)
NextCharTbl:
lpm morspart,Z+ ;precti znak z tabulky
cpi morspart,0 ;je to 0? (= konec tabulky)
breq CharDone ;pak jdi na CharDone
cp morspart,curchar ;je to hledany znak?
breq CharFound ;pak jdi na CharFound
adiw ZL,7 ;jinak jdi na nasledujici znak v tabulce (1 z postincrementu + 7 dalsich bytu)
rjmp NextCharTbl
;znak nalezen v tabulce
CharFound:
lpm morspart,Z+ ;nacti MorsPart
cpi morspart,0 ;je to 0? (= konec znaku)
breq CharDone ;pak jdi na CharDone
cpi morspart,1 ;je to tecka? (=1) - zustan tady
brne CARKA ;je to carka? (=3) - jdi na CARKA
;TECKA
cbi LEDPORT, ledm ;rozsvit ledm
BuzzOn ;zacni pipnuti
ldi r16,DelkaTecky ;cekej podle DelkaTecky
rcall delay
BuzzOff ;konec pipnuti
sbi LEDPORT, ledm ;zhasni ledm
rjmp MorsPartDone ;konec morspartu -> MorsPartDone
;CARKA
CARKA:
cbi LEDPORT, ledm ;rozsvit ledm
BuzzOn ;zacni pipnuti
ldi r16,DelkaCarky ;cekej podle DelkaTecky
rcall delay
BuzzOff ;konec pipnuti
sbi LEDPORT, ledm ;zhasni ledm
;tecka/carka dokoncena
MorsPartDone: ;konec morspartu (=tecka/carka)
ldi r16,MezeraMorspart ;udelej mezeru
rcall delay
rjmp CharFound ;jdi na dalsi cast morspartu
;znak dokoncen
CharDone:
ldi r16,MezeraZnak ;mezera za znakem
rcall delay
pop ZL ;obnov pointer pro text
pop ZH
rjmp NextCharTxt ;jdi na dalsi znak textu
EndCom:
ldi r16,10
rcall delay
BuzzOn
;plynule zhasnuti ledm + klesajici ton
ldi cmatch,0 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L3NEXTSTEP:
inc cmatch ;sniz jas
cpi cmatch,255 ;je jas=0? pak L3DONE
breq L3DONE
mov r16,cmatch
lsr r16
SetTone
ldi louter,25 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L3OUTER:
dec louter ;je konec louter? pak novy jas
breq L3NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsvit ledmain
L3INNER:
dec linner
breq L3OUTER
cp linner,cmatch ;je cmatch?
brne L3Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L3Ib:
rjmp L3INNER
L3DONE:
sbi LEDPORT, ledm ;zhasni ledm (pro jistotu)
ldi r16,2 ;prodleva, aby ton neznel tak uriznute
rcall delay
BuzzOff ;vypnout zvuk
USNI:
;SLEEP (a po probuzeni skok na RESET)
clr r16
out SWPORT,r16 ;vypni pullupy jumperu
sbi SYSPORT, speak ;vypni speaker (pro jistotu)
ser r16
out LEDPORT,r16 ;zhasni ledky, PB7 (ext. interrupt) pullup enabled
;nastavit navesti, ze jde o probuzeni po spanku
ldi r16,AFTER_SLEEP
mov r5,r16
;probudi se pinchange interruptem na PB7
in r16, MCUCR
ori r16, (1<<SE)
out MCUCR, r16 ;sleep enable && sleep
sleep
in r16, MCUCR
andi r16, ~(1<<SE)
out MCUCR, r16 ;sleep disable
;reset
rjmp RESET
;R U T I N Y
delay:
;ldi r16,#desetin
push r17
push r18
;255*225*7
d0:
ldi r17,255
d1:
ldi r18,227
d2:
nop
nop
nop
dec r18
brne d2
dec r17
brne d1
dec r16
brne d0
pop r18
pop r17
ret
PINCHANGE:
mov r16,r5
cpi r16,AFTER_SLEEP
brne NENIPOSLEEPU
;je po SLEEPu -> reset
ldi r16,2 ;cekej 0.2s
rcall delay
clr r5 ;vymazat navesti ze byl SLEEP
clr r16
out GIMSK,r16 ;zakaz pinchange interrupt (general)
sei
rjmp RESET ;pri resetu se vynuluje SP a sei uz bylo, takze se reti delat nemusi. bude reset
;preruseni normalniho behu programu tlacitkem -> usnout
NENIPOSLEEPU:
ser r16 ;zhasne ledky
out LEDPORT,r16
BuzzOff ;pro jistotu vypne speaker
ldi r16,20 ;ceka 2 sekundy (aby se tlacitko urcite stihlo uvolnit -> jinak se udela dalsi "pinchange" a hned se to probudi)
rcall delay
sei ;povol preruseni (vypnuto pri interruptu)
rjmp USNI ;usnout (probudi se zmenou PB7)
; T A B U L K A Z N A K U
MORSE:
.DB "A",1,3,0,0,0,0,0 ;A
.DB "B",3,1,1,1,0,0,0 ;B
.DB "C",3,1,3,1,0,0,0 ;C
.DB "D",3,1,1,0,0,0,0 ;D
.DB "E",1,0,0,0,0,0,0 ;E
.DB "F",1,1,3,1,0,0,0 ;F
.DB "G",3,3,1,0,0,0,0 ;G
.DB "H",1,1,1,1,0,0,0 ;H
.DB "I",1,1,0,0,0,0,0 ;I
.DB "J",1,3,3,3,0,0,0 ;J
.DB "K",3,1,3,0,0,0,0 ;K
.DB "L",1,3,1,1,0,0,0 ;L
.DB "M",3,3,0,0,0,0,0 ;M
.DB "N",3,1,0,0,0,0,0 ;N
.DB "O",3,3,3,0,0,0,0 ;O
.DB "P",1,3,3,1,0,0,0 ;P
.DB "Q",3,3,1,3,0,0,0 ;Q
.DB "R",1,3,1,0,0,0,0 ;R
.DB "S",1,1,1,0,0,0,0 ;S
.DB "T",3,0,0,0,0,0,0 ;T
.DB "U",1,1,3,0,0,0,0 ;U
.DB "V",1,1,1,3,0,0,0 ;V
.DB "W",1,3,3,0,0,0,0 ;W
.DB "X",3,1,1,3,0,0,0 ;X
.DB "Y",3,1,3,3,0,0,0 ;Y
.DB "Z",3,3,1,1,0,0,0 ;Z
.DB "0",3,3,3,3,3,0,0 ;0
.DB "1",1,3,3,3,3,0,0 ;1
.DB "2",1,1,3,3,3,0,0 ;2
.DB "3",1,1,1,3,3,0,0 ;3
.DB "4",1,1,1,1,3,0,0 ;4
.DB "5",1,1,1,1,1,0,0 ;5
.DB "6",3,1,1,1,1,0,0 ;6
.DB "7",3,3,1,1,1,0,0 ;7
.DB "8",3,3,3,1,1,0,0 ;8
.DB "9",3,3,3,3,1,0,0 ;9
.DB ".",1,3,1,3,1,3,0 ;.
.DB ",",3,3,1,1,3,3,0 ;,
.DB " ",0,0,0,0,0,0,0 ;space
.DB 0,0,0,0,0,0,0,0 ;nic
;T E X T Y K O D V Y S I L A N I
TEXT0:
.db "TOTO JE NAVIGATOR CHYBI ANTENA BYLA ZAMERENA NA POZICI N 50S 12.345 E014S 12.345",0
TEXT1:
.db "POTREBUJI ZESILOVAC LEZI TADY N 50S 12.345 E014S 12.345",0
TEXT2:
.db "SLABY SIGNAL DALSI ANTENA JE ZDE N 50S 12.345 E 14S 12.345",0
TEXT3:
.db "DOCHAZI ENERGIE IONTOVY GENERATOR DOPADL NA N 50S 12.345 E014S 12.345",0
TEXT4:
.db "POLOHA DALSI ANTENY JE N 50S 12.345 E014S 12.345",0
TEXT5:
.db "PRESNOST ZVYSI SUPERSENZOR N 50S 12.345 E014S 12.345",0
TEXT6:
.db "VRAK MODULU LOKALIZOVAN NA N 50S 12.345 E014S 12.345 SLIZ JE NESKODNY",0

@ -0,0 +1,605 @@
;SETI navigation module of extraterrestrial spaceship BY Ondrej Hruska (c) 2011
;-------------------------------------------------
;Co to dela:
;Po spusteni plynule rozsviti a zhasle LED MAIN, behem toho houka s promennou frekvenci
;Povoli uspani zmenou stavu pinu PB7
; Zapojeni:
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; SW0 G --+ PD0 PB7 +---[wakeswitch]--GND
; SW1 G --+ PD1 PB6 +-- LED MAIN K
; --+ PA1 PB5 +-- LED 5 K
; Vcc-[speaker]----+ PA0 PB4 +-- LED 4 K
; SW2 G --+ PD2 PB3 +-- LED 3 K
; SW3 G --+ PD3 PB2 +-- LED 2 K
; SW4 G --+ PD4 PB1 +-- LED 1 K
; SW5 G --+ PD5 PB0 +-- LED 0 K
; GND --+ GND PD6 +--
; +-------------+
;"K" = katoda (ledka zapojena mezi Vcc a timhle pinem, aktivni je 0)
;"G" = ground (spinac mezi tomhle pionem a zemi, aktivni je 0)
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;LFUSE: 0xE2
;HFUSE: 0xDF
;N A S T A V E N I V Y S I L A N E M O R S E O V K Y
.equ DelkaTecky = 4 ;delka tecky v desetinach
.equ DelkaCarky = 13 ;3x delka tecky = delka carky
.equ MezeraMorspart = 4 ;mezera mezi teckami/carkami v pismene
.equ MezeraZnak = 14 ;mezera za znakem (pripojena za vnitrni mezeru)
.equ FrekvenceMorse = 43 ;62500/tohle Hz
;K O N S T A N T Y + P R E Z D I V K Y P O U R T U A P I N U
;PORTA
.equ SYSPORT = PORTA
.equ SYSPIN = PINA
.equ SYSDDR = DDRA
.equ speak = 0
;PORTB
.equ LEDPORT = PORTB
.equ LEDDDR = DDRB
.equ LEDPIN = PINB
.equ led0 = 0
.equ led1 = 1
.equ led2 = 2
.equ led3 = 3
.equ led4 = 4
.equ led5 = 5
.equ ledm = 6
.equ wakepin = 7
.equ AFTER_SLEEP = 0b10101010 ;informace ze byl predtim sleep
;PORTD
.equ SWPORT = PORTD
.equ SWPIN = PIND
.equ SWDDR = DDRD
.equ sw0 = 0
.equ sw1 = 1
.equ sw2 = 2
.equ sw3 = 3
.equ sw4 = 4
.equ sw5 = 5
;A L I A S Y R E G I S T R U
.def cmatch = r19
.def louter = r18
.def linner = r17
.def curchar = r25
.def morspart = r24
;aliasy pointerů
.def ZH = r31
.def ZL = r30
.def YH = r29
.def YL = r28
.def XH = r27
.def XL = r26
; M A K R A
;Reprak (zapnuti a vypnuti pipani 1kHz)
.MACRO BuzzOn
sbi SYSPORT,speak
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 zapnut, prescaler na 64 (4000000/64=62500)
out TCCR0B,r16
.ENDMACRO
.MACRO BuzzOff
clr r16 ;TC0 vypnut (hodiny zastaveny)
out TCCR0B,r16
sbi SYSPORT,speak ;vymazat speak (aby netekl proud reprakem)
.ENDMACRO
.MACRO SetTone
out OCR0A,r16
.ENDMACRO
.MACRO DefaultTone
ldi r16,FrekvenceMorse
out OCR0A,r16
.ENDMACRO
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x000B ;pin change
rjmp PINCHANGE ;probuzeni nebo preruseni cinnosti
.org 0x000D ;TC0 Compare match A
sbi SYSPIN,speak ;přepnout speak
reti ;návrat do programu (0x000E)
.org 0x0013
;nastaveni po resetu
.DB "MORSE PIPAC SETI 2011",0 ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
clr r5 ;vymaz navesti ze je po probuzeni (r5=AFTER_SLEEP, ted bude 0)
ldi r16, (1<<SM0) ;nastavi sleep mode = power-down (nejuspornejsi)
out MCUCR, r16
; Nastaveni portu
;PORTA = SYSPORT
ldi r16,0b00000011 ;smer portu A - vse na výstup (shutdown a speak)
out SYSDDR,r16
ldi r16,0b00000001 ;shutdown=0 (continue), speak=1 (je mezi Vcc a timhle, takze skrz nej nic netece)
out SYSPORT,r16
;PORTB = LEDPORT
ldi r16,0b01111111 ;smer portu B - vystupni (ledky) - použijou se piny 0-6, 7. = wakepin
out LEDDDR,r16
ldi r16,0b11111111 ;vse v PORTB na 1 = ledky zhasnuty, wakepin pullup enabled
out LEDPORT,r16
;PORTD = SWPORT
ldi r16,0b00000000 ;smer portu D - vse na vstup (tlačítka) - použijou se jen piny 0-5, 6. zbyde
out SWDDR,r16
ldi r16,0b01111111 ;enable pullup
out SWPORT,r16
; timer0 - generator f=1kHz (pipak)
ldi r16,(1<<WGM01) ;port se neovlivnuje citacem, CTC mod
out TCCR0A,r16
ldi r16,62 ;compare match = 62 (vystupni frekvence 1kHz)
out OCR0A,r16
ldi r16,(1<<OCIE0A) ;povolit interupt z casovace (jeste nutno zapnout: makro BuzzOn)
out TIMSK,r16
;pipani aktivuje makro BuzzOn, vypne makro BuzzOff
;konfigurace pinchange interruptu (jeste je treba zapnout PCIE v GIMSK)
ldi r16,(1<<PCINT7)
out PCMSK,r16 ;povol pinchange interrupt pro PB7 (=wakepin)
sei ;Global Interrupt Enable
;plynule rozsviceni ledm + stoupajici ton
BuzzOn
ldi cmatch,255 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L1NEXTSTEP:
dec cmatch ;zvys jas
breq L1DONE ;je jas=255(full)? pak L1DONE
mov r16,cmatch
SetTone
ldi louter,25 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L1OUTER:
dec louter ;je konec louter? pak novy jas
breq L1NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsviť ledmain
L1INNER:
dec linner
breq L1OUTER
cp linner,cmatch ;je cmatch?
brne L1Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L1Ib:
rjmp L1INNER
L1DONE:
cbi LEDPORT, ledm ;rozsvit ledku (pro jistotu)
;plynule zhasnuti ledm + klesajici ton
ldi cmatch,0 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L2NEXTSTEP:
inc cmatch ;sniz jas
cpi cmatch,255 ;je jas=0? pak L2DONE
breq L2DONE
mov r16,cmatch
SetTone
ldi louter,20 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L2OUTER:
dec louter ;je konec louter? pak novy jas
breq L2NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsvit ledmain
L2INNER:
dec linner
breq L2OUTER
cp linner,cmatch ;je cmatch?
brne L2Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L2Ib:
rjmp L2INNER
L2DONE:
sbi LEDPORT, ledm ;zhasni ledm (pro jistotu)
ldi r16,1 ;prodleva, aby ton neznel tak uriznute
rcall delay
BuzzOff ;vypnout zvuk
;ted uz je dost douho po resetu, zepneme moznost uspani wakepinem
;vymaz zasobnik ext. preruseni
in r16,EIFR
andi r16,(1<<PCIF)
out EIFR,r16
;povol interrupt změny pinu PB7
ldi r16,(1<<PCIE)
out GIMSK,r16 ;povol pinchange interrupt (general)
;krouzeni cervenych ledek + pipani
ldi r18,24 ;celkem 24 preklopeni
ldi r17,0b11111110 ;posuvny registr - inicializace
KRUH1:
sbr r17,0b11000000 ;1 na nepouzite bity (ledky zhasnuty)
out LEDPORT, r17 ;vystup
lsr r17 ;rotuj doprava pres carry
brcs KRUH1b ;neni carry? preskoc
cbr r17,0b00100000 ;dopln mezeru na zacatek (emulace 6bitoveho posuvneho registru)
KRUH1b:
mov r16,r17 ;vypocet tonu pipnuti
com r16
lsl r16
eor r16,r18
SetTone
BuzzOn ;pipni
ldi r16,2
rcall delay
BuzzOff
dec r18
brne KRUH1 ;neni-li to posledni preklopeni, opakuj
K1DONE:
DefaultTone ;nastav normalni ton = 1kHz (pro morseovku)
;zhasni vse
ldi r16,0b11111111
out LEDPORT,r16 ;vypni ledky
ldi r16,4
rcall delay ;cekej 0.4s
;ukaz co je zapojeno (cervenymi ledkami)
in r25, SWPIN ;prijmout stav SWPORTu
andi r25,0b00111111 ;ignoruj nepouzite piny
mov r16,r25
sbr r16,0b11000000
out LEDPORT,r16 ;ukazat na LEDPORTu
;cekej 2 sekundy
ldi r16,20 ;pauza 2s
rcall delay
;spocitani zapnutych jumperu
;r25 obsahuje stav SWPINu (bity 0-5)
sbr r25,0b11000000 ;zapni i nepouzite bity
com r25 ;neguj (jumpery jsou na zem) -> aktivni budou 1
clr r24 ;priprav citac aktivnich jumperu
clr r16 ;nulovej registr pro ADC (aby procetl jen carry)
COUNTL:
lsr r25 ;(r25>>1) bit 0 do carry
adc r24,r16 ;pricti k citaci r24 carry (r16 je 0)
cpi r25,0 ;je r25 prazdny? ne -> opakuj COUNTL
brne COUNTL
;r24 obsahuje pocet zaplych bitu
COUNTDONE:
cpi r24,6 ;je 6 jumperu?
brne TEST5
ldi ZH,high(TEXT6*2)
ldi ZL,low(TEXT6*2)
rjmp TESTDONE
TEST5:
cpi r24,5 ;je 5 jumperu?
brne TEST4
ldi ZH,high(TEXT5*2)
ldi ZL,low(TEXT5*2)
rjmp TESTDONE
TEST4:
cpi r24,4 ;jsou 4 jumpery?
brne TEST3
ldi ZH,high(TEXT4*2)
ldi ZL,low(TEXT4*2)
rjmp TESTDONE
TEST3:
cpi r24,3 ;jsou 3 jumpery?
brne TEST2
ldi ZH,high(TEXT3*2)
ldi ZL,low(TEXT3*2)
rjmp TESTDONE
TEST2:
cpi r24,2 ;jsou 2 jumpery?
brne TEST1
ldi ZH,high(TEXT2*2)
ldi ZL,low(TEXT2*2)
rjmp TESTDONE
TEST1:
cpi r24,1 ;je 1 jumper?
brne TEST0
ldi ZH,high(TEXT1*2)
ldi ZL,low(TEXT1*2)
rjmp TESTDONE
TEST0:
ldi ZH,high(TEXT0*2) ;je 0 jumperu.
ldi ZL,low(TEXT0*2)
TESTDONE:
;Z obsahuje pointer na zacatek vysilaneho textu.
;Dalsi znak textu (nebo prvni)
NextCharTxt:
lpm curchar,Z+ ;do curchar nacti soucasny znak. Z je pointer na dalsi
cpi curchar,0
breq EndCom ;curchar = 0? (konec komunikace) - jdi na konec
push ZH ;uschovej Z pointer (bude pouzivan jako pointer tabulky)
push ZL
;hledani znaku v tabulce
ldi ZH,high(MORSE*2) ;zacatek MORSE tabulky do Z
ldi ZL,low(MORSE*2)
NextCharTbl:
lpm morspart,Z+ ;precti znak z tabulky
cpi morspart,0 ;je to 0? (= konec tabulky)
breq CharDone ;pak jdi na CharDone
cp morspart,curchar ;je to hledany znak?
breq CharFound ;pak jdi na CharFound
adiw ZL,7 ;jinak jdi na nasledujici znak v tabulce (1 z postincrementu + 7 dalsich bytu)
rjmp NextCharTbl
;znak nalezen v tabulce
CharFound:
lpm morspart,Z+ ;nacti MorsPart
cpi morspart,0 ;je to 0? (= konec znaku)
breq CharDone ;pak jdi na CharDone
cpi morspart,1 ;je to tecka? (=1) - zustan tady
brne CARKA ;je to carka? (=3) - jdi na CARKA
;TECKA
cbi LEDPORT, ledm ;rozsvit ledm
BuzzOn ;zacni pipnuti
ldi r16,DelkaTecky ;cekej podle DelkaTecky
rcall delay
BuzzOff ;konec pipnuti
sbi LEDPORT, ledm ;zhasni ledm
rjmp MorsPartDone ;konec morspartu -> MorsPartDone
;CARKA
CARKA:
cbi LEDPORT, ledm ;rozsvit ledm
BuzzOn ;zacni pipnuti
ldi r16,DelkaCarky ;cekej podle DelkaTecky
rcall delay
BuzzOff ;konec pipnuti
sbi LEDPORT, ledm ;zhasni ledm
;tecka/carka dokoncena
MorsPartDone: ;konec morspartu (=tecka/carka)
ldi r16,MezeraMorspart ;udelej mezeru
rcall delay
rjmp CharFound ;jdi na dalsi cast morspartu
;znak dokoncen
CharDone:
ldi r16,MezeraZnak ;mezera za znakem
rcall delay
pop ZL ;obnov pointer pro text
pop ZH
rjmp NextCharTxt ;jdi na dalsi znak textu
EndCom:
ldi r16,10
rcall delay
BuzzOn
;plynule zhasnuti ledm + klesajici ton
ldi cmatch,0 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
in r24,LEDPORT ;uloz stav ledportu
cbr r24,0b01000000 ;zapni ledm
sbr r24,0b10000000 ;zapni pullup
ldi r23,0b11111111 ;priprav stav pro vypnute ledky
L3NEXTSTEP:
inc cmatch ;sniz jas
cpi cmatch,255 ;je jas=255? pak L3DONE
breq L3DONE
mov r16,cmatch
lsr r16
SetTone
ldi louter,25 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L3OUTER:
dec louter ;je konec louter? pak novy jas
breq L3NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
;cbi LEDPORT,ledm ;rozsvit ledmain
out LEDPORT,r24 ;zapni ledky
L3INNER:
dec linner
breq L3OUTER
cp linner,cmatch ;je cmatch?
brne L3Ib
;sbi LEDPORT,ledm ;jo -> zhasni ledmain
out LEDPORT,r23 ;zhasni ledky
L3Ib:
rjmp L3INNER
L3DONE:
sbi LEDPORT, ledm ;zhasni ledm (pro jistotu)
ldi r16,2 ;prodleva, aby ton neznel tak uriznute
rcall delay
BuzzOff ;vypnout zvuk
USNI:
;SLEEP (a po probuzeni skok na RESET)
clr r16
out SWPORT,r16 ;vypni pullupy jumperu
sbi SYSPORT, speak ;vypni speaker (pro jistotu)
ser r16
out LEDPORT,r16 ;zhasni ledky, PB7 (ext. interrupt) pullup enabled
;nastavit navesti, ze jde o probuzeni po spanku
ldi r16,AFTER_SLEEP
mov r5,r16
;probudi se pinchange interruptem na PB7
in r16, MCUCR
ori r16, (1<<SE)
out MCUCR, r16 ;sleep enable && sleep
sleep
in r16, MCUCR
andi r16, ~(1<<SE)
out MCUCR, r16 ;sleep disable
;reset
rjmp RESET
;R U T I N Y
delay:
;ldi r16,#desetin
push r17
push r18
;255*225*7
d0:
ldi r17,255
d1:
ldi r18,227
d2:
nop
nop
nop
dec r18
brne d2
dec r17
brne d1
dec r16
brne d0
pop r18
pop r17
ret
PINCHANGE:
mov r16,r5
cpi r16,AFTER_SLEEP
brne NENIPOSLEEPU
;je po SLEEPu -> reset
ldi r16,2 ;cekej 0.2s
rcall delay
clr r5 ;vymazat navesti ze byl SLEEP
clr r16
out GIMSK,r16 ;zakaz pinchange interrupt (general)
sei
rjmp RESET ;pri resetu se vynuluje SP a sei uz bylo, takze se reti delat nemusi. bude reset
;preruseni normalniho behu programu tlacitkem -> usnout
NENIPOSLEEPU:
ser r16 ;zhasne ledky
out LEDPORT,r16
BuzzOff ;pro jistotu vypne speaker
ldi r16,20 ;ceka 2 sekundy (aby se tlacitko urcite stihlo uvolnit -> jinak se udela dalsi "pinchange" a hned se to probudi)
rcall delay
sei ;povol preruseni (vypnuto pri interruptu)
rjmp USNI ;usnout (probudi se zmenou PB7)
; T A B U L K A Z N A K U
MORSE:
.DB "A",1,3,0,0,0,0,0 ;A
.DB "B",3,1,1,1,0,0,0 ;B
.DB "C",3,1,3,1,0,0,0 ;C
.DB "D",3,1,1,0,0,0,0 ;D
.DB "E",1,0,0,0,0,0,0 ;E
.DB "F",1,1,3,1,0,0,0 ;F
.DB "G",3,3,1,0,0,0,0 ;G
.DB "H",1,1,1,1,0,0,0 ;H
.DB "I",1,1,0,0,0,0,0 ;I
.DB "J",1,3,3,3,0,0,0 ;J
.DB "K",3,1,3,0,0,0,0 ;K
.DB "L",1,3,1,1,0,0,0 ;L
.DB "M",3,3,0,0,0,0,0 ;M
.DB "N",3,1,0,0,0,0,0 ;N
.DB "O",3,3,3,0,0,0,0 ;O
.DB "P",1,3,3,1,0,0,0 ;P
.DB "Q",3,3,1,3,0,0,0 ;Q
.DB "R",1,3,1,0,0,0,0 ;R
.DB "S",1,1,1,0,0,0,0 ;S
.DB "T",3,0,0,0,0,0,0 ;T
.DB "U",1,1,3,0,0,0,0 ;U
.DB "V",1,1,1,3,0,0,0 ;V
.DB "W",1,3,3,0,0,0,0 ;W
.DB "X",3,1,1,3,0,0,0 ;X
.DB "Y",3,1,3,3,0,0,0 ;Y
.DB "Z",3,3,1,1,0,0,0 ;Z
.DB "0",3,3,3,3,3,0,0 ;0
.DB "1",1,3,3,3,3,0,0 ;1
.DB "2",1,1,3,3,3,0,0 ;2
.DB "3",1,1,1,3,3,0,0 ;3
.DB "4",1,1,1,1,3,0,0 ;4
.DB "5",1,1,1,1,1,0,0 ;5
.DB "6",3,1,1,1,1,0,0 ;6
.DB "7",3,3,1,1,1,0,0 ;7
.DB "8",3,3,3,1,1,0,0 ;8
.DB "9",3,3,3,3,1,0,0 ;9
.DB ".",1,3,1,3,1,3,0 ;.
.DB ",",3,3,1,1,3,3,0 ;,
.DB " ",0,0,0,0,0,0,0 ;space
.DB 0,0,0,0,0,0,0,0 ;nic=konec tabulky
;T E X T Y K O D V Y S I L A N I
;
; 0 1 2 3 4 5 6 7 8 minut9
TEXT0:
.db "TOTO JE NAVIGATOR CHYBI ANTENA HLEDEJ TADY N 50S 12.345 E014S 12.345",0
TEXT1:
.db "POTREBUJI ZESILOVAC LEZI TADY N 50S 12.345 E014S 12.345",0
TEXT2:
.db "SLABY SIGNAL DALSI ANTENA JE ZDE N 50S 12.345 E 14S 12.345",0
TEXT3:
.db "USMERNOVAC VYKONU DOPADL NA N 50S 12.345 E014S 12.345",0
TEXT4:
.db "POLOHA DALSI ANTENY JE N 50S 12.345 E014S 12.345",0
TEXT5:
.db "PRESNOST ZVYSI SUPERSENZOR N 50S 12.345 E014S 12.345",0
TEXT6:
.db "VRAK MODULU ZAMEREN NA N 50S 12.345 E014S 12.345 SLIZ JE NESKODNY",0

@ -0,0 +1,630 @@
;SETI navigation module of extraterrestrial spaceship BY Ondrej Hruska (c) 2011
;-------------------------------------------------
;Co to dela:
;Po spusteni plynule rozsviti a zhasle LED MAIN, behem toho houka s promennou frekvenci
;Povoli uspani zmenou stavu pinu PB7
; Zapojeni:
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; SW0 G --+ PD0 PB7 +---[wakeswitch]--GND
; SW1 G --+ PD1 PB6 +-- LED MAIN K
; --+ PA1 PB5 +-- LED 5 K
; Vcc-[speaker]----+ PA0 PB4 +-- LED 4 K
; SW2 G --+ PD2 PB3 +-- LED 3 K
; SW3 G --+ PD3 PB2 +-- LED 2 K
; SW4 G --+ PD4 PB1 +-- LED 1 K
; SW5 G --+ PD5 PB0 +-- LED 0 K
; GND --+ GND PD6 +--
; +-------------+
;"K" = katoda (ledka zapojena mezi Vcc a timhle pinem, aktivni je 0)
;"G" = ground (spinac mezi tomhle pionem a zemi, aktivni je 0)
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;LFUSE: 0xE2
;HFUSE: 0xDF
;N A S T A V E N I V Y S I L A N E M O R S E O V K Y
;tecka mmorspart carka mznak mmezera mznak carka mmorspart
.equ DelkaTecky = 3 ;delka tecky v desetinach
.equ DelkaCarky = 14 ;3x delka tecky = delka carky
.equ DelkaMezery = 4 ;mznak+tohle+mznak
.equ MezeraMorspart = 3 ;mezera mezi teckami/carkami v pismene
.equ MezeraZnak = 19 ;mezera za znakem
.equ FrekvenceMorse = 50 ;62500/tohle Hz tón 42
;.equ DelkaTecky = 4 ;delka tecky v desetinach
;.equ DelkaCarky = 14 ;3x delka tecky = delka carky
;.equ MezeraMorspart = 3 ;mezera mezi teckami/carkami v pismene
;.equ MezeraZnak = 14 ;mezera za znakem (pripojena za vnitrni mezeru)
;.equ FrekvenceMorse = 43 ;62500/tohle Hz
;K O N S T A N T Y + P R E Z D I V K Y P O U R T U A P I N U
;PORTA
.equ SYSPORT = PORTA
.equ SYSPIN = PINA
.equ SYSDDR = DDRA
.equ speak = 0
;PORTB
.equ LEDPORT = PORTB
.equ LEDDDR = DDRB
;.equ LEDPIN = PINB
;.equ led0 = 0
;.equ led1 = 1
;.equ led2 = 2
;.equ led3 = 3
;.equ led4 = 4
;.equ led5 = 5
.equ ledm = 6
;.equ wakepin = 7
.equ AFTER_SLEEP = 0b10101010 ;informace ze byl predtim sleep
;PORTD
.equ SWPORT = PORTD
.equ SWPIN = PIND
.equ SWDDR = DDRD
;.equ sw0 = 0
;.equ sw1 = 1
;.equ sw2 = 2
;.equ sw3 = 3
;.equ sw4 = 4
;.equ sw5 = 5
;A L I A S Y R E G I S T R U
.def cmatch = r19
.def louter = r18
.def linner = r17
.def curchar = r25
.def morspart = r24
;aliasy pointerů
.def ZH = r31
.def ZL = r30
;.def YH = r29
;.def YL = r28
;.def XH = r27
;.def XL = r26
; M A K R A
;Reprak (zapnuti a vypnuti pipani 1kHz)
.MACRO BuzzOn
sbi SYSPORT,speak
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 zapnut, prescaler na 64 (4000000/64=62500)
out TCCR0B,r16
.ENDMACRO
.MACRO BuzzOff
clr r16 ;TC0 vypnut (hodiny zastaveny)
out TCCR0B,r16
sbi SYSPORT,speak ;vymazat speak (aby netekl proud reprakem)
.ENDMACRO
.MACRO SetTone
out OCR0A,r16
.ENDMACRO
.MACRO DefaultTone
ldi r16,FrekvenceMorse
out OCR0A,r16
.ENDMACRO
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x000B ;pin change
rjmp PINCHANGE ;probuzeni nebo preruseni cinnosti
.org 0x000D ;TC0 Compare match A
sbi SYSPIN,speak ;přepnout speak
reti ;návrat do programu (0x000E)
.org 0x0013
;nastaveni po resetu
.DB "MORSE PIPAC SETI 2011",0 ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
clr r5 ;vymaz navesti ze je po probuzeni (r5=AFTER_SLEEP, ted bude 0)
ldi r16, (1<<SM0) ;nastavi sleep mode = power-down (nejuspornejsi)
out MCUCR, r16
; Nastaveni portu
;PORTA = SYSPORT
ldi r16,0b00000011 ;smer portu A - vse na výstup (shutdown a speak)
out SYSDDR,r16
ldi r16,0b00000001 ;shutdown=0 (continue), speak=1 (je mezi Vcc a timhle, takze skrz nej nic netece)
out SYSPORT,r16
;PORTB = LEDPORT
ldi r16,0b01111111 ;smer portu B - vystupni (ledky) - použijou se piny 0-6, 7. = wakepin
out LEDDDR,r16
ldi r16,0b11111111 ;vse v PORTB na 1 = ledky zhasnuty, wakepin pullup enabled
out LEDPORT,r16
;PORTD = SWPORT
ldi r16,0b00000000 ;smer portu D - vse na vstup (tlačítka) - použijou se jen piny 0-5, 6. zbyde
out SWDDR,r16
ldi r16,0b01111111 ;enable pullup
out SWPORT,r16
; timer0 - generator f=1kHz (pipak)
ldi r16,(1<<WGM01) ;port se neovlivnuje citacem, CTC mod
out TCCR0A,r16
ldi r16,62 ;compare match = 62 (vystupni frekvence 1kHz)
out OCR0A,r16
ldi r16,(1<<OCIE0A) ;povolit interupt z casovace (jeste nutno zapnout: makro BuzzOn)
out TIMSK,r16
;pipani aktivuje makro BuzzOn, vypne makro BuzzOff
;konfigurace pinchange interruptu (jeste je treba zapnout PCIE v GIMSK)
ldi r16,(1<<PCINT7)
out PCMSK,r16 ;povol pinchange interrupt pro PB7 (=wakepin)
sei ;Global Interrupt Enable
;plynule rozsviceni ledm + stoupajici ton
BuzzOn
ldi cmatch,255 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L1NEXTSTEP:
dec cmatch ;zvys jas
breq L1DONE ;je jas=255(full)? pak L1DONE
mov r16,cmatch
SetTone
ldi louter,25 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L1OUTER:
dec louter ;je konec louter? pak novy jas
breq L1NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsviť ledmain
L1INNER:
dec linner
breq L1OUTER
cp linner,cmatch ;je cmatch?
brne L1Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L1Ib:
rjmp L1INNER
L1DONE:
cbi LEDPORT, ledm ;rozsvit ledku (pro jistotu)
;plynule zhasnuti ledm + klesajici ton
ldi cmatch,0 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L2NEXTSTEP:
inc cmatch ;sniz jas
cpi cmatch,255 ;je jas=0? pak L2DONE
breq L2DONE
mov r16,cmatch
SetTone
ldi louter,20 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L2OUTER:
dec louter ;je konec louter? pak novy jas
breq L2NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsvit ledmain
L2INNER:
dec linner
breq L2OUTER
cp linner,cmatch ;je cmatch?
brne L2Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L2Ib:
rjmp L2INNER
L2DONE:
sbi LEDPORT, ledm ;zhasni ledm (pro jistotu)
ldi r16,1 ;prodleva, aby ton neznel tak uriznute
rcall delay
BuzzOff ;vypnout zvuk
;ted uz je dost douho po resetu, zepneme moznost uspani wakepinem
;vymaz zasobnik ext. preruseni
in r16,EIFR
andi r16,(1<<PCIF)
out EIFR,r16
;povol interrupt změny pinu PB7
ldi r16,(1<<PCIE)
out GIMSK,r16 ;povol pinchange interrupt (general)
;krouzeni cervenych ledek + pipani
ldi r18,24 ;celkem 24 preklopeni
ldi r17,0b11111110 ;posuvny registr - inicializace
KRUH1:
sbr r17,0b11000000 ;1 na nepouzite bity (ledky zhasnuty)
out LEDPORT, r17 ;vystup
lsr r17 ;rotuj doprava pres carry
brcs KRUH1b ;neni carry? preskoc
cbr r17,0b00100000 ;dopln mezeru na zacatek (emulace 6bitoveho posuvneho registru)
KRUH1b:
mov r16,r17 ;vypocet tonu pipnuti
com r16
lsl r16
eor r16,r18
SetTone
BuzzOn ;pipni
ldi r16,2
rcall delay
BuzzOff
dec r18
brne KRUH1 ;neni-li to posledni preklopeni, opakuj
K1DONE:
DefaultTone ;nastav normalni ton = 1kHz (pro morseovku)
;zhasni vse
ldi r16,0b11111111
out LEDPORT,r16 ;vypni ledky
ldi r16,4
rcall delay ;cekej 0.4s
;ukaz co je zapojeno (cervenymi ledkami)
in r25, SWPIN ;prijmout stav SWPORTu
andi r25,0b00111111 ;ignoruj nepouzite piny
mov r16,r25
sbr r16,0b11000000
out LEDPORT,r16 ;ukazat na LEDPORTu
;cekej 2 sekundy
ldi r16,20 ;pauza 2s
rcall delay
;spocitani zapnutych jumperu
;r25 obsahuje stav SWPINu (bity 0-5)
sbr r25,0b11000000 ;zapni i nepouzite bity
com r25 ;neguj (jumpery jsou na zem) -> aktivni budou 1
clr r24 ;priprav citac aktivnich jumperu
clr r16 ;nulovej registr pro ADC (aby procetl jen carry)
COUNTL:
lsr r25 ;(r25>>1) bit 0 do carry
adc r24,r16 ;pricti k citaci r24 carry (r16 je 0)
cpi r25,0 ;je r25 prazdny? ne -> opakuj COUNTL
brne COUNTL
;r24 obsahuje pocet zaplych bitu
COUNTDONE:
cpi r24,6 ;je 6 jumperu?
brne TEST5
ldi ZH,high(TEXT6*2)
ldi ZL,low(TEXT6*2)
rjmp TESTDONE
TEST5:
cpi r24,5 ;je 5 jumperu?
brne TEST4
ldi ZH,high(TEXT5*2)
ldi ZL,low(TEXT5*2)
rjmp TESTDONE
TEST4:
cpi r24,4 ;jsou 4 jumpery?
brne TEST3
ldi ZH,high(TEXT4*2)
ldi ZL,low(TEXT4*2)
rjmp TESTDONE
TEST3:
cpi r24,3 ;jsou 3 jumpery?
brne TEST2
ldi ZH,high(TEXT3*2)
ldi ZL,low(TEXT3*2)
rjmp TESTDONE
TEST2:
cpi r24,2 ;jsou 2 jumpery?
brne TEST1
ldi ZH,high(TEXT2*2)
ldi ZL,low(TEXT2*2)
rjmp TESTDONE
TEST1:
cpi r24,1 ;je 1 jumper?
brne TEST0
ldi ZH,high(TEXT1*2)
ldi ZL,low(TEXT1*2)
rjmp TESTDONE
TEST0:
ldi ZH,high(TEXT0*2) ;je 0 jumperu.
ldi ZL,low(TEXT0*2)
TESTDONE:
;Z obsahuje pointer na zacatek vysilaneho textu.
;Dalsi znak textu (nebo prvni)
NextCharTxt:
lpm curchar,Z+ ;do curchar nacti soucasny znak. Z je pointer na dalsi
cpi curchar,0
breq EndCom ;curchar = 0? (konec komunikace) - jdi na konec
push ZH ;uschovej Z pointer (bude pouzivan jako pointer tabulky)
push ZL
;hledani znaku v tabulce
ldi ZH,high(MORSE*2) ;zacatek MORSE tabulky do Z
ldi ZL,low(MORSE*2)
NextCharTbl:
lpm morspart,Z+ ;precti znak z tabulky
cpi morspart,0 ;je to 0? (= konec tabulky)
breq CharDone ;pak jdi na CharDone
cp morspart,curchar ;je to hledany znak?
breq CharFound ;pak jdi na CharFound
adiw ZL,7 ;jinak jdi na nasledujici znak v tabulce (1 z postincrementu + 7 dalsich bytu)
rjmp NextCharTbl
;znak nalezen v tabulce
CharFound:
lpm morspart,Z+ ;nacti MorsPart
cpi morspart,0 ;je to 0? (= konec znaku)
breq CharDone ;pak jdi na CharDone
cpi morspart,1 ;je to tecka? (=1) - zustan tady
brne CARKA ;je to carka nebo mezera? (=3/4) - jdi na CARKA
;TECKA
cbi LEDPORT, ledm ;rozsvit ledm
BuzzOn ;zacni pipnuti
ldi r16,DelkaTecky ;cekej podle DelkaTecky
rcall delay
BuzzOff ;konec pipnuti
sbi LEDPORT, ledm ;zhasni ledm
rjmp MorsPartDone ;konec morspartu -> MorsPartDone
;CARKA
CARKA:
cpi morspart,3 ;je to carka? (=3) - zustan tady
brne MEZERA ;je to mezera? (=4) - jdi na MEZERA
cbi LEDPORT, ledm ;rozsvit ledm
BuzzOn ;zacni pipnuti
ldi r16,DelkaCarky ;cekej podle DelkaCarky
rcall delay
BuzzOff ;konec pipnuti
sbi LEDPORT, ledm ;zhasni ledm
rjmp MorsPartDone ;konec morspartu -> MorsPartDone
MEZERA:
ldi r16,DelkaMezery ;cekej podle DelkaMezery
rcall delay
rjmp CharFound
;tecka/carka/mezera dokoncena
MorsPartDone: ;konec morspartu (=tecka/carka)
ldi r16,MezeraMorspart ;udelej mezeru
rcall delay
rjmp CharFound ;jdi na dalsi cast morspartu
;znak dokoncen
CharDone:
ldi r16,MezeraZnak ;mezera za znakem
rcall delay
pop ZL ;obnov pointer pro text
pop ZH
rjmp NextCharTxt ;jdi na dalsi znak textu
EndCom:
ldi r16,10
rcall delay
BuzzOn
;plynule zhasnuti ledm + klesajici ton
ldi cmatch,0 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
in r24,LEDPORT ;uloz stav ledportu
cbr r24,0b01000000 ;zapni ledm
sbr r24,0b10000000 ;zapni pullup
ldi r23,0b11111111 ;priprav stav pro vypnute ledky
L3NEXTSTEP:
inc cmatch ;sniz jas
cpi cmatch,255 ;je jas=255? pak L3DONE
breq L3DONE
mov r16,cmatch
lsr r16
SetTone
ldi louter,25 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L3OUTER:
dec louter ;je konec louter? pak novy jas
breq L3NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
;cbi LEDPORT,ledm ;rozsvit ledmain
out LEDPORT,r24 ;zapni ledky
L3INNER:
dec linner
breq L3OUTER
cp linner,cmatch ;je cmatch?
brne L3Ib
;sbi LEDPORT,ledm ;jo -> zhasni ledmain
out LEDPORT,r23 ;zhasni ledky
L3Ib:
rjmp L3INNER
L3DONE:
sbi LEDPORT, ledm ;zhasni ledm (pro jistotu)
ldi r16,2 ;prodleva, aby ton neznel tak uriznute
rcall delay
BuzzOff ;vypnout zvuk
USNI:
;SLEEP (a po probuzeni skok na RESET)
ldi r16,(1<<PCIE)
out GIMSK,r16 ;povol pinchange interrupt (general)
clr r16
out SWPORT,r16 ;vypni pullupy jumperu
sbi SYSPORT, speak ;vypni speaker (pro jistotu)
ser r16
out LEDPORT,r16 ;zhasni ledky, PB7 (ext. interrupt) pullup enabled
;nastavit navesti, ze jde o probuzeni po spanku
ldi r16,AFTER_SLEEP
mov r5,r16
;probudi se pinchange interruptem na PB7
in r16, MCUCR
ori r16, (1<<SE)
out MCUCR, r16 ;sleep enable && sleep
sleep
in r16, MCUCR
andi r16, ~(1<<SE)
out MCUCR, r16 ;sleep disable
;reset
rjmp RESET
;R U T I N Y
delay:
;ldi r16,#desetin
push r17
push r18
;255*225*7
d0:
ldi r17,255
d1:
ldi r18,227
d2:
nop
nop
nop
dec r18
brne d2
dec r17
brne d1
dec r16
brne d0
pop r18
pop r17
ret
PINCHANGE:
mov r16,r5
cpi r16,AFTER_SLEEP
brne NENIPOSLEEPU
;je po SLEEPu -> reset
ldi r16,2 ;cekej 0.2s
rcall delay
clr r5 ;vymazat navesti ze byl SLEEP
clr r16
out GIMSK,r16 ;zakaz pinchange interrupt (general)
sei
rjmp RESET ;pri resetu se vynuluje SP a sei uz bylo, takze se reti delat nemusi. bude reset
;preruseni normalniho behu programu tlacitkem -> usnout
NENIPOSLEEPU:
ser r16 ;zhasne ledky
out LEDPORT,r16
BuzzOff ;pro jistotu vypne speaker
ldi r16,15 ;ceka 1.5 sekundy (aby se tlacitko urcite stihlo uvolnit -> jinak se udela dalsi "pinchange" a hned se to probudi)
rcall delay
in r16,EIFR ;vymaz zasobnik ext. preruseni (behem cekani bylo tlacitko pusteno -> vygenerovan dalsi interrupt)
andi r16,(1<<PCIF)
out EIFR,r16
sei ;povol preruseni (vypnuto pri interruptu)
rjmp USNI ;usnout (probudi se zmenou PB7)
; T A B U L K A Z N A K U
MORSE:
.DB "A",1,3,0,0,0,0,0 ;A
.DB "B",3,1,1,1,0,0,0 ;B
.DB "C",3,1,3,1,0,0,0 ;C
.DB "D",3,1,1,0,0,0,0 ;D
.DB "E",1,0,0,0,0,0,0 ;E
.DB "F",1,1,3,1,0,0,0 ;F
.DB "G",3,3,1,0,0,0,0 ;G
.DB "H",1,1,1,1,0,0,0 ;H
.DB "I",1,1,0,0,0,0,0 ;I
.DB "J",1,3,3,3,0,0,0 ;J
.DB "K",3,1,3,0,0,0,0 ;K
.DB "L",1,3,1,1,0,0,0 ;L
.DB "M",3,3,0,0,0,0,0 ;M
.DB "N",3,1,0,0,0,0,0 ;N
.DB "O",3,3,3,0,0,0,0 ;O
.DB "P",1,3,3,1,0,0,0 ;P
.DB "Q",3,3,1,3,0,0,0 ;Q
.DB "R",1,3,1,0,0,0,0 ;R
.DB "S",1,1,1,0,0,0,0 ;S
.DB "T",3,0,0,0,0,0,0 ;T
.DB "U",1,1,3,0,0,0,0 ;U
.DB "V",1,1,1,3,0,0,0 ;V
.DB "W",1,3,3,0,0,0,0 ;W
.DB "X",3,1,1,3,0,0,0 ;X
.DB "Y",3,1,3,3,0,0,0 ;Y
.DB "Z",3,3,1,1,0,0,0 ;Z
.DB "0",3,3,3,3,3,0,0 ;0
.DB "1",1,3,3,3,3,0,0 ;1
.DB "2",1,1,3,3,3,0,0 ;2
.DB "3",1,1,1,3,3,0,0 ;3
.DB "4",1,1,1,1,3,0,0 ;4
.DB "5",1,1,1,1,1,0,0 ;5
.DB "6",3,1,1,1,1,0,0 ;6
.DB "7",3,3,1,1,1,0,0 ;7
.DB "8",3,3,3,1,1,0,0 ;8
.DB "9",3,3,3,3,1,0,0 ;9
.DB ".",1,3,1,3,1,3,0 ;.
.DB ",",3,3,1,1,3,3,0 ;,
.DB " ",4,0,0,0,0,0,0 ;space
.DB 0,0,0,0,0,0,0,0 ;nic=konec tabulky
;T E X T Y K O D V Y S I L A N I
;
; 0 1 2 3 4 5 6 minut cca
TEXT0:
.db "JSEM NAVIGATOR NEMOHU ZAMERIT MODUL HLEDEJTE ANTENU NA N50 03.264 E014 24.965",0 ;gps=vesl.ostrov FINAL
TEXT1:
.db "POTREBUJI ZESILOVAC LEZI ZDE N50 03.067 E014 25.170",0 ;gps=kavky FINAL
TEXT2:
.db "SLABY SIGNAL ZAPOJTE DALSI ANTENU N50 02.547 E014 24.823 NAHORE",0 ;gps=dobeska FINAL
TEXT3:
.db "USMERNOVAC VYKONU DOPADL NA N50 02.858 E014 24.529",0 ;gps=kostel zlichov FINAL
TEXT4:
.db "POLOHA DALSI ANTENY JE N50 03.073 E014 24.150",0 ;gps=skala prokopak FINAL
TEXT5:
.db "PRESNOST ZVYSI SUPERSENZOR N50 03.344 E014 24.822",0 ;gps=kempovy ostrov FINAL
TEXT6:
.db "VRAK MODULU ZAMEREN NA N50 03.034 E014 24.928 MUZETE SI HO NECHAT",0 ;gps=bosan FINAL

@ -0,0 +1,175 @@
; Zapojeni:
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; SW0 G --+ PD0 PB7 +---[wakeswitch]--GND
; SW1 G --+ PD1 PB6 +-- LED MAIN K
; --+ PA1 PB5 +-- LED 5 K
; Vcc-[speaker]----+ PA0 PB4 +-- LED 4 K
; SW2 G --+ PD2 PB3 +-- LED 3 K
; SW3 G --+ PD3 PB2 +-- LED 2 K
; SW4 G --+ PD4 PB1 +-- LED 1 K
; SW5 G --+ PD5 PB0 +-- LED 0 K
; GND --+ GND PD6 +--
; +-------------+
;"K" = katoda (ledka zapojena mezi Vcc a timhle pinem, aktivni je 0)
;"G" = ground (spinac mezi tomhle pionem a zemi, aktivni je 0)
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;LFUSE: 0xE2
;HFUSE: 0xDF
.equ FrekvenceMorse = 50 ;62500/tohle Hz tón 42
;K O N S T A N T Y + P R E Z D I V K Y P O U R T U A P I N U
;PORTA
.equ SYSPORT = PORTA
.equ SYSPIN = PINA
.equ SYSDDR = DDRA
.equ speak = 0
.equ inkey = 7
;PORTB
.equ LEDPORT = PORTB
.equ LEDDDR = DDRB
.equ LEDPIN = PINB
.equ ledm = 6
;PORTD
.equ SWPORT = PORTD
.equ SWPIN = PIND
.equ SWDDR = DDRD
;A L I A S Y R E G I S T R U
.def cmatch = r19
.def louter = r18
.def linner = r17
.def curchar = r25
.def morspart = r24
;aliasy pointerů
.def ZH = r31
.def ZL = r30
;.def YH = r29
;.def YL = r28
;.def XH = r27
;.def XL = r26
; M A K R A
;Reprak (zapnuti a vypnuti pipani 1kHz)
.MACRO BuzzOn
sbi SYSPORT,speak
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 zapnut, prescaler na 64 (4000000/64=62500)
out TCCR0B,r16
.ENDMACRO
.MACRO BuzzOff
clr r16 ;TC0 vypnut (hodiny zastaveny)
out TCCR0B,r16
sbi SYSPORT,speak ;vymazat speak (aby netekl proud reprakem)
.ENDMACRO
.MACRO SetTone
out OCR0A,r16
.ENDMACRO
;.MACRO DefaultTone
; ldi r16,FrekvenceMorse
; out OCR0A,r16
;.ENDMACRO
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x000D ;TC0 Compare match A
sbi SYSPIN,speak ;přepnout speak
reti ;návrat do programu (0x000E)
.org 0x0013
;nastaveni po resetu
.DB "PIPAC PRO PUNTU NA MORSE"
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli
; Nastaveni portu
;PORTA = SYSPORT
ldi r16,0b00000011 ;smer portu A - vse na výstup (speak)
out SYSDDR,r16
ldi r16,0b00000001 ;speak=1 (je mezi Vcc a timhle, takze skrz nej nic netece)
out SYSPORT,r16
;PORTB = LEDPORT
ldi r16,0b01111111 ;smer portu B - vystupni (ledky) - použijou se piny 0-6, 7. = pip
out LEDDDR,r16
ldi r16,0b11111111 ;vse v PORTB na 1 = ledky zhasnuty, pip pullup enabled
out LEDPORT,r16
;PORTD = SWPORT
ldi r16,0b00000000 ;smer portu D - vse na vstup (tlačítka) - použijou se jen piny 0-5, 6. zbyde
out SWDDR,r16
ldi r16,0b01111111 ;enable pullup
out SWPORT,r16
; timer0 - generator f=1kHz (pipak)
ldi r16,(1<<WGM01) ;port se neovlivnuje citacem, CTC mod
out TCCR0A,r16
ldi r16,62 ;compare match = 62 (vystupni frekvence 1kHz)
out OCR0A,r16
ldi r16,(1<<OCIE0A) ;povolit interupt z casovace (jeste nutno zapnout: makro BuzzOn)
out TIMSK,r16
ldi r16,50
SetTone
;pipani aktivuje makro BuzzOn, vypne makro BuzzOff
sei ;Global Interrupt Enable
ldi r20,0b10000000
loop:
in r19,LEDPIN
andi r19,0b10000000
cp r19,r20
breq loop ;beze zmeny, opakuj test
ldi r16,255
l1: in r18,LEDPIN
andi r18,0b10000000
cp r18,r19 ;nacti LEDPIN. je porad stajny? (255x)
brne loop ;ne -> loop
dec r16 ;jo -> dalsi test shodnosti, l1
brne l1
mov r20,r19 ;uloz jako minulou hodnotu pinu
cpi r20,0b10000000 ;je nestisknuto?
breq beepoff ;vypni pip
ldi r16,0b10000000
out LEDPORT,r16 ;rozsvit ledky
BuzzOn ;jinak pipej
rjmp loop
beepoff:
BuzzOff
ldi r16,0b11111111
out LEDPORT, r16 ;zhasni ledky
out LEDPORT,r16
rjmp loop

@ -0,0 +1,630 @@
;SETI navigation module of extraterrestrial spaceship BY Ondrej Hruska (c) 2011
;-------------------------------------------------
;Co to dela:
;Po spusteni plynule rozsviti a zhasle LED MAIN, behem toho houka s promennou frekvenci
;Povoli uspani zmenou stavu pinu PB7
; Zapojeni:
; +------u------+
; Vcc -> reset --+ /RST Vcc +-- napajeni +5V
; SW0 G --+ PD0 PB7 +---[wakeswitch]--GND
; SW1 G --+ PD1 PB6 +-- LED MAIN K
; --+ PA1 PB5 +-- LED 5 K
; Vcc-[speaker]----+ PA0 PB4 +-- LED 4 K
; SW2 G --+ PD2 PB3 +-- LED 3 K
; SW3 G --+ PD3 PB2 +-- LED 2 K
; SW4 G --+ PD4 PB1 +-- LED 1 K
; SW5 G --+ PD5 PB0 +-- LED 0 K
; GND --+ GND PD6 +--
; +-------------+
;"K" = katoda (ledka zapojena mezi Vcc a timhle pinem, aktivni je 0)
;"G" = ground (spinac mezi tomhle pionem a zemi, aktivni je 0)
.device attiny2313
;běží na 4MHz, ckdiv8=1 (vypnuto)
;LFUSE: 0xE2
;HFUSE: 0xDF
;N A S T A V E N I V Y S I L A N E M O R S E O V K Y
;tecka mmorspart carka mznak mmezera mznak carka mmorspart
.equ DelkaTecky = 3 ;delka tecky v desetinach
.equ DelkaCarky = 14 ;3x delka tecky = delka carky
.equ DelkaMezery = 6 ;mznak+tohle+mznak
.equ MezeraMorspart = 3 ;mezera mezi teckami/carkami v pismene
.equ MezeraZnak = 21 ;mezera za znakem
.equ FrekvenceMorse = 50 ;62500/tohle Hz tón 42
;.equ DelkaTecky = 4 ;delka tecky v desetinach
;.equ DelkaCarky = 14 ;3x delka tecky = delka carky
;.equ MezeraMorspart = 3 ;mezera mezi teckami/carkami v pismene
;.equ MezeraZnak = 14 ;mezera za znakem (pripojena za vnitrni mezeru)
;.equ FrekvenceMorse = 43 ;62500/tohle Hz
;K O N S T A N T Y + P R E Z D I V K Y P O U R T U A P I N U
;PORTA
.equ SYSPORT = PORTA
.equ SYSPIN = PINA
.equ SYSDDR = DDRA
.equ speak = 0
;PORTB
.equ LEDPORT = PORTB
.equ LEDDDR = DDRB
;.equ LEDPIN = PINB
;.equ led0 = 0
;.equ led1 = 1
;.equ led2 = 2
;.equ led3 = 3
;.equ led4 = 4
;.equ led5 = 5
.equ ledm = 6
;.equ wakepin = 7
.equ AFTER_SLEEP = 0b10101010 ;informace ze byl predtim sleep
;PORTD
.equ SWPORT = PORTD
.equ SWPIN = PIND
.equ SWDDR = DDRD
;.equ sw0 = 0
;.equ sw1 = 1
;.equ sw2 = 2
;.equ sw3 = 3
;.equ sw4 = 4
;.equ sw5 = 5
;A L I A S Y R E G I S T R U
.def cmatch = r19
.def louter = r18
.def linner = r17
.def curchar = r25
.def morspart = r24
;aliasy pointerů
.def ZH = r31
.def ZL = r30
;.def YH = r29
;.def YL = r28
;.def XH = r27
;.def XL = r26
; M A K R A
;Reprak (zapnuti a vypnuti pipani 1kHz)
.MACRO BuzzOn
sbi SYSPORT,speak
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 zapnut, prescaler na 64 (4000000/64=62500)
out TCCR0B,r16
.ENDMACRO
.MACRO BuzzOff
clr r16 ;TC0 vypnut (hodiny zastaveny)
out TCCR0B,r16
sbi SYSPORT,speak ;vymazat speak (aby netekl proud reprakem)
.ENDMACRO
.MACRO SetTone
out OCR0A,r16
.ENDMACRO
.MACRO DefaultTone
ldi r16,FrekvenceMorse
out OCR0A,r16
.ENDMACRO
; Z A C A T E K P R O G R A M U
;vektory preruseni
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x000B ;pin change
rjmp PINCHANGE ;probuzeni nebo preruseni cinnosti
.org 0x000D ;TC0 Compare match A
sbi SYSPIN,speak ;přepnout speak
reti ;návrat do programu (0x000E)
.org 0x0013
;nastaveni po resetu
.DB "MORSE PIPAC SETI 2011",0 ;(nazev programu)
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
clr r5 ;vymaz navesti ze je po probuzeni (r5=AFTER_SLEEP, ted bude 0)
ldi r16, (1<<SM0) ;nastavi sleep mode = power-down (nejuspornejsi)
out MCUCR, r16
; Nastaveni portu
;PORTA = SYSPORT
ldi r16,0b00000011 ;smer portu A - vse na výstup (shutdown a speak)
out SYSDDR,r16
ldi r16,0b00000001 ;shutdown=0 (continue), speak=1 (je mezi Vcc a timhle, takze skrz nej nic netece)
out SYSPORT,r16
;PORTB = LEDPORT
ldi r16,0b01111111 ;smer portu B - vystupni (ledky) - použijou se piny 0-6, 7. = wakepin
out LEDDDR,r16
ldi r16,0b11111111 ;vse v PORTB na 1 = ledky zhasnuty, wakepin pullup enabled
out LEDPORT,r16
;PORTD = SWPORT
ldi r16,0b00000000 ;smer portu D - vse na vstup (tlačítka) - použijou se jen piny 0-5, 6. zbyde
out SWDDR,r16
ldi r16,0b01111111 ;enable pullup
out SWPORT,r16
; timer0 - generator f=1kHz (pipak)
ldi r16,(1<<WGM01) ;port se neovlivnuje citacem, CTC mod
out TCCR0A,r16
ldi r16,62 ;compare match = 62 (vystupni frekvence 1kHz)
out OCR0A,r16
ldi r16,(1<<OCIE0A) ;povolit interupt z casovace (jeste nutno zapnout: makro BuzzOn)
out TIMSK,r16
;pipani aktivuje makro BuzzOn, vypne makro BuzzOff
;konfigurace pinchange interruptu (jeste je treba zapnout PCIE v GIMSK)
ldi r16,(1<<PCINT7)
out PCMSK,r16 ;povol pinchange interrupt pro PB7 (=wakepin)
sei ;Global Interrupt Enable
;plynule rozsviceni ledm + stoupajici ton
BuzzOn
ldi cmatch,255 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L1NEXTSTEP:
dec cmatch ;zvys jas
breq L1DONE ;je jas=255(full)? pak L1DONE
mov r16,cmatch
SetTone
ldi louter,25 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L1OUTER:
dec louter ;je konec louter? pak novy jas
breq L1NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsviť ledmain
L1INNER:
dec linner
breq L1OUTER
cp linner,cmatch ;je cmatch?
brne L1Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L1Ib:
rjmp L1INNER
L1DONE:
cbi LEDPORT, ledm ;rozsvit ledku (pro jistotu)
;plynule zhasnuti ledm + klesajici ton
ldi cmatch,0 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
L2NEXTSTEP:
inc cmatch ;sniz jas
cpi cmatch,255 ;je jas=0? pak L2DONE
breq L2DONE
mov r16,cmatch
SetTone
ldi louter,20 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L2OUTER:
dec louter ;je konec louter? pak novy jas
breq L2NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
cbi LEDPORT,ledm ;rozsvit ledmain
L2INNER:
dec linner
breq L2OUTER
cp linner,cmatch ;je cmatch?
brne L2Ib
sbi LEDPORT,ledm ;jo -> zhasni ledmain
L2Ib:
rjmp L2INNER
L2DONE:
sbi LEDPORT, ledm ;zhasni ledm (pro jistotu)
ldi r16,1 ;prodleva, aby ton neznel tak uriznute
rcall delay
BuzzOff ;vypnout zvuk
;ted uz je dost douho po resetu, zepneme moznost uspani wakepinem
;vymaz zasobnik ext. preruseni
in r16,EIFR
andi r16,(1<<PCIF)
out EIFR,r16
;povol interrupt změny pinu PB7
ldi r16,(1<<PCIE)
out GIMSK,r16 ;povol pinchange interrupt (general)
;krouzeni cervenych ledek + pipani
ldi r18,24 ;celkem 24 preklopeni
ldi r17,0b11111110 ;posuvny registr - inicializace
KRUH1:
sbr r17,0b11000000 ;1 na nepouzite bity (ledky zhasnuty)
out LEDPORT, r17 ;vystup
lsr r17 ;rotuj doprava pres carry
brcs KRUH1b ;neni carry? preskoc
cbr r17,0b00100000 ;dopln mezeru na zacatek (emulace 6bitoveho posuvneho registru)
KRUH1b:
mov r16,r17 ;vypocet tonu pipnuti
com r16
lsl r16
eor r16,r18
SetTone
BuzzOn ;pipni
ldi r16,2
rcall delay
BuzzOff
dec r18
brne KRUH1 ;neni-li to posledni preklopeni, opakuj
K1DONE:
DefaultTone ;nastav normalni ton = 1kHz (pro morseovku)
;zhasni vse
ldi r16,0b11111111
out LEDPORT,r16 ;vypni ledky
ldi r16,4
rcall delay ;cekej 0.4s
;ukaz co je zapojeno (cervenymi ledkami)
in r25, SWPIN ;prijmout stav SWPORTu
andi r25,0b00111111 ;ignoruj nepouzite piny
mov r16,r25
sbr r16,0b11000000
out LEDPORT,r16 ;ukazat na LEDPORTu
;cekej 2 sekundy
ldi r16,20 ;pauza 2s
rcall delay
;spocitani zapnutych jumperu
;r25 obsahuje stav SWPINu (bity 0-5)
sbr r25,0b11000000 ;zapni i nepouzite bity
com r25 ;neguj (jumpery jsou na zem) -> aktivni budou 1
clr r24 ;priprav citac aktivnich jumperu
clr r16 ;nulovej registr pro ADC (aby procetl jen carry)
COUNTL:
lsr r25 ;(r25>>1) bit 0 do carry
adc r24,r16 ;pricti k citaci r24 carry (r16 je 0)
cpi r25,0 ;je r25 prazdny? ne -> opakuj COUNTL
brne COUNTL
;r24 obsahuje pocet zaplych bitu
COUNTDONE:
cpi r24,6 ;je 6 jumperu?
brne TEST5
ldi ZH,high(TEXT6*2)
ldi ZL,low(TEXT6*2)
rjmp TESTDONE
TEST5:
cpi r24,5 ;je 5 jumperu?
brne TEST4
ldi ZH,high(TEXT5*2)
ldi ZL,low(TEXT5*2)
rjmp TESTDONE
TEST4:
cpi r24,4 ;jsou 4 jumpery?
brne TEST3
ldi ZH,high(TEXT4*2)
ldi ZL,low(TEXT4*2)
rjmp TESTDONE
TEST3:
cpi r24,3 ;jsou 3 jumpery?
brne TEST2
ldi ZH,high(TEXT3*2)
ldi ZL,low(TEXT3*2)
rjmp TESTDONE
TEST2:
cpi r24,2 ;jsou 2 jumpery?
brne TEST1
ldi ZH,high(TEXT2*2)
ldi ZL,low(TEXT2*2)
rjmp TESTDONE
TEST1:
cpi r24,1 ;je 1 jumper?
brne TEST0
ldi ZH,high(TEXT1*2)
ldi ZL,low(TEXT1*2)
rjmp TESTDONE
TEST0:
ldi ZH,high(TEXT0*2) ;je 0 jumperu.
ldi ZL,low(TEXT0*2)
TESTDONE:
;Z obsahuje pointer na zacatek vysilaneho textu.
;Dalsi znak textu (nebo prvni)
NextCharTxt:
lpm curchar,Z+ ;do curchar nacti soucasny znak. Z je pointer na dalsi
cpi curchar,0
breq EndCom ;curchar = 0? (konec komunikace) - jdi na konec
push ZH ;uschovej Z pointer (bude pouzivan jako pointer tabulky)
push ZL
;hledani znaku v tabulce
ldi ZH,high(MORSE*2) ;zacatek MORSE tabulky do Z
ldi ZL,low(MORSE*2)
NextCharTbl:
lpm morspart,Z+ ;precti znak z tabulky
cpi morspart,0 ;je to 0? (= konec tabulky)
breq CharDone ;pak jdi na CharDone
cp morspart,curchar ;je to hledany znak?
breq CharFound ;pak jdi na CharFound
adiw ZL,7 ;jinak jdi na nasledujici znak v tabulce (1 z postincrementu + 7 dalsich bytu)
rjmp NextCharTbl
;znak nalezen v tabulce
CharFound:
lpm morspart,Z+ ;nacti MorsPart
cpi morspart,0 ;je to 0? (= konec znaku)
breq CharDone ;pak jdi na CharDone
cpi morspart,1 ;je to tecka? (=1) - zustan tady
brne CARKA ;je to carka nebo mezera? (=3/4) - jdi na CARKA
;TECKA
cbi LEDPORT, ledm ;rozsvit ledm
BuzzOn ;zacni pipnuti
ldi r16,DelkaTecky ;cekej podle DelkaTecky
rcall delay
BuzzOff ;konec pipnuti
sbi LEDPORT, ledm ;zhasni ledm
rjmp MorsPartDone ;konec morspartu -> MorsPartDone
;CARKA
CARKA:
cpi morspart,3 ;je to carka? (=3) - zustan tady
brne MEZERA ;je to mezera? (=4) - jdi na MEZERA
cbi LEDPORT, ledm ;rozsvit ledm
BuzzOn ;zacni pipnuti
ldi r16,DelkaCarky ;cekej podle DelkaCarky
rcall delay
BuzzOff ;konec pipnuti
sbi LEDPORT, ledm ;zhasni ledm
rjmp MorsPartDone ;konec morspartu -> MorsPartDone
MEZERA:
ldi r16,DelkaMezery ;cekej podle DelkaMezery
rcall delay
rjmp CharFound
;tecka/carka/mezera dokoncena
MorsPartDone: ;konec morspartu (=tecka/carka)
ldi r16,MezeraMorspart ;udelej mezeru
rcall delay
rjmp CharFound ;jdi na dalsi cast morspartu
;znak dokoncen
CharDone:
ldi r16,MezeraZnak ;mezera za znakem
rcall delay
pop ZL ;obnov pointer pro text
pop ZH
rjmp NextCharTxt ;jdi na dalsi znak textu
EndCom:
ldi r16,10
rcall delay
BuzzOn
;plynule zhasnuti ledm + klesajici ton
ldi cmatch,0 ;comparematch (cita se od 255 do 0, tady se ledka vypne)
in r24,LEDPORT ;uloz stav ledportu
cbr r24,0b01000000 ;zapni ledm
sbr r24,0b10000000 ;zapni pullup
ldi r23,0b11111111 ;priprav stav pro vypnute ledky
L3NEXTSTEP:
inc cmatch ;sniz jas
cpi cmatch,255 ;je jas=255? pak L3DONE
breq L3DONE
mov r16,cmatch
lsr r16
SetTone
ldi louter,25 ;vnejsi smycka (pocet cyklu se stejnym jasem)
L3OUTER:
dec louter ;je konec louter? pak novy jas
breq L3NEXTSTEP
ldi linner,255 ;vnitrni smycka, stara se o regulaci jasu
;cbi LEDPORT,ledm ;rozsvit ledmain
out LEDPORT,r24 ;zapni ledky
L3INNER:
dec linner
breq L3OUTER
cp linner,cmatch ;je cmatch?
brne L3Ib
;sbi LEDPORT,ledm ;jo -> zhasni ledmain
out LEDPORT,r23 ;zhasni ledky
L3Ib:
rjmp L3INNER
L3DONE:
sbi LEDPORT, ledm ;zhasni ledm (pro jistotu)
ldi r16,2 ;prodleva, aby ton neznel tak uriznute
rcall delay
BuzzOff ;vypnout zvuk
USNI:
;SLEEP (a po probuzeni skok na RESET)
ldi r16,(1<<PCIE)
out GIMSK,r16 ;povol pinchange interrupt (general)
clr r16
out SWPORT,r16 ;vypni pullupy jumperu
sbi SYSPORT, speak ;vypni speaker (pro jistotu)
ser r16
out LEDPORT,r16 ;zhasni ledky, PB7 (ext. interrupt) pullup enabled
;nastavit navesti, ze jde o probuzeni po spanku
ldi r16,AFTER_SLEEP
mov r5,r16
;probudi se pinchange interruptem na PB7
in r16, MCUCR
ori r16, (1<<SE)
out MCUCR, r16 ;sleep enable && sleep
sleep
in r16, MCUCR
andi r16, ~(1<<SE)
out MCUCR, r16 ;sleep disable
;reset
rjmp RESET
;R U T I N Y
delay:
;ldi r16,#desetin
push r17
push r18
;255*225*7
d0:
ldi r17,255
d1:
ldi r18,227
d2:
nop
nop
nop
dec r18
brne d2
dec r17
brne d1
dec r16
brne d0
pop r18
pop r17
ret
PINCHANGE:
mov r16,r5
cpi r16,AFTER_SLEEP
brne NENIPOSLEEPU
;je po SLEEPu -> reset
ldi r16,2 ;cekej 0.2s
rcall delay
clr r5 ;vymazat navesti ze byl SLEEP
clr r16
out GIMSK,r16 ;zakaz pinchange interrupt (general)
sei
rjmp RESET ;pri resetu se vynuluje SP a sei uz bylo, takze se reti delat nemusi. bude reset
;preruseni normalniho behu programu tlacitkem -> usnout
NENIPOSLEEPU:
ser r16 ;zhasne ledky
out LEDPORT,r16
BuzzOff ;pro jistotu vypne speaker
ldi r16,15 ;ceka 1.5 sekundy (aby se tlacitko urcite stihlo uvolnit -> jinak se udela dalsi "pinchange" a hned se to probudi)
rcall delay
in r16,EIFR ;vymaz zasobnik ext. preruseni (behem cekani bylo tlacitko pusteno -> vygenerovan dalsi interrupt)
andi r16,(1<<PCIF)
out EIFR,r16
sei ;povol preruseni (vypnuto pri interruptu)
rjmp USNI ;usnout (probudi se zmenou PB7)
; T A B U L K A Z N A K U
MORSE:
.DB "A",1,3,0,0,0,0,0 ;A
.DB "B",3,1,1,1,0,0,0 ;B
.DB "C",3,1,3,1,0,0,0 ;C
.DB "D",3,1,1,0,0,0,0 ;D
.DB "E",1,0,0,0,0,0,0 ;E
.DB "F",1,1,3,1,0,0,0 ;F
.DB "G",3,3,1,0,0,0,0 ;G
.DB "H",1,1,1,1,0,0,0 ;H
.DB "I",1,1,0,0,0,0,0 ;I
.DB "J",1,3,3,3,0,0,0 ;J
.DB "K",3,1,3,0,0,0,0 ;K
.DB "L",1,3,1,1,0,0,0 ;L
.DB "M",3,3,0,0,0,0,0 ;M
.DB "N",3,1,0,0,0,0,0 ;N
.DB "O",3,3,3,0,0,0,0 ;O
.DB "P",1,3,3,1,0,0,0 ;P
.DB "Q",3,3,1,3,0,0,0 ;Q
.DB "R",1,3,1,0,0,0,0 ;R
.DB "S",1,1,1,0,0,0,0 ;S
.DB "T",3,0,0,0,0,0,0 ;T
.DB "U",1,1,3,0,0,0,0 ;U
.DB "V",1,1,1,3,0,0,0 ;V
.DB "W",1,3,3,0,0,0,0 ;W
.DB "X",3,1,1,3,0,0,0 ;X
.DB "Y",3,1,3,3,0,0,0 ;Y
.DB "Z",3,3,1,1,0,0,0 ;Z
.DB "0",3,3,3,3,3,0,0 ;0
.DB "1",1,3,3,3,3,0,0 ;1
.DB "2",1,1,3,3,3,0,0 ;2
.DB "3",1,1,1,3,3,0,0 ;3
.DB "4",1,1,1,1,3,0,0 ;4
.DB "5",1,1,1,1,1,0,0 ;5
.DB "6",3,1,1,1,1,0,0 ;6
.DB "7",3,3,1,1,1,0,0 ;7
.DB "8",3,3,3,1,1,0,0 ;8
.DB "9",3,3,3,3,1,0,0 ;9
.DB ".",1,3,1,3,1,3,0 ;.
.DB ",",3,3,1,1,3,3,0 ;,
.DB " ",4,0,0,0,0,0,0 ;space
.DB 0,0,0,0,0,0,0,0 ;nic=konec tabulky
;T E X T Y K O D V Y S I L A N I
;
; 0 1 2 3 4 5 6 minut cca
TEXT0:
.db "HLEDEJ ANTENU NA ZADNIM ZACHODE",0 ;gps=vesl.ostrov FINAL
TEXT1:
.db "DALSI ANTENA JE V KLUBOVNE",0 ;gps=kavky FINAL
TEXT2:
.db "HLEDEJ V HALE NA NASTENCE",0 ;gps=dobeska FINAL
TEXT3:
.db "KONTEJNER NA ODPADKY",0 ;gps=kostel zlichov FINAL
TEXT4:
.db "TAJEMSTVI UKRYVA BOTNIK",0 ;gps=skala prokopak FINAL
TEXT5:
.db "K CILI TE DOVEDE VYPINAC",0 ;gps=kempovy ostrov FINAL
TEXT6:
.db "ZAMETTE HALU A KLUBOVNU PAK HLEDEJTE CHROCHTAVE ZVIRE",0 ;gps=bosan FINAL

@ -0,0 +1,151 @@
.device attiny13
.def cnt=r17
.def P0=r20
.def P1=r21
.def P2=r22
.def P3=r23
.def P4=r24
.def chc=r18
.def faze=r19
;### NASTAVENI ###
.equ CChDelay=6 ;DELAY pro zmenu barev - cim min tim rychlejsi je zmena
.equ ColDepth=128 ;Barevna hloubka - urcuje na kolik kroku se rozdeli prepinani 2 barev
.equ TIMEROV=2 ;porovnavaci hodnota pro timer - konstanta
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow
rjmp CASOVAC
.org 0x0007
rjmp casovac
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b00011111 ;výstupní = 1
out DDRB,r16
ldi r16,0 ;vypnout PullUp
out PORTB,r16
ldi r16,0b00000001 ;TC0 prescaler na 1 - velice plynule, bez blikani
out TCCR0B,r16 ;4800000Hz
ldi r16,0b00000010 ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,TIMEROV ;overflow 32 clks - upravuje rychlost prepinani (konstanta)
out OCR0A,r16 ;
in r16, TIMSK0 ;interrupt enable
ori r16, 0b00000100
out timsk0,r16
ldi P0,0 ;0
ldi P1,ColDepth ;1
ldi P2,ColDepth ;2
ldi P3,ColDepth ;3
ldi P4,ColDepth ;4
clr cnt
clr chc
clr faze ;faze: 0 = 0->1, 1=1->2, 2=2->3 atd
sei ;zapnout globalne interrupt
LOOP:
rjmp LOOP ;skok na loop
CASOVAC:
inc cnt ;cnt=cnt+1
cpi cnt,ColDepth ;cnt==ColorDepth? ANO->pokracovat, NE->skok na NOV
brne nov
clr cnt ;CNT je ColorDepth -> vymazat CNT
;vynulovat LED kanaly:
cbi portb,0 ; (0)
cbi portb,1 ; (1)
cbi portb,2 ; (2)
cbi portb,3 ; (3)
cbi portb,4 ; (4)
inc chc ;Zvysime citac pro zmenu barvy CHC o 1
cpi chc,CChDelay ;CHC==delay? ANO->pokracovat, NE->skok na NOV
brne nov
clr chc ;MENI SE BARVY
cpi faze,0
brne FazeNot0
;FAZE je 0
inc P0
dec P1
cpi P1,0
brne nov
inc faze
FazeNot0:
cpi faze,1
brne FazeNot1
;FAZE je 1
inc P1
dec P2
cpi P2,0
brne nov
inc faze
FazeNot1:
cpi faze,2
brne FazeNot2
;FAZE je 2
inc P2
dec P3
cpi P3,0
brne nov
inc faze
FazeNot2:
cpi faze,3
brne FazeNot3
;FAZE je 3
inc P3
dec P4
cpi P4,0
brne nov
inc faze
FazeNot3:
;FAZE je 4
inc P4
dec P0
cpi P0,0
brne nov
clr faze
;sprava PWM kanalu - podminene zapnuti LED
nov: ;NOV label
cp cnt,P0 ;P0==CNT? ANO->zapni P0, NE->skok na NOT0
brne not0
sbi portb,0
not0: ;NOTR label
cp cnt,P1 ;P1==CNT? ANO->zapni P1, NE->skok na NOT1
brne not1
sbi portb,1
not1: ;NOTG label
cp cnt,P2 ;P2==CNT? ANO->zapni P2, NE->skok na NOT2
brne not2
sbi portb,2
not2: ;NOTG label
cp cnt,P3 ;P3==CNT? ANO->zapni P3, NE->skok na NOT3
brne not3
sbi portb,4
not3: ;NOTG label
cp cnt,P4 ;P4==CNT? ANO->zapni P4, NE->skok na NOT4
brne endcounter
sbi portb,3
endcounter: ;ENDCOUNTER label - konec preruseni
reti ;navrat z obsluhy preruseni

@ -0,0 +1,53 @@
;pokus
.include "tn13def.inc"
.def POM=r16
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010 ;zacatek vlastniho programu
RESET:
LDI POM,low(RAMEND) ;nastavi stack pointer
OUT SPL,POM
LDI POM,0B00000011 ;nastavi vystupni piny
OUT DDRB,POM
LOOP:
SBI PORTB,0 ;PB0=0, PB1=1
CBI PORTB,1
RCALL CEKANI ;CEKACI SUB
CBI PORTB,0 ;PB0=1, PB1=0
SBI PORTB,1
RCALL CEKANI ;CEKACI SUB
RJMP LOOP ;znovu na navesti LOOP
CEKANI:
PUSH r18 ;ulozit pouzivane registry do STACKU
PUSH r17
PUSH r16
LDI r16, 100
L1: DEC r16
LDI r17, 100
L2: DEC r17
LDI r18, 125
L3: DEC r18
CPI r18, 0
BRNE L3
CPI r17, 0
BRNE L2
CPI r16, 0
BRNE L1
POP r16 ;nacist puvodni obsah registru ze STACKU
POP r17
POP r18
RET ;navrat do hlavniho programu

@ -0,0 +1,287 @@
AVRASM ver. 2.1.12 C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\pokus\pokus.asm Tue Sep 04 20:36:18 2007
EQU SIGNATURE_000 0000001e
EQU SIGNATURE_001 00000090
EQU SIGNATURE_002 00000007
EQU SREG 0000003f
EQU SPL 0000003d
EQU GIMSK 0000003b
EQU GIFR 0000003a
EQU TIMSK0 00000039
EQU TIFR0 00000038
EQU SPMCSR 00000037
EQU OCR0A 00000036
EQU MCUCR 00000035
EQU MCUSR 00000034
EQU TCCR0B 00000033
EQU TCNT0 00000032
EQU OSCCAL 00000031
EQU TCCR0A 0000002f
EQU DWDR 0000002e
EQU OCR0B 00000029
EQU GTCCR 00000028
EQU CLKPR 00000026
EQU WDTCR 00000021
EQU EEAR 0000001e
EQU EEDR 0000001d
EQU EECR 0000001c
EQU PORTB 00000018
EQU DDRB 00000017
EQU PINB 00000016
EQU PCMSK 00000015
EQU DIDR0 00000014
EQU ACSR 00000008
EQU ADMUX 00000007
EQU ADCSRA 00000006
EQU ADCH 00000005
EQU ADCL 00000004
EQU ADCSRB 00000003
EQU MUX0 00000000
EQU MUX1 00000001
EQU ADLAR 00000005
EQU REFS0 00000006
EQU ADPS0 00000000
EQU ADPS1 00000001
EQU ADPS2 00000002
EQU ADIE 00000003
EQU ADIF 00000004
EQU ADATE 00000005
EQU ADSC 00000006
EQU ADEN 00000007
EQU ADCH0 00000000
EQU ADCH1 00000001
EQU ADCH2 00000002
EQU ADCH3 00000003
EQU ADCH4 00000004
EQU ADCH5 00000005
EQU ADCH6 00000006
EQU ADCH7 00000007
EQU ADCL0 00000000
EQU ADCL1 00000001
EQU ADCL2 00000002
EQU ADCL3 00000003
EQU ADCL4 00000004
EQU ADCL5 00000005
EQU ADCL6 00000006
EQU ADCL7 00000007
EQU ADTS0 00000000
EQU ADTS1 00000001
EQU ADTS2 00000002
EQU ADC1D 00000002
EQU ADC3D 00000003
EQU ADC2D 00000004
EQU ADC0D 00000005
EQU ACME 00000006
EQU ACIS0 00000000
EQU ACIS1 00000001
EQU ACIE 00000003
EQU ACI 00000004
EQU ACO 00000005
EQU ACBG 00000006
EQU AINBG 00000006
EQU ACD 00000007
EQU AIN0D 00000000
EQU AIN1D 00000001
EQU EEARL 0000001e
EQU EEAR0 00000000
EQU EEAR1 00000001
EQU EEAR2 00000002
EQU EEAR3 00000003
EQU EEAR4 00000004
EQU EEAR5 00000005
EQU EEDR0 00000000
EQU EEDR1 00000001
EQU EEDR2 00000002
EQU EEDR3 00000003
EQU EEDR4 00000004
EQU EEDR5 00000005
EQU EEDR6 00000006
EQU EEDR7 00000007
EQU EERE 00000000
EQU EEWE 00000001
EQU EEPE 00000001
EQU EEMWE 00000002
EQU EEMPE 00000002
EQU EERIE 00000003
EQU EEPM0 00000004
EQU EEPM1 00000005
EQU SREG_C 00000000
EQU SREG_Z 00000001
EQU SREG_N 00000002
EQU SREG_V 00000003
EQU SREG_S 00000004
EQU SREG_H 00000005
EQU SREG_T 00000006
EQU SREG_I 00000007
EQU SP0 00000000
EQU SP1 00000001
EQU SP2 00000002
EQU SP3 00000003
EQU SP4 00000004
EQU SP5 00000005
EQU SP6 00000006
EQU SP7 00000007
EQU ISC00 00000000
EQU ISC01 00000001
EQU SM0 00000003
EQU SM1 00000004
EQU SE 00000005
EQU PUD 00000006
EQU PORF 00000000
EQU EXTRF 00000001
EQU BORF 00000002
EQU WDRF 00000003
EQU CAL0 00000000
EQU CAL1 00000001
EQU CAL2 00000002
EQU CAL3 00000003
EQU CAL4 00000004
EQU CAL5 00000005
EQU CAL6 00000006
EQU CLKPS0 00000000
EQU CLKPS1 00000001
EQU CLKPS2 00000002
EQU CLKPS3 00000003
EQU CLKPCE 00000007
EQU DWDR0 00000000
EQU DWDR1 00000001
EQU DWDR2 00000002
EQU DWDR3 00000003
EQU DWDR4 00000004
EQU DWDR5 00000005
EQU DWDR6 00000006
EQU DWDR7 00000007
EQU SPMEN 00000000
EQU PGERS 00000001
EQU PGWRT 00000002
EQU RFLB 00000003
EQU CTPB 00000004
EQU PORTB0 00000000
EQU PB0 00000000
EQU PORTB1 00000001
EQU PB1 00000001
EQU PORTB2 00000002
EQU PB2 00000002
EQU PORTB3 00000003
EQU PB3 00000003
EQU PORTB4 00000004
EQU PB4 00000004
EQU PORTB5 00000005
EQU PB5 00000005
EQU DDB0 00000000
EQU DDB1 00000001
EQU DDB2 00000002
EQU DDB3 00000003
EQU DDB4 00000004
EQU DDB5 00000005
EQU PINB0 00000000
EQU PINB1 00000001
EQU PINB2 00000002
EQU PINB3 00000003
EQU PINB4 00000004
EQU PINB5 00000005
EQU GICR 0000003b
EQU PCIE 00000005
EQU INT0 00000006
EQU PCIF 00000005
EQU INTF0 00000006
EQU PCINT0 00000000
EQU PCINT1 00000001
EQU PCINT2 00000002
EQU PCINT3 00000003
EQU PCINT4 00000004
EQU PCINT5 00000005
EQU TOIE0 00000001
EQU OCIE0A 00000002
EQU OCIE0B 00000003
EQU TOV0 00000001
EQU OCF0A 00000002
EQU OCF0B 00000003
EQU OCR0_0 00000000
EQU OCR0_1 00000001
EQU OCR0_2 00000002
EQU OCR0_3 00000003
EQU OCR0_4 00000004
EQU OCR0_5 00000005
EQU OCR0_6 00000006
EQU OCR0_7 00000007
EQU WGM00 00000000
EQU WGM01 00000001
EQU COM0B0 00000004
EQU COM0B1 00000005
EQU COM0A0 00000006
EQU COM0A1 00000007
EQU TCNT0_0 00000000
EQU TCNT0_1 00000001
EQU TCNT0_2 00000002
EQU TCNT0_3 00000003
EQU TCNT0_4 00000004
EQU TCNT0_5 00000005
EQU TCNT0_6 00000006
EQU TCNT0_7 00000007
EQU CS00 00000000
EQU CS01 00000001
EQU CS02 00000002
EQU WGM02 00000003
EQU FOC0B 00000006
EQU FOC0A 00000007
EQU PSR10 00000000
EQU TSM 00000007
EQU WDP0 00000000
EQU WDP1 00000001
EQU WDP2 00000002
EQU WDE 00000003
EQU WDCE 00000004
EQU WDP3 00000005
EQU WDTIE 00000006
EQU WDTIF 00000007
EQU LB1 00000000
EQU LB2 00000001
EQU CKSEL0 00000000
EQU CKSEL1 00000001
EQU SUT0 00000002
EQU SUT1 00000003
EQU CKDIV8 00000004
EQU WDTON 00000005
EQU EESAVE 00000006
EQU SPIEN 00000007
EQU RSTDISBL 00000000
EQU BODLEVEL0 00000001
EQU BODLEVEL1 00000002
EQU DWEN 00000003
EQU SELFPRGEN 00000004
DEF XH r27
DEF XL r26
DEF YH r29
DEF YL r28
DEF ZH r31
DEF ZL r30
EQU FLASHEND 000001ff
EQU IOEND 0000003f
EQU SRAM_START 00000060
EQU SRAM_SIZE 00000040
EQU RAMEND 0000009f
EQU XRAMEND 00000000
EQU E2END 0000003f
EQU EEPROMEND 0000003f
EQU EEADRBITS 00000006
EQU PAGESIZE 00000010
EQU INT0addr 00000001
EQU PCI0addr 00000002
EQU OVF0addr 00000003
EQU ERDYaddr 00000004
EQU ACIaddr 00000005
EQU OC0Aaddr 00000006
EQU OC0Baddr 00000007
EQU WDTaddr 00000008
EQU ADCCaddr 00000009
EQU INT_VECTORS_SIZE 0000000a
DEF POM r16
CSEG RESET 00000010
CSEG LOOP 00000014
CSEG CEKANI 0000001b
CSEG L1 0000001f
CSEG L2 00000021
CSEG L3 00000023

@ -0,0 +1,100 @@
.device attiny13
.def cnt=r17
.def P0=r20
.def chc=r18
.def faze=r19
;### NASTAVENI ###
.equ CChDelay=8 ;DELAY pro zmenu barev - cim min tim rychlejsi je zmena
.equ TIMEROV=2 ;porovnavaci hodnota pro timer - konstanta
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow
rjmp CASOVAC
.org 0x0007
rjmp casovac
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b00011111 ;výstupní = 1
out DDRB,r16
ldi r16,0 ;vypnout PullUp
out PORTB,r16
ldi r16,0b00000001 ;TC0 prescaler na 1 - velice plynule, bez blikani
out TCCR0B,r16 ;4800000Hz
ldi r16,0b00000010 ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,TIMEROV ;overflow 32 clks - upravuje rychlost prepinani (konstanta)
out OCR0A,r16 ;
in r16, TIMSK0 ;interrupt enable
ori r16, 0b00000100
out timsk0,r16
ldi P0,0 ;0
clr cnt
clr chc
clr faze ;faze: 0 = nahoru 1=dolu
sei ;zapnout globalne interrupt
LOOP:
rjmp LOOP ;skok na loop
CASOVAC:
inc cnt ;cnt=cnt+1
cpi cnt,128 ;cnt==128? ANO->pokracovat, NE->skok na NOV
brne nov
clr cnt ;CNT je 128 -> vymazat CNT
;vynulovat LED kanaly:
cbi portb,0 ; (0)
cbi portb,1 ; (1)
cbi portb,2 ; (2)
cbi portb,3 ; (3)
cbi portb,4 ; (4)
inc chc ;Zvysime citac pro zmenu barvy CHC o 1
cpi chc,CChDelay ;CHC==delay? ANO->pokracovat, NE->skok na NOV
brne nov
clr chc ;MENI SE BARVY
cpi faze,0
brne FazeNot0
;FAZE je 0
inc P0
cpi P0,85
brne nov
inc faze
FazeNot0:
;FAZE je 1
dec P0
cpi P0,0
brne nov
clr faze
;sprava PWM kanalu - podminene zapnuti LED
nov: ;NOV label
cp cnt,P0 ;P0==CNT? ANO->zapni P0, NE->skok na NOT0
brne endcounter
sbi portb,0
sbi portb,1
sbi portb,2
sbi portb,3
sbi portb,4
endcounter: ;ENDCOUNTER label - konec preruseni
reti ;navrat z obsluhy preruseni

@ -0,0 +1,179 @@
;pracuje jako 5-ti bitovy binarni citac
;vystupy 3 a 4 jsou prohozene kvuli desce
.device attiny13
.def cnt=r18
.def RED=r19
.def GREEN=r20
.def BLUE=r21
.def chc=r22
.def faze=r23
.org 0x0000 ;RESET
RJMP RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow
RJMP CASOVAC
.org 0x0007
rjmp casovac
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b00011111 ;výstupní = 1
out DDRB,r16
ldi r16,0 ;vypnout PullUp
out PORTB,r16
ldi r16,0b00000011 ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/32
ldi r16,0b00000010 ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,20 ;overflow 22
out OCR0A,r16 ;
in r16, TIMSK0 ;interrupt enable
ORI r16, 0b00000100
out timsk0,r16
ldi RED,0 ;R
ldi GREEN,16 ;G
ldi BLUE,32 ;B
clr cnt
clr chc
clr faze
sei ;zapnout globalne interrupt
LOOP:
rjmp LOOP ;skok na loop
CASOVAC:
inc cnt
cpi cnt,32
breq ov0
rjmp nov
ov0:
clr cnt
cbi portb,0
cbi portb,1
cbi portb,2
inc chc
cpi chc,30
breq ov1
rjmp nov
ov1:
inc faze
clr chc
cpi faze,12
brne fazenov
clr faze
fazenov:
cpi faze,0
breq f0
cpi faze,1
breq f1
cpi faze,2
breq f2
cpi faze,3
breq f3
cpi faze,4
breq f4
cpi faze,5
breq f5
cpi faze,6
breq f6
cpi faze,7
breq f7
cpi faze,8
breq f8
cpi faze,9
breq f9
cpi faze,10
breq f10
cpi faze,11
breq f11
f0:
ldi RED,0
ldi GREEN,32
ldi BLUE,32
rjmp nov
f1:
ldi RED,0
ldi GREEN,16
ldi BLUE,32
rjmp nov
f2:
ldi RED,8
ldi GREEN,8
ldi BLUE,32
rjmp nov
f3:
ldi RED,16
ldi GREEN,0
ldi BLUE,32
rjmp nov
f4:
ldi RED,32
ldi GREEN,0
ldi BLUE,32
rjmp nov
f5:
ldi RED,32
ldi GREEN,0
ldi BLUE,16
rjmp nov
f6:
ldi RED,32
ldi GREEN,8
ldi BLUE,8
rjmp nov
f7:
ldi RED,32
ldi GREEN,16
ldi BLUE,0
rjmp nov
f8:
ldi RED,32
ldi GREEN,32
ldi BLUE,0
rjmp nov
f9:
ldi RED,16
ldi GREEN,32
ldi BLUE,0
rjmp nov
f10:
ldi RED,8
ldi GREEN,32
ldi BLUE,8
rjmp nov
f11:
ldi RED,0
ldi GREEN,32
ldi BLUE,16
rjmp nov
nov:
cp cnt,RED
brne notr
sbi portb,0
notr: cp cnt,GREEN
brne notg
sbi portb,1
notg: cp cnt,BLUE
brne notb
sbi portb,2
notb:
reti

@ -0,0 +1,133 @@
;pracuje jako 5-ti bitovy binarni citac
;vystupy 3 a 4 jsou prohozene kvuli desce
.device attiny13
.def cnt=r18
.def RED=r19
.def GREEN=r20
.def BLUE=r21
.def chc=r22
.def faze=r23
.org 0x0000 ;RESET
RJMP RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow
RJMP CASOVAC
.org 0x0007
rjmp casovac
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b00011111 ;výstupní = 1
out DDRB,r16
ldi r16,0 ;vypnout PullUp
out PORTB,r16
ldi r16,0b00000011 ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/32
ldi r16,0b00000010 ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,20 ;overflow 22
out OCR0A,r16 ;
in r16, TIMSK0 ;interrupt enable
ORI r16, 0b00000100
out timsk0,r16
ldi RED,0 ;R
ldi GREEN,16 ;G
ldi BLUE,32 ;B
clr cnt
clr chc
clr faze
sei ;zapnout globalne interrupt
LOOP:
rjmp LOOP ;skok na loop
CASOVAC:
inc cnt
cpi cnt,32
brne nov
clr cnt
cbi portb,0
cbi portb,1
cbi portb,2
inc chc
cpi chc,255
brne nov
inc faze
cpi faze,6
brne fazenov
clr faze
fazenov:
cpi faze,0
breq f0
cpi faze,1
breq f1
cpi faze,2
breq f2
cpi faze,3
breq f3
cpi faze,4
breq f4
cpi faze,5
breq f5
f0:
ldi RED,0
ldi GREEN,32
ldi BLUE,32
rjmp nov
f1:
ldi RED,0
ldi GREEN,0
ldi BLUE,32
rjmp nov
f2:
ldi RED,32
ldi GREEN,0
ldi BLUE,32
rjmp nov
f3:
ldi RED,32
ldi GREEN,0
ldi BLUE,10
rjmp nov
f4:
ldi RED,32
ldi GREEN,32
ldi BLUE,0
rjmp nov
f5:
ldi RED,0
ldi GREEN,32
ldi BLUE,0
rjmp nov
nov:
cp cnt,RED
brne notr
sbi portb,0
notr: cp cnt,GREEN
brne notg
sbi portb,1
notg: cp cnt,BLUE
brne notb
sbi portb,2
notb:
reti

@ -0,0 +1,156 @@
;pracuje jako 5-ti bitovy binarni citac
;vystupy 3 a 4 jsou prohozene kvuli desce
.device attiny13
.def cnt=r18
.def RED=r19
.def GREEN=r20
.def BLUE=r21
.def chc=r22
.def faze=r23
.org 0x0000 ;RESET
RJMP RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow
RJMP CASOVAC
.org 0x0007
rjmp casovac
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b00011111 ;výstupní = 1
out DDRB,r16
ldi r16,0 ;vypnout PullUp
out PORTB,r16
ldi r16,0b00000011 ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/32
ldi r16,0b00000010 ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,20 ;overflow 22
out OCR0A,r16 ;
in r16, TIMSK0 ;interrupt enable
ORI r16, 0b00000100
out timsk0,r16
ldi RED,0 ;R
ldi GREEN,16 ;G
ldi BLUE,32 ;B
clr cnt
clr chc
clr faze
sei ;zapnout globalne interrupt
LOOP:
rjmp LOOP ;skok na loop
CASOVAC:
inc cnt
cpi cnt,32
breq ov
rjmp nov
ov:
clr cnt
cbi portb,0
cbi portb,1
cbi portb,2
inc chc
cpi chc,150
brne nov
inc faze
cpi faze,9
brne fazenov
clr faze
fazenov:
cpi faze,0
breq f0
cpi faze,1
breq f1
cpi faze,2
breq f2
cpi faze,3
breq f3
cpi faze,4
breq f4
cpi faze,5
breq f5
cpi faze,6
breq f6
cpi faze,7
breq f7
cpi faze,8
breq f8
f0:
ldi RED,0
ldi GREEN,32
ldi BLUE,32
rjmp nov
f1:
ldi RED,0
ldi GREEN,16
ldi BLUE,32
rjmp nov
f2:
ldi RED,16
ldi GREEN,0
ldi BLUE,32
rjmp nov
f3:
ldi RED,32
ldi GREEN,0
ldi BLUE,32
rjmp nov
f4:
ldi RED,32
ldi GREEN,0
ldi BLUE,16
rjmp nov
f5:
ldi RED,32
ldi GREEN,16
ldi BLUE,0
rjmp nov
f6:
ldi RED,32
ldi GREEN,32
ldi BLUE,0
rjmp nov
f7:
ldi RED,16
ldi GREEN,32
ldi BLUE,0
rjmp nov
f8:
ldi RED,0
ldi GREEN,32
ldi BLUE,16
rjmp nov
nov:
cp cnt,RED
brne notr
sbi portb,0
notr: cp cnt,GREEN
brne notg
sbi portb,1
notg: cp cnt,BLUE
brne notb
sbi portb,2
notb:
reti

@ -0,0 +1,493 @@
;Imitace sacovane bomby, Ondrej Hruska (c) 2010
;-------------------------------------------------
; Zapojeni:
; +------u------+
; reset --+ /RST Vcc +-- napajeni +5V
; Anoda jednotek --+ PD0 PB7 +-- segment D
; Anoda desitek --+ PD1 PB6 +-- sedment E
; (nezapojeno) --+ XT2 PB5 +-- segment C
; (nezapojeno) --+ XT1 PB4 +-- segment H
; Spatny drat 1 --+ PD2 PB3 +-- segment G
; Spatny drat 2 --+ PD3 PB2 +-- segment A
; Spatny drat 3 --+ PD4 PB1 +-- segment F
; Spatny drat 4 --+ PD5 PB0 +-- segment B
; GND --+ GND PD6 +-- Spravny drat
; +-------------+
;
; Nazvy segmentu na displeji:
; ---A---
; | |
; F B
; | |
; ---G---
; | |
; E C
; | |
; ---D--- H
;
.device attiny2313
;běží na 8MHz, ckdiv8=1 (vypnuto)
;LFUSE: 0xE4
;HFUSE: 0xDF
; A L I A S Y
.def numL = r20
.def numH = r21
.def dispL = r22
.def dispH = r23
.def wOld = r24
.def InitLoopN = r25
.equ CUvodniIntervaly = 60 ;pocet intervalu cekani
.equ CInitLoopMax = 180 ;delka 1 intervalu cekani (s)
.equ CUnitSecs = 60 ;delka 1 jednotky (s) - zacina se s 99 jednotkami
; M A K R A
.MACRO TimIntEnable
ldi r16,(1<<OCIE1A)
out TIMSK,r16 ;povolit interrupt pri Compare Match A
.ENDMACRO
.MACRO TimIntDisable
ldi r16,0
out TIMSK,r16 ;zakazat interrupt pri Compare Match A
.ENDMACRO
; Z A C A T E K P R O G R A M U
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0004 ;TC1 Compare match A
rjmp TIMER
.org 0x0010
; NASTAVENI PO RESETU
.DB "IMITACE CASOVANE BOMBY. Ondrej Hruska 2010"
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
ldi r16,0b11111111 ;smer portu B - vystupni: segmenty (=katody)
out DDRB,r16
ldi r16,0b11111111 ;vse v PORTB na 1, segmenty zhasnuty
out PORTB,r16
ldi r16,0b00000011 ;smer portu D - PD0 a PD1 jsou vystupni - spinaji anody displeje. Zbytek: dratky. PD2 je spravny drat
out DDRD,r16
ldi r16,0b01111100 ;enable pullup, 0 na anody = zhasnout. dratky pripojeny na GND, s pullupy
out PORTD,r16
; 16bitovy citac - generator f=1Hz
ldi r16,0 ;port se neovlivnuje citacem
out TCCR1A,r16
ldi r16,(1<<WGM12)|(1<<CS12) ;TC1 prescaler na 256 (8000000/256=31250), CTC mod
out TCCR1B,r16
ldi r16,0b01111010 ;Compare Match 1 A high
ldi r17,0b00010010 ;Compare Match 1 A low (celkem 31250, overflow f=1Hz)
out OCR1AH,r16 ;set high
out OCR1AL,r17 ;set low
TimIntDisable ;vypni casovac (makro)
sei ;Global Interrupt Enable
; Navesti, ze se povedl start
; DEChGAFB
ldi dispH,0b00011000
ldi dispL,0b10010111
ldi r16,100
nav:
ldi r17,255
nav2:
rcall multiplex
dec r17
brne nav2
dec r16
brne nav
ldi r16,0b00000000 ;disable pullupy a 0 na anody. Musime setrit energii!
out PORTD,r16
clr r16
clr r17
; INIT LOOP
ldi InitLoopN, CUvodniIntervaly ;cekej n intervalu
ldi r19,CInitLoopMax ;delka prvniho intervalu jako obecny interval
;soucasny interval: r19, defaultni interval: CInitLoopMax
TimIntEnable ;zapni casovac (makro)
InitLoop:
;kontroluje se InitLoopN. snizovani zajistuje casovac.
cpi InitLoopN,0 ;zbyva 0 intervalu?
brne InitLoop ;pokud ne, testuj znova
; P R I P R A V Y N A H L A V N I P R O G R A M
cli ;vypni preruseni - skoncila uvodni smycka, zacina odpocitavani
;vycisteni registru
clr r16 ;vynuluj registry
clr r17
clr r18
clr r19
;pullupy PORTD
ldi r16,0b01111100 ;enable pullup
out PORTD,r16
;cas 99
ldi numL,9
ldi numH,9
mov r17,numL ;zpracovat numL
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
mov dispL,r16 ;presunout vysledek do vystupu displeje
mov r17,numH ;zpracovat numH
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
mov dispH,r16 ;presunout vysledek do vystupu displeje
;vychozi rozlozeni dratu
in wOld,PIND ;nastaveni stareho rozlozeni dratu
andi wOld,0b01111000 ;ignorovat anody a spravny drat
;nastaveni vychoziho rozlozeni dratu k prestrihnuti
mov r16, wOld ;uloz wOld -> r16
;v r16 jsou pouze rozpojene draty: 0b00010000
in r17, PORTD ;do r17 stav portu D
mov r18,r16
com r18
and r17,r18 ;v r17 vynuluj bity patrici k rozpojenym dratum (ochrana X zkratu)
out PORTD,r17 ;dej na vystup
in r17, DDRD ;do r17 DDRD
or r17, r16 ;k vystupnim pinum pridej prave rozpojeny drat
out DDRD,r17
ldi r19,CUnitSecs ;nastav citac intervalu pro hlavni odpocet
ldi r16,0b11111111 ;255 na PORTB, vse zhasnuto
out PORTB, r16
sei ;zacina hlavni program s casovacem, bude se pouzivat preruseni
loop:
rcall WireTest ;test dratku
sbic PIND,2 ;pokud je spravny drat PD2 = 0, preskoc
rjmp CHCIP ;skoc na CHCIP
;spravny drat je neprerusen
rcall multiplex
rjmp loop ;hlavni smycka se opakuje
multiplex:
push r16
push r17
;DISPLEJ JEDNOTEK
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
cbi PORTD,0
sbi PORTD,1 ;PORTD = 01 - zapnout anodu pro jednotky
out PORTB,dispL ;PORTB = dispL (displej jednotek)
ldi r17,100 ;pocet smycek
dL: ;smycka
nop
nop
nop
dec r17
brne dL
;DISPLEJ DESITEK
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
cbi PORTD,1
sbi PORTD,0 ;PORTD 10 - zapnout anodu pro desitky
out PORTB,dispH ;PORTB = dispH (displej desitek)
ldi r17,100 ;pocet smycek
dH:
nop
nop
nop
dec r17
brne dH
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
cbi PORTD,0
cbi PORTD,1
pop r17
pop r16
ret
; r17 konvertuj do 7segmentovyho kodu pro displej se spol. anodou DECGAFB ---> r16
dec7seg: ;dec7seg(r17) -> r16
clr r16 ;do r16 budeme ukladat vystup, v r17 je vstupni cislo 0-9
cpi r17,9 ;je r17 = 9?
brne dec7segN8 ;neni -> pokracuj s 8
; DEChGAFB
ldi r16, 0b01000000 ;katody DCGAFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN8:
cpi r17,8 ;je r17 = 8?
brne dec7segN7 ;neni -> pokracuj s 7
; DEChGAFB
ldi r16, 0b00000000 ;katody DECGAFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN7:
cpi r17,7 ;je r17 = 7?
brne dec7segN6 ;neni -> pokracuj s 6
; DEChGAFB
ldi r16, 0b11001010 ;katody CAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN6:
cpi r17,6 ;je r17 = 6?
brne dec7segN5 ;neni -> pokracuj s 5
; DEChGAFB
ldi r16, 0b00000001 ;katody DECGAF na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN5:
cpi r17,5 ;je r17 = 5?
brne dec7segN4 ;neni -> pokracuj s 4
; DEChGAFB
ldi r16, 0b01000001 ;katody DCGAF na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN4:
cpi r17,4 ;je r17 = 4?
brne dec7segN3 ;neni -> pokracuj s 3
; DEChGAFB
ldi r16, 0b11000100 ;katody CGFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN3:
cpi r17,3 ;je r17 = 3?
brne dec7segN2 ;neni -> pokracuj s 2
; DEChGAFB
ldi r16, 0b01000010 ;katody DCGAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN2:
cpi r17,2 ;je r17 = 2?
brne dec7segN1 ;neni -> pokracuj s 1
; DEChGAFB
ldi r16, 0b00100010 ;katody DEGAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN1:
cpi r17,1 ;je r17 = 1?
brne dec7segN0 ;neni -> pokracuj s 0
; DEChGAFB
ldi r16, 0b11001110 ;katody CB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN0:
; DEChGAFB
ldi r16, 0b00001000 ;katody DECAFB na 0; H = 0, ale bude prepsano pri vystupu
dec7segReturn:
ret
; TEST DRATU (nutno volat rucne)
WireTest:
push r16
push r17
push r18
in r16,PIND
andi r16, 0b01111000 ;odfiltrovat anody a spravny drat
;test dratku
cp wOld,r16 ;porovnej r16 a wOld
brsh WireTestReturn ;wOld >= r16: nebyl prestrizen dratek, nebo byl nejaky spojen
;dratek byl prestrizen
;ODECTENI 3 desitek
cpi numH,3 ;jsou aspon 3 desitky?
brlo WireTestMaloCasu ;nejsou-li ani 3 desitky, vynuluj vse a vybuchni
subi numH,3 ;jinak odecti 3 desitky
;nedoslo k vynulovani?
brne WireTestReturn ;desitky > 0: odejdi bez vybuchu
cpi numL,0 ;desitky = 0. kolik je jednotek?
breq WireTestBum ;je-li 0 jednotek, vybuchni
;0 desitek, n > 0 jednotek
rjmp WireTestReturn ;0 desitek ale n > 0 jednotek, odejdi bez vybuchu
WireTestMaloCasu:
clr numL ;vymazat jednotky
clr numH ;vymazat desitky
WireTestBum:
rcall BUM ;vybuchnout
WireTestReturn:
mov wOld, r16 ;uloz soucasny stav dratu do wOld
;v r16 jsou pouze rozpojene draty: 0b00010000
in r17, PORTD ;do r17 stav portu D
mov r18,r16
com r18
and r17,r18 ;v r17 vynuluj bity patrici k rozpojenym dratum (ochrana X zkratu)
out PORTD,r17 ;dej na vystup
in r17, DDRD ;do r17 DDRD
or r17, r16 ;k vystupnim pinum prodej prave rozpojeny drat
out DDRD,r17
;obnovit displej
mov r17,numL ;zpracovat numL
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbrc dispL,4 ;neni-li H nastaven na displeji, preskoc
sbr r16,0b00010000 ;nastaveni H v novem stavu displeje
mov dispL,r16 ;presunout vysledek do vystupu displeje
mov r17,numH ;zpracovat numL
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbrc dispH,4 ;neni-li H nastaven na displeji, preskoc
sbr r16,0b00010000 ;nastaveni H v novem stavu displeje
mov dispH,r16 ;presunout vysledek do vystupu displeje
pop r18
pop r17
pop r16
ret ;navrat
; B U M
BUM:
;vybuch - blikajici nuly
cli ;vypni preruseni
ldi r17,0 ;0 jednotek
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbr r16,0b00010000 ;1 na katodu H - zhasnout tecku
mov dispL,r16 ;presunout vysledek do vystupu displeje
ldi r17,0 ;0 desitek
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbr r16,0b00010000 ;1 na katodu H - zhasnout tecku
mov dispH,r16 ;presunout vysledek do vystupu displeje
BUMsmycka: ;nekonecna smycka, blikaji nuly
ldi r16, 255
BUMsmyckaMX:
rcall multiplex
dec r16
brne BUMsmyckaMX
ldi r16, 255
BUMsmyckaPAUZA:
ldi r17, 255
BUMsmyckaPAUZAb:
dec r17
brne BUMsmyckaPAUZAb
dec r16
brne BUMsmyckaPAUZA
rjmp BUMsmycka
; C H C I P
CHCIP:
;nekdo prestrihl spravny drat
cli
;ldi dispL,0b00000000
;ldi dispH,0b00000000
ldi r16,180 ; citac delky cekani
CHCIPsmycka:
mov r17,r16
com r17
CHCIPsmyckaMX:
rcall multiplex
dec r17
brne CHCIPsmyckaMX
mov r17,r16 ; nastaveni smycky cekani
inc r16
cpi r16,255
brsh CHCIPsleep ;uz je to moc dlouhy, usnout
CHCIPsmyckaPAUZA: ;r17*200
mov r18,r16
CHCIPsmyckaPAUZAb:
dec r18
brne CHCIPsmyckaPAUZAb
dec r17
brne CHCIPsmyckaPAUZA
rjmp CHCIPsmycka
CHCIPsleep:
cli
ldi r16,(1<<SE)|(1<<SM0)
out MCUCR,r16
sleep
; PRERUSENI OD CASOVACE f=1Hz
TIMER: ; casovac ma frekvenci 1Hz
push r16
push r17
push r18
; r19 je citac intervalu
cpi InitLoopN,0 ;je InitLoopN = 0?
breq TIMERnormal ;Je-li InitLoopN = 0, pokracuj normalnim prerusenim
; probiha uvodni cekani
; test intervaloveho citace (pokud je InitLoopN > 0, pouziva k tomu se r19)
cpi r19,0 ;je r19 = 0?
breq TIMERsnizitILN ;je-li r19 = 0, snizit InitLoopN: jdi na TIMERsnizitILN
dec r19 ;jinak o 1 sniz r19 (intervalovy citac)
;out PORTB,r19 ;DEBUG test r19
rjmp TIMERreturn ;a odejdi
TIMERsnizitILN:
dec InitLoopN ;snizit InitLoopN
ldi r19,CInitLoopMax ;nastaveni delky dalsiho intervalu
rjmp TIMERreturn ;odejdi
TIMERnormal:
;invertuj tecku (Low)
ldi r16,0b00010000
eor dispL,r16
cbr dispH,0b00010000
sbrc dispL,4 ;do H zkopiruj tecku z L (tim se zajisti, ze budou vzdy stejne)
sbr dispH,0b00010000
; r19 slouzi jako citac sekund
dec r19 ;sniz citac intervalu o 1
brne TIMERreturn ;neni-li 0, odejdi
ldi r19,CUnitSecs ;nastaveni dalsiho intervalu
; ODECTENI JEDNOTKY
cpi numL,0 ;je jednotek vic nez 0?
brne TIMERnOdectiJednotku ;jednotky > 0, jdi na odecteni jednotky
;0 jednotek
cpi numH, 0 ;0 jednotek. je desitek vic nez 0?
brne TIMERnOdectiPresDesitku ;je-li desitek vic nez 0, jdi na odecteni desitky
;0 jednotek i desitek
rcall BUM
TIMERnOdectiPresDesitku:
;0 jednotek, n > 0 desitek
dec numH ;odecti desitku
ldi numL,9 ;dej jednotky=9
rjmp TIMERnOdecteniHotovo ;preskoc na TIMERnOdecteniHotovo
TIMERnOdectiJednotku:
dec numL ;odecti jednotku
TIMERnOdecteniHotovo:
cpi numH,0 ;test desitek
brne TIMERnHotovoNevybuch ; neni nula -> ok
cpi numL,0 ;test jednotek
brne TIMERnHotovoNevybuch ; neni nula -> ok
;je nula
rcall BUM ;je nula: vybuchni
TIMERnHotovoNevybuch:
;uprav displej
mov r17,numL ;zpracovat numL
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbrc dispL,4 ;neni-li H nastaven na displeji, preskoc
sbr r16,0b00010000 ;nastaveni H v novem stavu displeje
mov dispL,r16 ;presunout vysledek do vystupu displeje
mov r17,numH ;zpracovat numH
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbrc dispH,4 ;neni-li H nastaven na displeji, preskoc
sbr r16,0b00010000 ;nastaveni H v novem stavu displeje
mov dispH,r16 ;presunout vysledek do vystupu displeje
;je obnoven stav displeje, konec preruseni
TIMERreturn:
pop r18 ;navratit puvodni hodnoty registru
pop r17
pop r16
reti

@ -0,0 +1,233 @@
.device attiny2313
;běží na 8MHz, ckdiv8=1 (vypnuto)
; A L I A S Y
.def numL = r19
.def numH = r20
.def dispL = r21
.def dispH = r22
.def wNow = r23
.def wOld = r24
.def InitLoopN = r25
; M A K R A
.MACRO TimIntEnable
ldi r16,(1<<OCIE1A)
out TIMSK,r16 ;povolit interrupt pri Compare Match A
.ENDMACRO
.MACRO TimIntDisable
ldi r16,0
out TIMSK,r16 ;zakazat interrupt pri Compare Match A
.ENDMACRO
; Z A C A T E K P R O G R A M U
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0004 ;TC1 Compare match A
rjmp TIMER
.org 0x0010
; NASTAVENI PO RESETU
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
ldi r16,255 ;smer portu B - vystupni: segmenty (=katody)
out DDRB,r16
ser r16 ;r16=255 - vse na 1, segmenty zhasnuty
out PORTB,r16
ldi r16,0b00000011 ;smer portu D - PB0 a PB1 jsou vystupni - spinaji anody displeje. Zbytek: dratky.
out DDRD,r16
ldi r16,0b11111100 ;enable pullup, 0 na anody = zhasnout
;dratky pripojeny na GND, s pullupy
out PORTD,r16
; 16bitovy citac - generator f=1Hz
ldi r16,0 ;port se neovlivnuje citacem
out TCCR1A,r16
ldi r16,(1<<WGM12)|(1<<CS12) ;TC1 prescaler na 256 (8000000/256=31250), CTC mod
out TCCR1B,r16
ldi r16,0b01111010 ;Compare Match 1 A high
ldi r17,0b00010010 ;Compare Match 1 A low (celkem 31250, overflow f=1Hz)
out OCR1AH,r16 ;set high
out OCR1AL,r17 ;set low
TimIntDisable ;vypni casovac (makro)
; Nastaveni promennych
;cas 99
ldi numL,9
ldi numH,9
;vychozi rozlozeni dratu
in r16,PORTD
andi r16, 0b11111100 ;ignorovat anody
mov wOld, r16 ;nastaveni stareho rozlozeni dratu
mov wNow, r16 ;nastaveni soucasneho rozlozeni dratu
sei ;Global Interrupt Enable
; INIT LOOP
ldi InitLoopN, 0 ;cekej n intervalu
ldi r18,60 ;delka intervalu v sekundach
mov r17,r18 ;delka prvniho intervalu jako obecny interval
;soucasny interval: r17, defaultni interval: r18.
TimIntEnable ;zapni casovac (makro)
InitLoop:
;kontroluje se InitLoopN. snizovani zajistuje casovac.
cpi InitLoopN,0
brne InitLoop
; HLAVNI PROGRAM
TimIntDisable ;vypni casovac (makro) - skoncila uvodni smycka, zacina odpocitavani
;nastaveni
clr r16 ;vynuluj registry ovlivnene uvodnim cekanim
clr r17
clr r18
TimIntEnable ;zacina hlavni program s casovacem.
ser r16 ;255 na PORTB, vse zhasnuto
out PORTB, r16
loop:
rjmp loop
; r17 konvertuj do 7segmentovyho kodu pro displej se spol. anodou DECGAFB ---> r16
dec7seg:
clr r16 ;do r16 budeme ukladat vystup, v r17 je vstupni cislo 0-9
cpi r17,9 ;je r17 = 9?
brne dec7segN8 ;neni -> pokracuj s 8
; DEChGAFB
ldi r16, 0b01000000 ;katody DCGAFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN8:
cpi r17,8 ;je r17 = 8?
brne dec7segN7 ;neni -> pokracuj s 7
; DEChGAFB
ldi r16, 0b00000000 ;katody DECGAFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN7:
cpi r17,7 ;je r17 = 7?
brne dec7segN6 ;neni -> pokracuj s 6
; DEChGAFB
ldi r16, 0b11001010 ;katody CAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN6:
cpi r17,6 ;je r17 = 6?
brne dec7segN5 ;neni -> pokracuj s 5
; DEChGAFB
ldi r16, 0b00000001 ;katody DECGAF na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN5:
cpi r17,5 ;je r17 = 5?
brne dec7segN4 ;neni -> pokracuj s 4
; DEChGAFB
ldi r16, 0b01000001 ;katody DCGAF na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN4:
cpi r17,4 ;je r17 = 4?
brne dec7segN3 ;neni -> pokracuj s 3
; DEChGAFB
ldi r16, 0b11000100 ;katody CGFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN3:
cpi r17,3 ;je r17 = 3?
brne dec7segN2 ;neni -> pokracuj s 2
; DEChGAFB
ldi r16, 0b01000010 ;katody DCGAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN2:
cpi r17,2 ;je r17 = 2?
brne dec7segN1 ;neni -> pokracuj s 1
; DEChGAFB
ldi r16, 0b00100010 ;katody DEGAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN1:
cpi r17,1 ;je r17 = 1?
brne dec7segN0 ;neni -> pokracuj s 0
; DEChGAFB
ldi r16, 0b11001110 ;katody CB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN0:
; DEChGAFB
ldi r16, 0b00001000 ;katody DECAFB na 0; H = 0, ale bude prepsano pri vystupu
dec7segReturn:
ret
; TEST DRATU (nutno volat rucne)
WireTest:
in r16,PORTD
andi r16, 0b11111100 ;odfiltrovat anody
mov wNow, r16 ;nastaveni soucasneho rozlozeni dratu
;test dratku
cp wOld,wNow ;porovnej wOld a wNow
brge WireTestReturn ;wOld >= wNow: nebyl prestrizen dratek, nebo byl nejaky spojen
;dratek byl prestrizen
mov wOld, wNow ;nastaveni
;ODECTENI CASU
cpi numH,3 ;jsou aspon 3 desitky?
brlo WireTestLowTens ;nejsou-li ani 3 desitky, vynuluj vse a vybuchni
subi numH,3 ;jinak odecti 3 desitky
;nedoslo k vynulovani?
brne WireTestReturn ;desitky > 0: odejdi bez vybuchu
cpi numL,0 ;desitky = 0, kolik je jednotek?
breq WireTestBum ;je-li 0 jednotek, vybuchni
;0 desitek, n > 0 jednotek
rjmp WireTestReturn ;0 desitek ale n > 0 jednotek, odejdi bez vybuchu
WireTestLowTens:
clr numL ;vymazat jednotky
clr numH ;vymazat desitky
WireTestBum:
rcall BUM
WireTestReturn:
ret
; B U M
BUM:
;nekonecna smycka, blikaji nuly
TimIntDisable ;vypni casovac (makro)
smycka:
rjmp smycka
; PRERUSENI OD CASOVACE f=1Hz
rjmp loop ; aby se TIMER nevykonal mimo preruseni, kdyby procesor zabloudil
TIMER: ; casovac ma frekvenci 1Hz
cpi InitLoopN,0 ;je InitLoopN = 0?
breq TIMERnormal ;Je-li InitLoopN = 0, pokracuj normalnim prerusenim
; probiha uvodni cekani
; test intervaloveho citace
cpi r17,0 ;je r17 = 0?
breq TIMERsnizitILN ;je-li r17 = 0, snizit InitLoopN: jdi na TIMERsnizitILN
dec r17 ;jinak o 1 sniz r17 (intervalovy citac)
;out PORTB,r17 ;DEBUG test r17
rjmp TIMERreturn ;a odejdi
TIMERsnizitILN:
dec InitLoopN ;snizit InitLoopN
mov r17,r18 ;nastaveni delky dalsiho intervalu
rjmp TIMERreturn ;odejdi
TIMERnormal:
; STANDARTNI PRERUSENI (1s)
sbi PINB,4 ;toogle PB4 (tecka na displeji)
TIMERreturn:
reti

@ -0,0 +1,439 @@
.device attiny2313
;běží na 8MHz, ckdiv8=1 (vypnuto)
; A L I A S Y
.def numL = r20
.def numH = r21
.def dispL = r22
.def dispH = r23
.def wOld = r24
.def InitLoopN = r25
.equ CUvodniIntervaly = 1 ;pocet intervalu cekani
.equ CInitLoopMax = 10 ;delka 1 intervalu cekani (s)
.equ CUnitSecs = 1 ;delka 1 jednotky (s) - zacina se s 99 jednotkami
; M A K R A
.MACRO TimIntEnable
ldi r16,(1<<OCIE1A)
out TIMSK,r16 ;povolit interrupt pri Compare Match A
.ENDMACRO
.MACRO TimIntDisable
ldi r16,0
out TIMSK,r16 ;zakazat interrupt pri Compare Match A
.ENDMACRO
; Z A C A T E K P R O G R A M U
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0004 ;TC1 Compare match A
rjmp TIMER
.org 0x0010
; NASTAVENI PO RESETU
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
ldi r16,0b11111111 ;smer portu B - vystupni: segmenty (=katody)
out DDRB,r16
ldi r16,0b11111111 ;vse v PORTB na 1, segmenty zhasnuty
out PORTB,r16
ldi r16,0b00000011 ;smer portu D - PD0 a PD1 jsou vystupni - spinaji anody displeje. Zbytek: dratky. PD2 je spravny drat
out DDRD,r16
ldi r16,0b11111100 ;enable pullup, 0 na anody = zhasnout. dratky pripojeny na GND, s pullupy
out PORTD,r16
; 16bitovy citac - generator f=1Hz
ldi r16,0 ;port se neovlivnuje citacem
out TCCR1A,r16
ldi r16,(1<<WGM12)|(1<<CS12) ;TC1 prescaler na 256 (8000000/256=31250), CTC mod
out TCCR1B,r16
ldi r16,0b01111010 ;Compare Match 1 A high
ldi r17,0b00010010 ;Compare Match 1 A low (celkem 31250, overflow f=1Hz)
out OCR1AH,r16 ;set high
out OCR1AL,r17 ;set low
TimIntDisable ;vypni casovac (makro)
sei ;Global Interrupt Enable
; Navesti, ze se povedl start
; DEChGAFB
ldi dispH,0b00011000
ldi dispL,0b10010111
ldi r16,100
nav:
ldi r17,255
nav2:
rcall multiplex
dec r17
brne nav2
dec r16
brne nav
clr r16
clr r17
cbi PORTD,0
cbi PORTD,1
; INIT LOOP
ldi InitLoopN, CUvodniIntervaly ;cekej n intervalu
ldi r19,CInitLoopMax ;delka prvniho intervalu jako obecny interval
;soucasny interval: r19, defaultni interval: CInitLoopMax
TimIntEnable ;zapni casovac (makro)
InitLoop:
;kontroluje se InitLoopN. snizovani zajistuje casovac.
cpi InitLoopN,0 ;zbyva 0 intervalu?
brne InitLoop ;pokud ne, testuj znova
; P R I P R A V Y N A H L A V N I P R O G R A M
cli ;vypni preruseni - skoncila uvodni smycka, zacina odpocitavani
;vycisteni registru
clr r16 ;vynuluj registry
clr r17
clr r18
clr r19
;cas 99
ldi numL,9
ldi numH,9
;vychozi rozlozeni dratu
in wOld,PIND ;nastaveni stareho rozlozeni dratu
andi wOld,0b01111000 ;ignorovat anody a spravny drat
mov r16, wOld ;uloz wOld -> r16
;v r16 jsou pouze rozpojene draty: 0b00010000
in r17, PORTD ;do r17 stav portu D
mov r18,r16
com r18
and r17,r18 ;v r17 vynuluj bity patrici k rozpojenym dratum (ochrana X zkratu)
out PORTD,r17 ;dej na vystup
in r17, DDRD ;do r17 DDRD
or r17, r16 ;k vystupnim pinum pridej prave rozpojeny drat
out DDRD,r17
mov r17,numL ;zpracovat numL
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
mov dispL,r16 ;presunout vysledek do vystupu displeje
mov r17,numH ;zpracovat numH
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
mov dispH,r16 ;presunout vysledek do vystupu displeje
;dispL a dispH maji nastaveny obsah
ldi r19,CUnitSecs ;nastav citac intervalu pro hlavni odpocet
ldi r16,0b11111111 ;255 na PORTB, vse zhasnuto
out PORTB, r16
sei ;zacina hlavni program s casovacem, bude se pouzivat preruseni
loop:
rcall WireTest ;test dratku
sbic PIND,2 ;pokud je spravny drat PD2 = 0, preskoc
rjmp CHCIP ;skoc na CHCIP
;spravny drat je neprerusen
rcall multiplex
rjmp loop ;hlavni smycka se opakuje
multiplex:
push r16
push r17
;DISPLEJ JEDNOTEK
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
cbi PORTD,1
sbi PORTD,0 ;PORTD = 01 - zapnout anodu pro jednotky
out PORTB,dispL ;PORTB = dispL (displej jednotek)
ldi r17,100 ;pocet smycek
dL: ;smycka
nop
nop
nop
dec r17
brne dL
;DISPLEJ DESITEK
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
cbi PORTD,0
sbi PORTD,1 ;PORTD 10 - zapnout anodu pro desitky
out PORTB,dispH ;PORTB = dispH (displej desitek)
ldi r17,100 ;pocet smycek
dH:
nop
nop
nop
dec r17
brne dH
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
pop r17
pop r16
ret
; r17 konvertuj do 7segmentovyho kodu pro displej se spol. anodou DECGAFB ---> r16
dec7seg: ;dec7seg(r17) -> r16
clr r16 ;do r16 budeme ukladat vystup, v r17 je vstupni cislo 0-9
cpi r17,9 ;je r17 = 9?
brne dec7segN8 ;neni -> pokracuj s 8
; DEChGAFB
ldi r16, 0b01000000 ;katody DCGAFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN8:
cpi r17,8 ;je r17 = 8?
brne dec7segN7 ;neni -> pokracuj s 7
; DEChGAFB
ldi r16, 0b00000000 ;katody DECGAFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN7:
cpi r17,7 ;je r17 = 7?
brne dec7segN6 ;neni -> pokracuj s 6
; DEChGAFB
ldi r16, 0b11001010 ;katody CAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN6:
cpi r17,6 ;je r17 = 6?
brne dec7segN5 ;neni -> pokracuj s 5
; DEChGAFB
ldi r16, 0b00000001 ;katody DECGAF na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN5:
cpi r17,5 ;je r17 = 5?
brne dec7segN4 ;neni -> pokracuj s 4
; DEChGAFB
ldi r16, 0b01000001 ;katody DCGAF na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN4:
cpi r17,4 ;je r17 = 4?
brne dec7segN3 ;neni -> pokracuj s 3
; DEChGAFB
ldi r16, 0b11000100 ;katody CGFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN3:
cpi r17,3 ;je r17 = 3?
brne dec7segN2 ;neni -> pokracuj s 2
; DEChGAFB
ldi r16, 0b01000010 ;katody DCGAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN2:
cpi r17,2 ;je r17 = 2?
brne dec7segN1 ;neni -> pokracuj s 1
; DEChGAFB
ldi r16, 0b00100010 ;katody DEGAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN1:
cpi r17,1 ;je r17 = 1?
brne dec7segN0 ;neni -> pokracuj s 0
; DEChGAFB
ldi r16, 0b11001110 ;katody CB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN0:
; DEChGAFB
ldi r16, 0b00001000 ;katody DECAFB na 0; H = 0, ale bude prepsano pri vystupu
dec7segReturn:
ret
; TEST DRATU (nutno volat rucne)
WireTest:
push r16
push r17
push r18
in r16,PIND
andi r16, 0b01111000 ;odfiltrovat anody a spravny drat
;test dratku
cp wOld,r16 ;porovnej r16 a wOld
brsh WireTestReturn ;wOld >= r16: nebyl prestrizen dratek, nebo byl nejaky spojen
;dratek byl prestrizen
;ODECTENI 3 desitek
cpi numH,3 ;jsou aspon 3 desitky?
brlo WireTestMaloCasu ;nejsou-li ani 3 desitky, vynuluj vse a vybuchni
subi numH,3 ;jinak odecti 3 desitky
;nedoslo k vynulovani?
brne WireTestReturn ;desitky > 0: odejdi bez vybuchu
cpi numL,0 ;desitky = 0. kolik je jednotek?
breq WireTestBum ;je-li 0 jednotek, vybuchni
;0 desitek, n > 0 jednotek
rjmp WireTestReturn ;0 desitek ale n > 0 jednotek, odejdi bez vybuchu
WireTestMaloCasu:
clr numL ;vymazat jednotky
clr numH ;vymazat desitky
WireTestBum:
rcall BUM ;vybuchnout
WireTestReturn:
mov wOld, r16 ;uloz soucasny stav dratu do wOld
;v r16 jsou pouze rozpojene draty: 0b00010000
in r17, PORTD ;do r17 stav portu D
mov r18,r16
com r18
and r17,r18 ;v r17 vynuluj bity patrici k rozpojenym dratum (ochrana X zkratu)
out PORTD,r17 ;dej na vystup
in r17, DDRD ;do r17 DDRD
or r17, r16 ;k vystupnim pinum prodej prave rozpojeny drat
out DDRD,r17
pop r18
pop r17
pop r16
ret ;navrat
; B U M
BUM:
;vybuch - blikajici nuly
cli ;vypni preruseni
ldi r17,0 ;0 jednotek
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbr r16,0b00010000 ;1 na katodu H - zhasnout tecku
mov dispL,r16 ;presunout vysledek do vystupu displeje
ldi r17,0 ;0 desitek
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbr r16,0b00010000 ;1 na katodu H - zhasnout tecku
mov dispH,r16 ;presunout vysledek do vystupu displeje
BUMsmycka: ;nekonecna smycka, blikaji nuly
ldi r16, 255
BUMsmyckaMX:
rcall multiplex
dec r16
brne BUMsmyckaMX
ldi r16, 255
BUMsmyckaPAUZA:
ldi r17, 255
BUMsmyckaPAUZAb:
dec r17
brne BUMsmyckaPAUZAb
dec r16
brne BUMsmyckaPAUZA
rjmp BUMsmycka
; C H C I P
CHCIP:
;nekdo prestrihl spravny drat
cli
ldi dispL,0b00000000
ldi dispH,0b00000000
clr r16 ; citac delky cekani
CHCIPsmycka:
ldi r17, 120 ;smycka multiplexu
CHCIPsmyckaMX:
rcall multiplex
dec r17
brne CHCIPsmyckaMX
mov r17,r16 ; nastaveni smycky cekani
inc r16
cpi r16,255
brsh CHCIPsleep ;uz je to moc dlouhy, usnout
CHCIPsmyckaPAUZA: ;r17*200
ldi r18,255
CHCIPsmyckaPAUZAb:
dec r18
brne CHCIPsmyckaPAUZAb
dec r17
brne CHCIPsmyckaPAUZA
rjmp CHCIPsmycka
CHCIPsleep:
cli
ldi r16,(1<<SE)|(1<<SM0)
out MCUCR,r16
sleep
; PRERUSENI OD CASOVACE f=1Hz
TIMER: ; casovac ma frekvenci 1Hz
push r16
push r17
push r18
; r19 je citac intervalu
cpi InitLoopN,0 ;je InitLoopN = 0?
breq TIMERnormal ;Je-li InitLoopN = 0, pokracuj normalnim prerusenim
; probiha uvodni cekani
; test intervaloveho citace (pokud je InitLoopN > 0, pouziva k tomu se r19)
cpi r19,0 ;je r19 = 0?
breq TIMERsnizitILN ;je-li r19 = 0, snizit InitLoopN: jdi na TIMERsnizitILN
dec r19 ;jinak o 1 sniz r19 (intervalovy citac)
;out PORTB,r19 ;DEBUG test r19
rjmp TIMERreturn ;a odejdi
TIMERsnizitILN:
dec InitLoopN ;snizit InitLoopN
ldi r19,CInitLoopMax ;nastaveni delky dalsiho intervalu
rjmp TIMERreturn ;odejdi
TIMERnormal:
;invertuj tecky
ldi r16,0b00010000
eor dispL,r16
eor dispH,r16
; r19 slouzi jako citac sekund
dec r19 ;sniz citac intervalu o 1
brne TIMERreturn ;neni-li 0, odejdi
ldi r19,CUnitSecs ;nastaveni dalsiho intervalu
; ODECTENI JEDNOTKY
cpi numL,0 ;je jednotek vic nez 0?
brne TIMERnOdectiJednotku ;jednotky > 0, jdi na odecteni jednotky
;0 jednotek
cpi numH, 0 ;0 jednotek. je desitek vic nez 0?
brne TIMERnOdectiPresDesitku ;je-li desitek vic nez 0, jdi na odecteni desitky
;0 jednotek i desitek
rcall BUM
TIMERnOdectiPresDesitku:
;0 jednotek, n > 0 desitek
dec numH ;odecti desitku
ldi numL,9 ;dej jednotky=9
rjmp TIMERnOdecteniHotovo ;preskoc na TIMERnOdecteniHotovo
TIMERnOdectiJednotku:
dec numL ;odecti jednotku
TIMERnOdecteniHotovo:
cpi numH,0 ;test desitek
brne TIMERnHotovoNevybuch ; neni nula -> ok
cpi numL,0 ;test jednotek
brne TIMERnHotovoNevybuch ; neni nula -> ok
;je nula
rcall BUM ;je nula: vybuchni
TIMERnHotovoNevybuch:
;uprav displej
mov r17,numL ;zpracovat numL
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbrc dispL,4 ;neni-li H nastaven na displeji, preskoc
sbr r16,0b00010000 ;nastaveni H v novem stavu displeje
mov dispL,r16 ;presunout vysledek do vystupu displeje
mov r17,numH ;zpracovat numH
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbrc dispH,4 ;neni-li H nastaven na displeji, preskoc
sbr r16,0b00010000 ;nastaveni H v novem stavu displeje
mov dispH,r16 ;presunout vysledek do vystupu displeje
;je obnoven stav displeje, konec preruseni
TIMERreturn:
pop r18 ;navratit puvodni hodnoty registru
pop r17
pop r16
reti

@ -0,0 +1,462 @@
.device attiny2313
;běží na 8MHz, ckdiv8=1 (vypnuto)
; A L I A S Y
.def numL = r20
.def numH = r21
.def dispL = r22
.def dispH = r23
.def wOld = r24
.def InitLoopN = r25
.equ CUvodniIntervaly = 60 ;pocet intervalu cekani
.equ CInitLoopMax = 180 ;delka 1 intervalu cekani (s)
.equ CUnitSecs = 60 ;delka 1 jednotky (s) - zacina se s 99 jednotkami
; M A K R A
.MACRO TimIntEnable
ldi r16,(1<<OCIE1A)
out TIMSK,r16 ;povolit interrupt pri Compare Match A
.ENDMACRO
.MACRO TimIntDisable
ldi r16,0
out TIMSK,r16 ;zakazat interrupt pri Compare Match A
.ENDMACRO
; Z A C A T E K P R O G R A M U
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0004 ;TC1 Compare match A
rjmp TIMER
.org 0x0010
; NASTAVENI PO RESETU
.DB "Ondrej Hruska (C) 2010"
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
ldi r16,0b11111111 ;smer portu B - vystupni: segmenty (=katody)
out DDRB,r16
ldi r16,0b11111111 ;vse v PORTB na 1, segmenty zhasnuty
out PORTB,r16
ldi r16,0b00000011 ;smer portu D - PD0 a PD1 jsou vystupni - spinaji anody displeje. Zbytek: dratky. PD2 je spravny drat
out DDRD,r16
ldi r16,0b01111100 ;enable pullup, 0 na anody = zhasnout. dratky pripojeny na GND, s pullupy
out PORTD,r16
; 16bitovy citac - generator f=1Hz
ldi r16,0 ;port se neovlivnuje citacem
out TCCR1A,r16
ldi r16,(1<<WGM12)|(1<<CS12) ;TC1 prescaler na 256 (8000000/256=31250), CTC mod
out TCCR1B,r16
ldi r16,0b01111010 ;Compare Match 1 A high
ldi r17,0b00010010 ;Compare Match 1 A low (celkem 31250, overflow f=1Hz)
out OCR1AH,r16 ;set high
out OCR1AL,r17 ;set low
TimIntDisable ;vypni casovac (makro)
sei ;Global Interrupt Enable
; Navesti, ze se povedl start
; DEChGAFB
ldi dispH,0b00011000
ldi dispL,0b10010111
ldi r16,100
nav:
ldi r17,255
nav2:
rcall multiplex
dec r17
brne nav2
dec r16
brne nav
ldi r16,0b00000000 ;disable pullupy a 0 na anody. Musime setrit energii!
out PORTD,r16
clr r16
clr r17
; INIT LOOP
ldi InitLoopN, CUvodniIntervaly ;cekej n intervalu
ldi r19,CInitLoopMax ;delka prvniho intervalu jako obecny interval
;soucasny interval: r19, defaultni interval: CInitLoopMax
TimIntEnable ;zapni casovac (makro)
InitLoop:
;kontroluje se InitLoopN. snizovani zajistuje casovac.
cpi InitLoopN,0 ;zbyva 0 intervalu?
brne InitLoop ;pokud ne, testuj znova
; P R I P R A V Y N A H L A V N I P R O G R A M
cli ;vypni preruseni - skoncila uvodni smycka, zacina odpocitavani
;vycisteni registru
clr r16 ;vynuluj registry
clr r17
clr r18
clr r19
;pullupy PORTD
ldi r16,0b01111100 ;enable pullup
out PORTD,r16
;cas 99
ldi numL,9
ldi numH,9
mov r17,numL ;zpracovat numL
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
mov dispL,r16 ;presunout vysledek do vystupu displeje
mov r17,numH ;zpracovat numH
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
mov dispH,r16 ;presunout vysledek do vystupu displeje
;vychozi rozlozeni dratu
in wOld,PIND ;nastaveni stareho rozlozeni dratu
andi wOld,0b01111000 ;ignorovat anody a spravny drat
;nastaveni vychoziho rozlozeni dratu k prestrihnuti
mov r16, wOld ;uloz wOld -> r16
;v r16 jsou pouze rozpojene draty: 0b00010000
in r17, PORTD ;do r17 stav portu D
mov r18,r16
com r18
and r17,r18 ;v r17 vynuluj bity patrici k rozpojenym dratum (ochrana X zkratu)
out PORTD,r17 ;dej na vystup
in r17, DDRD ;do r17 DDRD
or r17, r16 ;k vystupnim pinum pridej prave rozpojeny drat
out DDRD,r17
ldi r19,CUnitSecs ;nastav citac intervalu pro hlavni odpocet
ldi r16,0b11111111 ;255 na PORTB, vse zhasnuto
out PORTB, r16
sei ;zacina hlavni program s casovacem, bude se pouzivat preruseni
loop:
rcall WireTest ;test dratku
sbic PIND,2 ;pokud je spravny drat PD2 = 0, preskoc
rjmp CHCIP ;skoc na CHCIP
;spravny drat je neprerusen
rcall multiplex
rjmp loop ;hlavni smycka se opakuje
multiplex:
push r16
push r17
;DISPLEJ JEDNOTEK
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
cbi PORTD,0
sbi PORTD,1 ;PORTD = 01 - zapnout anodu pro jednotky
out PORTB,dispL ;PORTB = dispL (displej jednotek)
ldi r17,100 ;pocet smycek
dL: ;smycka
nop
nop
nop
dec r17
brne dL
;DISPLEJ DESITEK
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
cbi PORTD,1
sbi PORTD,0 ;PORTD 10 - zapnout anodu pro desitky
out PORTB,dispH ;PORTB = dispH (displej desitek)
ldi r17,100 ;pocet smycek
dH:
nop
nop
nop
dec r17
brne dH
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
cbi PORTD,0
cbi PORTD,1
pop r17
pop r16
ret
; r17 konvertuj do 7segmentovyho kodu pro displej se spol. anodou DECGAFB ---> r16
dec7seg: ;dec7seg(r17) -> r16
clr r16 ;do r16 budeme ukladat vystup, v r17 je vstupni cislo 0-9
cpi r17,9 ;je r17 = 9?
brne dec7segN8 ;neni -> pokracuj s 8
; DEChGAFB
ldi r16, 0b01000000 ;katody DCGAFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN8:
cpi r17,8 ;je r17 = 8?
brne dec7segN7 ;neni -> pokracuj s 7
; DEChGAFB
ldi r16, 0b00000000 ;katody DECGAFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN7:
cpi r17,7 ;je r17 = 7?
brne dec7segN6 ;neni -> pokracuj s 6
; DEChGAFB
ldi r16, 0b11001010 ;katody CAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN6:
cpi r17,6 ;je r17 = 6?
brne dec7segN5 ;neni -> pokracuj s 5
; DEChGAFB
ldi r16, 0b00000001 ;katody DECGAF na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN5:
cpi r17,5 ;je r17 = 5?
brne dec7segN4 ;neni -> pokracuj s 4
; DEChGAFB
ldi r16, 0b01000001 ;katody DCGAF na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN4:
cpi r17,4 ;je r17 = 4?
brne dec7segN3 ;neni -> pokracuj s 3
; DEChGAFB
ldi r16, 0b11000100 ;katody CGFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN3:
cpi r17,3 ;je r17 = 3?
brne dec7segN2 ;neni -> pokracuj s 2
; DEChGAFB
ldi r16, 0b01000010 ;katody DCGAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN2:
cpi r17,2 ;je r17 = 2?
brne dec7segN1 ;neni -> pokracuj s 1
; DEChGAFB
ldi r16, 0b00100010 ;katody DEGAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN1:
cpi r17,1 ;je r17 = 1?
brne dec7segN0 ;neni -> pokracuj s 0
; DEChGAFB
ldi r16, 0b11001110 ;katody CB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN0:
; DEChGAFB
ldi r16, 0b00001000 ;katody DECAFB na 0; H = 0, ale bude prepsano pri vystupu
dec7segReturn:
ret
; TEST DRATU (nutno volat rucne)
WireTest:
push r16
push r17
push r18
in r16,PIND
andi r16, 0b01111000 ;odfiltrovat anody a spravny drat
;test dratku
cp wOld,r16 ;porovnej r16 a wOld
brsh WireTestReturn ;wOld >= r16: nebyl prestrizen dratek, nebo byl nejaky spojen
;dratek byl prestrizen
;ODECTENI 3 desitek
cpi numH,3 ;jsou aspon 3 desitky?
brlo WireTestMaloCasu ;nejsou-li ani 3 desitky, vynuluj vse a vybuchni
subi numH,3 ;jinak odecti 3 desitky
;nedoslo k vynulovani?
brne WireTestReturn ;desitky > 0: odejdi bez vybuchu
cpi numL,0 ;desitky = 0. kolik je jednotek?
breq WireTestBum ;je-li 0 jednotek, vybuchni
;0 desitek, n > 0 jednotek
rjmp WireTestReturn ;0 desitek ale n > 0 jednotek, odejdi bez vybuchu
WireTestMaloCasu:
clr numL ;vymazat jednotky
clr numH ;vymazat desitky
WireTestBum:
rcall BUM ;vybuchnout
WireTestReturn:
mov wOld, r16 ;uloz soucasny stav dratu do wOld
;v r16 jsou pouze rozpojene draty: 0b00010000
in r17, PORTD ;do r17 stav portu D
mov r18,r16
com r18
and r17,r18 ;v r17 vynuluj bity patrici k rozpojenym dratum (ochrana X zkratu)
out PORTD,r17 ;dej na vystup
in r17, DDRD ;do r17 DDRD
or r17, r16 ;k vystupnim pinum prodej prave rozpojeny drat
out DDRD,r17
;obnovit displej
mov r17,numL ;zpracovat numL
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbrc dispL,4 ;neni-li H nastaven na displeji, preskoc
sbr r16,0b00010000 ;nastaveni H v novem stavu displeje
mov dispL,r16 ;presunout vysledek do vystupu displeje
mov r17,numH ;zpracovat numL
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbrc dispH,4 ;neni-li H nastaven na displeji, preskoc
sbr r16,0b00010000 ;nastaveni H v novem stavu displeje
mov dispH,r16 ;presunout vysledek do vystupu displeje
pop r18
pop r17
pop r16
ret ;navrat
; B U M
BUM:
;vybuch - blikajici nuly
cli ;vypni preruseni
ldi r17,0 ;0 jednotek
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbr r16,0b00010000 ;1 na katodu H - zhasnout tecku
mov dispL,r16 ;presunout vysledek do vystupu displeje
ldi r17,0 ;0 desitek
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbr r16,0b00010000 ;1 na katodu H - zhasnout tecku
mov dispH,r16 ;presunout vysledek do vystupu displeje
BUMsmycka: ;nekonecna smycka, blikaji nuly
ldi r16, 255
BUMsmyckaMX:
rcall multiplex
dec r16
brne BUMsmyckaMX
ldi r16, 255
BUMsmyckaPAUZA:
ldi r17, 255
BUMsmyckaPAUZAb:
dec r17
brne BUMsmyckaPAUZAb
dec r16
brne BUMsmyckaPAUZA
rjmp BUMsmycka
; C H C I P
CHCIP:
;nekdo prestrihl spravny drat
cli
;ldi dispL,0b00000000
;ldi dispH,0b00000000
ldi r16,180 ; citac delky cekani
CHCIPsmycka:
mov r17,r16
com r17
CHCIPsmyckaMX:
rcall multiplex
dec r17
brne CHCIPsmyckaMX
mov r17,r16 ; nastaveni smycky cekani
inc r16
cpi r16,255
brsh CHCIPsleep ;uz je to moc dlouhy, usnout
CHCIPsmyckaPAUZA: ;r17*200
mov r18,r16
CHCIPsmyckaPAUZAb:
dec r18
brne CHCIPsmyckaPAUZAb
dec r17
brne CHCIPsmyckaPAUZA
rjmp CHCIPsmycka
CHCIPsleep:
cli
ldi r16,(1<<SE)|(1<<SM0)
out MCUCR,r16
sleep
; PRERUSENI OD CASOVACE f=1Hz
TIMER: ; casovac ma frekvenci 1Hz
push r16
push r17
push r18
; r19 je citac intervalu
cpi InitLoopN,0 ;je InitLoopN = 0?
breq TIMERnormal ;Je-li InitLoopN = 0, pokracuj normalnim prerusenim
; probiha uvodni cekani
; test intervaloveho citace (pokud je InitLoopN > 0, pouziva k tomu se r19)
cpi r19,0 ;je r19 = 0?
breq TIMERsnizitILN ;je-li r19 = 0, snizit InitLoopN: jdi na TIMERsnizitILN
dec r19 ;jinak o 1 sniz r19 (intervalovy citac)
;out PORTB,r19 ;DEBUG test r19
rjmp TIMERreturn ;a odejdi
TIMERsnizitILN:
dec InitLoopN ;snizit InitLoopN
ldi r19,CInitLoopMax ;nastaveni delky dalsiho intervalu
rjmp TIMERreturn ;odejdi
TIMERnormal:
;invertuj tecku (Low)
ldi r16,0b00010000
eor dispL,r16
cbr dispH,0b00010000
sbrc dispL,4 ;do H zkopiruj tecku z L (tim se zajisti, ze budou vzdy stejne)
sbr dispH,0b00010000
; r19 slouzi jako citac sekund
dec r19 ;sniz citac intervalu o 1
brne TIMERreturn ;neni-li 0, odejdi
ldi r19,CUnitSecs ;nastaveni dalsiho intervalu
; ODECTENI JEDNOTKY
cpi numL,0 ;je jednotek vic nez 0?
brne TIMERnOdectiJednotku ;jednotky > 0, jdi na odecteni jednotky
;0 jednotek
cpi numH, 0 ;0 jednotek. je desitek vic nez 0?
brne TIMERnOdectiPresDesitku ;je-li desitek vic nez 0, jdi na odecteni desitky
;0 jednotek i desitek
rcall BUM
TIMERnOdectiPresDesitku:
;0 jednotek, n > 0 desitek
dec numH ;odecti desitku
ldi numL,9 ;dej jednotky=9
rjmp TIMERnOdecteniHotovo ;preskoc na TIMERnOdecteniHotovo
TIMERnOdectiJednotku:
dec numL ;odecti jednotku
TIMERnOdecteniHotovo:
cpi numH,0 ;test desitek
brne TIMERnHotovoNevybuch ; neni nula -> ok
cpi numL,0 ;test jednotek
brne TIMERnHotovoNevybuch ; neni nula -> ok
;je nula
rcall BUM ;je nula: vybuchni
TIMERnHotovoNevybuch:
;uprav displej
mov r17,numL ;zpracovat numL
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbrc dispL,4 ;neni-li H nastaven na displeji, preskoc
sbr r16,0b00010000 ;nastaveni H v novem stavu displeje
mov dispL,r16 ;presunout vysledek do vystupu displeje
mov r17,numH ;zpracovat numH
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
sbrc dispH,4 ;neni-li H nastaven na displeji, preskoc
sbr r16,0b00010000 ;nastaveni H v novem stavu displeje
mov dispH,r16 ;presunout vysledek do vystupu displeje
;je obnoven stav displeje, konec preruseni
TIMERreturn:
pop r18 ;navratit puvodni hodnoty registru
pop r17
pop r16
reti

@ -0,0 +1,180 @@
.device attiny2313
;běží na 8MHz, ckdiv8=1 (vypnuto)
; A L I A S Y
.def numL = r20
.def numH = r21
.def dispL = r22
.def dispH = r23
.def wOld = r24
.def InitLoopN = r25
.equ CUvodniIntervaly = 1 ;pocet intervalu cekani
.equ CInitLoopMax = 10 ;delka 1 intervalu cekani (s)
.equ CUnitSecs = 1 ;delka 1 jednotky (s) - zacina se s 99 jednotkami
; Z A C A T E K P R O G R A M U
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0010
; NASTAVENI PO RESETU
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
; Nastaveni portu
ldi r16,0b11111111 ;smer portu B - vystupni: segmenty (=katody)
out DDRB,r16
ldi r16,0b11111111 ;vse v PORTB na 1, segmenty zhasnuty
out PORTB,r16
ldi r16,0b00000011 ;smer portu D - PB0 a PB1 jsou vystupni - spinaji anody displeje. Zbytek: dratky. PB2 je spravny drat
out DDRD,r16
ldi r16,0b11111100 ;enable pullup, 0 na anody = zhasnout. dratky pripojeny na GND, s pullupy
out PORTD,r16
sei ;Global Interrupt Enable
; P R I P R A V Y N A H L A V N I P R O G R A M
cli ;vypni preruseni - skoncila uvodni smycka, zacina odpocitavani
;vycisteni registru
clr r16 ;vynuluj registry
clr r17
clr r18
clr r19
;cas 99
ldi numL,3
ldi numH,7
;vychozi rozlozeni dratu
in wOld,PORTD ;nastaveni stareho rozlozeni dratu
andi wOld,0b01111000 ;ignorovat anody a spravny drat
mov r17,numL ;zpracovat numL
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
mov dispL,r16 ;presunout vysledek do vystupu displeje
mov r17,numH ;zpracovat numH
rcall dec7seg ;najdi 7seg. reprezentaci jednotek a dej ji do r16
mov dispH,r16 ;presunout vysledek do vystupu displeje
;dispL a dispH maji nastaveny obsah
ldi r19,CUnitSecs ;nastav citac intervalu pro hlavni odpocet
ldi r16,0b111111 ;255 na PORTB, vse zhasnuto
out PORTB, r16
sei ;zacina hlavni program s casovacem, bude se pouzivat preruseni
loop:
rcall multiplex
rjmp loop ;hlavni smycka se opakuje
multiplex:
push r16
push r17
;DISPLEJ JEDNOTEK
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
cbi PORTD,1
sbi PORTD,0 ;PORTD = 01 - zapnout anodu pro jednotky
out PORTB,dispL ;PORTB = dispL (displej jednotek)
ldi r17,100 ;pocet smycek
dL: ;smycka
nop
nop
nop
dec r17
brne dL
;DISPLEJ DESITEK
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
cbi PORTD,0
sbi PORTD,1 ;PORTD 10 - zapnout anodu pro desitky
out PORTB,dispH ;PORTB = dispH (displej desitek)
ldi r17,100 ;pocet smycek
dH:
nop
nop
nop
dec r17
brne dH
ser r16 ;katody na +: vypnout vsechny segmenty
out PORTB,r16
pop r17
pop r16
ret
; r17 konvertuj do 7segmentovyho kodu pro displej se spol. anodou DECGAFB ---> r16
dec7seg: ;dec7seg(r17) -> r16
clr r16 ;do r16 budeme ukladat vystup, v r17 je vstupni cislo 0-9
cpi r17,9 ;je r17 = 9?
brne dec7segN8 ;neni -> pokracuj s 8
; DEChGAFB
ldi r16, 0b01000000 ;katody DCGAFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN8:
cpi r17,8 ;je r17 = 8?
brne dec7segN7 ;neni -> pokracuj s 7
; DEChGAFB
ldi r16, 0b00000000 ;katody DECGAFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN7:
cpi r17,7 ;je r17 = 7?
brne dec7segN6 ;neni -> pokracuj s 6
; DEChGAFB
ldi r16, 0b11001010 ;katody CAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN6:
cpi r17,6 ;je r17 = 6?
brne dec7segN5 ;neni -> pokracuj s 5
; DEChGAFB
ldi r16, 0b00000001 ;katody DECGAF na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN5:
cpi r17,5 ;je r17 = 5?
brne dec7segN4 ;neni -> pokracuj s 4
; DEChGAFB
ldi r16, 0b01000001 ;katody DCGAF na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN4:
cpi r17,4 ;je r17 = 4?
brne dec7segN3 ;neni -> pokracuj s 3
; DEChGAFB
ldi r16, 0b11000100 ;katody CGFB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN3:
cpi r17,3 ;je r17 = 3?
brne dec7segN2 ;neni -> pokracuj s 2
; DEChGAFB
ldi r16, 0b01000010 ;katody DCGAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN2:
cpi r17,2 ;je r17 = 2?
brne dec7segN1 ;neni -> pokracuj s 1
; DEChGAFB
ldi r16, 0b00100010 ;katody DEGAB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN1:
cpi r17,1 ;je r17 = 1?
brne dec7segN0 ;neni -> pokracuj s 0
; DEChGAFB
ldi r16, 0b11001110 ;katody CB na 0; H = 0, ale bude prepsano pri vystupu
rjmp dec7segReturn
dec7segN0:
; DEChGAFB
ldi r16, 0b00001000 ;katody DECAFB na 0; H = 0, ale bude prepsano pri vystupu
dec7segReturn:
ret

@ -0,0 +1,80 @@
;pracuje jako 5-ti bitovy binarni citac
;vystupy 3 a 4 jsou prohozene kvuli desce
.device attiny13
.def i=r20 ;prvni citac, cita jen pro zpomaleni
.def j=r21 ;druhy citac, cita az do TOP, pak se oba vynulujou
.def top=r22 ;maximalni hodnota pro citac j -> vynulovani a dalsi faze
.org 0x0000 ;RESET
rjmp RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow A
rjmp CASOVAC
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
LDI r16,0b11111110 ;smer pinu
OUT DDRB,r16
LDI r16,0 ;PullUpy
OUT PORTB,r16
ldi r16,(1<<CS01)|(1<<CS00) ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/64=75000Hz
ldi r16,(1<<WGM01) ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,75 ;Compare Match 0 A je 75
out OCR0A,r16 ;75000/75=1000Hz interrupt
in r16, TIMSK0 ;povolit interrupt od preteceni
ori r16, (1<<OCIE0A)
out timsk0,r16
clr i ;nastavime pocatecni hodnoty
clr j
ldi top,2
SEI ;Global Interrupt Enable
LOOP:
in r16,PINB ;kontrola jestli je PINB0 zapnutej
sbrs r16, 0
rjmp LOOP ;NE -> jdi na loop
ldi top,1 ;ANO -> nastavit top na 1 a vymazat citace
clr i
clr j
CEKANI:
ldi top,2 ;cekame na uvolneni, zatim se prepina s top=2
in r16,PINB ;kontrola jestli je PINB0 vypnutej
sbrc r16, 0
rjmp CEKANI
rjmp LOOP ;skok na loop
CASOVAC:
cpi top,40
breq CASEND
inc i
cpi i,10
brne CASEND
clr i
inc j
cp j,top
brne CASEND
inc top
clr i
clr j
in r16,PORTB
sbrs r16,1
sbi PORTB,1
sbrc r16,1
cbi PORTB,1
CASEND:
RETI

@ -0,0 +1,96 @@
;pokus
.include "tn13def.inc"
.def CNTt=r24 ;CNTt pro tecku
.def CNTc=r25 ;CNTc pro carku
.def POM=r16
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010 ;zacatek vlastniho programu
RESET:
LDI POM,low(RAMEND) ;nastavi stack pointer
OUT SPL,POM
LDI POM,0B00000100 ;nastavi vystupni piny
OUT DDRB,POM
;PB0 tecka
;PB1 carka
;PB2 vystup
LOOP:
IN r16,PINB ;dej do r16 stav PINB
SBRS r16,0 ;neni-li bit 0 v r16 1, vymaz CNTt
CLR CNTt ;
INC CNTt ;CNTt+1
IN r16,PINB ;dej do r16 stav PINB
SBRS r16,1 ;neni-li bit 1 v r16 1, vymaz CNTc
CLR CNTc ;
INC CNTc ;CNTc+1
CPI CNTt,100 ;je-li CNTt=100,
BREQ TECKA ;jdi na TECKA
CPI CNTc,100 ;je-li CNTc=100,
BREQ CARKA
RJMP LOOP ;jsi na LOOP
KONEC:
IN r16,PINB ;r16=PINB
SBRC r16,0b00000001 ;je-li bit 0 v r16 0, praskoc nasledujici
RJMP KONEC ;jdi na KONEC
RJMP LOOP ;jdi na LOOP
TECKA:
LDI r16,0b00000100 ;na PORTB dej 0b00000100
OUT PORTB,r16
RCALL CEKANI ;udelej 1x cekani
CLR r16 ;vynuluj r16 a dej ho do PORTB
OUT PORTB,r16
RCALL CEKANI ;udelej 1x cekani - mezera mezi znaky
RJMP LOOP ;navrat na LOOP
CARKA:
LDI r16,0b00000100 ;na PORTB dej 0b00000100
OUT PORTB,r16
RCALL CEKANI ;udelej 3x cekani
RCALL CEKANI
RCALL CEKANI
CLR r16 ;vymaz r16 a dej ho na PORTB
OUT PORTB,r16
RCALL CEKANI ;udelej 1x cekani - mezera mezi znaky
RJMP LOOP
CEKANI:
PUSH r18 ;ulozit pouzivane registry do STACKU
PUSH r17
PUSH r16
LDI r16, 30
L1: DEC r16 ;cekaci smycka vnejsi - zacatek
LDI r17, 100
L2: DEC r17 ; cekaci smycka stredni - zacatek
LDI r18, 130
L3: DEC r18 ; cekaci smycka vnitrni - zacatek
CPI r18, 0
BRNE L3 ; cekaci smycka vnitrni - konec
CPI r17, 0
BRNE L2 ; cekaci smycka stredni - konec
CPI r16, 0
BRNE L1 ;cekaci smycka vnejsi - konec
POP r16 ;nacist puvodni obsah registru ze STACKU
POP r17
POP r18
RET ;navrat z rutiny do kodu

@ -0,0 +1,130 @@
;pracuje jako 5-ti bitovy binarni citac
;vystupy 3 a 4 jsou prohozene kvuli desce
.device attiny13
.def ze=r19
.def pr=r20
.def sc=r21
.def te=r22
.def kv=r23
.def qi=r24
.def divf=r25
.org 0x0000 ;RESET
RJMP RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow
RJMP CASOVAC
.org 0x0007
rjmp casovac
.org 0x0010
RESET:
LDI r16,low(RAMEND) ;nastavi stack pointer
OUT SPL,r16
CLI ;zakazat vsechna preruseni
LDI r16,0b00011111 ;výstupní = 1
OUT DDRB,r16
LDI r16,0 ;vypnout PullUp
OUT PORTB,r16
ldi r16,0b00000011 ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/64=75000Hz
ldi r16,0b00000010 ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,75 ;Compare Match 0 A je 75
out OCR0A,r16 ;75000/75=1000Hz interrupt
in r16, TIMSK0
ORI r16, 0b00000100
out timsk0,r16
clr r16
clr r17
clr r18
clr pr
clr sc
clr te
clr kv
ldi divf,2
SEI ;Global Interrupt Enable
LOOP:
rjmp LOOP ;skok na loop
CASOVAC:
inc ze
cpi ze,100
BRNE CASEND
clr ze
INC pr
CPi pr,10
BRNE CASEND
clr pr
INC sc
in r16,PORTB
SBRC r16,0
cbi portb,0
SBRS r16,0
sbi portb,0
CP sc,divf
BRNE CASEND
clr pr
clr sc
inc te
in r16,PORTB
SBRC r16,1
cbi portb,1
SBRS r16,1
sbi portb,1
CP te,divf
BRNE CASEND
clr pr
clr sc
clr te
inc kv
in r16,PORTB
SBRC r16,2
cbi portb,2
SBRS r16,2
sbi portb,2
CP kv,divf
BRNE CASEND
clr pr
clr sc
clr te
clr kv
inc qi
in r16,PORTB
SBRC r16,4
cbi portb,4
SBRS r16,4
sbi portb,4
CP qi,divf
BRNE CASEND
clr pr
clr sc
clr te
clr kv
clr qi
in r16,PORTB
SBRC r16,3
cbi portb,3
SBRS r16,3
sbi portb,3
CASEND:
RETI

@ -0,0 +1,87 @@
;pracuje jako 5-ti bitovy binarni citac
;vystupy 3 a 4 jsou prohozene kvuli desce
.device attiny13
.def cnt=r18
.def cm0=r19
.def cm1=r20
.def cm2=r21
.def chc=r22
.def dirs=r23
.org 0x0000 ;RESET
RJMP RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow
RJMP CASOVAC
.org 0x0007
rjmp casovac
.org 0x0010
RESET:
ldi r16,low(RAMEND) ;nastavi stack pointer
out SPL,r16
cli ;zakazat vsechna preruseni
ldi r16,0b00011111 ;výstupní = 1
out DDRB,r16
ldi r16,0 ;vypnout PullUp
out PORTB,r16
ldi r16,0b00000011 ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/32
ldi r16,0b00000010 ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,20 ;overflow 22
out OCR0A,r16 ;
in r16, TIMSK0 ;interrupt enable
ORI r16, 0b00000100
out timsk0,r16
ldi cm0,32 ;R
ldi cm1,16 ;G
ldi cm2,0 ;B
clr cnt
clr chc
ldi dirs,0b00000000
sei ;zapnout globalne interrupt
LOOP:
rjmp LOOP ;skok na loop
CASOVAC:
inc cnt
cpi cnt,32
brne nov
clr cnt
cbi portb,0
cbi portb,1
cbi portb,2
inc chc
cpi chc,255
brne nov
nov:
cp cnt,cm0
brne not0
sbi portb,0
not0: cp cnt,cm1
brne not1
sbi portb,1
not1: cp cnt,cm2
brne not2
sbi portb,2
not2:
CASEND:
reti

@ -0,0 +1,2 @@
@ECHO OFF
"C:\Program Files\Atmel\AVR Tools\AvrAssembler2\avrasm2.exe" -S "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\labels.tmp" -fI -W+ie -o "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.hex" -d "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.obj" -e "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.eep" -m "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.map" "C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm"

@ -0,0 +1 @@
<AVRStudio><MANAGEMENT><ProjectName>EEPROM_nahoda</ProjectName><Created>14-Sep-2007 21:26:15</Created><LastEdit>14-Sep-2007 21:30:30</LastEdit><ICON>208</ICON><ProjectType>0</ProjectType><Created>14-Sep-2007 21:26:15</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>Atmel AVR Assembler</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>EEPROM_nahoda.obj</ObjectFile><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_nahoda\EEPROM_nahoda.asm</EntryFile><SaveFolder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_nahoda\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATtiny13.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AvrAssembler><Folder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_nahoda\</Folder><RelPath>EEPROM_nahoda.asm</RelPath><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_nahoda\EEPROM_nahoda.asm</EntryFile><IncludePath>C:\Program Files\Atmel\AVR Tools\AvrAssembler\Appnotes</IncludePath><V2IncludePath></V2IncludePath><V2Parameters></V2Parameters><FileType>I</FileType><ObjectName>EEPROM_nahoda</ObjectName><Wrap>0</Wrap><ErrorAsWarning>0</ErrorAsWarning><MapFile>1</MapFile><ListFile>0</ListFile><Version1>0</Version1><PreCompile></PreCompile><PostCompile></PostCompile><SourceFiles>,</SourceFiles></AvrAssembler><ProjectIncludeDirs><Dirs><Dir>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</Dir></Dirs></ProjectIncludeDirs><ProjectFiles><Files><Name>\EEPROM_nahoda.asm</Name></Files></ProjectFiles><IOView><usergroups/></IOView><Files><File00000><FileId>00000</FileId><FileName>EEPROM_nahoda.asm</FileName><Status>1</Status></File00000></Files><Workspace><File00000><Position>197 71 1026 566</Position><LineCol>108 0</LineCol><State>Maximized</State></File00000></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

@ -0,0 +1,108 @@
;EEPROM_nahoda
;pokud je stisknuto tlacitko PB0,
;hrozne rychle se z EEPROM ctou hodnoty na adresach 0-3
;a davaji se na PORTB
;Vypada to pak, jako by se pri drzeni tlacitka rozsvitily obe ledky PB1 a PB2,
;ale po pusteni tlacitka na nich zustane 'nahodna' kombinace 1 a 0.
.include "tn13def.inc"
.def CNT=r20
.cseg
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010 ;zacatek vlastniho programu
RESET:
LDI r16,low(RAMEND) ;nastavi stack pointer
OUT SPL,r16
LDI r16,0b00000110 ;nastavi I/O nohy
OUT DDRB,r16
LOOP:
RCALL cekani ;zavolej cekani pro zpomaleni celeho programu
IN r16,PINB ;Porovnej stav PB0 s 1 a pokud neni rovno, jdi na LOOP
ANDI r16,0b00000001
CPI r16,0b00000001
BRNE LOOP
MOV r17,CNT ;do r17 (adresovy registr) dej CNT
RCALL EEread ;zavolej cteni z EEPROM - adresa je r17, do r16 se ulozi data.
OUT PORTB,r16 ;posli data z r16 ven
INC CNT ;inkrementuj CNT
CPI CNT,4 ;pokud je mensi nez 4, jdi na loop
BRLT LOOP
CLR CNT ;jinak vynuluj CNT
RJMP LOOP ;a jdi na LOOP
;
;EEread je funkce pro cteni z EEPROM
;do r17 se ulozi adresa,
;zavola se EEread
;a v r16 se objevi hodnota, ktera je na adrese.
EEread:
SBIC EECR,1
RJMP EEread ;cekani dokud neni EEPROM ready
OUT EEARL, r17 ;ulozit adresu z r17
SBI EECR,0 ;nastavenim EERE zacina cteni
IN r16,EEDR ;cteni dat z EEDR do r16
RET
;zapis do EEPROM, v R17 je ADRESA, v R16 jsou DATA
EEwrite:
SBIC EECR,EEPE
RJMP EEwrite ;cekani dokud neni EEPROM ready
LDI r16, 0 ;nastavit programovaci mod
OUT EECR, r16
OUT EEARL, r17 ;dej adresu z r17 do EEARL
OUT EEDR, r16 ;dej data z r16 do EEDR
SBI EECR,EEMPE ;master program enable
SBI EECR,EEPE ;program enable
RET
;cekaci cyklus
CEKANI:
PUSH r18 ;ulozit pouzivane registry do STACKU
PUSH r17
PUSH r16
LDI r16, 3
L1: DEC r16 ;cekaci smycka vnejsi - zacatek
LDI r17, 3
L2: DEC r17 ; cekaci smycka stredni - zacatek
LDI r18, 3
L3: DEC r18 ; cekaci smycka vnitrni - zacatek
CPI r18, 0
BRNE L3 ; cekaci smycka vnitrni - konec
CPI r17, 0
BRNE L2 ; cekaci smycka stredni - konec
CPI r16, 0
BRNE L1 ;cekaci smycka vnejsi - konec
POP r16 ;nacist puvodni obsah registru ze STACKU
POP r17
POP r18
RET ;navrat do hlavniho programu
.eseg ;zacatek ESEGu
.org 0x00 ;adresa 0
.DB 0b00000000 ;tady se definujou byty postupne podle adres.
.DB 0b00000010
.DB 0b00000100
.DB 0b00000110

@ -0,0 +1,289 @@
AVRASM ver. 2.1.12 C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm Fri Sep 14 21:26:55 2007
EQU SIGNATURE_000 0000001e
EQU SIGNATURE_001 00000090
EQU SIGNATURE_002 00000007
EQU SREG 0000003f
EQU SPL 0000003d
EQU GIMSK 0000003b
EQU GIFR 0000003a
EQU TIMSK0 00000039
EQU TIFR0 00000038
EQU SPMCSR 00000037
EQU OCR0A 00000036
EQU MCUCR 00000035
EQU MCUSR 00000034
EQU TCCR0B 00000033
EQU TCNT0 00000032
EQU OSCCAL 00000031
EQU TCCR0A 0000002f
EQU DWDR 0000002e
EQU OCR0B 00000029
EQU GTCCR 00000028
EQU CLKPR 00000026
EQU WDTCR 00000021
EQU EEAR 0000001e
EQU EEDR 0000001d
EQU EECR 0000001c
EQU PORTB 00000018
EQU DDRB 00000017
EQU PINB 00000016
EQU PCMSK 00000015
EQU DIDR0 00000014
EQU ACSR 00000008
EQU ADMUX 00000007
EQU ADCSRA 00000006
EQU ADCH 00000005
EQU ADCL 00000004
EQU ADCSRB 00000003
EQU MUX0 00000000
EQU MUX1 00000001
EQU ADLAR 00000005
EQU REFS0 00000006
EQU ADPS0 00000000
EQU ADPS1 00000001
EQU ADPS2 00000002
EQU ADIE 00000003
EQU ADIF 00000004
EQU ADATE 00000005
EQU ADSC 00000006
EQU ADEN 00000007
EQU ADCH0 00000000
EQU ADCH1 00000001
EQU ADCH2 00000002
EQU ADCH3 00000003
EQU ADCH4 00000004
EQU ADCH5 00000005
EQU ADCH6 00000006
EQU ADCH7 00000007
EQU ADCL0 00000000
EQU ADCL1 00000001
EQU ADCL2 00000002
EQU ADCL3 00000003
EQU ADCL4 00000004
EQU ADCL5 00000005
EQU ADCL6 00000006
EQU ADCL7 00000007
EQU ADTS0 00000000
EQU ADTS1 00000001
EQU ADTS2 00000002
EQU ADC1D 00000002
EQU ADC3D 00000003
EQU ADC2D 00000004
EQU ADC0D 00000005
EQU ACME 00000006
EQU ACIS0 00000000
EQU ACIS1 00000001
EQU ACIE 00000003
EQU ACI 00000004
EQU ACO 00000005
EQU ACBG 00000006
EQU AINBG 00000006
EQU ACD 00000007
EQU AIN0D 00000000
EQU AIN1D 00000001
EQU EEARL 0000001e
EQU EEAR0 00000000
EQU EEAR1 00000001
EQU EEAR2 00000002
EQU EEAR3 00000003
EQU EEAR4 00000004
EQU EEAR5 00000005
EQU EEDR0 00000000
EQU EEDR1 00000001
EQU EEDR2 00000002
EQU EEDR3 00000003
EQU EEDR4 00000004
EQU EEDR5 00000005
EQU EEDR6 00000006
EQU EEDR7 00000007
EQU EERE 00000000
EQU EEWE 00000001
EQU EEPE 00000001
EQU EEMWE 00000002
EQU EEMPE 00000002
EQU EERIE 00000003
EQU EEPM0 00000004
EQU EEPM1 00000005
EQU SREG_C 00000000
EQU SREG_Z 00000001
EQU SREG_N 00000002
EQU SREG_V 00000003
EQU SREG_S 00000004
EQU SREG_H 00000005
EQU SREG_T 00000006
EQU SREG_I 00000007
EQU SP0 00000000
EQU SP1 00000001
EQU SP2 00000002
EQU SP3 00000003
EQU SP4 00000004
EQU SP5 00000005
EQU SP6 00000006
EQU SP7 00000007
EQU ISC00 00000000
EQU ISC01 00000001
EQU SM0 00000003
EQU SM1 00000004
EQU SE 00000005
EQU PUD 00000006
EQU PORF 00000000
EQU EXTRF 00000001
EQU BORF 00000002
EQU WDRF 00000003
EQU CAL0 00000000
EQU CAL1 00000001
EQU CAL2 00000002
EQU CAL3 00000003
EQU CAL4 00000004
EQU CAL5 00000005
EQU CAL6 00000006
EQU CLKPS0 00000000
EQU CLKPS1 00000001
EQU CLKPS2 00000002
EQU CLKPS3 00000003
EQU CLKPCE 00000007
EQU DWDR0 00000000
EQU DWDR1 00000001
EQU DWDR2 00000002
EQU DWDR3 00000003
EQU DWDR4 00000004
EQU DWDR5 00000005
EQU DWDR6 00000006
EQU DWDR7 00000007
EQU SPMEN 00000000
EQU PGERS 00000001
EQU PGWRT 00000002
EQU RFLB 00000003
EQU CTPB 00000004
EQU PORTB0 00000000
EQU PB0 00000000
EQU PORTB1 00000001
EQU PB1 00000001
EQU PORTB2 00000002
EQU PB2 00000002
EQU PORTB3 00000003
EQU PB3 00000003
EQU PORTB4 00000004
EQU PB4 00000004
EQU PORTB5 00000005
EQU PB5 00000005
EQU DDB0 00000000
EQU DDB1 00000001
EQU DDB2 00000002
EQU DDB3 00000003
EQU DDB4 00000004
EQU DDB5 00000005
EQU PINB0 00000000
EQU PINB1 00000001
EQU PINB2 00000002
EQU PINB3 00000003
EQU PINB4 00000004
EQU PINB5 00000005
EQU GICR 0000003b
EQU PCIE 00000005
EQU INT0 00000006
EQU PCIF 00000005
EQU INTF0 00000006
EQU PCINT0 00000000
EQU PCINT1 00000001
EQU PCINT2 00000002
EQU PCINT3 00000003
EQU PCINT4 00000004
EQU PCINT5 00000005
EQU TOIE0 00000001
EQU OCIE0A 00000002
EQU OCIE0B 00000003
EQU TOV0 00000001
EQU OCF0A 00000002
EQU OCF0B 00000003
EQU OCR0_0 00000000
EQU OCR0_1 00000001
EQU OCR0_2 00000002
EQU OCR0_3 00000003
EQU OCR0_4 00000004
EQU OCR0_5 00000005
EQU OCR0_6 00000006
EQU OCR0_7 00000007
EQU WGM00 00000000
EQU WGM01 00000001
EQU COM0B0 00000004
EQU COM0B1 00000005
EQU COM0A0 00000006
EQU COM0A1 00000007
EQU TCNT0_0 00000000
EQU TCNT0_1 00000001
EQU TCNT0_2 00000002
EQU TCNT0_3 00000003
EQU TCNT0_4 00000004
EQU TCNT0_5 00000005
EQU TCNT0_6 00000006
EQU TCNT0_7 00000007
EQU CS00 00000000
EQU CS01 00000001
EQU CS02 00000002
EQU WGM02 00000003
EQU FOC0B 00000006
EQU FOC0A 00000007
EQU PSR10 00000000
EQU TSM 00000007
EQU WDP0 00000000
EQU WDP1 00000001
EQU WDP2 00000002
EQU WDE 00000003
EQU WDCE 00000004
EQU WDP3 00000005
EQU WDTIE 00000006
EQU WDTIF 00000007
EQU LB1 00000000
EQU LB2 00000001
EQU CKSEL0 00000000
EQU CKSEL1 00000001
EQU SUT0 00000002
EQU SUT1 00000003
EQU CKDIV8 00000004
EQU WDTON 00000005
EQU EESAVE 00000006
EQU SPIEN 00000007
EQU RSTDISBL 00000000
EQU BODLEVEL0 00000001
EQU BODLEVEL1 00000002
EQU DWEN 00000003
EQU SELFPRGEN 00000004
DEF XH r27
DEF XL r26
DEF YH r29
DEF YL r28
DEF ZH r31
DEF ZL r30
EQU FLASHEND 000001ff
EQU IOEND 0000003f
EQU SRAM_START 00000060
EQU SRAM_SIZE 00000040
EQU RAMEND 0000009f
EQU XRAMEND 00000000
EQU E2END 0000003f
EQU EEPROMEND 0000003f
EQU EEADRBITS 00000006
EQU PAGESIZE 00000010
EQU INT0addr 00000001
EQU PCI0addr 00000002
EQU OVF0addr 00000003
EQU ERDYaddr 00000004
EQU ACIaddr 00000005
EQU OC0Aaddr 00000006
EQU OC0Baddr 00000007
EQU WDTaddr 00000008
EQU ADCCaddr 00000009
EQU INT_VECTORS_SIZE 0000000a
DEF CNT r20
CSEG RESET 00000010
CSEG LOOP 00000014
CSEG cekani 00000030
CSEG EEread 00000021
CSEG EEwrite 00000027
CSEG L1 00000034
CSEG L2 00000036
CSEG L3 00000038

@ -0,0 +1 @@
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATTINY13"/><Files><File00000 Name="C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_nahoda\EEPROM_nahoda.asm" Position="197 71 1026 566" LineCol="48 12" State="Maximized"/></Files></AVRWorkspace>

@ -0,0 +1,32 @@
<ASSEMBLER_INFO>
<VERSION>2.1.12</VERSION>
<DEVICE>ATtiny13</DEVICE>
<WORKING_DIR>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda</WORKING_DIR>
<INCLUDE_PATH>
<DIR>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</DIR>
</INCLUDE_PATH>
<SOURCE_FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</SOURCE_FILE>
<INCLUDED_FILES>
<FILE>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\tn13def.inc</FILE>
</INCLUDED_FILES>
<OBJECT_FILES>
<FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.obj</FILE>
</OBJECT_FILES>
<HEX_FILES>
<FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.hex</FILE>
<FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.eep</FILE>
</HEX_FILES>
<OUTPUT_FILES>
<FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.map</FILE>
</OUTPUT_FILES>
<LABELS>
<RESET><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>19</LINE></RESET>
<LOOP><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>26</LINE></LOOP>
<cekani><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>73</LINE></cekani>
<EEread><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>48</LINE></EEread>
<EEwrite><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>58</LINE></EEwrite>
<L1><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>79</LINE></L1>
<L2><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>81</LINE></L2>
<L3><FILE>C:\Documents and Settings\Ondra\Plocha\AVR\EEPROM_nahoda\EEPROM_nahoda.asm</FILE><LINE>83</LINE></L3>
</LABELS>
</ASSEMBLER_INFO>

@ -0,0 +1,2 @@
@ECHO OFF
"C:\Program Files\Atmel\AVR Tools\AvrAssembler2\avrasm2.exe" -S "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\labels.tmp" -fI -W+ie -o "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.hex" -d "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.obj" -e "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.eep" -m "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.map" "C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm"

@ -0,0 +1 @@
<AVRStudio><MANAGEMENT><Created>06-Sep-2007 20:57:13</Created><LastEdit>13-Sep-2007 21:45:27</LastEdit><ProjectType>0</ProjectType><Created>06-Sep-2007 20:57:13</Created><Version>4</Version><Build>4, 13, 0, 528</Build><Created>08-Sep-2007 21:57:32</Created><LastEdit>08-Sep-2007 21:57:32</LastEdit><ProjectType>0</ProjectType><Created>08-Sep-2007 21:57:32</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>Atmel AVR Assembler</ProjectTypeName><ICON>208</ICON><ProjectName>EEPROM_access</ProjectName><Created>10-Sep-2007 21:52:01</Created><LastEdit>10-Sep-2007 21:52:01</LastEdit><ICON>208</ICON><ProjectType>0</ProjectType><Created>10-Sep-2007 21:52:01</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>Atmel AVR Assembler</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>EEPROM_access.obj</ObjectFile><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</EntryFile><ObjectFile></ObjectFile><EntryFile></EntryFile><ObjectFile></ObjectFile><EntryFile></EntryFile><SaveFolder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_PART>ATtiny13</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><CURRENT_PART>ATmega16.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND></IO_EXPAND><REGISTERNAMES></REGISTERNAMES><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATtiny13.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND></IO_EXPAND><REGISTERNAMES></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><modules><module></module></modules><Triggers></Triggers></Debugger><AvrAssembler><Folder>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\</Folder><RelPath>EEPROM_access.asm</RelPath><EntryFile>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</EntryFile><IncludePath>C:\Program Files\Atmel\AVR Tools\AvrAssembler\Appnotes</IncludePath><V2IncludePath></V2IncludePath><V2Parameters></V2Parameters><FileType>I</FileType><ObjectName>EEPROM_access</ObjectName><Wrap>0</Wrap><ErrorAsWarning>0</ErrorAsWarning><MapFile>1</MapFile><ListFile>0</ListFile><Version1>0</Version1><PreCompile></PreCompile><PostCompile></PostCompile><SourceFiles>,</SourceFiles></AvrAssembler><ProjectIncludeDirs><Dirs><Dir>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</Dir></Dirs></ProjectIncludeDirs><ProjectFiles><Files><Name>\EEPROM_access.asm</Name></Files></ProjectFiles><IOView><usergroups/></IOView><Files><File00000><FileId>00000</FileId><FileName>EEPROM_access.asm</FileName><Status>257</Status></File00000></Files><Workspace><File00000><Position>197 71 1026 566</Position><LineCol>100 0</LineCol><State>Maximized</State></File00000></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

@ -0,0 +1,49 @@
;program cyklicky nacita z EEPROM adresy:0x00 hodnotu (0b00000101) a dava ji do PORTB.
.include "tn13def.inc"
.cseg
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010 ;zacatek vlastniho programu
RESET:
LDI r16,low(RAMEND) ;nastavi stack pointer
OUT SPL,r16
LDI r16,0b00000111
OUT DDRB,r16
LOOP:
LDI r17,0
RCALL EEread
OUT PORTB,r16
RJMP LOOP
;
;EEread je funkce pro cteni z EEPROM
;do r17 se ulozi adresa,
;zavola se EEread
;a v r16 se objevi hodnota, ktera je na adrese.
EEread:
SBIC EECR,1
RJMP EEread ;cekani dokud neni EEPROM ready
OUT EEARL, r17 ;ulozit adresu z r17
SBI EECR,0 ;nastavenim EERE zacina cteni
IN r16,EEDR ;cteni dat z EEDR do r16
RET
.eseg
.org 0x00
.DB 0b00000101

@ -0,0 +1,283 @@
AVRASM ver. 2.1.12 C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm Thu Sep 13 21:48:45 2007
EQU SIGNATURE_000 0000001e
EQU SIGNATURE_001 00000090
EQU SIGNATURE_002 00000007
EQU SREG 0000003f
EQU SPL 0000003d
EQU GIMSK 0000003b
EQU GIFR 0000003a
EQU TIMSK0 00000039
EQU TIFR0 00000038
EQU SPMCSR 00000037
EQU OCR0A 00000036
EQU MCUCR 00000035
EQU MCUSR 00000034
EQU TCCR0B 00000033
EQU TCNT0 00000032
EQU OSCCAL 00000031
EQU TCCR0A 0000002f
EQU DWDR 0000002e
EQU OCR0B 00000029
EQU GTCCR 00000028
EQU CLKPR 00000026
EQU WDTCR 00000021
EQU EEAR 0000001e
EQU EEDR 0000001d
EQU EECR 0000001c
EQU PORTB 00000018
EQU DDRB 00000017
EQU PINB 00000016
EQU PCMSK 00000015
EQU DIDR0 00000014
EQU ACSR 00000008
EQU ADMUX 00000007
EQU ADCSRA 00000006
EQU ADCH 00000005
EQU ADCL 00000004
EQU ADCSRB 00000003
EQU MUX0 00000000
EQU MUX1 00000001
EQU ADLAR 00000005
EQU REFS0 00000006
EQU ADPS0 00000000
EQU ADPS1 00000001
EQU ADPS2 00000002
EQU ADIE 00000003
EQU ADIF 00000004
EQU ADATE 00000005
EQU ADSC 00000006
EQU ADEN 00000007
EQU ADCH0 00000000
EQU ADCH1 00000001
EQU ADCH2 00000002
EQU ADCH3 00000003
EQU ADCH4 00000004
EQU ADCH5 00000005
EQU ADCH6 00000006
EQU ADCH7 00000007
EQU ADCL0 00000000
EQU ADCL1 00000001
EQU ADCL2 00000002
EQU ADCL3 00000003
EQU ADCL4 00000004
EQU ADCL5 00000005
EQU ADCL6 00000006
EQU ADCL7 00000007
EQU ADTS0 00000000
EQU ADTS1 00000001
EQU ADTS2 00000002
EQU ADC1D 00000002
EQU ADC3D 00000003
EQU ADC2D 00000004
EQU ADC0D 00000005
EQU ACME 00000006
EQU ACIS0 00000000
EQU ACIS1 00000001
EQU ACIE 00000003
EQU ACI 00000004
EQU ACO 00000005
EQU ACBG 00000006
EQU AINBG 00000006
EQU ACD 00000007
EQU AIN0D 00000000
EQU AIN1D 00000001
EQU EEARL 0000001e
EQU EEAR0 00000000
EQU EEAR1 00000001
EQU EEAR2 00000002
EQU EEAR3 00000003
EQU EEAR4 00000004
EQU EEAR5 00000005
EQU EEDR0 00000000
EQU EEDR1 00000001
EQU EEDR2 00000002
EQU EEDR3 00000003
EQU EEDR4 00000004
EQU EEDR5 00000005
EQU EEDR6 00000006
EQU EEDR7 00000007
EQU EERE 00000000
EQU EEWE 00000001
EQU EEPE 00000001
EQU EEMWE 00000002
EQU EEMPE 00000002
EQU EERIE 00000003
EQU EEPM0 00000004
EQU EEPM1 00000005
EQU SREG_C 00000000
EQU SREG_Z 00000001
EQU SREG_N 00000002
EQU SREG_V 00000003
EQU SREG_S 00000004
EQU SREG_H 00000005
EQU SREG_T 00000006
EQU SREG_I 00000007
EQU SP0 00000000
EQU SP1 00000001
EQU SP2 00000002
EQU SP3 00000003
EQU SP4 00000004
EQU SP5 00000005
EQU SP6 00000006
EQU SP7 00000007
EQU ISC00 00000000
EQU ISC01 00000001
EQU SM0 00000003
EQU SM1 00000004
EQU SE 00000005
EQU PUD 00000006
EQU PORF 00000000
EQU EXTRF 00000001
EQU BORF 00000002
EQU WDRF 00000003
EQU CAL0 00000000
EQU CAL1 00000001
EQU CAL2 00000002
EQU CAL3 00000003
EQU CAL4 00000004
EQU CAL5 00000005
EQU CAL6 00000006
EQU CLKPS0 00000000
EQU CLKPS1 00000001
EQU CLKPS2 00000002
EQU CLKPS3 00000003
EQU CLKPCE 00000007
EQU DWDR0 00000000
EQU DWDR1 00000001
EQU DWDR2 00000002
EQU DWDR3 00000003
EQU DWDR4 00000004
EQU DWDR5 00000005
EQU DWDR6 00000006
EQU DWDR7 00000007
EQU SPMEN 00000000
EQU PGERS 00000001
EQU PGWRT 00000002
EQU RFLB 00000003
EQU CTPB 00000004
EQU PORTB0 00000000
EQU PB0 00000000
EQU PORTB1 00000001
EQU PB1 00000001
EQU PORTB2 00000002
EQU PB2 00000002
EQU PORTB3 00000003
EQU PB3 00000003
EQU PORTB4 00000004
EQU PB4 00000004
EQU PORTB5 00000005
EQU PB5 00000005
EQU DDB0 00000000
EQU DDB1 00000001
EQU DDB2 00000002
EQU DDB3 00000003
EQU DDB4 00000004
EQU DDB5 00000005
EQU PINB0 00000000
EQU PINB1 00000001
EQU PINB2 00000002
EQU PINB3 00000003
EQU PINB4 00000004
EQU PINB5 00000005
EQU GICR 0000003b
EQU PCIE 00000005
EQU INT0 00000006
EQU PCIF 00000005
EQU INTF0 00000006
EQU PCINT0 00000000
EQU PCINT1 00000001
EQU PCINT2 00000002
EQU PCINT3 00000003
EQU PCINT4 00000004
EQU PCINT5 00000005
EQU TOIE0 00000001
EQU OCIE0A 00000002
EQU OCIE0B 00000003
EQU TOV0 00000001
EQU OCF0A 00000002
EQU OCF0B 00000003
EQU OCR0_0 00000000
EQU OCR0_1 00000001
EQU OCR0_2 00000002
EQU OCR0_3 00000003
EQU OCR0_4 00000004
EQU OCR0_5 00000005
EQU OCR0_6 00000006
EQU OCR0_7 00000007
EQU WGM00 00000000
EQU WGM01 00000001
EQU COM0B0 00000004
EQU COM0B1 00000005
EQU COM0A0 00000006
EQU COM0A1 00000007
EQU TCNT0_0 00000000
EQU TCNT0_1 00000001
EQU TCNT0_2 00000002
EQU TCNT0_3 00000003
EQU TCNT0_4 00000004
EQU TCNT0_5 00000005
EQU TCNT0_6 00000006
EQU TCNT0_7 00000007
EQU CS00 00000000
EQU CS01 00000001
EQU CS02 00000002
EQU WGM02 00000003
EQU FOC0B 00000006
EQU FOC0A 00000007
EQU PSR10 00000000
EQU TSM 00000007
EQU WDP0 00000000
EQU WDP1 00000001
EQU WDP2 00000002
EQU WDE 00000003
EQU WDCE 00000004
EQU WDP3 00000005
EQU WDTIE 00000006
EQU WDTIF 00000007
EQU LB1 00000000
EQU LB2 00000001
EQU CKSEL0 00000000
EQU CKSEL1 00000001
EQU SUT0 00000002
EQU SUT1 00000003
EQU CKDIV8 00000004
EQU WDTON 00000005
EQU EESAVE 00000006
EQU SPIEN 00000007
EQU RSTDISBL 00000000
EQU BODLEVEL0 00000001
EQU BODLEVEL1 00000002
EQU DWEN 00000003
EQU SELFPRGEN 00000004
DEF XH r27
DEF XL r26
DEF YH r29
DEF YL r28
DEF ZH r31
DEF ZL r30
EQU FLASHEND 000001ff
EQU IOEND 0000003f
EQU SRAM_START 00000060
EQU SRAM_SIZE 00000040
EQU RAMEND 0000009f
EQU XRAMEND 00000000
EQU E2END 0000003f
EQU EEPROMEND 0000003f
EQU EEADRBITS 00000006
EQU PAGESIZE 00000010
EQU INT0addr 00000001
EQU PCI0addr 00000002
EQU OVF0addr 00000003
EQU ERDYaddr 00000004
EQU ACIaddr 00000005
EQU OC0Aaddr 00000006
EQU OC0Baddr 00000007
EQU WDTaddr 00000008
EQU ADCCaddr 00000009
EQU INT_VECTORS_SIZE 0000000a
CSEG RESET 00000010
CSEG LOOP 00000014
CSEG EEread 00000018

@ -0,0 +1 @@
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATTINY13"/><Files><File00000 Name="C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm" Position="197 71 1026 566" LineCol="28 47" State="Maximized"/></Files></AVRWorkspace>

@ -0,0 +1,27 @@
<ASSEMBLER_INFO>
<VERSION>2.1.12</VERSION>
<DEVICE>ATtiny13</DEVICE>
<WORKING_DIR>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access</WORKING_DIR>
<INCLUDE_PATH>
<DIR>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes</DIR>
</INCLUDE_PATH>
<SOURCE_FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</SOURCE_FILE>
<INCLUDED_FILES>
<FILE>C:\Program Files\Atmel\AVR Tools\AvrAssembler2\Appnotes\tn13def.inc</FILE>
</INCLUDED_FILES>
<OBJECT_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.obj</FILE>
</OBJECT_FILES>
<HEX_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.hex</FILE>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.eep</FILE>
</HEX_FILES>
<OUTPUT_FILES>
<FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.map</FILE>
</OUTPUT_FILES>
<LABELS>
<RESET><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</FILE><LINE>12</LINE></RESET>
<LOOP><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</FILE><LINE>19</LINE></LOOP>
<EEread><FILE>C:\Documents and Settings\Ondra\Dokumenty\AVR projekty\t13-EEPROM_access\EEPROM_access.asm</FILE><LINE>30</LINE></EEread>
</LABELS>
</ASSEMBLER_INFO>

@ -0,0 +1,130 @@
;pracuje jako 5-ti bitovy binarni citac
;vystupy 3 a 4 jsou prohozene kvuli desce
.device attiny13
.def ze=r19
.def pr=r20
.def sc=r21
.def te=r22
.def kv=r23
.def qi=r24
.def divf=r25
.org 0x0000 ;RESET
RJMP RESET ;skok na start po resetu
.org 0x0006 ;TC0 overflow
RJMP CASOVAC
.org 0x0007
rjmp casovac
.org 0x0010
RESET:
LDI r16,low(RAMEND) ;nastavi stack pointer
OUT SPL,r16
CLI ;zakazat vsechna preruseni
LDI r16,0b00011111 ;výstupní = 1
OUT DDRB,r16
LDI r16,0 ;vypnout PullUp
OUT PORTB,r16
ldi r16,0b00000011 ;TC0 prescaler na 64
out TCCR0B,r16 ;4800000/64=75000Hz
ldi r16,0b00000010 ;TC0 je v rezimu CTC
out TCCR0A,r16
ldi r16,75 ;Compare Match 0 A je 75
out OCR0A,r16 ;75000/75=1000Hz interrupt
in r16, TIMSK0
ORI r16, 0b00000100
out timsk0,r16
clr r16
clr r17
clr r18
clr pr
clr sc
clr te
clr kv
ldi divf,2
SEI ;Global Interrupt Enable
LOOP:
rjmp LOOP ;skok na loop
CASOVAC:
inc ze
cpi ze,100
BRNE CASEND
clr ze
INC pr
CPi pr,10
BRNE CASEND
clr pr
INC sc
in r16,PORTB
SBRC r16,0
cbi portb,0
SBRS r16,0
sbi portb,0
CP sc,divf
BRNE CASEND
clr pr
clr sc
inc te
in r16,PORTB
SBRC r16,1
cbi portb,1
SBRS r16,1
sbi portb,1
CP te,divf
BRNE CASEND
clr pr
clr sc
clr te
inc kv
in r16,PORTB
SBRC r16,2
cbi portb,2
SBRS r16,2
sbi portb,2
CP kv,divf
BRNE CASEND
clr pr
clr sc
clr te
clr kv
inc qi
in r16,PORTB
SBRC r16,4
cbi portb,4
SBRS r16,4
sbi portb,4
CP qi,divf
BRNE CASEND
clr pr
clr sc
clr te
clr kv
clr qi
in r16,PORTB
SBRC r16,3
cbi portb,3
SBRS r16,3
sbi portb,3
CASEND:
RETI

@ -0,0 +1,53 @@
.device attiny13
.def CNT=r25
.def LED=r24
.org 0x0000 ;zacatek kodu
RJMP RESET ;skok na start po resetu
.org 0x0010
RESET:
LDI r16,low(RAMEND) ;nastavi stack pointer
OUT SPL,r16
CLI ;zakazat vsechna preruseni
LDI LED,0
LDI r16,0b11111110 ;PB2 je vystupni, PB0 vstupni
OUT DDRB,r16
LDI r16,0 ;vypnout PullUp
OUT PORTB,r16
LOOP:
IN r16,PINB ;dej do r16 stav PINB
ANDI r16,0b00000001
CPI r16,1 ;neni-li to 1, jdi na STORNO
BRNE STORNO
INC CNT ;CNT+1
CPI CNT,50 ;neni-li CNT=100, jdi na LOOP
BRNE LOOP
IN r16,PORTB ;r16=PORTB (vystupni port)
LDI r17,0b00000100 ;vyxoruj r16 s 0b00000100
EOR r16,R17
OUT PORTB,R16 ;a vysledek dej na PORTB
KONEC:
IN r16,PINB ;cekani na vstup nuly do PINB0
ANDI r16,0b00000001
CPI r16,0
BRNE KONEC ;neni-li r16=0, jdi na KONEC
RJMP LOOP ;jdi na LOOP
STORNO:
LDI CNT,0 ;do CNT dej 0
RJMP LOOP ;jdi na LOOP

@ -0,0 +1,5 @@
# AVR Projects
This repository holds my AVR projects. They're mostly too small to be worth a separate repository.
Any code here is free to use in your projects, according to the MIT license.

@ -0,0 +1,437 @@
//Imitace casovane bomby, Ondrej Hruska (c) 2010-2012
//-------------------------------------------------
// Zapojeni:
// +------u------+
// reset --+ /RST Vcc +-- napajeni +5V
// Anoda jednotek --+ PD0 PB7 +-- segment D
// Anoda desitek --+ PD1 PB6 +-- sedment E
// (nezapojeno) --+ XT2 PB5 +-- segment C
// (nezapojeno) --+ XT1 PB4 +-- segment H
// drat --+ PD2 PB3 +-- segment G
// drat --+ PD3 PB2 +-- segment A
// drat --+ PD4 PB1 +-- segment F
// drat --+ PD5 PB0 +-- segment B
// GND --+ GND PD6 +-- output signal (vybuch)
// +-------------+
//
// Nazvy segmentu na displeji:
// ---A---
// | |
// F B
// | |
// ---G---
// | |
// E C
// | |
// ---D--- H
//
/*
Ports:
PORTB - segments
PD0 anode L
PD1 anode H
PD2 w0
PD3 w1
PD4 w2
PD5 w3
PD6 BOMB
PD7 -nc-
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
#include <stdlib.h>
#include <util/delay_basic.h>
#include <avr/eeprom.h>
#include <avr/sleep.h>
void updateDisplayBuffer();
void ports_init();
void timer_init();
void multiplex(uint8_t times);
void boom();
void halt();
void init_animation();
/*FUSES =
{
.low = 0xE4,
.high = 0xDF
};*/
/** initial number of intervals */
#define INIT_MINS 60
/** seconds in one interval */
#define INIT_MAX 60
/** seconds in one interval */
#define RAPID_MAX 8
/** seconds in one interval */
#define RAPID_COUNT 5
/* MACROS */
/** set one hertz interrupt */
#define timer_enable() TIMSK=(1<<OCIE1A)
/** disable timer interrupt */
#define timer_disable() TIMSK=0
// segments DEChGAFB
#define B (1<<0)
#define F (1<<1)
#define A (1<<2)
#define G (1<<3)
#define H (1<<4)
#define C (1<<5)
#define E (1<<6)
#define D (1<<7)
// anodes
#define AL 1
#define AH 0
// wires
#define W0 2
#define W1 3
#define W2 4
#define W3 5
//bomb pin
#define BM 6
// pin groups
#define WIRES ((1<<W0)|(1<<W1)|(1<<W2)|(1<<W3))
#define ANODES ((1<<AL)|(1<<AH))
#define BOMB (1<<BM)
#define SEGMENTS 0xFF
uint8_t num2seg[10]; // array for num -> 7seg translation
#define BLANK 0
/* VARIABLES */
uint8_t EEMEM wireset;
uint8_t volatile cnt; // time counter (countdown)
uint8_t volatile cnt_interval; // current interval counter in seconds
uint8_t volatile cnt_interval_max; // length of current interval in seconds
uint8_t disp_H; // display buffer - ones
uint8_t disp_L; // tens
uint8_t volatile wires;
uint8_t volatile last_wires;
uint8_t is_one_digit;
uint8_t wire_shutdown; //absolute mask
uint8_t wire_boom;
//remaining two are for RAPID COUNTDOWN (30 s)
/* INTERRUPT VECTORS */
/** one second interrupt */
ISR(TIMER1_COMPA_vect){
cnt_interval++;
if(!is_one_digit) disp_H ^= H;
disp_L ^= H;
if(cnt_interval >= cnt_interval_max){
cnt_interval=0;
cnt--;
//to tens and ones
updateDisplayBuffer();
}
//time over?
if(cnt==0){
boom();
}
}
/** MAIN */
int main()
{
cnt = INIT_MINS;
cnt_interval = 0;
cnt_interval_max = INIT_MAX;
is_one_digit = 0;
disp_H = 0;
disp_L = 0;
last_wires = WIRES;
num2seg[0] = A|B|C|D|E|F;
num2seg[1] = B|C;
num2seg[2] = A|B|G|E|D;
num2seg[3] = A|B|G|C|D;
num2seg[4] = F|G|B|C;
num2seg[5] = A|F|G|C|D;
num2seg[6] = A|C|D|E|F|G;
num2seg[7] = A|B|C;
num2seg[8] = A|B|C|D|E|F|G;
num2seg[9] = A|B|C|D|F|G;
timer_disable();
timer_init();
timer_reset();
ports_init();
init_animation();
last_wires = ~(PIND & WIRES);
//wire set
//read wireset number
uint8_t wireset_r = eeprom_read_byte((uint8_t*)&wireset);
//go to next one, reset if >11
wireset_r++;
if(wireset_r>=12) wireset_r=0;
//store new value
eeprom_write_byte((uint8_t*)&wireset,wireset_r);
//select wires for wireset
uint8_t ws_boom[12] = {(1<<W1), (1<<W0), (1<<W2), (1<<W0), (1<<W3), (1<<W0), (1<<W1), (1<<W1), (1<<W3), (1<<W2), (1<<W2), (1<<W3)};
uint8_t ws_shutdown[12] = {(1<<W0), (1<<W3), (1<<W1), (1<<W2), (1<<W2), (1<<W1), (1<<W3), (1<<W2), (1<<W1), (1<<W0), (1<<W3), (1<<W0)};
wire_boom = ws_boom[wireset_r];
wire_shutdown = ws_shutdown[wireset_r];
updateDisplayBuffer();
timer_enable();
sei();
uint8_t diff;
while(1){
multiplex(50);
//check wire
wires = ~(PIND & WIRES);
diff = wires ^ last_wires;
//wire changed
if(diff != 0){
//shutdown wire was connected last time
if( (last_wires & wire_shutdown) != 0 && (diff & wire_shutdown) != 0){
//shutdown wire!
halt();
exit(0);
}else if( (last_wires & wire_boom) != 0 && (diff & wire_boom) != 0){
//bomb launched!
boom();
exit(0);
}else{
//rapid
if(cnt_interval_max > RAPID_MAX){
cnt_interval_max = RAPID_MAX;
if(cnt>RAPID_COUNT){
cnt = RAPID_COUNT;
cnt_interval = 0;
timer_reset();
updateDisplayBuffer();
}
}
}
}
last_wires = wires;
}
cli();
return 0;
}
/** put corrent segments into display buffer (from cnt) */
void updateDisplayBuffer(){
div_t foo = div((int)cnt,10);
//keep decimal dots
disp_H = (disp_L & H) | num2seg[foo.quot];
disp_L = (disp_L & H) | num2seg[foo.rem];
if(foo.quot == 0){
disp_H = 0;
is_one_digit = 1;
}else{
is_one_digit = 0;
}
}
/** show display, repeat "times" x */
void multiplex(uint8_t times){
for(; times>0; times--){
PORTB = ~disp_L; // TENS segments; common anode, needs invert
PORTD &= ~ANODES; // reset anodes
PORTD |= (1<<AL); // turn TENS anode on
_delay_loop_1(255); // wait
PORTB = ~disp_H; // ONES segments; common anode, needs invert
PORTD &= ~ANODES; // reset anodes
PORTD |= (1<<AH); // turn ONES anode on
_delay_loop_1(255); // wait
}
PORTB = ~BLANK; //display off
}
void multiplex_pwm(uint8_t times, uint8_t delay){
for(; times>0; times--){
PORTB = ~disp_L; // TENS segments; common anode, needs invert
PORTD &= ~ANODES; // reset anodes
PORTD |= (1<<AL); // turn TENS anode on
_delay_loop_1(255-delay); // wait
PORTD &= ~(1<<AL);
_delay_loop_1(delay);
PORTB = ~disp_H; // ONES segments; common anode, needs invert
PORTD &= ~ANODES; // reset anodes
PORTD |= (1<<AH); // turn ONES anode on
_delay_loop_1(255-delay); // wait
PORTD &= ~(1<<AH);
_delay_loop_1(delay);
}
PORTB = ~BLANK; //display off
}
/** the boom */
void boom(){
cli();
PORTD |= BOMB; //activate bomb
PORTD &= ~WIRES; // turn off wire pullups
disp_H = 0b01010101;
disp_L = 0b10101010;
while(1){
disp_H ^= 0xff;
disp_L ^= 0xff;
longmpx();
}
// PORTD |= ANODES; // turn both anodes on
// PORTB = 0x00; // all segments on
// __asm__("cli");
exit(0);
}
/** the boom */
void halt(){
PORTD &= ~WIRES;
for(uint8_t volatile pause=0; pause < 0xff; pause++){
multiplex_pwm(40,pause);
}
//animation
PORTD = (1<<AL); // higher part
PORTB = ~H; // show one dot
timer_disable();
cli();
for(;;){}
exit(0);
}
/** set up ports */
void ports_init(){
DDRB = SEGMENTS; // segments to output
PORTB = SEGMENTS; // turned off (cathodes!)
DDRD = ANODES|BOMB; // set outputs
PORTD = WIRES; // enable wire pullups
}
/** set timer1 to one hertz */
void timer_init(){
TCCR1A = 0;
TCCR1B=(1<<WGM12)|(1<<CS12);
OCR1AH=0b01111010;
OCR1AL=0b00010010;
}
/** clear timer */
void timer_reset(){
TCNT0 = 0;
}
void longmpx(){
for(uint8_t i=2; i>0; i--){
multiplex(250);
}
}
/** animation on startup */
void init_animation(){
disp_H = BLANK;
disp_L = BLANK;
for(uint8_t i=0; i<10; i++){
disp_H ^= 0xff;
disp_L ^= 0xff;
longmpx();
}
disp_H = BLANK;
disp_L = BLANK;
_delay_loop_1(255);
}

@ -0,0 +1,74 @@
PRG = main
MCU_TARGET = attiny2313
OPTIMIZE = 2
LFUSE = 0xE4
HFUSE = 0xDF
DEFS =-std=gnu99 -funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums -ffreestanding --combine -fwhole-program -fno-inline-small-functions -fno-split-wide-types -fno-tree-scev-cprop -Wl,--relax,--gc-sections
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
OBJ = $(PRG).o
override CFLAGS = -g2 -Wall -O$(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)
# program: $(PRG).elf lst hex
#
all: $(PRG).elf lst eeprom
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
avr-size -C -d --mcu=$(MCU_TARGET) $(PRG).elf
lst: $(PRG).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
hex: $(PRG).hex lst
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
install: wflash wfuses
install_ee: weeprom
install_fl: wflash
install_fu: wfuses
wflash: $(PRG).hex
avrdude -P usb -c dragon_isp -p $(MCU_TARGET) -B 16 -U flash:w:$(PRG).hex
wfuses:
avrdude -P usb -c dragon_isp -p $(MCU_TARGET) -B 16 -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m
weeprom: ehex
avrdude -P usb -c dragon_isp -p $(MCU_TARGET) -B 16 -U lfuse:w:$(LFUSE):m -U eeprom:w:$(PRG)_eeprom.hex
ee: ehex
eeprom: ehex
ehex: $(PRG)_eeprom.hex
%_eeprom.hex: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
clean:
rm -f *.o $(PRG).elf *.hex *.lst *~
term:
avrdude -P usb -c dragon_isp -p $(MCU_TARGET) -B 16 -t

@ -0,0 +1,69 @@
PRG = main
MCU_TARGET = attiny13
OPTIMIZE = 2
HZ = 9600000UL
LFUSE = 0x7A
HFUSE = 0xFF
DEFS =-std=gnu99 -funsigned-char -funsigned-bitfields -ffunction-sections -fpack-struct -fshort-enums -ffreestanding -fwhole-program -fno-inline-small-functions -fno-split-wide-types -fno-tree-scev-cprop -Wl,--relax,--gc-sections
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
OBJ = $(PRG).o
override CFLAGS = -g2 -Wall -O$(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) -DF_CPU=$(HZ)
# program: $(PRG).elf lst hex
#
$(PRG).elf: $(OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
avr-size -C -d --mcu=$(MCU_TARGET) $(PRG).elf
lst: $(PRG).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
hex: $(PRG).hex lst
build: hex ehex
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
wflash: hex
sudo avrdude -P usb -c dragon_isp -p $(MCU_TARGET) -U flash:w:$(PRG).hex
wfuses:
sudo avrdude -P usb -c dragon_isp -p $(MCU_TARGET) -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m
weeprom: ehex
sudo avrdude -P usb -c dragon_isp -p $(MCU_TARGET) -U lfuse:w:$(LFUSE):m -U eeprom:w:$(PRG)_eeprom.hex
ee: ehex
eeprom: ehex
ehex: $(PRG)_eeprom.hex
%_eeprom.hex: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
clean:
rm -f *.o $(PRG).elf *.hex *.lst *~
term:
sudo avrdude -P usb -c dragon_isp -p $(MCU_TARGET) -t

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save