• Revista PROGRAMAR: Já está disponível a edição #53 da revista programar. Faz já o download aqui!

Junior_rdm

Led's RGB com PWM PIC

3 mensagens neste tópico

[move]Led's RGB com PWM PIC[/move]

Este foi um pequeno  projecto que encontrei na net.

Simulei no proteus e funcionou..

=D

Algumas imagens:

45171536.jpg

################################

122.JPG

################################

width=750 height=465http://www.uploaddeimagens.com.br/imagem/ver/663.JPG[/img]

################################

width=750 height=562http://www.uploaddeimagens.com.br//imagem/ver/31072009493.jpg[/img]

################################

Video:

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Não queres partilhar connosco o código que usaste no PIC?

Sem mais,

Pessanha24

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Não queres partilhar connosco o código que usaste no PIC?

Sem mais,

Pessanha24

Aki Tá O HEX:

http://www.baixa.la/arquivo/6135349

Codigo fonte em JAL(http://pic.flappie.nl/):

--        file    : ikea_mood_lamp.jal

--      author    : Junior

--        date    : 21 August 2008

--      purpose    : mood lamp program

--      contact    :junior_rdm_@hotmail.com

--      website    : http://www.portugal-a-programar.org

--

-- Copyright © 2006 Toon Beerten

-- Free for non-commercial use

-- This software must be purchased if it is to be used in commercial endeavors,

-- but may be used free-of-charge for other purposes.

include 16f628_4

include jpic

include jlib

include jpwm3    -- custom pwm library

include jdelay

include jrtl      -- jrtl = operators

include random3   -- random library

-- i use IntRC I/O, PWRT ON, BODEN ON, rest off

-- tick MCLR off when programming!!!!

var byte time = 1

var byte R = 255

var byte G = 1

var byte B = 1

var bit pause = false

option = option & 0x7f

disable_a_d_functions

-- disable_ad_inputs

pin_a0_direction = output

pin_a6_direction = input  -- controls pause

pin_a2_direction = input  -- random function

pin_a3_direction = output

pin_a4_direction = output

pin_a5_direction = output

pin_a1_direction = input  -- controls transition

pin_a7_direction = input  -- controls speed

pin_b0_direction = output

pin_b1_direction = output

pin_b2_direction = output

pin_b3_direction = output

pin_b4_direction = output

pin_b5_direction = output

pin_b6_direction = output

pin_b7_direction = output

-- randomize

randomize(34)

-- procedures

procedure speed is    -- controls speed

if pin_a7 == high then

  time = 50

else

  time = 5

end if

end procedure

procedure flash is    -- program to abruptly switch to another color

  var byte RR

  var byte GG

  var byte BB

  if pin_a2 == high then

  RR = random_byte

  GG = random_byte

  BB = random_byte

  else

  RR = 255

  GG = 1

  BB = 1

  end if

  For 254 loop

  speed

  if pin_a1 == low then

    return

  end if

    PWM_OUT(RR,GG,BB, time)

  end loop

 

  while pin_a6 == high loop

  PWM_OUT(RR,GG,BB, time)

  end loop

  if pin_a2 == high then

  RR = random_byte

  GG = random_byte

  BB = random_byte

  else

  RR = 255

  GG = 255

  BB = 1

  end if

 

  For 254 loop

  speed

  if pin_a1 == low then

    return

  end if

  PWM_OUT(RR,GG,BB, time)

  end loop

 

  while pin_a6 == high loop

  PWM_OUT(RR,GG,BB, time)

  end loop

  if pin_a2 == high then

  RR = random_byte

  GG = random_byte

  BB = random_byte

  else

  RR = 1

  GG = 255

  BB = 1

  end if

 

  For 254 loop

  speed

  if pin_a1 == low then

    return

  end if

  PWM_OUT(RR,GG,BB, time)

  end loop

 

  while pin_a6 == high loop

  PWM_OUT(RR,GG,BB, time)

  end loop

  if pin_a2 == high then

  RR = random_byte

  GG = random_byte

  BB = random_byte

  else

  RR = 1

  GG = 255

  BB = 255

  end if

 

  For 254 loop

  speed

  if pin_a1 == low then

    return

  end if

  PWM_OUT(RR,GG,BB, time)

  end loop

 

  while pin_a6 == high loop

  PWM_OUT(RR,GG,BB, time)

  end loop

  if pin_a2 == high then

  RR = random_byte

  GG = random_byte

  BB = random_byte

  else

  RR = 1

  GG = 1

  BB = 255

  end if

 

  For 254 loop

  speed

  if pin_a1 == low then

    return

  end if

    PWM_OUT(RR,GG,BB, time)

  end loop

 

  while pin_a6 == high loop

  PWM_OUT(RR,GG,BB, time)

  end loop

  if pin_a2 == high then

  RR = random_byte

  GG = random_byte

  BB = random_byte

  else

  RR = 255

  GG = 1

  BB = 255

  end if

 

  For 254 loop

  speed

  if pin_a1 == low then

    return

  end if

    PWM_OUT(RR,GG,BB, time)

  end loop

 

  while pin_a6 == high loop

  PWM_OUT(RR,GG,BB, time)

  end loop

  if pin_a2 == high then

  RR = random_byte

  GG = random_byte

  BB = random_byte

  else

  RR = 255

  GG = 1

  BB = 1

  end if

end procedure

 

procedure fade(byte in Rnew, byte in Gnew, byte in Bnew) is 

-- fade from 1 colour to another

-- passing 0 means stay the same

  var byte counter = 0

  if Rnew != 0 then

  if Rnew > R then

    counter = Rnew - R

  elsif Rnew < R then

    counter = R - Rnew

  end if

  For counter loop    -- (R,G,:)

    speed

    PWM_OUT(R,G,B, time)

    if Rnew > R then

    R = R + 1

    else

    R = R - 1

    end if

    if pin_a1 == high then    -- other mode

    flash

    end if

    while pin_a6 == high loop  -- pause

    PWM_OUT(R,G,B, time)

    end loop

  end loop        -- (Rnew,Gnew,Bnew)

  end if

  if Gnew != 0 then

  if Gnew > G then

    counter = Gnew - G

  elsif Gnew < G then

    counter = G - Gnew

  end if

  For counter loop    -- (R,G,B)

    speed

    PWM_OUT(R,G,B, time)

    if Gnew > G then

    G = G + 1

    else

    G = G - 1

    end if

    if pin_a1 == high then    -- other mode

    flash

    end if

    while pin_a6 == high loop  -- pause

    PWM_OUT(R,G,B, time)

    end loop

  end loop        -- (Rnew,Gnew,Bnew)

  end if

  if Bnew != 0 then

  if Bnew > B then

    counter = Bnew - B

  elsif Bnew < B then

    counter = B - Bnew

  end if

  For counter loop    -- (R,G,B)

    speed

    PWM_OUT(R,G,B, time)

    if Bnew > B then

    B = B + 1

    else

    B = B - 1

    end if

    if pin_a1 == high then    -- other mode

    flash

    end if

    while pin_a6 == high loop  -- pause

    PWM_OUT(R,G,B, time)

    end loop

  end loop        -- (Rnew,Gnew,Bnew)

  end if

end procedure

-- main loop

forever loop

-- we start at R = 255, G = 1, B = 1

if pin_a2 == high then

  fade(random_byte,0,0)

  fade(0,random_byte,0)

  fade(0,0,random_byte)

else

  R = 255

  G = 1

  B = 1

  fade(0,255,0)

  fade(1,0,0)

  fade(0,0,255)

  fade(0,1,0)

  fade(255,0,0)

  fade(0,0,1)

end if

end loop

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Crie uma conta ou ligue-se para comentar

Só membros podem comentar

Criar nova conta

Registe para ter uma conta na nossa comunidade. É fácil!


Registar nova conta

Entra

Já tem conta? Inicie sessão aqui.


Entrar Agora