?? tailb.asm
字號:
.file "tailA.asm"
;;
;; ATmega8 taillight circuit
;;
;; Last edited: 12-7-2004
;; Base on 'tailA.c'
;; Purpose: An assembly to strobe the LEDsvia Port D.
;; The strobe rate is to be set by adjusting the voltage
;; drop over a potentiometer that is sampled by an ADC
;;
;; A compared C code is followed by "--> " and before the assembly
;; List of all registers are defined in this code
;;------------------------------------------------;;
;; R18 --- 0xFF ---> DDRD
;; R19 --- ADCH & OCR1AL
;; R20 --- ADCH & OCR1AH
;; R21 --- TIFR
;; R22 --- ADMUX
;; R23 --- ADCSRA
;; R25 --- Pattern
;; R26 --- 0x00 ---> TCCR1A
;; R27 --- TCCR1B
;;------------------------------------------------;;
;; Access the register and register bit definitions
.include "avr-mega8.asm"
;; The variable 'pattern' is kept in register 25
;; Bit set means LED on (complemented before output)
;; --> unsigned char pattern = 0x00;
LDI R25,0x00 ;;Load immediate
;; Set up ADMUX
;; --> ADMUX = (1 << REFS0) | (1 << ADLAR);
LDI R22,0x60 ;;Load immediate
OUT ADMUX,R22 ;;Out to I/O location
;; Set up ADCSRA
;; --> ADCSRA = (1 << ADEN) | 0x07;
LDI R23,0x87 ;;Load immediate
OUT ADCSRA,R23 ;;Out to I/O location
;; Set up timer 1A control registers
;; --> TCCR1A = 0;
LDI R26,0x00 ;;Load immediate
OUT TCCR1A,R26 ;;Out to I/O location
;; Set up timer 1C : divide by 256 prescaler using OCR1A
;; Frequency of operation is about 61 Hz
;; --> TCCR1B = 0x0B;
LDI R27, 0x0C ;;Load immediate
OUT TCCR1B,R27 ;;Out to I/O location
;; Set up Port D for OUTput
;; --> DDRD = 0xFF;
SER R18 ;;Set all Bits in Register
OUT DDRD, R18 ;;Out to I/O location
loop:
;; Update LEDs
;; --> PORTD = pattern;
COM R25 ;;One's complement
OUT PORTD,R25 ;;Out to I/O location
;; Set up ADCSRA start a conversion
;; --> ADCSRA |= (1 << ADSC);
SBI ADCSRA,6 ;;Set Bit in I/O Register
;; Update OCR1A from ADC
;; OCR1AH is 0x2B
;; --> OCR1AH = (ADCH >> 4);
IN R20,ADCH ;;In from I/O location
SWAP R20 ;;Swap Nibbles
ANDI R20,0x0F ;;Logical AND with Immediate
OUT 0x2B,R20 ;;Out to I/O location
;; OCR1AA is 0x2A
;; --> OCR1AL = (0x01 | ADCH) << 4;
IN R19,ADCH ;;In from I/O location
ORI R19,0x0F ;;Logical OR with Immediate
SWAP R19 ;;Swap Nibbles
ANDI R19,0xF0 ;;Logical AND with Immediate
OUT 0x2A,R19 ;;Out to I/O location
checktime:
;; Test OCF1A flag in TIFR
;; --> while (!(TIFR & (1 << OCF1A)));
IN R21,TIFR ;;In from I/O location
ANDI R21,0x10 ;;Logical AND with Immediate
BREQ checktime ;;Branch if Equal
;; OCF1A flag bit is set, so reset it (write 1 to it)
;; --> TIFR |= (1 << OCF1A);
ORI R21, 0x10 ;;Logical OR with Immediate
OUT TIFR, R21 ;;Out to I/O location
;; Continue forever
RJMP loop ;;Relative jump
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -