Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  2. ; 1DT301, Computer Technology I
  3. ; Date: 2017-09-289
  4. ; Author:
  5. ; Christian Fagerholm
  6. ; Amelie Löwe
  7. ;
  8. ; Lab number: 4
  9. ; Title: How to use the PORTs. Digital input/output. Subroutine call.
  10. ;
  11. ; Hardware: STK600, CPU ATmega2560
  12. ;
  13. ; Function: Sending characters from keyboard to the STK600
  14. ;
  15. ;
  16. ; Input ports: None
  17. ;
  18. ; Output ports: on-board LEDs connected to PORTB.
  19. ;
  20. ;
  21. ; Subroutines: If applicable.
  22. ; Included files: m2560def.inc
  23. ;
  24. ; Other information:
  25. ;
  26. ; Changes in program: (Description and date)
  27. ;
  28. ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  29. .include "m2560def.inc"
  30. .def temp = r17
  31. .def char = r16
  32. .equ ubbrval = 12
  33.  
  34. .org 0x00
  35. rjmp start
  36.  
  37. .org 0x30
  38. setup:
  39.  
  40. ldi temp, 0xFF
  41. out DDRB, temp ; Ports for output
  42.  
  43. ldi temp, 0x55
  44. out PORTB, temp
  45.  
  46. ldi temp, ubbrval ; store prescaler value
  47. sts UBRR1l, temp
  48.  
  49. ldi temp, (1<<TXEN1) | (1<<RXEN1)
  50. sts UCSR1B, temp ; setting TX and RX flags enabled
  51.  
  52.  
  53. start:
  54. lds temp, UCSR1A ; read input
  55. sbrs temp, RXC1 ; RXC1 = 1 => new character
  56. rjmp start ; RXC1 = 0 => no character
  57. lds char, UDR1 ;Read character in UDR
  58.  
  59. output:
  60. com char
  61. out PORTB, char
  62. com char
  63.  
  64. putChar:
  65.  
  66. lds temp, UCSR1A
  67. sbrs temp, UDRE1 ;UDRE1=1 == buffer empty
  68. rjmp putChar ;UDRE1=0 ==buffer not empty
  69. sts UDR1, char ;write character to UDR
  70. rjmp start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement