Question

Having trouble with an automatic traffic light program. Red LED and Yellow LED won't show. We...

Having trouble with an automatic traffic light program. Red LED and Yellow LED won't show. We are using a Dragon12 Plus 2 board, Code is below

    #include C:\Users\schwarzenbar\Desktop\hcs12.inc
  
   RED: EQU $10 ;PP4
    GREEN:   EQU $40 ;PP6


   org $2000
   movb   #$FF, DDRP
   bset   PTP, #RED
    bset    DDRT,%00110000   ;PT4=Output for for IR Transmiter (IRTX)
    bclr    DDRT,%00001000   ;PT3=Input pin for IR receiver (IRRX)
    bclr    PTT,%00001000   ;PT4=0 to turn on IR Trans (IRTX)


Sensor    brclr    PTT,%00001000,Car ;Detect car, go to yes. If not execute istruction below
   bset   PTP, #RED   ;Red light ON
    bra     Sensor              ;Repeat till yes

Car    bclr    PTP,#RED   ;Red light OFF
    ldy    #500
    jsr    delayby1ms        ;delay 0.5 second
    bset    PTP,#RED         ;Red light ON
    ldy    #500
    jsr    delayby1ms        ;delay 0.5 second
    bclr    PTP,#RED         ;Red light OFF
   ldy    #500
    jsr    delayby1ms        ;delay 0.5 second
    bset    PTP,#RED         ;Red light ON
    ldy    #500
    jsr    delayby1ms        ;delay 0.5 second
    bclr    PTP,#RED         ;Red light OFF

    bset    PTP,#GREEN         ;Green light ON
    ldaa    #1
    movb    #$FF,DDRB       ;Configure Port B pins as output
    movb    #$F7,DDRP        ;Configure Port P pins (PP7,PP6,PP5,PP4,PP2,PP1 and PP0) as output


    ldx       #disp1
seg    movb    1,x+,ptb
    movb    1,x+,ptp
    ldy     #10
    jsr     delayby100ms
    cpx     #disp1+8
    bne     seg


    ldx     #disp2
seg2    movb    1,x+,ptb
    movb    1,x+,ptp
    ldy     #500
    jsr     delayby1ms
    cpx     #disp2+20
    bne     seg2
        lbra    Sensor              ;End program. Using long loop. Go to the loop label
     
   #include C:\Users\schwarzenbar\Desktop\delay.asm

disp1    dc.b    $67,$47
        dc.b    $7F,$47
        dc.b    $07,$47
        dc.b    $7D,$47


disp2    dc.b $6D,$67
         dc.b $6D,$07
         dc.b $66,$67
         dc.b $66,$07
         dc.b $4F,$67
         dc.b $4F,$07
         dc.b $5B,$67
         dc.b $5B,$07
         dc.b $06,$67
         dc.b $3F,$27

        end

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Try this...

#include "C:\Users\Alekhya\Desktop\hcs12.inc"

org $2000

movb #$FF, DDRP

bset PTP, $20

bset DDRB, 000011

bset DDRT, 010000

bclr DDRT, 001000

bclr PTT, 010000

loop brclr PTT, 001000,yes ;Detect car, go to yes. If not execute

; istruction below

bset PTP, $20 ;

bra loop;

yes bclr PTP, $20 ;

ldy #500

jsr delayby1ms ; delay

bset PTP, $20 ;Red ON

ldy #500

jsr delayby1ms ;delay again

bclr PTP, $20 ;Red OFF

ldy #500

jsr delayby1ms   ;delay 0.5

bset PTP, $20   ;Red ON

ldy #500

jsr delayby1ms   ;delay

bclr PTP, $20   ;Red OFF

ldy #500

jsr delayby1ms ;delay

bset PTP, $20 ;Red ON

ldy #500

jsr delayby1ms ;delay

bclr PTP, $20 ;Red OFF

bset PTP, $40 ;Green ON

ldaa #1

movb #$FF, DDRB ;Configure Port B pins as output

movb #$F7, DDRP ;Configure Port P pins (PP7,PP6,PP5,

;PP4,PP2,PP1 and PP0) as output

ldx   #disp1

seg movb 1,x+,ptb

movb 1,x+,ptp

ldy   #10

jsr   delayby100ms

cpx   #disp1+8

bne   seg

ldx #disp2

seg2 movb 1, x+,ptb

movb 1, x+,ptp

ldy   #500

jsr   delayby1ms

cpx   #disp2+20

bne   seg2

lbra loop ;

disp1 dc.b $67, $47

     dc.b $7F, $47

     dc.b $07, $47

     dc.b $7D, $47

     bne seg2

disp2 dc.b $6D,$67

     dc.b $6D,$07

     dc.b $66,$67

     dc.b $66,$07

     dc.b $4F,$67

     dc.b $4F,$07

     dc.b $5B,$67

     dc.b $5B,$07

     dc.b $06,$67

     dc.b $3F,$27

   end

Add a comment
Know the answer?
Add Answer to:
Having trouble with an automatic traffic light program. Red LED and Yellow LED won't show. We...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT