پاسخ : مدارات عملی تابلوهای ثابت
یه فیلمی میذارم تا فید شدن ال ای دی ها رو خودتون ببینید.
[hide]
مشاهده فایلپیوست 10 canal pic16f628a - .rar[/hide]
واین هم سورسش
Desc : 10 outputs light controler
allowing fast light-on and slow light-off
PIC 16F628A - 4 MHz int osc
written and compiled with Mikro Pascal Pro V2.50
History
- 05/08/2009 : first version
}
program electronique_chenillard_012_16f628;
var
bStart, bStop, bProg: boolean;
iMode: byte; // 0..2
iDelayStart: word; // ms
iDelayStop: word; // ms
Out_1: sbit at PORTB.4;
Out_2: sbit at PORTB.5;
Out_3: sbit at PORTB.3;
Out_4: sbit at PORTB.2;
Out_5: sbit at PORTB.1;
Out_6: sbit at PORTB.0;
Out_7: sbit at PORTA.3;
Out_8: sbit at PORTA.2;
Out_9: sbit at PORTA.1;
Out_10: sbit at PORTA.0;
procedure Delay_Save;
begin
EEProm_Write(0, Lo(iDelayStart));
EEProm_Write(1, Hi(iDelayStart));
EEProm_Write(2, Lo(iDelayStop));
EEProm_Write(3, Hi(iDelayStop));
end;
procedure Delay_Load;
var
tmpLo, tmpHi: byte;
begin
tmpLo := EEProm_Read(0);
tmpHi := EEProm_Read(1);
if tmpHi = $FF then tmpHi := 0;
iDelayStart := (256 * tmpHi) + tmpLo;
tmpLo := EEProm_Read(2);
tmpHi := EEProm_Read(3);
if tmpHi = $FF then tmpHi := 0;
iDelayStop := (256 * tmpHi) + tmpLo;
end;
procedure Init;
begin
CMCON := 7;
OPTION_REG := 0;
OPTION_REG.NOT_RBPU := 0; // enable pullups
INTCON.GIE := 1; // enable global ints
INTCON.T0IE := 0; // disable Timer 0 int
INTCON.INTE := 0; // disable RB0 int
INTCON.RBIE := 1; // enable RB4..RB7 int
ClearBit(INTCON, RBIF);
TRISA := %00010000; // PORTA as output, but RA4 as input
TRISB := %11000000; // RB0..RB5 as output, RB6..RB7 as input
PORTA := %00000000; // clear porta
PORTB := %11000000; // clear portb
iMode := 0;
end;
function GetDelayStart: word;
begin
result := 150;
end;
function GetDelayStop: word;
begin
result := 150;
end;
procedure Out_Set(bState: boolean; iDelay: word);
begin
Out_1 := bState;
VDelay_ms(iDelay);
Out_2 := bState;
VDelay_ms(iDelay);
Out_3 := bState;
VDelay_ms(iDelay);
Out_4 := bState;
VDelay_ms(iDelay);
Out_5 := bState;
VDelay_ms(iDelay);
Out_6 := bState;
VDelay_ms(iDelay);
Out_7 := bState;
VDelay_ms(iDelay);
Out_8 := bState;
VDelay_ms(iDelay);
Out_9 := bState;
VDelay_ms(iDelay);
Out_10 := bState;
VDelay_ms(iDelay);
end;
procedure Start;
begin
Out_Set(true, iDelayStart);
end;
procedure Stop;
begin
Out_Set(false, iDelayStop);
end;
procedure interrupt;
begin
if TestBit(INTCON, RBIF) = 1 then
begin
if TestBit(PORTB, 7) = 0 then
bStart := true;
if TestBit(PORTB, 6) = 0 then
bStop := true;
ClearBit(INTCON, RBIF);
end;
end;
procedure Led_Blink;
var
i: byte;
begin
for i := 1 to 3 do
begin
ClearBit(PORTA, 7);
Case iMode of
1 : VDelay_ms(iDelayStart);
2 : VDelay_ms(iDelayStop);
end;
SetBit(PORTA, 7);
Case iMode of
1 : VDelay_ms(iDelayStart);
2 : VDelay_ms(iDelayStop);
end;
end;
end;
begin
{ Main program }
Init;
Delay_Load;
while true do
begin
// prog mode ?
if Button(PORTA, 4, 50, 0) and (bProg = false) then
begin
if iMode < 2 then inc(iMode) else iMode := 0;
bProg := true;
PORTA.7 := (iMode > 0);
case iMode of
0 : Delay_Save
else Led_Blink;
end;
end;
if PORTA.4 = 1 then bProg := false;
if bStart then
begin
case iMode of
0 : Start;
1 : begin
if iDelayStart < 1000 then
iDelayStart := iDelayStart + 100
else
iDelayStart := 100;
Led_Blink;
end;
2 : begin
if iDelayStop < 2000 then
iDelayStop := iDelayStop + 1000
else
iDelayStop := 100;
Led_Blink;
end;
end;
bStart := false;
end;
if bStop then
begin
case iMode of
0 : Stop;
1 : begin
if iDelayStart > 100 then
iDelayStart := iDelayStart - 100
else
iDelayStart := 1000;
Led_Blink;
end;
2 : begin
if iDelayStop > 100 then
iDelayStop := iDelayStop - 100
else
iDelayStop := 2000;
Led_Blink;
end;
end;
bStop := false;
end;
Delay_ms(50);
end;
end.