Guest User

Untitled

a guest
Jan 15th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .include "tn2313def.inc"
  2.  
  3. ; IS A HINT TO GET STARTED WITH THE TEMP SENSOR...
  4.  
  5. ; NOTE: The ATTINY is set to 1MHZ.
  6. ; You should look at the sample loop. If we run flat out
  7. ; How many samples of the input signal do we get at if
  8. ; Each single cycle instruction takes 1uS
  9. ; You need to count the following instructions...
  10. ;
  11. ;
  12. ;
  13.  
  14.  
  15. ; Variable Allocations
  16.     .def temp = R16
  17.     .def mask = R19
  18.     .def tmpc = R20
  19.  
  20. ; zeros in [XH:XL]
  21. ; ones in [YH;YL]
  22. ; Total in [ZH,ZL]
  23.  
  24. ;********* INIT
  25. ; WARNING:: This overlaps the IVT
  26. start:  ldi mask,0b11110111 ; [UUUUIOOO]
  27.         out DDRB,mask ; port B set up
  28.         ldi mask,0b11111111 ; [UUOOOOUU]
  29.         out DDRD,mask ; port D set up
  30.         ldi mask,0b00001000 ; [UUOOOOUU]
  31.         out PORTB,mask ; port D set up
  32.  
  33.  
  34.  
  35. ;******** STATE0
  36. state0: ldi XH,0x00 ; ones <-- 1*25
  37.         ldi XL,0x19
  38.  
  39.         ldi YH,0x00 ; zeros <-- 1
  40.         ldi YL,0x01
  41.  
  42.  
  43. whl00:  in temp,PINB ; block until 1
  44.         ldi mask,0b00001000
  45.         and temp,mask
  46.         breq whl00
  47.  
  48.  
  49. ;******** STATE1 :: COUNT THE NUMBER OF ONES
  50.  
  51. whl10:  adiw XL,0x0019 ; ONES <- ONES + 25 (Ones * 25)
  52.         ldi temp,10
  53.         d10: nop
  54.         dec temp
  55.         brne d10
  56.         in temp,PINB ; block until 0
  57.         ldi mask,0b00001000
  58.         and temp,mask
  59.         brne whl10
  60. ;******** STATE2 :: COUNT THE NUMBER OF ZER0S
  61.  
  62. whl01:  adiw YL,0x0001 ; zeros <- zeros + 1
  63.         ldi temp,10
  64.         d01: nop
  65.         dec temp
  66.         brne d01
  67.         in temp,PINB ; block until 1
  68.         ldi mask,0b00001000
  69.         and temp,mask
  70.         breq whl01
  71.  
  72. ;********* STATE 3 :: DISPLAY THE TEMP
  73. ; Shift down YL (the number of zeros/16)
  74. ;
  75.         clc
  76.         ror YH
  77.         ror YL
  78.  
  79.         clc
  80.         ror YH
  81.         ror YL
  82.  
  83.         clc
  84.         ror YH
  85.         ror YL
  86.        
  87.         clc
  88.         ror YH
  89.         ror YL
  90.  
  91. ; Now loop until Z equals [XH,XL
  92.     clr ZL
  93.     clr ZH
  94.  
  95.     ldi tmpc,235
  96.  
  97. RES:    add ZL,YL
  98.         adc ZH,YH
  99.         dec tmpc
  100.  
  101.         cp ZH,XH
  102.         brlo RES
  103.         cp ZL,XL
  104.         brlo RES
  105.  
  106.  
  107. ; Toggle PB0 and PB1
  108.  
  109.  
  110.         mov temp,tmpc ; HERE WE SIMPLE DUMP YL to PORTB
  111.         lsr temp
  112.         lsr temp
  113.         lsr temp
  114.         lsr temp
  115.         com temp
  116.         ori temp,0b00001000 ; make sure the pull up is on
  117.         out PORTB,temp
  118.    
  119.         mov temp,tmpc ; Dump YL to PORTD
  120.         lsl temp
  121.         lsl temp
  122.         com temp
  123.         out PORTD,temp
  124.  
  125. ;********* STATE 4 :: WAIT FOR A ZERO
  126. whl11:  in temp,PINB ; block until 0
  127.         ldi mask,0b00001000
  128.         and temp,mask
  129.         brne whl11
  130.  
  131.         rjmp state0
  132. ; End of program
Add Comment
Please, Sign In to add comment