Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .include "m32def.inc"
  2. .org 0
  3.  ldi zh, high(ASCII_TABLE << 1) ;28 because we take the value of .org 20 which is 14hex shifted by 1 ==28HEX
  4.  ldi zl, low(ASCII_TABLE << 1)  ;28 and since high() and low() uses 16 bits we convert it 2 16bit format 00000000 00101000
  5.                                 ; so high() becomes 00000000 and low() becomes 00101000
  6.  
  7.  ldi r16, 0x0
  8.  out DDRC, r16  input  ;next we set ddrc as input 0-> 0x0
  9.  ldi r16, 0xff
  10.  out DDRD, r16  ;and ddrB as output -> 0xFF
  11. BEGIN:
  12.  in r16, PINC  ; now we take input from pinC and put it in register 16 (in this case 0)
  13.  andi r16, 0b00000111 ;mask upper 5 bits to allow only 3 bits for input we do this with ANDi
  14.  add zl, r16 ;now we the input of r16 into zl
  15.  lpm r17, z  ; here it gets tricky lpm loads the content of z into the register but we need to find either if we get
  16.              ;the least significant bit or most significant bit. since the value of Z is 00101000 which
  17.              ;is 0x28 which is stored in the memory adress
  18.              ;now we go find in the memory and take the 8 bits (LPM) and we find 30
  19.  out PORTD, r17
  20.  rjmp BEGIN
  21. .org 20
  22. ASCII_TABLE:
  23. A+C 5/5
  24.  .DB '0','1','2','3','4','5','6','7'
  25.  ;so the output is 30 ASCI 0 DEC
  26.   0b00000111
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement