Search the web
Sign In
New User? Sign Up
AVRButterFly · AVR ButterFly & Beginners Group
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
WAIT-FOR TIMER SOUND DEMO (34 Bytes)   Message List  
Reply | Forward Message #983 of 1000 |
Program shows use of timer 0 as a wait-for timer in Assembler for the AVR Butterfly/Atmega169 to emit a tone on the speaker. (approx 35 bytes)


;--------------------------------------------------;
; WAIT_TIMER.ASM for AVR BUTTERFLY                 ;
; AUTHOR: DANIEL J. DOREY (RETRODAN AT AVR FREAKS) ;
; CREATED: 20-OCT-09            UPDATED: 20-OCT-09 ;
;                                                  ;
; PROGRAM DEMONSTRATES USE OF 8-BIT WAIT-FOR TIMER ;
;--------------------------------------------------;

.INCLUDE "M169DEF.INC" ;(BUTTERFLY DEFINITIONS)

;----------------------------------------;
; FIRST I'LL DEFINE SOME REGISTER TO USE ;
;----------------------------------------;
.DEF A = R16   ;GENERAL PURPOSE ACCUMULATOR
.DEF I = R21   ;INDEXES FOR LOOP CONTROL
.DEF J = R22

.ORG 0000
    RJMP ON_RESET  ;REBOOT/START-UP VECTOR   
                   ;INTO OUR PROGRAM

;-----------------------------------------;
; WE START HERE ON ALL RESEST AND REBOOTS ;
; FIRST WE SETUP A STACK AREA AT HIGH RAM ;
;-----------------------------------------;
START:
ON_RESET:
    LDI A,LOW(RAMEND)   ;SETUP STACK POINTER
    OUT SPL,A           ;SO CALLS TO SUBROUTINES
    LDI A,HIGH(RAMEND)  ;WORK CORRECTLY
    OUT SPH,A           ;

;--------------;
; MAIN ROUTINE ;
;--------------;
MAIN: SBI DDRB,5        ;SET FOR SPEAKER OUTPUT ON PORT B
      LDI A,3           ;SET PRESCALE TO 64,
      OUT TCCR0A,A      ;~=2,000,000Hz/64/2 ~= 15KHz
MAINL:SBI PORTB,5       ;TURN SPEAKER ON
      RCALL WAITER      ;WAIT
      CBI PORTB,5       ;TURN SPEAKER OFF
      RCALL WAITER      ;WAIT
       RJMP MAINL       ;GO ROUND

;-----------------------------;
; WAITS FOR CLOCK TO HIT ZERO ;
;-----------------------------;              
WAITER:
WLOOP:IN A,TCNT0        ;READ THE CLOCK
      CPI A,0           ;CHECK IF ZERO YET
       BRNE WLOOP       ;WAIT FOR ZERO
        RET










Tue Oct 20, 2009 9:57 pm

retr0dan
Offline Offline
Send Email Send Email

Forward
Message #983 of 1000 |
Expand Messages Author Sort by Date

Program shows use of timer 0 as a wait-for timer in Assembler for the AVR Butterfly/Atmega169 to emit a tone on the speaker. (approx 35 bytes) ...
retr0dan
Offline Send Email
Oct 20, 2009
9:58 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help