[ บทความ : ตัวอย่างสำหรับ AVR ตอนที่ 6 ] ทดสอบ Timer ของ ET-AVR V1/2 |
ตัวอย่างซอร์สโค้ดสำหรับติดต่อกับ TIMER ของบอร์ด ET-AVR V1/2 เป็นดังนี้
;*************************************************************************** ;* A P P L I C A T I O N N O T E F O R T H E A V R F A M I L Y ;* ;* Number : ET-AVR V1/V2 ;* File Name :"timer0.asm" ;* Title :rs232 echo ;* Date :6/1/42 ;* Version :1.0 ;* Support telephone :712 1120-1 (ETT) ;* Support fax :3917216 (ETT) ;* Support www :www.etteam.com,www.ett.co.th ;* Target MCU :AT90S8535/AT90LS8535 ;* ;*************************************************************************** ; .include "8535def.inc" .org $000 rjmp RESET ;Reset Handle .org $009 ;Timer0 overflow Handle rjmp TIM0_OVF ;**************************************************************************** ;* ;* Test/Example Program ;* ;**************************************************************************** ; .def temp =r19 ; RESET: ldi temp,low(RAMEND) out SPL,temp ;init Stack Pointer Low ldi temp,high(RAMEND) out SPL+1,temp ;init Stack Pointer High sei ;set golbal interrupt ldi temp,0b00000001 ;set timer0 interrupt out TIMSK,temp ldi temp,0xFF ;set PORTD.1 output port out DDRB,temp ldi temp,0x00 out TCNT0,temp ;initial value of timer/counter0 ldi temp,0b00000101 ;set set prescale and start timer/counter0 out TCCR0,temp ldi temp,0xFF loop: rjmp loop TIM0_OVF: com temp out PORTB,temp reti
;*************************************************************************** ;* A P P L I C A T I O N N O T E F O R T H E A V R F A M I L Y ;* ;* Number : ET-AVR V1/V2 ;* File Name :"timer20v.asm" ;* Title :rs232 echo ;* Date :6/1/42 ;* Version :1.0 ;* Support telephone :712 1120-1 (ETT) ;* Support fax :3917216 (ETT) ;* Support www :www.etteam.com,www.ett.co.th ;* Target MCU :AT90S8535/AT90LS8535 ;* ;*************************************************************************** ; .include "8535def.inc" .org $000 rjmp RESET ;Reset Handle .org $004 ;Timer0 overflow Handle rjmp TIM2_OVF ;**************************************************************************** ;* ;* Test/Example Program ;* ;**************************************************************************** ; .def temp =r19 ; RESET: ldi temp,low(RAMEND) out SPL,temp ;init Stack Pointer Low ldi temp,high(RAMEND) out SPL+1,temp ;init Stack Pointer High sei ;set golbal interrupt ldi temp,0b01000000 ;set timer2 interrupt out TIMSK,temp ldi temp,0xFF ;set PORTC output port out DDRB,temp ldi temp,0x00 out TCNT2,temp ;initial value of timer/counter2 ldi temp,0b00000101 ;set set prescale and start timer/counter1 out TCCR2,temp ldi temp,0xFF loop: rjmp loop TIM2_OVF: com temp out PORTB,temp reti
;*************************************************************************** ;* A P P L I C A T I O N N O T E F O R T H E A V R F A M I L Y ;* ;* Number : ET-AVR V1/V2 ;* File Name :"timer10v.asm" ;* Title :rs232 echo ;* Date :6/1/42 ;* Version :1.0 ;* Support telephone :712 1120-1 (ETT) ;* Support fax :3917216 (ETT) ;* Support www :www.etteam.com,www.ett.co.th ;* Target MCU :AT90S8535/AT90LS8535 ;* ;*************************************************************************** ; .include "8535def.inc" .org $000 rjmp RESET ;Reset Handle .org $008 ;Timer0 overflow Handle rjmp TIM1_OVF ;**************************************************************************** ;* ;* Test/Example Program ;* ;**************************************************************************** ; .def temp =r19 ; RESET: ldi temp,low(RAMEND) out SPL,temp ;init Stack Pointer Low ldi temp,high(RAMEND) out SPL+1,temp ;init Stack Pointer High sei ;set golbal interrupt ldi temp,0b00000100 ;set timer1 interrupt out TIMSK,temp ldi temp,0xFF ;set PORTD output port out DDRD,temp ldi temp,0x00 out TCNT1H,temp ;initial value of timer/counter1 out TCNT1L,temp ldi temp,0b00000010 ;set set prescale and start timer/counter1 out TCCR1B,temp ldi temp,0xFF loop: rjmp loop TIM1_OVF: com temp out PORTD,temp retiสามารถ download ไฟล์ตัวอย่างของบอร์ด พร้อม assembler ได้เลยครับ