EASy68K
http://www.easy68k.com/EASy68Kforum/

need help for the program 7 segment counter up/down
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1147
Page 1 of 1

Author:  Zaf_3677 [ Sun Dec 09, 2012 7:44 am ]
Post subject:  need help for the program 7 segment counter up/down

helo......i have a question about the program of 7 segment counter up/dwon...actually, i really didn't understand how to make a program for the switch button...i will give the specification for this project..i hope u can help me...i really need it...below the program that i had did a little bit...if there is a mistake...please re-recorrect...thnz so much..

project specification:
Motorola Microprocessor 68000 based system project is to display up and down counting upon the switch button pushed on a 7-segment display. This project requires two switches S1 and S2 as shown in figure 1. Switch S1 is to start and stop the counting operation and switch 2 for counting up and down operation. In this system number will increase or decrease continuously until S1 is pushed, then the system stop and show the exact number for that time. The system will run when S1 is once again pushed, the counting will continue from the last number stopped. Each group will be given unique input and output ports connection as shown in Table 1. These input and output devices will be interfaced to the 68000 based system through PI/T (Peripheral Interface/ Timer) chip.

Input and Output Ports Connection:
Table 1

Group 2
Input Port Setting Output Port Setting
SW1 SW2 a b c d e f g
PB1 PB7 PA1 PA2 PA3 PA4 PA5 PA6 PA7

programming that i had did a little bit:

Code:
ORG $080C00
START
MOVE.B #$80, $10000D                                      ;Configure Port A Control Register to mode 1X
MOVE.B #$FF, $100005                                      ;Configure Port A Data Register bits to output
MOVE.B #$80, $10000F                                      ;Configure Port B Control Register to mode 1X
MOVE.B #$00, $100007                                      ;Configure Port B Data Register bits to input

PB
EQU          $100013                                          ;Configure Port B Data Register to input
MOVE.B     #$FF,PB                                          ;Activate the Port B as input button

DDD
MOVE.B     #$00,D0                                          ;Clear the first digit of 7-segment
MOVE.L     #$00FF, D5                                      ;store $FF to D5 register as temporary counter
MOVE.B     #$00, $100011                                 ;Activate the LSB digit (first 7-seg display)
LEA           DIGIT,A1                                         ;call digit for count up

CUP
MOVE.B      (A1)+,D0                                         ;move data inside A1 into D0
MOVE.B       D0, $100011                                   ;Display the D0 data to Port A
BSR            DELAY                                           ;Branch to DELAY routine

CONT
CMPI          #$6F,D0                                         ;Compare value 9 with D0
BEQ            DDD                                              ;If equal, branch to DDD
CMP.B         #$F8,PB                                         ;Compares if button2 is pushed
BEQ            LOOP                                             ;if equal, loop to routine PAUSE
CMP.B         #$07,PB                                          ;Compares if button1 is pushed
BEQ            EEE                                                ;Branch to EEE for count down
BRA            CUP                                                ;Loop to routine CUP
RTS

EEE
MOVE.B       #$00,D0                                        ;Clear the first digit of 7-segment
MOVE.L       #$00FF, D5                                    ;store $FF to D5 register as temporary counter
MOVE.B       #$00, $100011                               ;Activate the LSB digit (first 7-seg display)
LEA             DIGIT1,A2                                     ;call digit for count down

CDOWN
MOVE.B       (A2)+,D0                                      ;move data inside A2 into D0
MOVE.B       D0, $100011                                  ;Display the D0 data to Port A
BSR            DELAY                                          ;Branch to DELAY routine

CONT1

CMPI          #$3F,D0                                        ;Compare value 0 with D0
BEQ            EEE                                             ;If equal, branch to EEE
CMP.B         #$F8,PB                                       ;compares if button2 is pushed
BEQ            LOOP1                                         ;if equal, loop to PAUSE1
CMP.B         #$07,PB                                       ;Compares if button1 is pushed
BEQ            DDD                                            ;Branch to DDD for count up
BRA            CDOWN                                        ;Loop to routine CDOWN
RTS

DELAY        MOVE.L #$5FFFF, D6                       ;DELAY subroutine

DEL1
SUBQ.L       #1, D6
BNE            DEL1
RTS

LOOP
CMP.B        #$F8,PB                                         ;pause subroutine for CUP
BEQ           CONT
BRA           LOOP

LOOP1
CMP.B        #$F8,PB                                         ;pause subroutine for CDOWN
BEQ           CONT1
BRA           LOOP1

DIGIT:
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

DIGIT1:
dc.b $6F digit 9
dc.b $7F digit 8
dc.b $07 digit 7
dc.b $7D digit 6
dc.b $6D digit 5
dc.b $66 digit 4
dc.b $4F digit 3
dc.b $5B digit 2
dc.b $06 digit 1
dc.b $3F digit 0

END START

Author:  lee [ Sun Dec 09, 2012 4:07 pm ]
Post subject:  Re: need help for the program 7 segment counter up/down

