.include "tn45def.inc" ; This program generates morse code on keyout (active low) ; in response to switch closures on keyin which is also ; echoed to keyout. Keying speed is controled by pi. ; ; ATtiny45 ; --v-- ; rst pb5 -| |- vcc ; pi pb3 -| |- pb2 sck ; po pb4 -| |- pb1 miso keyin -----O--->O--- gnd ; gnd -| |- pb0 mosi keyout --+-UUUUUU--- vcc ; ----- +---|<----- gnd ; 8Mhz ; ; (c) 2006 Ward Cunningham ; Released under GPL v2 or higher .set keyout =pb0 .set keyin =pb1 .def a =r17 .def b =r18 .def c =r19 .def char =r20 .include "bynase2.inc" ; uses r12-r16 reset: ldi a,$9e out osccal,a sbi ddrb,keyout loop: ldi zl,low(ascii*2) ldi zh,high(ascii*2) rcall text rjmp loop text: lpm char,z+ cpi char,0 breq tex1 push zl push zh rcall send pop zh pop zl rjmp text tex1: ret send: mov zl,char subi zl,'a' brmi sen2 subi zl,low(-(morse*2)) ldi zh,0 sbci zh,high(-(morse*2)) lpm char,z ; 3 ticks for fetch rjmp code sen2: ldi char,0b10000000 code: lsl char brne cod0 rcall tick ; letter space rcall tick ret cod0: cbi portb,keyout brcc cod1 rcall tick ; dah rcall tick cod1: rcall tick ; dit sbi portb,keyout rcall tick ; element space rjmp code tick: mov c,byin ; use pi com c lsr c subi c,-40 tic0: rcall byop ; get pi ldi b,7 tic1: dec a brne tic1 dec b brne tic1 dec c brne tic0 ret ascii: .db "now is the time for all good men to come to the aid of their country " .db "the quick brown fox jumped over the lazy dogs back ",0 morse: .db 0b01100000,0b10001000,0b10101000,0b10010000 .db 0b01000000,0b00101000,0b11010000,0b00001000 .db 0b00100000,0b01111000,0b10110000,0b01001000 .db 0b11100000,0b10100000,0b11110000,0b01101000 .db 0b11011000,0b01010000,0b00010000,0b11000000 .db 0b00110000,0b00011000,0b01110000,0b10011000 .db 0b10111000,0b11001000