EASy68K  
It is currently Fri Dec 15, 2017 8:14 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri Oct 31, 2014 9:07 am 
Offline

Joined: Thu Oct 30, 2014 2:26 pm
Posts: 5
Hi, I am quite new to EASy68K. I am searching for a way to store address of the H/W toggle switch in hexadecimal format so that I can display it on the 7-segment LED display.
E.g.:
Let A0 refers to toggle switch address: 00E00012
and D1 contain the address in A0.
For example toggle switches 1 and 2 are ON = 0000 0110
which means D1 will be equal to 0000 0006 (in hexadecimal format, as seen on H/W Simulator)
Now I want last bit of 7-segment LED Display, the address of which is 00E0000E to represent this 6.
Here is my code:

Code:
*----------------------------------------------------------------------
* Description: Display address of toggle switch as hexadecimal
*                  in the right most bit of 7-segment LED display
*----------------------------------------------------------------------
        ORG $1000
START:                     

* Get address of toggle switches in D1.L
        MOVE.B  #32,D0      ; Trap task #32
        MOVE.B  #3, D1       ; D1.B = 03 (to get address of toggle switches into D1.L)
        TRAP    #15           
        MOVE.L  D1, A0        ; A0 is pointer to toggle switches

* Read starting state of toggle switches
        MOVE.B  (A0),D2       ; write A0 value in to D2
        BSR     DISPLAY        ; display switch states

* Terminate the program
        MOVE.B  #9,D0
        TRAP    #15           ; halt simulator

* Display D2's hexadecimal value in $E0000E
DISPLAY   MOVEM.L D0/D1/A1,-(SP)  ; save registers
         MOVE.B  $D1, $E0000E   ; how do I retrieve the hexadecimal value of D1
                                      ; (which contains address of toggle switch) so that
                                      ; it can be something in the form: MOVE.B #$06, $E0000E ? for above example of hex value = 06
       
         MOVEM.L (SP)+,D0/D1/A1  ; restore registers
         RTS                      ; return to next instruction
         END       START


Any help will be greatly appreciated. Tq.


Top
 Profile  
 
PostPosted: Fri Oct 31, 2014 7:57 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1056
jimbex wrote:
Code:
         MOVE.B  $D1, $E0000E   ; how do I retrieve the hexadecimal value of D1
                                      ; (which contains address of toggle switch) so that
                                      ; it can be something in the form: MOVE.B #$06, $E0000E ? for above example of hex value = 06


D1 contains the binary data from the switches. In order to display it on the 7-segment display you must determine which segments in the digit should be on then write the appropriate number to the seven segment address. The clockDigital example that is included with EASy68K does this for the digits 0-9. You will need to extend this code to include hexadecimal digits.


Code:
*-----------------------------------------------------------
*         A
*       -----
*     F|     |B
*      |  G  |
*       -----
*     E|     |C
*      |  D  |
*       -----   .H
*
* Bit Number  7 6 5 4 3 2 1 0
* Segment     H G F E D C B A

* bit patterns to form digits on readout
digits:
    dc.b  $3F           digit 0
    dc.b  $06           digit 1
    dc.b  $5B           digit 2
    dc.b  $4F           digit 3
    dc.b  $66           digit 4
    dc.b  $6D           digit 5
    dc.b  $7D           digit 6
    dc.b  $07           digit 7
    dc.b  $7F           digit 8
    dc.b  $6F           digit 9
    dc.b  $00           digit off
    dc.b  $40           dash

    ds.w  0             force word boundary

*----------------------------------------------------------
* Display a digit on the 7-segment display
* Pre:  D3.B contains 1 digit to display
*       A2 points to 7-segment LED to use
* Post: A2 points to next 7-segment LED

segment7:
    movem.l d3/a0,-(a7)     save registers
    lea     digits,a0       bit pattern table
    and.l   #$00ff,d3
    move.b  (a0,d3),(a2)    display digit
    adda.l  #2,a2
    movem.l (a7)+,d3/a0     restore registers
    rts

_________________
Prof. Kelly


Top
 Profile  
 
PostPosted: Sat Nov 01, 2014 7:19 am 
Offline

