Hi everyone!

Can anybody help me with a homework which I got.

Make a program that emit sounds of different frequencies depending on the key pressed.

I need to do this on z80 and i don't know how to do it.Some ideas?

thx in advance
You could probably use Axe Parser. It includes functions to output a sound which could be tied to a getkey routine.
I might also add TI Band as an example of a program that uses Axe's sound output routine. Remember that you need a 2.5mm <-> 3.5mm adapter to hear sound through regular headphones.
Another way would be to write mobileTunes 3.1 sounds, if you want a pre-packaged solution. However, the root of your homework is asking you to generate a tone at a specific frequency, if you think about it. In other words, you have to do a few things:
1) Read the keys, and pick a frequency based on which key is pressed.
2) Use math to determine how many CPU cycles to wait in between toggling the link port line(s) to get the desired frequency. The CPU can run in either 6MHz or 15MHz, depending on which calculator you have.
3) Toggle the link port line(s), wait that many cycles, toggle again, repeat.

You should also get us in touch with your teacher; this sounds like an awesome project.
Thank you both for the replies,but i need something very simple in assemble to do.I write some code,but i don' t know if it's good.To generate the sound i must do it with the subroutine TONE.

Code:

    .ORG 1800H
SCAN .EQU 05FEH
TONE .EQU 05E4H
   CALL SCAN
   CP 01h
   CALL key1
   
   CALL SCAN
   CP 02h
   CALL key2
   
   CALL SCAN
   CP 03h
   CALL key3
   
   CALL SCAN
   CP 04h
   CALL key4
   
   CALL SCAN   
   CP 05h
   CALL key5
      
   
key1:
   LD C,80H
   LD HL,0C0H
   CALL TONE  ;   Generate sound.Input:    C controls the frequency of the sound. The period is about (44 + C x 13) x 1.12 µs. The frequency is 200 / (10 + 3 x C) Hz.
        ;   HL contains the number of cycles. Maximum value is 34768.
key2:
   LD C,80H
   LD HL,0C0H
   CALL TONE ;Generate sound at 1khz
key3:
   LD C,80H
   LD HL,0C0H
   CALL TONE  ;Generate sound at  2khz
key4:
   LD C,40H
   LD HL,0C0H
   CALL TONE 
key5:
   LD C,60H
   LD HL,0C0H
   CALL TONE
.END


Do you mean that you have already been given the routine TONE, with the properties listed in that comment? If so, your job is much, much easier. I do see some mistakes in your code, however. For example, in each Key: routine, you call TONE and then continue into the next Key subroutine. You should jump back to the main key-detection routine after you call TONE.
Thank you KermMartian for the hint.This is the final code and it works...

Code:

    .ORG 3000H
SCAN .EQU 05FEH
TONE .EQU 05E4H
TONE2 .EQU 05DEH ;generate sound at  1khz
TONE3 .EQU 05E2H ;generate sound at 2 khz



main:
   CALL SCAN
   CP 01h
   JP Z,key1
   
   
   CP 02h
   JP Z,key2
   
   
   CP 03h
   JP Z,key3
   
   
   CP 04h
   JP Z,key4
   
      
   CP 05h
   JP Z,key5
   
   CP 06h
   JP Z,key6
   
   CP 07h
   JP Z,key7

   CP 08h
   JP Z,key8

   CP 09h
   JP Z,key9

   CP 0h
   JP Z,key0
   
   jp nz, main
 
      
   
key1:
   LD C,80H
      LD HL,0C0H
   CALL TONE;   Generate sound.Input:    C controls the frequency of the sound. The period is about (44 + C x 13) x 1.12 µs. The frequency is 200 / (10 + 3 x C) Hz. 
   jp main   ;   HL contains the number of cycles. Maximum value is 34768.
       
key2:
   LD C,80H
      LD HL,0C0H
   CALL TONE2;
   jp main
key3:
   LD C,80H
      LD HL,0C0H
   CALL TONE3
   jp main ;
key4:
   LD C,50H
      LD HL,5BC
   CALL TONE
   jp main
key5:
   LD C,3H
      LD HL,5BC
   CALL TONE
   jp main
key6:
   LD C,0FH
      LD HL,0C0H
   CALL TONE
   jp main
key7:
   LD C,1AH
      LD HL,2BC
   CALL TONE
   jp main
key8:
   LD C,0C2H
      LD HL,2BC
   CALL TONE
   jp main
key9:
   LD C,0B2H
      LD HL,0C0H
   CALL TONE3
   jp main
key0:
   LD C,1EH
      LD HL,2BC
   CALL TONE
   jp main
.END


In the original code you could've jumped (jp) to TONE instead of calling it.

I agree with Kerm, this sounds like a really fun project! I'd also be interested in seeing the code of the TONE routine Wink

Kerm: Where can i read about how sound actually works on the calculator?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement