Je vous ai fait quelques photos, mais avec l'iPhone et trop peu de lumière (soir), ça donne pas grand chose. On a quand meme une idée du résultat :
Les petits circuits (4 exemplaires) ce sont les drivers de leds. 2cm x 2cm en taille réelle.
Le plus grand (enfin...5 par 4...) c'est la carte embarquant le 16F690, ainsi que les condos de filtrage du 12v (pour gagner de la place sur les drivers), le régulateur pour produire le 5V du pic ainsi que les picots qui vont recevoir tous les fils (5 par driver, il y a du diming...) et les 4 fils en provenance du futur coeur de controle.
J'ai pris le temps d'assembler un driver, pour donner une idée du résultat. La carte PIC est terminée quant à elle...mais je n'ai plus le courage de faire des tests pour ce soir.
@Termi : voila un exemple de source pour ta carte 16F690. Il compilera directement sous MPLAB avec le compilateur HiTec. Si tu utilises un compilo autre, il faudra adapter les includes et les noms des flags du word de config (voir certains noms de registres / bits de registres). Dis moi ce que tu en penses
Tu peux modifier le résultat obtenu en choisissant la fonction appelée (il y a trois appels, n'en garde qu'un seul actif, les deux autres restent en commentaire.
C'est dans la fonction "timer1" que ça se passe :
Code : Tout sélectionner
//chenillard();
//gradateur();
variateur();
Code : Tout sélectionner
#include <htc.h>
#include <pic16f685.h>
//
// INTCON bits
//
#define INTERRUPT_CONTROL_GLOBAL_INTERRUPT_ENABLE 0b10000000
#define INTERRUPT_CONTROL_PERIPHERAL_INTERRUPT_ENABLE 0b01000000
#define INTERRUPT_CONTROL_TIMER0_OVERFLOW_ENABLE 0b00100000
#define INTERRUPT_CONTROL_EXTERNAL_INTERRUPT_ENABLE 0b00010000
#define INTERRUPT_CONTROL_PORTA_PORTB_ENABLE 0b00001000
#define INTERRUPT_CONTROL_TIMER0_0VERFLOW_FLAG 0b00000100
#define INTERRUPT_CONTROL_EXTERNAL_INTERRUPT_FLAG 0b00000010
#define INTERRUPT_CONTROL_PORTA_PORTB_FLAG 0b00000001
//
// PIE1 bits
//
#define PERIPHERAL_INTERRUPT_ENABLE_1_TIMER1 0b00000001
//
// T1CON bits
//
#define TIMER1_CONTROL_GATE_INVERTED 0b10000000
#define TIMER1_CONTROL_GATE_ENABLE 0b01000000
#define TIMER1_CONTROL_PRESCALE_1_8 0b00110000
#define TIMER1_CONTROL_PRESCALE_1_4 0b00100000
#define TIMER1_CONTROL_PRESCALE_1_2 0b00010000
#define TIMER1_CONTROL_PRESCALE_1_1 0b00000000
#define TIMER1_CONTROL_LP_OSCILLATOR_ENABLE 0b00001000
#define TIMER1_CONTROL_EXTERNAL_NOSYNC 0b00000100
#define TIMER1_CONTROL_EXTERNAL_CLOCK 0b00000010
#define TIMER1_CONTROL_ENABLE 0b00000001
__CONFIG
(
INTIO // Internal clock, no clock output
& MCLRDIS // Master Clear is disabled
& WDTDIS // Watchdog timer disabled
& PWRTDIS // Power-Up timer disabled
& BORDIS // Brown Out Detect disabled
& UNPROTECT // Code is not protected
);
char volatile enabled = 1;
int volatile counter = 1;
int volatile direction = 1;
void chenillard(void)
{
if (enabled)
{
if (direction == +1)
counter <<= 1;
else
counter >>= 1;
if (counter == 0x8)
{
direction = -1;
}
else if (counter == 1)
{
direction = +1;
}
// Write port output
PORTC = counter;
}
}
int niveaux[4] = { 1, 5, 10, 20};
int divider = 0;
int cpt2[4] = { 0, 5, 10, 15};
int delta[4] = { 1, 1, 1, 1};
const char bitsets[21][20]=
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 0
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 1
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // 2
{ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, // 3
{ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, // 4
{ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 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, 1, 1, 1, 1, 1, 1 } // 20
};
void gradateur(void)
{
char bits = 0;
int mask = 1;
if (enabled==1)
{
for (int i=0;i<4;i++)
{
int n = niveaux[i];
char flag = bitsets[n][counter];
if (flag == 1)
{
bits |= mask;
}
mask <<= 1;
}
counter++;
if (counter>=20)
counter = 0;
}
PORTC = bits;
TMR1H = 0xFF;
TMR1L = 0x80;
}
void variateur(void)
{
char bits = 0;
char mask = 1;
if (enabled==1)
{
for (int i=0;i<4;i++)
{
char flag = bitsets[cpt2[i]][counter];
if (flag == 1)
{
bits |= mask;
}
mask <<= 1;
}
counter++;
if (counter>=20)
{
counter = 0;
divider++;
if (divider == 1)
{
divider = 0;
for (int j=0;j<4;j++)
{
cpt2[j] += delta[j];
if ((cpt2[j] >= 20) || (cpt2[j]<=0))
{
delta[j] = -delta[j];
}
}
}
}
}
PORTC = bits;
TMR1H = 0xFF;
TMR1L = 0x80;
}
void interrupt timer1(void)
{
if ((TMR1IE)&&(TMR1IF))
{
//chenillard();
//gradateur();
variateur();
// Clear the timer interrupt bit
TMR1IF=0;
}
}
void init(void)
{
// Enable port A as output
TRISA = 0b00000000;
PORTA = 0b00000000;
TRISA = 0b11111111;
ANSEL = 0b00000000;
IOCA = 0b00000000;
// Enable port C as output
TRISC = 0b00000000;
PORTC = 0b00000001;
// Setup timer 1
OPTION = 0b10000000;
T1CON = TIMER1_CONTROL_PRESCALE_1_1 | TIMER1_CONTROL_ENABLE;
// Enable timer1 interruption and peripheral interruption (timer1 is a peripheral)
PIE1 |= PERIPHERAL_INTERRUPT_ENABLE_1_TIMER1;
INTCON |= INTERRUPT_CONTROL_PERIPHERAL_INTERRUPT_ENABLE;
}
char lastA = 0;
void main(void)
{
init();
ei();
lastA = PORTA & 0x08;
while (1)
{
_delay(5000);
char newA = PORTA & 0x08;
if (newA != lastA)
{
lastA = newA;
if (enabled)
{
enabled = 0;
}
else
{
enabled = 1;
}
}
}
}