Question
An automaic traffic light. When the traffic light does not detect a vehicle (using infrared transceiver), the traffic light (RGB LED) will continuously display RED.When
An automaic traffic light. When the traffic light does not detect a vehicle (using infrared transceiver), the traffic light (RGB LED) will continuously display RED.When a vehicle is detected, the traffic light will blink RED 3 times. before turning to GREEN. By the time it is GREEN, the 7segment DSP1 and DSP2 will display '10' and counting down each second. By the time the counting reaches 5, the traffic light turns form GREEN to YELLOW. The YELLOW will blinks each second until the count reaches 0 and turns RED. The code blow is by MiniIDE software, using Dragon 12 board. We need to change the code that do the same thing by using freecale codewarrior software in c language or assembly language with dragon 12 plus board. We transiformed some of them but not working well, please help us find out what's wrong with our code or give us new code that work well in c or assembly language in codewarrior, appreciate for help!
#include "c:\miniide\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 ;Red light ON
bra loop ;Loop
yes bclr PTP, $20 ;Red light OFF
ldy #500
jsr delayby1ms ;delay 0.5 second
bset PTP, $20 ;Red light ON
ldy #500
jsr delayby1ms ;delay 0.5 second
bclr PTP, $20 ;Red light OFF
ldy #500
jsr delayby1ms ;delay 0.5 second
bset PTP, $20 ;Red light ON
ldy #500
jsr delayby1ms ;delay 0.5 second
bclr PTP, $20 ;Red light OFF
ldy #500
jsr delayby1ms ;delay 0.5 second
bset PTP, $20 ;Red light ON
ldy #500
jsr delayby1ms ;delay 0.5 second
bclr PTP, $20 ;Red light OFF
bset PTP, $40 ;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 loop ;End program. Using long loop.
; Go to the loop label
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
#include "c:\miniide\delay.asm"
Our code :
XDEF Entry, _Startup ABSENTRY Entry
INCLUDE 'derivative.inc' ROMStart EQU $4000 ; absolute address to place my code/constant data R1 EQU $1001 R2 EQU $1002 R3 EQU $1003 R4 EQU $1004 R5 EQU $1005 R6 EQU $1006 ORG ROMStart Entry: _Startup:
ORG $2000 MOVB #$FF, DDRP ;Enable RGB LED ;BSET DDRP, %01110000 ;Enable RGB (Red: PP4, Blue: PP5, Green: PP6) BSET PTP, %00010000 ;Red light ON initially when vehicle not detected BSET DDRB, %11111111 ;Enable LEDs BSET DDRJ, %00000010 ;PTJ1 controls the LEDs connected to PORTB BCLR DDRT, %00001000 ;Configure IR Detector as input (PT3) BSET DDRM, %00000100 ;RGB Common Anode BCLR PTM, %00000100
Loop: BRCLR PTT, %00001000, Detected ;Go to Detected if car is detected. If not, execute BSET PTP, %00010000 ;Red light ON BRA Loop ;Branch back to Loop
Detected: BCLR PTP, %00010000 ;Red light OFF LDY #500 JSR DELAY1ms ;Delay 500ms BSET PTP, %00010000 ;Red light ON LDY #500 JSR DELAY1ms ;Delay 500ms BCLR PTP, %00010000 ;Red light OFF LDY #500 JSR DELAY1ms ;Delay 500ms BSET PTP, %00010000 ;Red light ON LDY #500 JSR DELAY1ms ;Delay 500ms BCLR PTP, %00010000 ;Red light OFF LDY #500 JSR DELAY1ms ;Delay 500ms BSET PTP, %00010000 ;Red light ON LDY #500 JSR DELAY1ms ;Delay 500ms BCLR PTP, %00010000 ;Red light OFF
BSET PTP, %01000000 ;Green light ON LDAA #1 MOVB #$FF, DDRB ;Configure Port B pins as output MOVB #$EF, DDRP ;Configure Port P pins LDX #Disp1 Seg1: MOVB 1, X+, PORTB ;Output segment pattern MOVB 1, X+, PTP ;Output display select LDY #10 JSR DELAY100ms ;Wait for 100ms CPX #Disp1 + 8 ;Reach the end of the table? BNE Seg1 LDX #Disp2 Seg2: MOVB 1, X+, PORTB ;Output segment pattern MOVB 1, X+, PTP ;Output display select LDY #500 JSR DELAY1ms ;Wait for 500ms CPX #Disp2 + 20 BNE Seg2 LBRA Loop ;End program using long loop Disp1: DC.B $67, $47 ;Number 9 DC.B $7F, $47 ;Number 8 DC.B $07, $47 ;Number 7 DC.B $7D, $47 ;Number 6 BNE Seg2
Disp2: DC.B $6D, $67 ;Number 5 DC.B $6D, $07 ;Number 5 DC.B $66, $67 ;Number 4 DC.B $66, $07 ;Number 4 DC.B $4F, $67 ;Number 3 DC.B $4F, $07 ;Number 3 DC.B $5B, $67 ;Number 2 DC.B $5B, $07 ;Number 2 DC.B $06, $67 ;Number 1 DC.B $3F, $27 ;Number 0 DELAY1ms:
MOVB #1, R3 ;Change this value to see how fast 7-Seg displays data L3 MOVB #10, R2 L2 MOVB #240, R1 L1 NOP ;1 Intruction Clk Cycle NOP ;1 NOP ;1 DEC R1 ;4 BNE L1 ;3 DEC R2 ;Total Instr.Clk=10 BNE L2 DEC R3 BNE L3 RTS DELAY100ms:
MOVB #100, R6 ;Change this value to see how fast 7-Seg displays data L6 MOVB #100, R5 L5 MOVB #240, R4 L4 NOP ;1 Intruction Clk Cycle NOP ;1 NOP ;1 DEC R4 ;4 BNE L4 ;3 DEC R5 ;Total Instr.Clk=10 BNE L5 DEC R6 BNE L6 RTS ;************************************************************** ;* Interrupt Vectors * ;************************************************************** ORG $FFFE DC.W Entry ; Reset Vector
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started