Code: Select all
program Segnapunti;
var SHIFTER, i, portd_index , VarOut, oldstate0, oldstate1, oldstate2, oldstate3: byte;
digit, number, tmp : word;
portd_array: array[4] of Word;
function mask(num: Word): Word;
begin
case num of
0 : result:= $3F;
1 : result:= $06;
2 : result:= $5B;
3 : result:= $4F;
4 : result:= $66;
5 : result:= $6D;
6 : result:= $7D;
7 : result:= $07;
8 : result:= $7F;
9 : result:= $6F;
end; //case end
end;//~
procedure interrupt;
begin
PORTA := 0; // Turn off all 7seg displays
PORTD := portd_array[portd_index]; // bring appropriate value to PORTD
PORTA := shifter; // turn on appropriate 7seg. display
// move shifter to next digit
shifter:= shifter shl 1;
if (shifter > 8) then
shifter := 1;
// increment portd_index
Inc(portd_index);
if (portd_index > 3) then
portd_index := 0; // turn on 1st, turn off 2nd 7seg.
// number:=tmp;
TMR0 := 0; // reset TIMER0 value
INTCON := $20; // Clear T0IF
end;//~
procedure testButton;
begin
varOut:=0;
if Button(PORTC, 0, 1, 1) then oldstate0 := 255;
if Button(PORTC, 1, 1, 1) then oldstate1 := 255;
if Button(PORTC, 2, 1, 1) then oldstate2 := 255;
if Button(PORTC, 3, 1, 1) then oldstate3 := 255;
if oldstate0 and Button(PORTC, 0, 1, 0) then
begin
//number:=number+1;
varOut:=VarOut+1;
oldstate0:=0;
end;
if oldstate1 and Button(PORTC, 1, 1, 0) then
begin
//number:=number+100;
varOut:=VarOut+2;
oldstate1:=0;
end;
if oldstate2 and Button(PORTC, 2, 1, 0) then
begin
//number:=0;
varOut:=VarOut+4;
oldstate2:=0;
end;
if oldstate3 and Button(PORTC, 3, 1, 0) then
begin
varOut:=VarOut+8;
oldstate3:=0;
end;
case VarOut of
1: number:=number+1;
2: number:=number+100;
// 4: number:=0;
// 8,0: number:=number;
end;
end;
begin
ANSEL := 0; // Set AN pins to Digital I/O
ANSELH := 0;
OPTION_REG := $80; // Timer0 settings
digit := 0;
portd_index := 0;
shifter := 1;
TMR0 := 0;
INTCON := $A0; // Enable GIE, T0IE
PORTA := 0;
TRISA := 0; // Set PORTA as output
PORTD := 0;
TRISD := 0; // Set PORTD as output
PORTB := 0;
TRISB := 0;
TRISC := 0xFF;
{
while TRUE do
begin
for i := 0 to 9 do
begin
PORTA := 0; // Turn off all 7seg displays
PORTD := mask(i); // bring appropriate value to PORTD
PORTA := 1; // turn on appropriate 7seg. display
Delay_ms(1000);
end;
end; //endless loop
}
number := 0; // some initial value
oldstate0:=0;
oldstate1:=0;
oldstate2:=0;
oldstate3:=0;
while TRUE do
begin
testButton;
portb:=varout;
digit := number / 1000 ; // extract thousands digit
portd_array[3] := mask(digit); // and store it to PORTD array
digit := (number / 100) mod 10; // extract hundreds digit
portd_array[2] := mask(digit); // and store it to PORTD array
digit := (number / 10) mod 10; // extract tens digit
portd_array[1] := mask(digit); // and store it to PORTD array
digit := number mod 10; // extract ones digit
portd_array[0] := mask(digit); // and store it to PORTD array
{ PORTA := 0; // Turn off all 7seg displays
PORTD := portd_array[portd_index]; // bring appropriate value to PORTD
PORTA := shifter;
shifter:= shifter shl 1;
if (shifter > 8) then
shifter := 1;
// increment portd_index
Inc(portd_index);
if (portd_index > 3) then
portd_index := 0;
}
end; // endless loop
end.
M.P. Conte
Elder