Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Acquiring Atmega8 ADC0 Data using AVR Studio 4

Status
Not open for further replies.

mostafagb

Newbie level 1
Joined
Jan 16, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Bangladesh
Activity points
1,319
.include "m8def.inc"
.cseg
.org $000
nop
RESET: rjmp STKINIT


.org $0012
rjmp TIMER1OVF ;to genertae 5-sec Time Tick using Timer-1 Overflow Interrupt




.org $0030
STKINIT:
ldi r16, 0x5F ; stack initialize
out spl, r16
ldi r16, 0x04
out sph, r16



L1: ;--Port-B Init--------
ldi r16, 0xD7; 1101 0111 ;
out ddrb, r16

ldi r16, 0x00
out ddrc, r16

ldi r16, 0xFF;
out ddrd, r16 ;11110000


TIMINIT: ;--- Timer-1 Initialization-- to generate 5-sec Time Tick from interna/ 1MHz/256
ldi r16, 0xF7 ; initial value for TCNT1L for 5sec
ldi r17, 0xC2 ; for TCNT1H
out TCNT1H, r17
out TCNT1L, r16

ldi r16, 0x00 ; configure normal T1 operation as upcounter
out TCCR1A, r16
ldi r16, 0x04 ; stopped internal clock /1024 for connection : use 0x05 to statrt Timer1
out TCCR1B, r16 ; Counter0 is started in Normal Mode

ldi r16, 0x04 ; 05 enables T1, T0 and 04 only for Timer-1
out TIMSK, r16
sei ; interrupt enabled



L2: ; CCTAB: ; cc-code table initialization 0060h - 006Fh

ldi r16, 0x3F ; cc0code of 0
sts 0x60, r16

ldi r16, 0x06 ; cc0code of 1
sts 0x61, r16

ldi r16, 0x5B ; cc0code of 2
sts 0x62, r16

ldi r16, 0x4F ; cc0code of 3
sts 0x63, r16

ldi r16, 0x66 ; cc0code of 4
sts 0x64, r16

ldi r16, 0x6D ; cc0code of 5
sts 0x65, r16

ldi r16, 0x7D ; cc0code of 6
sts 0x66, r16

ldi r16, 0x07 ; cc0code of 7
sts 0x67, r16

ldi r16, 0x7F ; cc0code of 8
sts 0x68, r16

ldi r16, 0x6F ; cc0code of 9
sts 0x69, r16

ldi r16, 0x77 ; cc0code of A
sts 0x6A, r16

ldi r16, 0x7C ; cc0code of b
sts 0x6B, r16

ldi r16, 0x39 ; cc0code of C
sts 0x6C, r16

ldi r16, 0x5E ; cc0code of d
sts 0x6D, r16

ldi r16, 0x79 ; CC-code of E
sts 0x6E, r16

ldi r16, 0x71 ; cc0code of F
sts 0x6F, r16

ldi r21, 0x00
sts 0x76, r21
sts 0x77, r21

rcall HEX2CC
HERE: rcall CCXPD
rjmp HERE


TIMER1OVF: ;----Timer-1 Overflow Interrupt----
ldi r21, 0x00
out TCCR1B, r21 ; Timer OFF

ldi r16, 0xF7 ; initial value for TCNT1L for 5sec
ldi r17, 0xC2 ; for TCNT1H
out TCNT1H, r17
out TCNT1L, r16 ;

ldi r21, 0x04
out TCCR1B, r21 ; Timer ON

;a -- indication of ISRT1---
sbi portb, pb0
rcall DELAY1
cbi portb, pb0
rcall DELAY1
;----------------
rcall ACQ
sei
reti

;--------------------------------------------------------------------------------
ACQ: ;rjmp LQ
L3A: ldi r16, 0x80 ;ADEN=1,
out ADCSR, r16

L3AA: ldi r21, 0x40; r16, 0x40 ; 0100 0000 ref = Vcc
out ADMUX, r21; r16 ; ch-0
;---------------------------
MDISP:

L3B: in r16, ADCSR
ori r16, 0x40 ; ADC is started
out ADCSR, r16 ; ADC is stared single conversion



AGNCHKX:in r16, ADCSR
sbrc r16, 4 ; skip next instruction if bit-4 of r16 is found cleared
rjmp RDADC
rjmp AGNCHKX


RDADC: in r16, ADCSR
andi r16, 0xFF ; resetting the ADIF-bit
out ADCSR, r16
;---------------------------------
;XL: ; --Input BIN-----
in r12, ADCL ; ldi r16, 0xFE ;in r18, ADCL
in r13, ADCH ;
LQ:
mov r21, r13
;ldi r21, 0x23
sts 0x76, r21

mov r21, r12
; ldi r21, 0x67
sts 0x77, r21



;--- converting Hex into CC7S codes----------
rcall HEX2CC

LQ1: rcall CCXPD

;rcall DELAY1

ret
;------------------------------------------
HEX2CC: clr r27 ; x = r27, r26
clr r29 ; y = r29, r28
clr r31 ; z = r31, r30

ldi r26, $76 ; X = 0075h STAB
ldi r30, $84 ; Z = 0082h CCTAB

ldi r16, $02 ; 2 byte Hex to convert
;--------------------------
AGN: ld r17, X+ ; r17 = 12 X points at STAB
mov r18, r17 ; r18 = 23
swap r17 ; 32
andi r17, 0x0F ; r17 = 02
ldi r19, 0x60
add r17, r19 ; r17 = 62

mov r28, r17
;------------------
ld r17, Y ; getting CC-code from LUTAB
st Z+, r17 ; outting into CCTAB
;------------------

mov r17, r18
andi r17, 0x0F ; r17 = 01
ldi r19, 0x60
add r17, r19 ; r17 = 61

mov r28, r17
;------------------
ld r17, Y ; getting CC-code from LUTAB
st Z+, r17
;------------------

dec r16

breq DONE

rjmp AGN


DONE: ret

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

;----------------------------------------------------
CCXPD: clr r31
ldi r30, $84

ldi r16, $04

ld r17, Z+ ; DP0
out PORTD, r17
cbi PORTB, pb7
sbi PORTB, pb6
sbi PORTB, pb2
sbi PORTB, pb1

rcall DELAY

ld r17, Z+ ; DP1
out PORTD, r17
sbi PORTB, pb7
cbi PORTB, pb6
sbi PORTB, pb2
sbi PORTB, pb1
rcall DELAY

ld r17, Z+ ; DP2
out PORTD, r17
sbi PORTB, pb7
sbi PORTB, pb6
cbi PORTB, pb2
sbi PORTB, pb1
rcall DELAY

ld r17, Z+ ; DP3
out PORTD, r17
sbi PORTB, pb7
sbi PORTB, pb6
sbi PORTB, pb2
cbi PORTB, pb1
rcall DELAY

ret

;-----------------------------------------------------
DELAY: ldi r17, 20
cag: ldi r18, 20
mag: dec r18
brne mag
dec r17
brne cag
ret

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

DELAY1: ldi r17, 10
cagainx:ldi r18, 10
magainx:ldi r19, 10
fagainx:dec r19
brne fagainx
dec r18
brne magainx
dec r17
brne cagainx
ret
;----------------------


.exit
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top