Menu

Somthing Wrong with math and 7 Segment displa

Help
2010-05-10
2013-05-30
  • Reynaldo Díaz

    Reynaldo Díaz - 2010-05-10

    Hi, I'm new to microcontrollers but old in Basic programing.
    I'm tring to do a function that separeates the digits in a word variable. e.g. 5976, I need the 1000 units ("5"), 100 units ("9"), 10 units ("7") and 1  units ("6") and display them in a 7 segment display. I get the 5, 9 and the 2, but can't get the 7 (10 units) in the display.

    here is the code:

    #chip 16F628, 20
    #config HS_OSC, WDT_Off, LVP_OFF

    #define DisplayPortA PORTB

    dir B 0

    Dim Entero as word
    dim Miles as word
    Dim Centenas as word
    Dim Decenas as Word
    Dim Unidades as Word

    Entero = 5976

    UndMil = entero / 1000
    Miles = undmil*1000
    UndCentena = (entero - miles) / 100
    Centenas = Undcentenas*100
    UndDecenas = (Entero - miles-centenas)/10
    Decenas = unddecenas*10
    Unidades =(entero - miles -centenas - decenas )

    Main:
    DisplayValue(1,undMil) 'Nunber 5
    wait 25 10ms
    DisplayValue (1,undCentena) 'Number 9
    wait 25 10ms
    DisplayValue(1,undDecenas) 'Here number 9 stay instead of showing number 7. why?
    wait 25 10ms
    DisplayValue (1,unidades) 'Number 6
    wait 25 10ms

    goto Main

     
  • gcha44

    gcha44 - 2010-05-10

    Hi,
    16F628 datasheet cans help you because 16F628 as one particularity :
    After power and reset ,the defaut configuration for PortA is in comparator mode .
    then PortA.0 to PortA.3 are analog inputs .
    AN0 and AN3 are connected to Comparator1 (CMP1) , and AN1 and AN2 to Comparator2 (CMP2)

    To define PortA as I/O port you must write :
    CMCON=7   'CM2-0=111  because defaut mode is CM2-0=000
    and then you'll write
    Dir PortA out
    Dir PortB out

    I think it's the reason why you can't display the correct values.

    GC

     
  • Reynaldo Díaz

    Reynaldo Díaz - 2010-05-16

    The problem was the misspelled variable UndCentena, I use UndCentenas instead.

    Sorry.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.