Chip’s Internal Timer in ’Normal' mode will count from 0 to 255, set the overflow flag TOV0 to 0 and count again from 0 to 255, set the flag to 0 and so on.
As usual, I used LED as output indicator on Port B0
We used 1024 for pre-scaler/divider value. Set the TCCR0B to 0000 0101
Note that we have to reset the overflow flag to 1 after timer count reached 255 (and set the flag to 0).
Oh, by the way, the register/variable/things that count from 0 to 255 is called TCNT0. We didn’t touch it in the code this time, maybe next.
.include "../tn13Adef.inc"
.def a=r16
.org 0000
init:
sbi ddrb,0 ; pin b0 output
ldi a,0b00000101 ; prescaler 1024
out TCCR0B,a
main:
sbi pinb,0 ; flip the B0 bit
rcall timer
rjmp main
timer:
loop:
in a,TIFR0 ; wait
andi a, 0b00000010 ; (1<<TOV0) is TOV0 still 1 or flagged to 0?
breq loop
ldi a, 0b00000010 ; set TOV0 to 1 again after flagged
out TIFR0,a
ret
Last login: Thu May 28 11:54:47 on ttys001
Nugrohos-MacBook-Air:~ nugroho$ cd attiny13a/timer/
Nugrohos-MacBook-Air:timer nugroho$ avra -o timerNormal.hex timerNormal.s
AVRA: advanced AVR macro assembler Version 1.3.0 Build 1 (8 May 2010)
Copyright (C) 1998-2010. Check out README file for more info
AVRA is an open source assembler for Atmel AVR microcontroller family
It can be used as a replacement of 'AVRASM32.EXE' the original assembler
shipped with AVR Studio. We do not guarantee full compatibility for avra.
AVRA comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of avra under the terms
of the GNU General Public License.
For more information about these matters, see the files named COPYING.
Pass 1...
Pass 2...
done
Used memory blocks:
Code : Start = 0x0000, End = 0x000B, Length = 0x000C
Assembly complete with no errors.
Segment usage:
Code : 12 words (24 bytes)
Data : 0 bytes
EEPROM : 0 bytes
Nugrohos-MacBook-Air:timer nugroho$ vavrdisasm timerNormal.s.hex
0: 9a b8 sbi $17, 0
2: e0 05 ldi R16, 0x05
4: bf 03 out $33, R16
6: 9a b0 sbi $16, 0
8: d0 01 rcall .+2 ; 0xc
a: cf fd rjmp .-6 ; 0x6
c: b7 08 in R16, 0x38
e: 70 02 andi R16, 0x02
10: f3 e9 breq .-6 ; 0xc
12: e0 02 ldi R16, 0x02
14: bf 08 out $38, R16
16: 95 08 ret
Nugrohos-MacBook-Air:timer nugroho$
Nugrohos-MacBook-Air:timer nugroho$ avrdude -p t13 -P usb -c usbasp -B4 -n
avrdude: set SCK frequency to 187500 Hz
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9007
avrdude: safemode: Fuses OK (H:FF, E:FF, L:6A)
avrdude done. Thank you.
Nugrohos-MacBook-Air:timer nugroho$ avrdude -p t13 -P usb -c usbasp -B4 -U flash:w:timerNormal.s.hex
avrdude: set SCK frequency to 187500 Hz
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9007
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: set SCK frequency to 187500 Hz
avrdude: reading input file "timerNormal.s.hex"
avrdude: input file timerNormal.s.hex auto detected as Intel Hex
avrdude: writing flash (24 bytes):
Writing | ################################################## | 100% 0.02s
avrdude: 24 bytes of flash written
avrdude: verifying flash memory against timerNormal.s.hex:
avrdude: load data flash data from input file timerNormal.s.hex:
avrdude: input file timerNormal.s.hex auto detected as Intel Hex
avrdude: input file timerNormal.s.hex contains 24 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.01s
avrdude: verifying ...
avrdude: 24 bytes of flash verified
avrdude: safemode: Fuses OK (H:FF, E:FF, L:6A)
avrdude done. Thank you.
Nugrohos-MacBook-Air:timer nugroho$
No comments:
Post a Comment