I have some project and 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 1101 number on my segments? in this page http://www.mikrocontroller.net/articles/AVR-Tutorial:_7-Segment-Anzeige there is some tutorial about multiplexting but the example is about counting..so in my project I need only to display wanted data on segments.
you may solve it this way: first timer0 int: PORTB gets information for the first number and PC0 goes low to switch the first seven-segment on. nex timer0 int: PC0 goes high to deactivate the first seven segment. PORTB gets information for the second number. PC1 goes low to activate second seven segment. same for the next interupts, so that the result will be like: first segment, then next, then next, then last, begin aggain with first. with 4 ms timer interrupt u get about 64 Hz display rate. :-) hope it helps
ähm short qustion: what resistor values do you use for the segments? Because you must ensure not to exceed the maximum current into PC0,PC1,PC2 or PC3. current int these pins is the sum of all acivated cathodes of the seven segment with my program idea described above. :-)
thank you very much:)hmm I just want to programm it.:)I haven't built it
yet..so I don't know what is resistor's values..:
here is my trying but it dosn't work.. maybe u can help me...I don't
know exactly how to display data on portB
.include "m32def.inc"
.equ Nbr_of_digits=4
.equ A=0x1234
.dseg
.org 0x60
t0_ovf_cnt: .byte 2 ;timer 0 overflow counter(16-bit)
NextDigit: .byte 1
Tulos: .byte 1
.org 0x100
Result: .byte 20
B: .byte 2
.cseg
.org 0
jmp Start
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
Start:
ldi R16, Low(RAMEND)
out SPL, R16
ldi R16,HIGH(RAMEND)
out SPH,R16
clr r17
ldi r19, Nbr_of_digits ;laskuri
ldi YL,LOW(Result)
ldi YH,HIGH(Result)
ldi r16, $FF
out DDRB, r16
;
ldi r16, $0F
out DDRC, r16
ldi r16,0b11111110
sts NextDigit, r16
;
call ShowHex
call TIMER0_OVF_SVC_INIT
sei ;Global Interrupt Enable
LOOP:
rjmp LOOP
TIMER0_OVF_SVC_INIT:
in r16,TCCR0
ori r16,(1<<CS00) ;bittien asetus
;ori r16,(1<<CS02)|(1<<CS00) ;bittien asetus
out TCCR0, r16
in r16,TIMSK
ori r16,(1<<TOIE0)
out TIMSK,r16
clr r16
sts t0_ovf_cnt,r16 ;alapään nollaus
sts t0_ovf_cnt+1,r16 ;yläpään nollaus
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
;tähän toiminto eli digitien päivitys
;joku tila muuttuja, jonka arvo kasvaa yhdellä(ram:ssa)
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
Nibble2Bin:
ldi ZL,LOW ( ConvTbl<<1 )
ldi ZH,HIGH( ConvTbl<<1 )
andi r16,0x0f
clr r17
add ZL,r16
adc ZH,r17
lpm r18,Z
st Y+, r18
out PORTB, Y+
ret
.org 0x200
ConvTbl:
.db 0b00111111,0b00000110,0b01011011,0b01001111,0b01100110,0b01101101
.db 0b01111100,0b00000111,0b01111111,0b01100111,0b00001010,0b00001011
.db 0b00001100,0b00001101,0b00001110,0b00001111
ShowHex:
clr r16
clr r17
ldi r16,LOW(A)
ldi r17,HIGH(A)
sts B,r16
sts B+1,r17
call Byte2Nibble
;lds r16,A
;swap r16
;andi r16,0x0f
ret
Byte2Nibble:
push r16
swap r16
andi r16,0x0f
call Nibble2bin
pop r16
andi r16,0x0f
call Nibble2bin
ret
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.
