字體:小 中 大 | |
|
|
2014/11/14 12:37:20瀏覽528|回應0|推薦0 | |
因為要製作界面使用的關係,以及在一些舊機種沒支援快鍵的發報方式,所以就利用ATtiny13來寫一個界面來使用,原本是使用DL4YHF的電路來使用,但零件接腳太多,週邊的零件也多,較不實用. 電路圖如下: DOT , DASH 接到快鍵,RV1調整拍碼速度,輸出可接晶體或光藕合,夠簡單吧!! 程式動作: 開始 => 快鍵是否有動作 =否> 回開始 =是> 判斷按DOT =是> 輸出,並呼叫延時一週期 = =否> 輸出,並呼叫延時三週期 = 延時 讀AD值,決定延時長度. 程式碼如下: ; TINY13 ;PIN Pinout Project ; 1 PB5(PCINT5/ADC0/dW/RESET) ; 2 PB3(PCINT3/ADC3/CLKI) ; 3 PB4(PCINT4/ADC2) OUT ; 4 GND ==================== ; 5 PB0(PCINT0/AIN0/MOSI/OC0A) DOT ; 6 PB1(PCINT1/AIN1/MISO/OC0B/INT0) DASH ; 7 PB2(PCINC2/ADC1/SCK/T0) VR-SPEED ; 8 VCC ==================== .include "tn13def.inc" ;I/O .def temp =r16 .equ key2 = 0 ;PB .equ key3 = 1 ;PB .equ led = 4 ;PB ;------------------------------------------------------------ ;DELAY
delay_10ms:
cpi temp,$10 brsh d0 ldi temp,$10 mov r20,temp d0: ldi r21,$4 d2: ldi r22,0 d1: dec r22 ;1 * 0.1356 brne d1 ;0.5 * 0.1356 dec r21 brne d2 dec r20 brne d0 ret delay2: ldi r21,$02 d4: ldi r22,0 d3: dec r22 brne d3 dec r21 brne d4 ret ;------------------------------------------------------------------------------------- ;AD READ ;temp
;ADMUX: - REFS0 ADLAR - - - MUX1 MUX0 ad: ; 0 0 1 0 0 0 0 1 ldi temp,$61 ;Avcc,,ADC1 out ADMUX,temp ldi temp,$c6 ;ADCSRA: ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 out ADCSRA,temp ; 1 1 0 0 0 1 1 0 nop nop nop in temp,adch ret ;---------------------------------------------------------------------------- ;keyin INPUT C=1 ;R20 ,R21 ,R22 ;DATA = R22
;CHANGE C=1 ;R20 key_buff,temp keyin: clc in temp,pinb ori temp,0b11111100 cpi temp,$ff ; brne ke1 ;CHANGE to ke1 ret ke1: sec ret ;----------------------------------------------------------------------- ;************************************************** main: ;************* Program start ********************
;DOT = PB0(key2) DASH = PB1(key3) OUT = PB4(led) ldi temp,low(ramend) out spl,temp
ldi temp,0b11111100 out ddrb,temp ;set portB 765432 output ldi temp,0b00000011 ;set portB 01 PULL out portb,temp sbi portb,led start: rcall keyin brcs kin nop nop rjmp start kin: sbic pinb,key2 ;DOT(key2) rjmp dash ;DASH(key3) clc dot: cbi portb,led ;OUT rcall delay1 sbi portb,led ;OFF rcall delay1 sbic pinb,key3 ;DASH rjmp start dash: clc cbi portb,led rcall delay3 sbi portb,led rcall delay1 sbic pinb,key2 rjmp start rjmp dot
delay1: rcall ad mov r20,temp rcall delay_10ms ret delay3: rcall ad mov r20,temp rcall delay_10ms mov r20,temp rcall delay_10ms mov r20,temp rcall delay_10ms ret |
|
( 不分類|不分類 ) |