понеделник, 10 ноември 2014 г.

First project with microcontroller - Relay control

Relay controlled by microcontroller

This is my first project with microcontroller. 

 

Relay is connected on pin PORTB4 (PB4)
and controlled by switch on pin PORTD0 (PD0)





Source code

.include "8515def.inc"

RESET:
    ser    r16
    out    DDRB,r16

    ldi r16,low(RAMEND)
    out SPL,r16
    ldi r16,high(RAMEND)
    out SPH,r16

    clr r16

LOOP:
    sbic PIND,0
    rjmp LOOP
    ldi     r16,0b00010000
    out PORTB,r16

LOOP1:
    sbis PIND,0
    rjmp LOOP1
    rjmp LOOP2

LOOP2:
    sbic PIND,0
    rjmp LOOP2
    clr r16
    out PORTB,r16

LOOP3:             
    sbis PIND,0x00
    rjmp LOOP3
    rjmp LOOP


Formule for LED Resistor

U = 5V
U forward led = 2V
I led = 12.5mA

I=U/R =>
R = U/I =>
R = (U - U forward led) / I led => R = (5-2) / 0.0125 => 240 ohm
R4 LED = 240 Ohm

Няма коментари:

Публикуване на коментар