;MCU is mega16 ,xtal for 8M
.include "m16def.inc"
.include "Reg_Mem_def.inc"
.include "Constant_def.inc"
;**************************************************************************************************************
;----------------------------------------------
.ORG 0x00
RJMP Reset
;*********************MEGA16***********************
.ORG $002 ;External Interrupt0 Vector Address
RETI
.ORG $004 ;External Interrupt1 Vector Address
RETI
.ORG $006 ;Output Compare2 Interrupt Vector Address
RETI
.ORG $008 ;Overflow2 Interrupt Vector Address
RETI
.ORG $00A ;Input Capture1 Interrupt Vector Address
RETI
.ORG $00C ;Output Compare1A Interrupt Vector Address
RETI
.ORG $00E ;Output Compare1B Interrupt Vector Address
RETI
.ORG $010 ;Overflow1 Interrupt Vector Address
RJMP Timer_1
.ORG $012 ;Overflow0 Interrupt Vector Address
RETI
.ORG $014 ;SPI Interrupt Vector Address
RETI
.ORG $016 ;UART Receive Complete Interrupt Vector Address
RETI
.ORG $018 ;UART Data Register Empty Interrupt Vector Address
RETI
.ORG $01A ;UART Transmit Complete Interrupt Vector Address
RETI
.ORG $01C ;ADC Interrupt Vector Address
RETI
.ORG $01E ;EEPROM Interrupt Vector Address
RETI
.ORG $020 ;Analog Comparator Interrupt Vector Address
RETI
.ORG $022 ;Irq. vector address for Two-Wire Interface
RETI
.ORG $024 ;External Interrupt2 Vector Address
RETI
.ORG $026 ;Output Compare0 Interrupt Vector Address
RETI
.ORG $028 ;Store Program Memory Ready Interrupt Vector Address
RETI
Timer_1:
push temp
in temp,sreg
push temp
LDI temp,high(65536-1250);10ms write:
OUT TCNT1H,temp ; first write to H and then L while write to TCNT1.
LDI temp,low(65536-1250) ; first read L and then H while read from TCNT1.
OUT TCNT1L,temp
;------------cpl the pc7 ----------------
ldi temp_2,(1<<;PC7)
in temp,PORTC
eor temp,temp_2
out PORTC,temp
;---------------------------------------------
pop temp
out sreg, temp
pop temp
RETI
;**********************************************************************
Reset:
LDI temp,Low(RAMEND)
OUT SPL,temp ;Set stack pointer to last internal RAM location
LDI temp,High(RAMEND)
OUT SPH,temp
;-------------------------------------------------------
LDI temp,0
OUT DDRD,temp
OUT DDRC,temp
OUT DDRB,temp
OUT DDRA,temp
OUT PORTA,temp
OUT PORTB,temp
OUT PORTC,temp
OUT PORTD,temp
;------------------------------
LDI temp,(1<<;PC7) ;enable bit7 of portc to output.
OUT DDRC,temp
;-----------------------------
cli ;off all interrupt
RCALL Initialize_Timer1
RCALL Enable_Timer1_interrupt
sei
loop_1:
rjmp loop_1
;-------------------------------------------
Initialize_Timer1:
LDI temp,CLK_DIV64 ;Timer1 base time for 0.125*64=8us
OUT TCCR1B,temp
RET
Enable_Timer1_interrupt:
;---------set timer1 to interrupt.----------------------
LDI temp,0xFF ;clear the interrupt mark of timer.
OUT TIFR,temp
LDI temp,0B00000100 ;enable timer1 interrupt
OUT TIMSK,temp
;------------------------------------------------
LDI temp,high(65536-1250);10ms,write:
OUT TCNT1H,temp ; first write to H and then L while write to TCNT1.
LDI temp,low(65536-1250);read:
OUT TCNT1L,temp ;first read L and then H while read from TCNT1.
RET |