Discussion Groups | | Re: Random Numbers and Keyboards (My design hopefully somebody can debug for me)
Re: Random Numbers and Keyboards (My design hopefully somebody can debug for me) - yew alex - May 5 23:57:00 2005
Hie Mike and everyone
After spending two weeks and more, I have finally done my program, but there are still
some error which I do not know, what when wrong. I hope you guys, can help me out to
assure this program works. Thanx
regards .
alex
This is my program:
*Description: Design and construct a small circuit board with two
* small potentiometers or trimmers wired as resistive dividers
* with thier wiper wired to PE1 and PE2 of the duet board.It must
* also have a momentary push-button that will bring PC2 high on
* your DUET board when pressed. It must also have nine LEDs
* wired to PortB and PortC on your Duet board plus any required
* resistor, buffers etc.
*--------------------------------------------------------------------
*Definition------------------------------------------------
CODE EQU $100 ;Start of the program
ADCTL EQU $30
ADR1 EQU $31
ADR2 EQU $32
ADR3 EQU $33
ADR4 EQU $34
OPTION EQU $39
DDRC EQU $1007
PORTB EQU $1004
PORTC EQU $1003
TCNT EQU $0E ;Free running timer
REGBAS EQU $1000
TEMP EQU $0000
*-----------------------------------------------------------
*Start of Program
ORG CODE ;Start of the program
LDX #REGBAS ;Load 1000 to index X
LDAA #%10000000
STAA OPTION,X ;Turn on ADC
LDAA #$21 ;Scan:MULT = 1:0
STAA ADCTL,X ;Single mode continous
LDY #TEMP ;Load 0000 to index Y
*-----------------------------------------------------------
*Delay 100 micro seconds
DELAY LDX #0F ;Delay approximately for 100microsec
YYY DEX
BNE YYY
RTS
*----------------------------------------------------------
*On CCF
CCF.ON BRCLR ADCTL,X,$80,CCF.ON ;Check if CCF is on
*---------------------------------------------------------
*Set PortC as output
LDAA #$01
STAA DDRC
*--------------------------------------------------------
*Joystick Instruction
*--------------------------------------------------------
LOOP1 LDAA ADR2,X
STAA O,Y ;Put data A to 0000
INX ;(1000,1001)
INY ;(0000,0001)
CPX #$1002
BNE LOOP1
POTX LDAA $0000 ;Load value of ADR2 from 0000 to A
CMPA #%10000000;Compare with 2.5V
BEQ POTY ;Go to POTY if equal to 2.5V
BHI AA ;Go to AA if higher than 2.5V
BLO BB ;Go to BB if lower than 2.5V
POTY LDAB $0001 ;Load value of ADR3 from 0001 to B
CMPB #%10000000;Compare with 2.5v
BEQ PB3 ;Go to PB3 if equal to 2.5V,lid up centre LED
BHI CC ;Go to CC if higher than 2.5V
BLO DD ;Go to DD if lower than 2.5V
AA LDAA $0000 ;Load value of ADR2 to A
CMPA #%10100110;Compare with 3.25v
BLS POTY ;Go to POTY if lower or same than 3.25
BHI EE ;Go to EE if higher than 3.25v
BB LDAA $0000 ;Load value of ADR2 to A
CMPA #%01011010;Compare with 1.75v
BHS POTY ;Go to POTY if higher or same than 1.75v
BLO FF ;Go to FF if lower than 1.75v
CC LDAB $0001 ;Load value of ADR3 to B
CMPB #%10100110;Compare with 3.25v
BLS PB3 ;Go to PB3 if lower or same than 3.25v
BHI PB7 ;Go to PB7 if higher than 3.25v
DD LDAB $0001 ;Load value of ADR3 to B
CMPB #%01011010;Compare with 1.75v
BHS PB3 ;Go to PB3 if higher or same than 1.75v
BLO PC0 ;Go to PC0 if lower than 1.75v
EE LDAB $0001 ;Load value of ADR3 to B
CMPB #%10000000;Compare with 2.5V
BHI GG ;Go to GG if higher than 2.5v
BLO HH ;Go to HH if lower than 2.5v
FF LDAB $0001 ;Load value of ADR3 to B
CMPB #%10000000;Compare with 2.5V
BHI II ;Go to II if higher than 2.5v
BLO JJ ;Go to JJ if lower than 2.5v
GG LDAB $0001 ;Load value of ADR3 to B
CMPB #%10100110;Compare with 3.25v
BLS PB2 ;Go to PB2 if lower or same than 3.25v
BHI PB0 ;Go to PBo if higher than 3.25v
HH LDAB $0001 ;Load value of ADR3 to B
CMPB #%01011010;Compare with 1.75v
BHS PB2 ;Go to PB2 if higher or same than 1.75v
BLO PB5 ;Go to PB5 if lower than 1.75v
II LDAB $0001 ;Load value of ADR3 to B
CMPB #%10100110;Compare with 3.25v
BLS PB4 ;Go to PB4 if lower or same than 3.25v
BHI PB1 ;Go to PB1 if higher than 3.25v
JJ LDAB $0001 ;Load value of ADR3 to B
CMPB #%01011010;Compare with 1.75v
BHS PB4 ;Go to PB4 if higher or same than 1.75v
BLO PB6 ;Go to PB6 if lower than 1.75v
*---------------------------------------------------------
*RANDOM NUMBER BETWEEN 100 TO 200
LDAA #$F4 ;Load Accumulator A with $F4
STAA DDRC ;store at DDRC, PC2 as input
LDAA PORTC ;Load value from Port C
TRIMX LDD TCNT,X ;Capture the value of TCNT,X and load to D
CPD #$64 ;Compare with 100
BEQ TRIMY ;Go to TRIMY if equal to 100
BHI HIGH ;Go to HIGH if higher than 100
BLO LOW ;Go to LOW if lower than 100
HIGH CPD #$C8 ;Compare with 200
BLS TRIMY ;Go to TRIMY if lower or same than 200
BHI MORE ;Go to MORE if higher than 200
LOW ADDD #$64 ;Add 100 to D
JSR TRIMY ;Jump to TRIMY
MORE SUBD #$64 ;Subtract 100 from D
JSR TRIMY ;Jump to TRIMY
TRIMY LDD TCNT,X ;Capture the value of TCNT,X and load to D
CPD #$64 ;Compare with 100
BEQ PB3 ;Go to PB3 if equal to 100, lid centre LED
BHI HIGH1 ;Go to HIGH1 if higher than 100
BLO LOW1 ;Go to LOW1 if lower than 100
HIGH1 CPD #$C8 ;Compare with 200
BLS PB3 ;Go to PB3 if lower or same than 200, lid centre LED
BHI MORE1 ;Go to MORE1 if higher than 200
LOW1 ADDD #$64 ;Add 100 to D
JSR PB3 ;Jump to PB3
MORE1 SUBD #$64 ;Subtract 100 from D
JSR PB3 ;Jump to PB3, lid centre LED
FOREVER BRA FOREVER
*---------------------------------------
*Definition of which LED lid
PB0 LDAA #$01 ;Load value of $01 to A
STAA PORTB ;Lid LED PortB 0
RTS LOOP1
PB1 LDAA #$02 ;Load value of $02 to A
STAA PORTB ;Lid LED PortB 1
RTS LOOP1
PB2 LDAA #$04 ;Load value of $04 to A
STAA PORTB ;Lid LED PortB 2
RTS LOOP1
PB3 LDAA #$08 ;Load value of $08 to A
STAA PORTB ;Lid LED PortB 3
RTS LOOP1
PB4 LDAA #$10 ;Load value of $10 to A
STAA PORTB ;Lid LED PortB 4
RTS LOOP1
PB5 LDAA #$20 ;Load value of $20 to A
STAA PORTB ;Lid LED PortB 5
RTS LOOP1
PB6 LDAA #$40 ;Load value of $40 to A
STAA PORTB ;Lid LED PortB 6
RTS LOOP1
PB7 LDAA #$40 ;Load value of $80 to A
STAA PORTB ;Lid LED PortB 6
RTS LOOP1
PC0 LDAB #$01 ;Load value of $01 to A
STAA PORTC ;Lid LED PortC 0
RTS LOOP1
Mike McCarty <Mike.McCarty@Mike...> wrote:
yew alex wrote:
>Hie Mike,
>
>Thanx for the advice and help, I will send my program code to you, I guess today.
Hopefully u can help.
>
>Thank you
>
>KInd regards,
>
>alex
If you post it to this group, then you'll get more help, I think.
Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
I speak only for myself, and I am unanimous in that!
---------------------------------
Yahoo! Groups Links
To
---------------------------------
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
----------
*-------------------------------------------------------------------------
*Author: Yew Chia Wen
*Description: Design and construct a small circuit board with two
* small potentiometers or trimmers wired as resistive dividers
* with thier wiper wired to PE1 and PE2 of the duet board.It must
* also have a momentary push-button that will bring PC2 high on
* your DUET board when pressed. It must also have nine LEDs
* wired to PortB and PortC on your Duet board plus any required
* resistor, buffers etc.
*--------------------------------------------------------------------
*Definition------------------------------------------------
CODE EQU $100 ;Start of the program
ADCTL EQU $30
ADR1 EQU $31
ADR2 EQU $32
ADR3 EQU $33
ADR4 EQU $34
OPTION EQU $39
DDRC EQU $1007
PORTB EQU $1004
PORTC EQU $1003
TCNT EQU $0E ;Free running timer
REGBAS EQU $1000
TEMP EQU $0000
*-----------------------------------------------------------
*Start of Program
ORG CODE ;Start of the program
LDX #REGBAS ;Load 1000 to index X
LDAA #%10000000
STAA OPTION,X ;Turn on ADC
LDAA #$21 ;Scan:MULT = 1:0
STAA ADCTL,X ;Single mode continous
LDY #TEMP ;Load 0000 to index Y
*-----------------------------------------------------------
*Delay 100 micro seconds
DELAY LDX #0F ;Delay approximately for 100microsec
YYY DEX
BNE YYY
RTS
*----------------------------------------------------------
*On CCF
CCF.ON BRCLR ADCTL,X,$80,CCF.ON ;Check if CCF is on
*---------------------------------------------------------
*Set PortC as output
LDAA #$01
STAA DDRC
*--------------------------------------------------------
*Joystick Instruction
*--------------------------------------------------------
LOOP1 LDAA ADR2,X
STAA O,Y ;Put data A to 0000
INX ;(1000,1001)
INY ;(0000,0001)
CPX #$1002
BNE LOOP1
POTX LDAA $0000 ;Load value of ADR2 from 0000 to A
CMPA #%10000000;Compare with 2.5V
BEQ POTY ;Go to POTY if equal to 2.5V
BHI AA ;Go to AA if higher than 2.5V
BLO BB ;Go to BB if lower than 2.5V
POTY LDAB $0001 ;Load value of ADR3 from 0001 to B
CMPB #%10000000;Compare with 2.5v
BEQ PB3 ;Go to PB3 if equal to 2.5V,lid up centre LED
BHI CC ;Go to CC if higher than 2.5V
BLO DD ;Go to DD if lower than 2.5V
AA LDAA $0000 ;Load value of ADR2 to A
CMPA #%10100110;Compare with 3.25v
BLS POTY ;Go to POTY if lower or same than 3.25
BHI EE ;Go to EE if higher than 3.25v
BB LDAA $0000 ;Load value of ADR2 to A
CMPA #%01011010;Compare with 1.75v
BHS POTY ;Go to POTY if higher or same than 1.75v
BLO FF ;Go to FF if lower than 1.75v
CC LDAB $0001 ;Load value of ADR3 to B
CMPB #%10100110;Compare with 3.25v
BLS PB3 ;Go to PB3 if lower or same than 3.25v
BHI PB7 ;Go to PB7 if higher than 3.25v
DD LDAB $0001 ;Load value of ADR3 to B
CMPB #%01011010;Compare with 1.75v
BHS PB3 ;Go to PB3 if higher or same than 1.75v
BLO PC0 ;Go to PC0 if lower than 1.75v
EE LDAB $0001 ;Load value of ADR3 to B
CMPB #%10000000;Compare with 2.5V
BHI GG ;Go to GG if higher than 2.5v
BLO HH ;Go to HH if lower than 2.5v
FF LDAB $0001 ;Load value of ADR3 to B
CMPB #%10000000;Compare with 2.5V
BHI II ;Go to II if higher than 2.5v
BLO JJ ;Go to JJ if lower than 2.5v
GG LDAB $0001 ;Load value of ADR3 to B
CMPB #%10100110;Compare with 3.25v
BLS PB2 ;Go to PB2 if lower or same than 3.25v
BHI PB0 ;Go to PBo if higher than 3.25v
HH LDAB $0001 ;Load value of ADR3 to B
CMPB #%01011010;Compare with 1.75v
BHS PB2 ;Go to PB2 if higher or same than 1.75v
BLO PB5 ;Go to PB5 if lower than 1.75v
II LDAB $0001 ;Load value of ADR3 to B
CMPB #%10100110;Compare with 3.25v
BLS PB4 ;Go to PB4 if lower or same than 3.25v
BHI PB1 ;Go to PB1 if higher than 3.25v
JJ LDAB $0001 ;Load value of ADR3 to B
CMPB #%01011010;Compare with 1.75v
BHS PB4 ;Go to PB4 if higher or same than 1.75v
BLO PB6 ;Go to PB6 if lower than 1.75v
*---------------------------------------------------------
*RANDOM NUMBER BETWEEN 100 TO 200
LDAA #$F4 ;Load Accumulator A with $F4
STAA DDRC ;store at DDRC, PC2 as input
LDAA PORTC ;Load value from Port C
TRIMX LDD TCNT,X ;Capture the value of TCNT,X and load to D
CPD #$64 ;Compare with 100
BEQ TRIMY ;Go to TRIMY if equal to 100
BHI HIGH ;Go to HIGH if higher than 100
BLO LOW ;Go to LOW if lower than 100
HIGH CPD #$C8 ;Compare with 200
BLS TRIMY ;Go to TRIMY if lower or same than 200
BHI MORE ;Go to MORE if higher than 200
LOW ADDD #$64 ;Add 100 to D
JSR TRIMY ;Jump to TRIMY
MORE SUBD #$64 ;Subtract 100 from D
JSR TRIMY ;Jump to TRIMY
TRIMY LDD TCNT,X ;Capture the value of TCNT,X and load to D
CPD #$64 ;Compare with 100
BEQ PB3 ;Go to PB3 if equal to 100, lid centre LED
BHI HIGH1 ;Go to HIGH1 if higher than 100
BLO LOW1 ;Go to LOW1 if lower than 100
HIGH1 CPD #$C8 ;Compare with 200
BLS PB3 ;Go to PB3 if lower or same than 200, lid centre LED
BHI MORE1 ;Go to MORE1 if higher than 200
LOW1 ADDD #$64 ;Add 100 to D
JSR PB3 ;Jump to PB3
MORE1 SUBD #$64 ;Subtract 100 from D
JSR PB3 ;Jump to PB3, lid centre LED
FOREVER BRA FOREVER
*---------------------------------------
*Definition of which LED lid
PB0 LDAA #$01 ;Load value of $01 to A
STAA PORTB ;Lid LED PortB 0
RTS LOOP1
PB1 LDAA #$02 ;Load value of $02 to A
STAA PORTB ;Lid LED PortB 1
RTS LOOP1
PB2 LDAA #$04 ;Load value of $04 to A
STAA PORTB ;Lid LED PortB 2
RTS LOOP1
PB3 LDAA #$08 ;Load value of $08 to A
STAA PORTB ;Lid LED PortB 3
RTS LOOP1
PB4 LDAA #$10 ;Load value of $10 to A
STAA PORTB ;Lid LED PortB 4
RTS LOOP1
PB5 LDAA #$20 ;Load value of $20 to A
STAA PORTB ;Lid LED PortB 5
RTS LOOP1
PB6 LDAA #$40 ;Load value of $40 to A
STAA PORTB ;Lid LED PortB 6
RTS LOOP1
PB7 LDAA #$40 ;Load value of $80 to A
STAA PORTB ;Lid LED PortB 6
RTS LOOP1
PC0 LDAB #$01 ;Load value of $01 to A
STAA PORTC ;Lid LED PortC 0
RTS LOOP1
[Non-text portions of this message have been removed]

