Introduction to Microcontroller lab 6

Discussion in 'Embedded Systems and Microcontrollers' started by jiwhun1989, Jun 18, 2013.

  1. jiwhun1989

    Thread Starter New Member

    Jun 18, 2013
    8
    0
    Hello, I am currently taking a summer class for microcontroller 1 and i am having issues doing one of the labs.

    The chip we are using is HC(S)12 with CodeWarrior.

    Basically our task is write a program to repetitively count from 0 to $FF.
    Advance the count every 0.5 second . Display the bytes in the Hex on seven segment display printed circuit board(PCB). using PORTE connections on HCS12.

    I got the board to display from 0 to $F (Least sig byte) but part i am having trouble is with displaying MSB after LSB finishes counting upto $F.

    Here is what i have so far:

    ; include derivative specific macros
    ; INCLUDE 'mc9s12dg128.inc'

    ;
    ; include files
    include 'constants.inc'
    ; (a file containing EQUATES of I/O port addresses, bit masks, etc)



    ;EQUATES
    RAM EQU $0800
    STACK EQU $0A00


    ABSENTRY Start

    ORG RAM


    Start lds #STACK
    ldaa #ALLBIT ;1111 1111 configure all LEDs as outputs
    staa DDRA
    ldaa #ALLBIT
    staa DDRE


    Here
    ldx #Table ;
    ldy #16
    ldab #0
    Count
    ldaa b,x ;b+x =a
    staa PORTA
    jsr FlashLS
    jsr Delay1
    stab PORTE
    inx ;increment one address in table by 1
    dey
    bne Count

    ;Subroutines

    Delay1 pshx
    psha
    ldaa #50 ;delay 0.5 Seconds
    Loop ldx #10000
    Delay dex
    bne Delay
    deca
    bne Loop
    pula
    pulx
    rts

    FlashLS
    pshx
    psha
    bset PORTE,%00000100
    clr PORTE
    pula
    pulx
    rts
    FlashMS
    pshx
    psha
    bset PORTE,%00001000
    clr PORTE
    pula
    pulx
    rts

    Table DC.B $FC,$60,$DA,$F2,$66,$B6,$BE,$E0,$FE,$E6,$EE,$3E,$9C,$7A,$9E,$8E

    END





    ;*********************************************************
    ;* Interrupt Vectors *
    ;*********************************************************
    ORG $FFFE
    DC.W Entry ; Reset Vector

    Any help will be appreciated
    Thanks
     
  2. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    You should also post your schematic and use the code tags (click the hash sign-#)....

    It would seem that you are meant to multiplex the display, no?
     
  3. jiwhun1989

    Thread Starter New Member

    Jun 18, 2013
    8
    0
    yea sorry segment displya multiplex!
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    ...uhhhh... what?:confused:
     
  5. jiwhun1989

    Thread Starter New Member

    Jun 18, 2013
    8
    0
    It would seem that you are meant to multiplex the display, no?

    i was saying yes to that question
     
  6. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Gotcha...

    So how about that schematic? Judging by your decoder table, you have the display hooked up with PORTE<7:1> connected to <a:g>, but I don't want to make assumptions....

    I'm not too familiar (as in at all) with this microcontroller, so take what I say with a grain of salt...
     
  7. WBahn

    Moderator

    Mar 31, 2012
    17,788
    4,807
    This may or may not be your problem, but each hex digit is a NIBBLE, not a BYTE. Many people can't keep them straight (at least at first) and make a lot of mistakes as a result.

    So be sure that you are looking for the next digit to display in the upper nibble of the least significant byte, and not the next byte up.
     
  8. absf

    Senior Member

    Dec 29, 2010
    1,493
    373
    Code ( (Unknown Language)):
    1. Here
    2. ldx #Table ;
    3. ldy #16
    4. ldab #0
    5. Count
    6. ldaa b,x ;b+x =a
    7. staa PORTA
    8. jsr FlashLS
    9. jsr Delay1
    10. stab PORTE
    11. inx ;increment one address in table by 1
    12. dey
    13. bne Count
    14.  
    15. ;Subroutines
    16.  
    17. Delay1 pshx
    18. psha
    19. ldaa #50 ;delay 0.5 Seconds
    20. Loop ldx #10000
    21. Delay dex
    22. bne Delay
    23. deca
    24. bne Loop
    25. pula
    26. pulx
    27. rts
    28.  
    29. FlashLS
    30. pshx
    31. psha
    32. bset PORTE,%00000100
    33. clr PORTE
    34. pula
    35. pulx
    36. rts
    37. FlashMS
    38. pshx
    39. psha
    40. bset PORTE,%00001000
    41. clr PORTE
    42. pula
    43. pulx
    44. rts
    45.  
    In your main routine, you called FlashLS to display the least significant digit but you never called the FlashMS even though the subroutine was defined...

    strange.

    Allen
     
    Last edited: Jun 18, 2013
  9. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    In addendum to what Allen said, you may want to move your display functionality to a timer interrupt...
     
    Last edited: Jun 18, 2013
    absf likes this.
  10. absf

    Senior Member

    Dec 29, 2010
    1,493
    373
    Code ( (Unknown Language)):
    1. Here
    2. ldx #Table ;
    3. ldy #16
    4. ldab #0
    5. Count
    6. ldaa b,x ;b+x =a
    7. staa PORTA
    8. jsr FlashLS
    9. jsr Delay1
    10. stab PORTE
    11. inx ;increment one address in table by 1
    12. dey
    13. bne Count
    You have to put more effort on this main routine.

    You need to define a variable that would hold $00-$FF. Select the lower nibble and copy to Acc B then index with the ldaa b,x to display the LSD. Then select the upper nibble and copy to Acc B again then display the MSD. Register Y is mot needed here.

    After displaying both LSD and MSD, increment the newly defined variable and repeat the whole process again.

    OR you can strengthen the FlashLS and FlashMS subroutines to display its own digit so your main routine would looked something like:

    main:
    jsr flashLS
    jsr delay1
    jsr flashMS
    jsr delay1
    inc variable
    bra main

    I never used HC12 but I have used HC11. Are the X and Y registers 16 bit registers?

    Allen
     
Loading...