TODOPIC
Microcontroladores PIC => Primeros pasos - Iniciación a los microcontroladores => Mensaje iniciado por: LUCHO512 en 07 de Noviembre de 2009, 23:48:48
-
Estimados tengo un peuqeño problema seguro es una pavada pero no doy con al tecla, intento hacer un contador con 4 display de 7 segmentos, el terma es que no se incrementa la variable number alguna sugerencia!!!
Codigo en Mikrobasic...
program Display7seg
dim shifter, digit, portd_index as byte
dim number as word
dim por as byte[4]
sub function Mask(dim num as byte) as byte ' this function returns masks
select case num ' for common cathode 7-seg. display
case 0 result = $3F
case 1 result = $06
case 2 result = $5B
case 3 result = $4F
case 4 result = $66
case 5 result = $6D
case 6 result = $7D
case 7 result = $07
case 8 result = $7F
case 9 result = $6F
end select 'case end
end sub
sub procedure interrupt
PORTA = shifter ' turn on appropriate 7seg. display
PORTB = por[portd_index]
Inc(portd_index) ' increment value of variable portd_index
shifter = shifter << 1
if shifter > 8 then
shifter = 1 ' prepare mask for digit
end if
if portd_index > 3 then
portd_index = 0 ' turn on 1st, turn off 2nd 7seg.
end if
TMR0 = 96
INTCON = $20
end sub
main:
OPTION_REG = $80
digit = 0
portd_index = 0
shifter = 1
TMR0 = 96
INTCON = $A0 ' Disable PEIE,INTE,RBIE,T0IE
TRISA = 0
TRISB = 0
PORTB = 0
PORTA = 0
number = 0
conta:
number=number+1
'number=1
digit = number div 1000 ' prepare digits for diplays
por[3] = Mask(digit)
digit = number div 100 mod 10
por[2] = Mask(digit)
digit = number div 10 mod 10
por[1] = Mask(digit)
digit = number mod 10
por[0] = Mask(digit)
Delay_ms(1000)
goto conta
end.