(You need to be a member of m68hc11 -- send a blank email to m68hc11-subscribe@yahoogroups.com )
Re: Random Numbers and Keyboards (My design hopefully somebody can debug for me) - Tony Papadimitriou - May 6 11:06:00 2005
----- Original Message -----
From: "yew alex" <kl_mistress@kl_m...>
To: <m68HC11@m68H...
> After spending two weeks and more, I have finally done my program, but
there are still some error which I do not know, what when wrong. I hope you
guys, can help me out to assure this program works. Thanx
It would help if we knew what kind of error you see. It's near to impossible
to know what's wrong when we don't know the symptom. Anyway, at first
sight, here's one error I see:
At label PB7, the value (based on the comment and the surrounding values)
should most likely be $80, not $40.
(By the way, this list isn't a homework support hotline.)
> alex
tonyp@tony...
______________________________
controlSUITE software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!

(You need to be a member of m68hc11 -- send a blank email to m68hc11-subscribe@yahoogroups.com ) Re: Random Numbers and Keyboards (My design hopefully somebody can debug for me) - Forrest J. Cavalier III - May 6 12:24:00 2005
yew alex wrote:
> Hie Mike and everyone
>
> After spending two weeks and more, I have finally done my program, but there are
still some error which I do not know, what when wrong. I hope you guys, can help me out to
assure this program works. Thanx
1. Please study branches and subroutines again. (This is sometimes
called controlling the sequence of execution. I do not know
what your learning materials have titled it.)
In the example you posted, I see many coding errors related
to control flow. For example you have JSR where the comment indicates
a JMP. You have conditional branches where you almost certainly
meant unconditional branches.
2. Remember that writing if-then-else constructs in microprocessor assembly language
requires more thought than using a high level language. In a high level
language, the else clause is automatically skipped if the first clause runs,
for example.
But in assembly language, you must skip over the else clause by an
unconditional branch at the end of the IF clause.
3. You often use a conditional branch, followed by the opposite conditional
branch.
BHS PB2 ;Go to PB2 if higher or same than 1.75v
BLO PB5 ;Go to PB5 if lower than 1.75v
You should instead write the second as an unconditional branch....
BHS PB2 ;Go to PB2 if higher or same than 1.75v
BRA PB5 ;Go to PB5 if lower than 1.75v
This helps understand your code, and it avoids this kind of error:
BHI HIGH1 ;Go to HIGH1 if higher than 100
BLO LOW1 ;Go to LOW1 if lower than 100
(The error is what happens when it is EQUAL?)
4. After fully understanding branches and control flow,
I expect you should rewrite your program, instead of modifying it.
Debugging is harder than writing. Despite years of assembly language
experience, I would have a hard time debugging your program.
I am afraid you won't be able to do it either, but it is
your code, so you can try.
5. Single-step execution in a simulator/emulator/debugger
helps understand control flow.
6. You are probably paying someone to take a course. You might
ask them for help, instead of asking here. Help in person
is going to be better for you at this point, I expect.
______________________________
controlSUITE software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!

(You need to be a member of m68hc11 -- send a blank email to m68hc11-subscribe@yahoogroups.com )