Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .include "tn2313def.inc"
- ; IS A HINT TO GET STARTED WITH THE TEMP SENSOR...
- ; NOTE: The ATTINY is set to 1MHZ.
- ; You should look at the sample loop. If we run flat out
- ; How many samples of the input signal do we get at if
- ; Each single cycle instruction takes 1uS
- ; You need to count the following instructions...
- ;
- ;
- ;
- ; Variable Allocations
- .def temp = R16
- .def mask = R19
- .def tmpc = R20
- ; zeros in [XH:XL]
- ; ones in [YH;YL]
- ; Total in [ZH,ZL]
- ;********* INIT
- ; WARNING:: This overlaps the IVT
- start: ldi mask,0b11110111 ; [UUUUIOOO]
- out DDRB,mask ; port B set up
- ldi mask,0b11111111 ; [UUOOOOUU]
- out DDRD,mask ; port D set up
- ldi mask,0b00001000 ; [UUOOOOUU]
- out PORTB,mask ; port D set up
- ;******** STATE0
- state0: ldi XH,0x00 ; ones <-- 1*25
- ldi XL,0x19
- ldi YH,0x00 ; zeros <-- 1
- ldi YL,0x01
- whl00: in temp,PINB ; block until 1
- ldi mask,0b00001000
- and temp,mask
- breq whl00
- ;******** STATE1 :: COUNT THE NUMBER OF ONES
- whl10: adiw XL,0x0019 ; ONES <- ONES + 25 (Ones * 25)
- ldi temp,10
- d10: nop
- dec temp
- brne d10
- in temp,PINB ; block until 0
- ldi mask,0b00001000
- and temp,mask
- brne whl10
- ;******** STATE2 :: COUNT THE NUMBER OF ZER0S
- whl01: adiw YL,0x0001 ; zeros <- zeros + 1
- ldi temp,10
- d01: nop
- dec temp
- brne d01
- in temp,PINB ; block until 1
- ldi mask,0b00001000
- and temp,mask
- breq whl01
- ;********* STATE 3 :: DISPLAY THE TEMP
- ; Shift down YL (the number of zeros/16)
- ;
- clc
- ror YH
- ror YL
- clc
- ror YH
- ror YL
- clc
- ror YH
- ror YL
- clc
- ror YH
- ror YL
- ; Now loop until Z equals [XH,XL
- clr ZL
- clr ZH
- ldi tmpc,235
- RES: add ZL,YL
- adc ZH,YH
- dec tmpc
- cp ZH,XH
- brlo RES
- cp ZL,XL
- brlo RES
- ; Toggle PB0 and PB1
- mov temp,tmpc ; HERE WE SIMPLE DUMP YL to PORTB
- lsr temp
- lsr temp
- lsr temp
- lsr temp
- com temp
- ori temp,0b00001000 ; make sure the pull up is on
- out PORTB,temp
- mov temp,tmpc ; Dump YL to PORTD
- lsl temp
- lsl temp
- com temp
- out PORTD,temp
- ;********* STATE 4 :: WAIT FOR A ZERO
- whl11: in temp,PINB ; block until 0
- ldi mask,0b00001000
- and temp,mask
- brne whl11
- rjmp state0
- ; End of program
Add Comment
Please, Sign In to add comment