чета не фурычит,не судите строго только изучаю АЦП.
пишу только на ASM. В инете не одного примера АЦП на ASM и Atmega8.
знающие люди помогите плизз.
- Код: Выделить всё • Развернуть
.include "m8def.inc"
#define F_CPU (4000000)
.def Temp1=R16
.def Temp2=R17
.equ AtBCD0 = 4 ;address of r4 äëÿ ïîäïðîãðàììû BIN2_BCD
.equ AtBCD2 = 6 ;address of r6
.dseg
Digit: .byte 2
.cseg
.org 0
rjmp RESET ;External Pin, Power-on Reset, Brown-out Reset, and Watchdog Reset
rjmp INT_0 ;External Interrupt Request 0
rjmp INT_1 ;External Interrupt Request 1
rjmp TIMER2_COMP ;Timer/Counter2 Compare Match
rjmp TIMER2_OVF ;Timer/Counter2 Overflow
rjmp TIMER1_CAPT ;Timer/Counter1 Capture Event
rjmp TIMER1_COMPA ;Timer/Counter1 Compare Match A
rjmp TIMER1_COMPB ;Timer/Counter1 Compare Match B
rjmp TIMER1_OVF ;Timer/Counter1 Overflow
rjmp TIMER0_OVF ;Timer/Counter0 Overflow
rjmp SPI_STC ;Serial Transfer Complete
rjmp USART_RXC ;USART, Rx Complete
rjmp USART_UDRE ;USART Data Register Empty
rjmp USART_TXC ;USART, Tx Complete
rjmp ADC_CC ;ADC Conversion Complete;;;;;;;;;;
rjmp EE_RDY ;EEPROM Ready
rjmp ANA_COMP ;Analog Comparator
rjmp TWI ;Two-wire Serial Interface
rjmp SPM_RDY ;Store Program Memory Ready
INT_0 : ret
INT_1 : ret
TIMER2_COMP : ret
TIMER2_OVF : ret
TIMER1_CAPT : ret
TIMER1_COMPA : ret
TIMER1_COMPB : ret
TIMER1_OVF : ret
TIMER0_OVF : ret
SPI_STC : ret
USART_RXC : ret
USART_UDRE : ret
USART_TXC : ret
;ADC_CC : ret
EE_RDY : ret
ANA_COMP : ret
TWI : ret
SPM_RDY : ret
reset:
ldi Temp1, LOW(RamEnd)
out SPL, Temp1
ldi Temp1, HIGH(RamEnd)
out SPH, Temp1
cli
ldi Temp1, 0b11111111
out ddrd, temp1
ldi Temp1, 0b10101011
out ADCSR, Temp1
ldi Temp1, 0b00000000
out ADMUX, Temp1
ldi r16,(1<<SE) ; Enable sleep mode
out MCUCR, r16
rcall lcd_init ; инициализация дисплея
sei
rjmp main2
main:
rjmp main
main2:
sbi ADCSR, 6
rjmp main
;********************************************************
ADC_CC:
in temp2, ADCL
in temp1, ADCH
;********************************************************
BIN_BCD:
; Input (r17:r16) output BCD number (r6:r5:r4:r3:r2).
; High registers used: 4(r16,r17,r18,r19)
; Pointers used: Z
ldi r18,16 ;Init loop counter ;init ñ÷åò÷èê öèêëà
clr r6 ;clear result (3 bytes); ÷åòêèé ðåçóëüòàò (3 áàéòà)
clr r5
clr r4
clr ZH ;clear ZH (not needed for AT90Sxx0x); ÿñíî, ZH (íå òðåáóåòñÿ äëÿ AT90Sxx0x)
bBCDx_1:
lsl r16 ;shift input value; ñäâèã âõîäíîãî çíà÷åíèÿ
rol r17 ;through all bytes, ÷åðåç âñåõ áàéòîâ
rol r4 ;
rol r5
rol r6
dec r18 ;decrement loop counter; óìåíüøåíèå ñ÷åò÷èê öèêëà
brne bBCDx_2 ;if counter not zero, åñëè ñ÷åò÷èê íå ðàâåí íóëþ
; ðàñïðåäåëèì ÷èñëà ïî ÿ÷åéêàì
ldi r18,0x0F
mov r2,r4
and r2,r18
swap r4
mov r3,r4
and r3,r18
mov r4,r5
and r4,r18
swap r5
and r5,r18
ret ;return
bBCDx_2:
ldi r30,AtBCD2+1 ;Z points to result MSB + 1; Z óêàçûâàåò íà ðåçóëüòàò MSB + 1
bBCDx_3:
ld r19,-Z ;get (Z) with pre-decrement, ïîëó÷èòü (Z) ñ ïðåäåêðåìåíòà
subi r19,-$03 ;add 0x03
sbrc r19,3 ;if bit 3 not clear; åñëè áèò 3 íå ÿñíî,
st Z,r19 ;store back
ld r19,Z ;get (Z)
subi r19,-$30 ;add 0x30
sbrc r19,7 ;if bit 7 not clear; åñëè áèò 7 íå ÿñíî,
st Z,r19 ;store back
cpi ZL,AtBCD0 ;done all three?; ñäåëàòü âñå òðè?
brne bBCDx_3 ;loop again if not; öèêë ñíîâà, åñëè íå
; rjmp bBCDx_1
;****************************************************************
;**********************************************************************
;ButtonRes:
;âûâîä íà lcd
ldi r16,0x45 ;;;;;;;;;;
rcall LCD_SetAddressDD ;êîîðäèíàòû â LCD ;;;;;;;;;;;
mov temp1,r6 ;;;;;;;;;;;
rcall LCD_WriteData ;;;;;;;;;;;
mov temp1,r5 ;;;;;;;;;;;;
rcall LCD_WriteData ;;;;;;;;;;
mov temp1,r4 ;;;;;;;;;;;;;;
rcall LCD_WriteData ;;;;;;;;;;
mov temp1,r3 ;;;;;;;;;;;;
rcall LCD_WriteData ;;;;;;;;
mov temp1,r2 ;;;;;;;;;;
rcall LCD_WriteData ;;;;;;;;;;;;;
;************************************************************************
; ADC_CC:
; in temp1, ADCH
; out portd,temp1
; in temp1, ADCH
; out portb,temp1
reti
.include file "C:\AVR\WH3\hd44780.asm"