Wednesday 9 October 2013

AVR signalling the NXP

The NXP code is pretty basic

#include "mbed.h"

DigitalOut led(LED1);
DigitalIn DATA(p23);

int main() {
    
    while(1) {
        led.write(0);
        while(DATA);
        led.write(1);
        while(!DATA);
    }
}

The AVR code was a bit trickier as it uses the timer interrupt. Took me a while to get my head round it

.include "TN13DEF.INC"

.org 0000   ;  reset interrupt vector
  rjmp on_reset

.org 0012   ;  timer0 overflow interrupt vector
  rjmp tim0_overflow

on_reset:
  ser r16
  out ddrb, r16 ; set the pin I/O

  ldi r16, 0b_0000_0101 ; set the clock multiplier
  out tccr0b, r16

  ldi r16, 0b_0000_010 ; turn the timer on
  out timsk0, r16

  sei ; turn on interrupts

main:
  nop ; I walk and walk, do nothing 
  rjmp main

tim0_overflow:
  ; negate portb
  in r17, portb
  com r17
  out portb, r17
  reti

No comments:

Post a Comment