I want to make a piezo buffer beeping with assembly code, but i haven't managed to yet. I have an Arduino UNO board (ATMega328p) and using avra and avrdude to build and load. The buzzer just stay silent. Here's my code:
.nolist
.include "m328pdef.inc"
.list
.equ _a = 141 ;(16000000 / 256) / 440(frequency of A) - 1
.cseg
;wgm02..0 = 7 (fast pwm, top = ocr0a)
;cs02..0 = 4 (N=256)
;com0b1..0 = 2 (clear on compare match, set at bottom)
ldi r16, 0b00100011
sts tccr0a, r16 ;need out!
ldi r16, 0b00001100
sts tccr0b, r16 ;need out!
;ocr0a = _a to obtain 440Hz
ldi r16, 141
out ocr0a, r16
;ocr0b = ocr0a/2 to obtain a duty cycle of 50%
ldi r16, 71
out ocr0b, r16
;enable output at D5 aka oc0b aka Arduino pin 5
sbi ddrd, 5
loop:
rjmp loop
Wiring is good and the buzzer too, since it works with a C sketch
EDIT: I found my answer by myself (with the help of answerers). I was accessing IO ports (tccr0a and tccr0b) with sts, while i had to use out. (tccr0a and tccr0b are IO ports defined in "m328pdef.inc" as IO addresses, not as memory addresses)