Joined: Thu Oct 30, 2014 2:26 pm
Posts: 5
Thank you for the fast reply, prof Kelly.
I managed to make it work by using if-statements to compare current toggle address value with each of the values of hex-alphabet (0 - F).
This is what I did:
Code:
*-----------------------------------------------------
* Display switch state as a hex in $E0000E
* Pre: - D3.B contains toggle switch data in hex
*        - D3 is unchanged after subroutine DISPLAY
DISPLAY
        * Compare D3 for the 16 values of hex-alphabet (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
               
        IF.B D3 <EQ> #$0 THEN.S     ; compare D3 with 0, if the contents are equal, then:
            MOVE.B  #$3F,$E0000E    ; display bit pattern for 0 ($3F) in $E0000E
        ENDI                        ; end if
                                       ; and so on ... if-endif statements to check for all other possible hex-digits


But I would like to make the program faster and shorter. Any ideas?

Also, for anyone one else who wants the full 7-segment display bit pattern for all hexadecimal values from 0 to F, you can use the following:
Code:
*-----------------------------------------------------------
* Note: Information about 7-segment display
*         A
*       -----
*     F|     |B
*      |  G  |
*       -----
*     E|     |C
*      |  D  |
*       -----   .H
*
* Bit Number  7 6 5 4 3 2 1 0
* Segment     H G F E D C B A
* Notes:
*   - each bit number is either 1 or 0.
*   - first 4 bits comprises of first hex digit
*   - second 4 bits comprises of second hex digit
* The following are bit patterns to form digits on readout

digits:
   dc.b  $3F         digit 0
   dc.b  $06         digit 1
   dc.b  $5B         digit 2
   dc.b  $4F         digit 3
   dc.b  $66         digit 4
   dc.b  $6D         digit 5
   dc.b  $7D         digit 6
   dc.b  $07         digit 7
   dc.b  $7F         digit 8
   dc.b  $6F         digit 9
   dc.b  $77         digit A
   dc.b  $7C         digit B
   dc.b  $39         digit C
   dc.b  $5E         digit D
   dc.b  $79         digit E
   dc.b  $71         digit F
   dc.b  $00         digit off
   dc.b  $40         dash
   ds.w  0           force word boundary


Top
 Profile  
 
PostPosted: Sat Nov 01, 2014 9:36 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1056
jimbex wrote:
But I would like to make the program faster and shorter. Any ideas?

Use an array to contain the seven segment data. The index into the array is the digit you wish to display.

_________________
Prof. Kelly


Top
 Profile  
 
PostPosted: Tue Nov 04, 2014 12:26 pm 
Offline

Joined: Thu Oct 30, 2014 2:26 pm
Posts: 5
Thankyou prof.kelly for the help.


Top
 Profile  
 
PostPosted: Tue Nov 25, 2014 10:39 am 
Offline

Joined: Thu Oct 30, 2014 2:26 pm
Posts: 5
Hi Prof.Kelly for the past help. i would like you to give me some idea or a solution to find a way to eliminate the flickering in a seven segment display. what may be the cause and what could be done to fix this problem. The codes are to display seven segment display to display hexa decimal values according to the input of toggle switches. Thank you in advance.


Top
 Profile  
 
PostPosted: Tue Nov 25, 2014 11:14 am 
Offline

Joined: Thu Oct 30, 2014 2:26 pm
Posts: 5
jimbex wrote:
Hi Prof.Kelly for the past help. i would like you to give me some idea or a solution to find a way to eliminate the flickering in a seven segment display. what may be the cause and what could be done to fix this problem. The codes are to display seven segment display to display hexa decimal values according to the input of toggle switches. Thank you in advance.



Finally managed to solve the flickering the in seven segment display.
The mistake was in the clearing of the seven segment digits part.
I placed zero to the last one to clear also,which was supposed to be kept for the display. So that made the program run but at the mean while want to clear the last segment as well.
MOVE.B #$00,$E00000
.
.
MOVE.B #$00,$E0000E
So it made the flickering in the last digit of display. so removed this, MOVE.B #$00,$E0000E. Now working fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group