The specification says that the segments a to g of the digit connect to PA1 to PA7 respectively but the values you use are for them connected to PA0 to PA6 respectively.

The specification says that the switches connect to PB1 and PB7 but that does not in any way match the $F8 and $07 values you are using as compare values to see if the switches are pressed.

The specification says that S1 is to start and stop the counting and S2 to change the direction, your code has this the other way around according to the comments.

If the button 2 press were ever to be detected your code immediately checks again for a button 2 press and branches back to do the same thing all over again. This would mean you have a roughly equal chance of the button working or doing nothing depending on exactly when you release it.

Lee.

Author:  Zaf_3677 [ Mon Dec 10, 2012 4:55 am ]
Post subject:  Re: need help for the program 7 segment counter up/down

if u dont mind..can u recorrect my program for this project..i really confused of this program....

Author:  lee [ Mon Dec 10, 2012 1:40 pm ]
Post subject:  Re: need help for the program 7 segment counter up/down

Quote:
if u dont mind..can u recorrect my program for this project..
No, sorry. There is a policy against doing other people's work for them which I agree with.

Also I don't have access to compatible hardware to test any code on, so I couldn't be sure that any code I wrote actually worked.
Quote:
i really confused of this program....
The project as posed looks quite simple but there are some real world issues that make this a little harder than it first looks.

This is a good example of the kind of problems you will encounter in writing programs.

If you ask specific questions about things you don't understand I will try to help you but I won't just give you a solution to the project.

Lee.

Author:  Zaf_3677 [ Mon Dec 10, 2012 2:59 pm ]
Post subject:  Re: need help for the program 7 segment counter up/down

ok...for this program..i just dont understand how to make a program for the switch???im confused about that..

Author:  lee [ Mon Dec 10, 2012 6:26 pm ]
Post subject:  Re: need help for the program 7 segment counter up/down

Quote:
i just dont understand how to make a program for the switch???
Ok, what confuses you about the programming for the switch?

How to read its state or what to do with the information?

Lee.

Author:  Zaf_3677 [ Tue Dec 11, 2012 6:16 am ]
Post subject:  Re: need help for the program 7 segment counter up/down

based on the specification...it provides two switch where s1 operates as to start and stop the counting operation and switch 2 for counting up and down operation. so...according to the input n output connection...i want to make the program for the switch...but i confuse how to make the program for the switch instruction.....can you teach me how to read its state???

Author:  lee [ Wed Dec 12, 2012 2:33 am ]
Post subject:  Re: need help for the program 7 segment counter up/down

Quote:
but i confuse how to make the program for the switch instruction.....can you teach me how to read its state???
Ok. The specification says ..

Code:
* Input Port Setting
* SW2   PB7
* SW1   PB1
I don't know how the switches are wired to your port but I'll assume the more usual arrangement of a pullup resistor with the switch going between the port line and 0V.

When the switch is open, i.e. not pressed, the port line will be pulled high and so read as a 1. When the switch is closed the port line will be 0V and read as 0.

Port B has eight lines numbered from 7, the most significant in the port B byte, to 0, the least significant. This number is also the power of two value that the port bit represents when you read a whole byte from port B.

Let's imagine a switch on PB3. This port line would have a value of 2^3, which is 00001000 in binary or 8 in decimal, were it to read as a 1.

So you just look for port B being eight or zero right? Well, no. The other seven lines on port B could be either 0s or 1s so our PB3 value gets lost among 128 other possible values.

To separate out the information for the switch we're interested in we use an AND mask to clear all of the other bits and just leave the one bit of interest.

If you have two bits, A and B, then the AND function operates as follows ..

Code:
 A B AND
 0 0  0
 0 1  0
 1 0  0
 1 1  1
Only when A = 1 AND B = 1 is the output = 1. This can be expressed as ..

Code:
 A B AND
 0 x  0
 1 B  B
If A = 0 then it doesn't matter what B is the result of the AND is always 0
If A = 1 then the result of the AND is always equal to B

This can be used to make a mask that only lets the bit we're interested in have an effect on the value. Input AND mask = result. This is a bitwise AND, bit 7 from the input is ANDed with bit 7 of the mask to make bit 7 of the result.

Code:
 bit    76543210  76543210
 input  xxxx1xxx  xxxx0xxx
 mask   00001000  00001000
 result 00001000  00000000
To do this in code, still for the imaginary switch on PB3, you'd do ..

Code:
      MOVE.b      PB,d0             * read port B
      ANDI.b      #%00001000,d0     * mask the PB3 bit
.. and you'd follow this with a branch, either BEQ or BNE, depending on the state you were testing for.

Change the value of the binary mask and the state of a switch on any of the port lines can be individually tested.

Lee.

Author:  Zaf_3677 [ Wed Dec 12, 2012 6:14 am ]
Post subject:  Re: need help for the program 7 segment counter up/down

thanz so much frenz....i understood now...this is helping me so much...

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/