Discussion Groups | | Fwd: Re: Random Numbers and Keyboards (My design hopefully somebody can debug for me)
Fwd: Re: Random Numbers and Keyboards (My design hopefully somebody can debug for me) - yew alex - May 6 0:23:00 2005
yew alex <kl_mistress@kl_m...> wrote: To: m68HC11@m68H...
From: yew alex <kl_mistress@kl_m...>
Date: Thu, 5 May 2005 20:57:32 -0700 (PDT)
Subject: Re: [m68HC11] Random Numbers and Keyboards (My design hopefully somebody can
debug for me)
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
__________________________________________________
">http://mail.yahoo.com
----------
*-------------------------------------------------------------------------
*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]
______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.
(You need to be a member of m68hc11 -- send a blank email to m68hc11-subscribe@yahoogroups.com )
Re: Fwd: Re: Random Numbers and Keyboards (My design hopefully somebody can debug for me) - Mike McCarty - May 6 11:22:00 2005
I echo Mr. Papadimitriou's comment about this not being a
homework hotline.
However, I do have some comments.
After DELAY, I see a return, but I don't see where any stack
got set up.
I also note that sometimes PORTC bit 0 is output, sometimes input.
This seems suspicious.
>HIGH CPD #$C8 ;Compare with 200
Why not just use 200? Or even better an equate which gives a hint.
>PB0 LDAA #$01 ;Load value of $01 to A
> STAA PORTB ;Lid LED PortB 0
> RTS LOOP1
>
Umm, what is the LOOP1 intended to convey after an RTS?
Just a style comment...
Generally, I try to avoid comments which explain what instructions
do, but rather what they accomplish. Something like...
PORTB EQU ...
PORTC EQU ...
DDRC EQU ...
...
LEDS EQU PORTB
LED0 EQU $01
...
LDAA #LED0 ; Turn on LED0
STAA LEDS,X ; .
Generally, your programming style is pretty good. Lots of comments.
I'd use fewer numbers in the actual code. If I later decide to move the
LED port to PORTD, I'd have to do a lot of editing. With an equate,
for LEDS, just one line changes.
Some of the label names are less explanatory than they could be.
More information about what is going wrong?
Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!

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