how to control multiplexed 4x7-seg by atmega32

Discussion in 'Programmer's Corner' started by qamishlo, May 25, 2010.

  1. qamishlo

    Thread Starter New Member

    Apr 8, 2009
    1
    0
    I have some project in school and I need some help. So project is make an asm code (asemmbly code)for 4 digit x 7-segment(4 digit multiplexed 7-seg) some thing like driver...so I have to control digits by PORTC (bits 0,1,2,3) and control segment's leds by PORTB (B0,...,B7), by using timer0 overflow interrup and ATmega32..:!!interrupt time is about 4 ms. so how to show as example 0x1101 number on my segments?
    I have done some code but I don't know how to continue::
    here is my code

    ;----------------------------------------------
    ;7-Segment


    ;----------------------------------------------

    .include "m32def.inc"

    .equ Nbr_of_digits=4
    .equ A=0x0111

    .dseg
    .org 0x60
    t0_ovf_cnt: .byte 2 ;timer 0 overflow counter(16-bit)
    B: .byte 2

    .org 0x100
    Result: .byte 20

    .cseg
    .org 0
    jmp Reset

    jmp EXT_INT0_SVC
    jmp EXT_INT1_SVC
    jmp EXT_INT2_SVC

    jmp TIMER2_COMP_SVC
    jmp TIMER2_OVF_SVC
    jmp TIMER2_CAPT_SVC

    jmp TIMER1_COMPA_SVC
    jmp TIMER1_COMPB_SVC
    jmp TIMER1_CVF_SVC

    jmp TIMER0_COMP_SVC
    jmp TIMER0_OVF_SVC

    jmp ST_COMPLETE_SVC ;serial transfer complete
    jmp RX_COMPLETE_SVC
    jmp DR_EMPTY_SVC ;USART DATA Reg Empty
    jmp TX_COMPLETE_SVC

    jmp AD_READY_SVC
    jmp EEPROM_READY_SVC

    jmp ANA_COMA_SVC
    jmp TWI_SVC ;2 Wire Serial Interface
    jmp SPM_READY_SVC

    RESET:
    ldi r16, LOW(RAMEND)
    out spl,r16
    ldi r16,HIGH(RAMEND)
    out sph,r16

    ldi YL,LOW ( Result )
    ldi YH,HIGH( Result )



    call TIMER0_OVF_SVC_INIT
    call ShowHex


    sei ;Global Interrupt Enable


    LOOP:
    rjmp LOOP

    TIMER0_OVF_SVC_INIT:


    in r16,TCCR0
    ori r16,(1<<CS00)
    ;ori r16,(1<<CS02)|(1<<CS00)
    out TCCR0, r16

    in r16,TIMSK
    ori r16,(1<<TOIE0)
    out TIMSK,r16

    clr r16
    sts t0_ovf_cnt,r16
    sts t0_ovf_cnt+1,r16

    ret

    TIMER0_OVF_SVC:

    push r24
    in r24,SREG
    push r24
    push r25

    lds r24,t0_ovf_cnt
    lds r25,t0_ovf_cnt+1
    adiw r25:r24,1
    sts t0_ovf_cnt,r24
    sts t0_ovf_cnt+1,r25


    pop r25
    pop r24
    out SREG,r24
    pop r24
    sei
    ldi r19,Nbr_of_digits
    dec r19
    breq TIMER0_OVF_SVC_INIT


    reti

    EXT_INT0_SVC:
    EXT_INT1_SVC:
    EXT_INT2_SVC:
    TIMER2_COMP_SVC:
    TIMER2_OVF_SVC:
    TIMER2_CAPT_SVC:
    TIMER1_COMPA_SVC:
    TIMER1_COMPB_SVC:
    TIMER1_CVF_SVC:
    TIMER0_COMP_SVC:
    ;TIMER0_OVF_SVC:
    ST_COMPLETE_SVC:
    RX_COMPLETE_SVC:
    DR_EMPTY_SVC:
    TX_COMPLETE_SVC:
    AD_READY_SVC:
    EEPROM_READY_SVC:
    ANA_COMA_SVC:
    TWI_SVC:
    SPM_READY_SVC:

    reti

    Hex2Bin:

    ldi ZL,LOW ( ConvTbl<<1 )
    ldi ZH,HIGH( ConvTbl<<1 )

    andi r16,0x0f
    clr r17

    add ZL,r16
    adc ZH,r17

    lpm r16,Z
    st Y+,r16
    ret
    .org 0x200
    ConvTbl:
    .db 0b00111111,0b00000110,0b01011011,0b01001111,0b01100110,0b01101101
    .db 0b01111100,0b00000111,0b01111111,0b01100111,0b00001010,0b00001011
    .db 0b00001100,0b00001101,0b00001110,0b00001111

    ShowHex:
    ldi r16,LOW(A)
    ldi r17,high(A)

    sts B,r16
    sts B+1,r17
    call Hex2Bin

    ret
     
Loading...