Advertisement
deaphroat

MOD21 ASM

Jan 21st, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .include "2323def.inc"
  2. ;.include "1200def.inc"
  3.  
  4. ;***** Pin definitions
  5.  
  6. .equ    DataInject  =0         ;Serial Transmit Pin PB0
  7. .equ    DataBlock   =1          ;Blocker pin is PB1
  8.  
  9. ;***** Global register variables
  10.  
  11. .def    bitcnt  =R16            ;bit counter
  12. .def    temp    =R17            ;temporary storage register
  13. .def    clock   =R18            ;temporary storage register
  14.  
  15.  
  16. .def    TXbyte  =R19            ;Data to be transmitted
  17. .def    Delay1  =R20
  18. .def    Delay2  =R21
  19. .def    CharCount=R22           ;Line Index
  20.  
  21. .cseg
  22. .org 0
  23. ;*INTERRUPT JUMP TABLE
  24.  
  25.         rjmp   reset  ;Reset
  26. ;       reti          ;IRQ handle
  27. ;       reti          ;Timer0
  28.        
  29.  
  30. ;***** Program Execution Starts Here
  31.  
  32. reset:
  33.  
  34.         ldi temp,low(RAMEND)
  35.     out SPL,temp
  36.  
  37.     sbi ddrb,PB0    ;pin PB0--> push_pull output
  38. ;   sbi ddrb,PB1    ;pin PB1--> push_pull output
  39. ;************************************************************************
  40. ;   sbi ddrb,PB4         ;Port PB4 (pin 3) output to check palse width
  41. ;************************************************************************
  42.     cbi PORTB,PB0
  43.     cbi PORTB,PB1   ;pin PB0--> push_pull output
  44.  
  45.     ldi clock,25   
  46.     sbis    PINB,PB4
  47.     ldi clock,56
  48.    
  49.  
  50. ;*************************************************************
  51.  
  52. DemoLoop:
  53.  
  54.                 Ldi Delay2,50
  55.                 Rcall Delay_Xms         ;Το πρώτο delay 50ms
  56.             sbi ddrb,PB0    ;pin PB0--> push_pull output
  57.    
  58.  
  59.                                            ;Το 2ο Delay είναι 850 ms (3*255)+85
  60.                 Ldi Delay2,255
  61.                 Rcall Delay_Xms
  62.  
  63.                 Ldi Delay2,255
  64.                 Rcall Delay_Xms
  65.  
  66.                 Ldi Delay2,255
  67.                 Rcall Delay_Xms
  68.  
  69.  
  70.                 Ldi Delay2,85
  71.                 Rcall Delay_Xms
  72.  
  73.             sbi ddrb,PB1    ;pin PB0--> Low
  74.  
  75.  
  76.                 Ldi Delay2,255           ;Το 3ο Delay είναι 314 ms (255+59)
  77.                 Rcall Delay_Xms
  78.  
  79.                 Ldi Delay2,59
  80.                 Rcall Delay_Xms
  81.  
  82.  
  83. ConstLoop:
  84.  
  85. ;                Ldi Delay2,100
  86. ;                Rcall Delay_Xms
  87.  
  88.  
  89. ;***********************************************************
  90. ;This line is for test perposes only
  91. ;                sbi PortB,PB4
  92. ;***********************************************************
  93.  
  94.  
  95.                 Rcall SendLine
  96.  
  97. ;                Ldi Delay2,100
  98. ;                Rcall Delay_Xms
  99.  
  100.  
  101. ;***********************************************************
  102. ;This line is for test perposes only
  103. ;                cbi PortB,PB4
  104. ;***********************************************************
  105.  
  106.        
  107.  
  108.  
  109.                 Rjmp ConstLoop
  110.  
  111.    
  112.        
  113.    
  114.  
  115. ;***************************************************************
  116.  
  117.  
  118. SendLine :
  119.  
  120.  
  121.  
  122.                Ldi ZL,Low(OutData*2)    ;Ο Ζ δείχνει στην αρχή των data
  123.                Ldi ZH,High(OutData*2)
  124.  
  125.  
  126. SendLine_InitDelay:
  127.  
  128.  
  129.                Ldi Delay2,72           ;Αρχικό delay 72 ms
  130.  
  131.  
  132.                Rcall Delay_Xms
  133.  
  134.  
  135.  
  136.                Ldi CharCount,0          ;Μηδενίζουμε και τον μετρητή χαρακτήρων  
  137.  
  138. SendLine_Loop:
  139.  
  140.                Lpm                     ;Φορτώνουμε τα περιεχόμενα της δν/σης
  141.                                        ;που δείχνει ο Ζ στην Flash στον R0              
  142.  
  143.                Mov TxByte,R0           ;κάνουμε copy τον R0 στον buffer
  144. ;               Ldi TxByte,$53
  145.                Cpi Txbyte,0            ;ελέγχουμε αν φτάσαμε στο τέλος
  146.                Breq SendLine_End       ;ναι
  147.  
  148.                Rcall Putchar           ;και τον στέλνουμε
  149.                
  150.                Inc ZL
  151.                Inc CharCount
  152.  
  153.                Cpi CharCount,4        ;Ελέγχουμε αν στείλαμε μια λέξη
  154.  
  155.                Breq SendLine_InitDelay ;αν ναι τότε delay 72ms
  156.                Rjmp SendLine_Loop      ;αλλιώς στέλνουμε τον επόμενο χαρακτήρα
  157.  
  158. SendLine_End:
  159.                Ret                     ;Τελειώσαμε
  160.  
  161.  
  162. ;**************************************************************************
  163.  
  164. Putchar:
  165.  
  166.     ldi bitcnt,9    ;1+8  StartBit +Databits
  167. ;       com Txbyte      ;Inverte everything
  168. ;       sec         ;Start bit
  169.                 clc
  170.  
  171. putchar0:   brcc    putchar1    ;If carry set
  172.             sbi ddrb,PB1    ;PB1--> Low
  173.  
  174.         rjmp    putchar2    ;else  
  175.  
  176. putchar1:   cbi DDRB,PB1    ;    send a '1'
  177.         nop
  178.  
  179. putchar2:   Ldi Delay2,4
  180.         rcall Delay_Xms
  181.  
  182.         lsr Txbyte      ;Get next bit
  183.         dec bitcnt      ;If not all bit sent
  184.         brne    putchar0    ;   send next
  185.                     ;else
  186.  
  187.  
  188.             sbi ddrb,PB1    ;pin PB1--> low
  189.                 Ldi Delay2,8
  190.                 Rcall Delay_Xms
  191.  
  192.  
  193.  
  194.  
  195.         ret         ;   return
  196.  
  197. ;************************************************
  198.  
  199.  
  200.  
  201. Delay_Xms :
  202.              
  203.              
  204. Delay_XmsLoop:
  205. ;             Rcall Delay_1000Cycles  ;1ms Delay at 1Mhz clock
  206.  
  207.  
  208. Delay_1000Cycles:
  209.              Mov Delay1,Clock
  210.              Rcall CycleDelay10
  211.          Rcall CycleDelay10
  212.  
  213. Delay_1000Loop:
  214.              Rcall CycleDelay10
  215.              Dec Delay1
  216.              nop
  217.          nop
  218.              nop   
  219.              nop
  220.              nop
  221.              nop
  222.              nop
  223.              Brne Delay_1000Loop
  224.              
  225.  
  226.  
  227.              Dec Delay2
  228.              Brne Delay_XmsLoop              
  229.              Ret
  230.  
  231.  
  232.  
  233.  
  234. ;Delay_1000Cycles:
  235. ;             Ldi Delay1,49
  236. ;             Rcall CycleDelay10
  237. ;             nop
  238. ;             nop
  239. ;             nop
  240.  
  241. ;Delay_1000Loop:
  242. ;             Rcall CycleDelay10
  243. ;             Dec Delay1
  244. ;             nop
  245. ;         nop
  246. ;             nop  
  247. ;             nop
  248. ;             nop
  249. ;             nop
  250. ;             nop
  251. ;             Brne Delay_1000Loop
  252. ;             Ret
  253.  
  254.  
  255.  
  256. CycleDelay10:
  257.              nop
  258.              nop
  259.              nop
  260.              Ret            ;4 cycles
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269. ;**************************************************************
  270. Delay_50ms :
  271.              Ldi Delay2,49
  272.  
  273. Delay_50msLoop:
  274.              Rcall Delay_1000Cycles  ;1ms Delay at 1Mhz clock
  275.              Dec Delay2
  276.              Brne Delay_50msLoop   ;49000
  277.  
  278.              Ldi Delay2,65
  279.  
  280. Delay_50msLoop2:
  281.  
  282.              Rcall CycleDelay10
  283.              Dec Delay2
  284.              Brne Delay_50msLoop2
  285.              nop
  286.  
  287.              Ret
  288.  
  289.  
  290. OutData : .DB "S","C","E","A","S","C","E","I","S","C","E","E",$00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement