Need Help Converting 8051 microcontroller to HCS12 assembly

Discussion in 'Embedded Systems and Microcontrollers' started by mikeknight, Oct 18, 2009.

  1. mikeknight

    Thread Starter New Member

    Sep 23, 2009
    8
    0
    Here's the code:

    //Define the Port PINS
    a_red bit p0.0
    a_amber bit p0.1
    a_green bit p0.2

    b_red bit p0.3
    b_amber bit p0.4
    b_green bit p0.5

    c_red bit p0.6
    c_amber bit p0.7
    c_green bit p2.7

    d_red bit p2.6
    d_amber bit p2.5
    d_green bit p2.4

    //Define RAM Locations
    multiplier equ 30h
    current_signal_duration equ 31h

    //DEFINE BIT ADDRESS
    signal_f bit 00h ;if 1 then switch to next signal

    //DEFINE Constants

    MULTIPLIER_DEFAULT DATA 20
    DURATION_GREEN DATA 10
    DURATION_AMBER DATA 2

    //TIMER SUBROUTINES
    timer:
    push acc
    push b
    push psw
    push dph
    push dpl
    clr TF0
    mov th0,#3ch
    mov tl0,#0B0h
    call check_timer
    pop dpl
    pop dph
    pop psw
    pop b
    pop acc
    reti

    check_timer:
    djnz multiplier,r1_check_timer
    mov multiplier,#MULTIPLIER_DEFAULT ;One second ended reload value
    djnz current_signal_duration,r1_check_timer
    setb signal_f ;signal duration ended move to nxt signal
    r1_check_timer:
    ret

    //MAIN Program
    org 0000h
    jmp main

    org 000bh
    jmp timer

    org 0030h
    main:
    mov multiplier,#MULTIPLIER_DEFAULT
    setb EA ;Enable Interrupt
    setb ET0 ;Enable timer 0 Interrupt
    clr signal_f
    mov th0,#3ch
    mov tl0,#0B0h
    setb tcon.4 ;start timer

    loop:
    mov current_signal_duration,#DURATION_GREEN
    clr a_green
    setb a_amber
    setb a_red
    setb b_green
    setb b_amber
    clr b_red
    setb c_green
    setb c_amber
    clr c_red
    setb d_green
    setb d_amber
    clr d_red


    jnb signal_f,$
    clr signal_f
    mov current_signal_duration,#DURATION_AMBER
    setb a_green
    clr a_amber
    jnb signal_f,$
    clr signal_f

    mov current_signal_duration,#DURATION_GREEN
    setb a_amber
    clr a_red
    clr b_green
    jnb signal_f,$
    clr signal_f

    mov current_signal_duration,#DURATION_AMBER
    setb b_green
    clr b_amber
    jnb signal_f,$
    clr signal_f

    mov current_signal_duration,#DURATION_GREEN
    setb b_amber
    clr b_red
    clr c_green
    jnb signal_f,$
    clr signal_f

    mov current_signal_duration,#DURATION_AMBER
    setb c_green
    clr c_amber
    jnb signal_f,$
    clr signal_f

    mov current_signal_duration,#DURATION_GREEN
    setb c_amber
    clr c_red
    clr d_green
    jnb signal_f,$
    clr signal_f

    mov current_signal_duration,#DURATION_AMBER
    setb d_green
    clr d_amber
    jnb signal_f,$
    clr signal_f
    ajmp loop

    $include(timer.inc)
    End


    Thanks!
    Mike
     
    Last edited: Oct 18, 2009
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
  3. mikeknight

    Thread Starter New Member

    Sep 23, 2009
    8
    0
    Can you help me find this. Is their any program that could do this for me.

    Or if you could just translate a part of the code that would be great.

    Most of it is repetitive anyways.

    Mike
     
Loading...