Labs‘Codes review(AVR)(2)

1.Write an AVR program to n read the value on port A pins n flip (invert) all the bits n write the value out to port C n do this repeatedly

.include "m324Adef.inc"
  jmp reset
RESET:
 ldi r16,0x00;
 out DDRA,r16
 ldi r16,0xFF;
 out DDRC,r16;
loop:
 in r16,PINA;
 com r16;
 out PORTC,r16;
rjmp loop

2.Modify your program to output the two’s complement (negative) of the input, rather than the ones’ complement (inversion). Build, download and test it.

.include "m324Adef.inc"
 jmp reset
RESET:
 ldi r16,0x00;
 out DDRA,r16;
 ldi r16,0xFF;
 out DDRC,r16;
loop:
 in r16,PINA;
 neg r16;
 out PORTC,r16;
jmp loop

3.Write an AVR assembly language program to repeatedly n Read the value on port A pins (8 bits) n Read the value on port D pins (8 bits) l Set the upper 4 bits of this value (read from port D) to 0 (consider bitwise AND to do this) l Add the two values and output the result to port C l Make sure you set the data direction registers appropriately. l Connect 8 switches on the IO Board to AVR port A; and 8 LEDs to AVR port C; and connect the 4 push buttons on the IO Board to AVR port D (4 least significant bits)

.include "m324Adef.inc"
  jmp reset
reset:
  ldi r16,0x00;
  out DDRA,r16;
  out DDRD,r16;
  ldi r16,0xFF;
  out DDRC,r16;
loop:
  in r16,DDRA;
  in r17,DDRD;
  Andi r17,0x0F;
  add r16,r17;
  out DDRC,r16;
jmp loop

你可能感兴趣的:(学习)