logo elektroda
logo elektroda
X
logo elektroda
REKLAMA
REKLAMA
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

[bascom]dziwny problem z mod 10

piotrva 20 Lis 2010 18:30 1341 2
REKLAMA
  • #1 8768061
    piotrva
    VIP Zasłużony dla elektroda
    witajcie!
    mam taki program do obsługi wyświetlacza LED, jak poniżej, niestety funkcja do wyświetlania liczb dziesiętnie nie działa poprawnie. Zamiast 1251 dostaję 1257, w terminalu też mam coś takiego:
    
    1251
    4- 7
    3- 5
    2- 2
    1- 1
    

    więc to nie problem z samym wyświetlaczem, tylko mod 10 się dziwnie zachowuje...
    Z góry dzięki za pomoc
    
    $regfile = "2313def.dat"
    $crystal = 11059200
    $hwstack = 50
    $swstack = 20
    $framesize = 40
    $baud = 9600
    Waitms 1
    '32
    '8
    '24
    
    Config Portb = Output
    Dataport Alias Portb
    '(
    Pb.0 - Dp
    Pb.1 - A
    Pb.2 - B
    Pb.3 - C
    Pb.4 - D
    Pb.5 - E
    Pb.6 - F
    Pb.7 - G
    ')
    Config Pind.3 = Output
    Led1 Alias Portd.3
    Config Pind.4 = Output
    Led2 Alias Portd.4
    Config Pind.5 = Output
    Led3 Alias Portd.5
    Config Pind.6 = Output
    Led4 Alias Portd.6
    '(
    Pd.0 - Led1
    Pd.1 - Led2
    Pd.2 - Led3
    Pd.3 - Led4
    ')
    
    Declare Sub Cyfra_poz(byval Liczba_p As Byte , Byval Wysw As Byte)
    Declare Sub Led_dec(byval Liczbaa As Word)
    Declare Sub Led_hex(byval Liczba As Word)
    Dim Akt_wysw As Byte , Delay_c As Byte
    Dim Dot As Byte
    Dim Temp_liczba As Byte
    Akt_wysw = 1
    Dim Led_data(4) As Byte
    
    Cyfra_poz 17 , 4
    Cyfra_poz 17 , 3
    Cyfra_poz 17 , 2
    Cyfra_poz 17 , 1
    
    Config Timer0 = Timer , Prescale = 8
    Enable Interrupts
    Enable Timer0
    On Timer0 Led_wysw
    
    Dim A As Word
    'A = 1251
    Reset Led1
    Reset Led2
    Reset Led3
    Reset Led4
    Dot = 3
    Led_dec 1251
    Do
    'Led_dec A
    Incr A
    Delay_c = 135
    Do
    Loop Until Delay_c = 0
    Loop
    
    End
    
    Led_wysw:
    Reset Led1
    Reset Led2
    Reset Led3
    Reset Led4
    Dataport = Led_data(akt_wysw)
    If Akt_wysw = Dot Then Incr Dataport
    Select Case Akt_wysw
    Case 1 : Set Led1
    Case 2 : Set Led2
    Case 3 : Set Led3
    Case 4 : Set Led4
    End Select
    Incr Akt_wysw
    If Akt_wysw > 4 Then
    Akt_wysw = 1
    If Delay_c > 0 Then Decr Delay_c
    End If
    Return
    
    Sub Cyfra_poz(byval Liczba_p As Byte , Byval Wysw As Byte)
    Led_data(wysw) = Lookup(liczba_p , Led_cyfry)
    End Sub
    
    Sub Led_dec(byval Liczbaa As Word)
    Print Liczbaa
    Temp_liczba = Liczbaa Mod 10
    Print "4- " ; Temp_liczba
    Cyfra_poz Temp_liczba , 4
    Liczbaa = Liczbaa / 10
    Temp_liczba = Liczbaa Mod 10
    Print "3- " ; Temp_liczba
    Cyfra_poz Temp_liczba , 3
    Liczbaa = Liczbaa / 10
    Temp_liczba = Liczbaa Mod 10
    Print "2- " ; Temp_liczba
    Cyfra_poz Temp_liczba , 2
    Liczbaa = Liczbaa / 10
    Temp_liczba = Liczbaa Mod 10
    Print "1- " ; Temp_liczba
    Cyfra_poz Temp_liczba , 1
    End Sub
    
    Sub Led_hex(byval Liczba As Word)
    Temp_liczba = Liczba Mod 16
    Cyfra_poz Temp_liczba , 4
    Liczba = Liczba / 16
    Temp_liczba = Liczba Mod 16
    Cyfra_poz Temp_liczba , 3
    Liczba = Liczba / 16
    Temp_liczba = Liczba Mod 16
    Cyfra_poz Temp_liczba , 2
    Liczba = Liczba / 16
    Temp_liczba = Liczba Mod 16
    Cyfra_poz Temp_liczba , 1
    End Sub
    
    Led_cyfry:
    Data &B01111110 , &B00001100 , &B10110110 , &B10011110 , &B11001100       '0-4
    Data &B11011010 , &B11111010 , &B00001110 , &B11111110 , &B11011110       '5-9
    Data &B11101110 , &B11111000 , &B01110010 , &B10111100 , &B11110010       'A-E
    Data &B11100010 , &B01000000 , &B00000000                   'F,(-),OFF
    
  • REKLAMA
  • Pomocny post
    #2 8768264
    Jaca
    Poziom 31  
    Temp_liczba musi być typu Word a nie Byte.
  • #3 8768321
    piotrva
    VIP Zasłużony dla elektroda
    Dzięki, załatwiłem to tak:
    
    Sub Led_dec(byval Liczbaa As Word)
    Local Tempa_liczba As Word
    Tempa_liczba = Liczbaa Mod 10
    Temp_liczba = Tempa_liczba
    Cyfra_poz Temp_liczba , 4
    Liczbaa = Liczbaa / 10
    Tempa_liczba = Liczbaa Mod 10
    Temp_liczba = Tempa_liczba
    Cyfra_poz Temp_liczba , 3
    Liczbaa = Liczbaa / 10
    Tempa_liczba = Liczbaa Mod 10
    Temp_liczba = Tempa_liczba
    Cyfra_poz Temp_liczba , 2
    Liczbaa = Liczbaa / 10
    Tempa_liczba = Liczbaa Mod 10
    Temp_liczba = Tempa_liczba
    Cyfra_poz Temp_liczba , 1
    End Sub
    

    To jeszcze jeden powód, do już sporego katalogu, dla którego bardziej lubię C ;-)
REKLAMA