Beginning with microcontrollers

Thread Starter

MusicTech

Joined Apr 4, 2008
144
Is that really the whole thing, just without the variables? I am new to MCU so I wouldn't know... Just a couple questions on that code...

What are TR1 TF1 TH1 TL1 and LED?
What does SpkPort = !SpkPort do?

So, if I understand correctly what this does, is loop the switch until one case is satisfied, break and output to whatever the speaker port pin is in some sort of PWM type deal?
 
Last edited:

Arm_n_Legs

Joined Mar 7, 2007
186
oop.. sorry... i forgot to mention that the program based on the 8051 running on 12 MHz. The program utilises the 8051 timer, so you need to understand how to use the 8051 timer. TR1, TF1, TH1, and TL1 are timer related flags and registers.

LED and SpkPort are defined I/O. Example:
#define LED P1.0 ; if LED is connected to P1.0
#define SpkPort P1.4 ; if a speaker is connected to P1.4

The concept is this:

If you need to generate the C5 note (frequency=523 Hz), you hv to pulse the I/O 0.96ms high and then 0.96 ms low, and generate a series of it. You use the timer to time this 0.96 ms. Feed this signal to a cheapy speaker via a npn transistor (preferably Darlington pair such as the MPSA14).

You can use the same concept for other microcontrollers (which i am not familiar) with built in timer.

SpkPort=!SpkPort is to pulse the I/O.
 

Thread Starter

MusicTech

Joined Apr 4, 2008
144
so in MCU's that Px is like a numerical value in C. So, the LED is attached to pin 1? is the .0 necessary?
THe reason I ask is just because I don't get how the speaker is connected to pin 1.4.... I didn't know there were like half pins, I hope i am misunderstanding you or the code....
you mean like in one N and out the other N? what will that do for the sound?

also, what does the ! do in SpkPort=!Spkport, or does that just represent a variable?
 

Arm_n_Legs

Joined Mar 7, 2007
186
I have attached a snapshot of a circuit showing how a speaker (those 8-ohm 0.1W cheapy speaker) can be connected to a 8051 port via a darlington NPN transistor (MPSA14).

SpkPort = !SpkPort

The exclaimation (!) is a "C" function called compliment - means to invert the value of the port from "1" to "0" or from "0" to "1".

Assuming you are holding a stop watch. You set the Spkport to "0" and you start your stopwatch. When 0.96 ms is reached, you compliment the value of SpkPort. When another 0.96 ms elapsed, you compliment the value of SpkPort again. Continue doing this, and you get a 563 Hz (the C5 note) square wave at the SpkPort.
 

Attachments

Thread Starter

MusicTech

Joined Apr 4, 2008
144
Oh wow, that's a really cool function thanks!!!!!

What if I wanted to hold two keys at once? How would I get two parts of the code to work at once, like 1 part that is generating the sound from one key already being held and then still looping the check to see if any other key is being pressed.

That diagram really helps, but it is a chip still attached to the programmer, right? After I take it out of the programmer, the circuit won't be that complicated, right?
 

Thread Starter

MusicTech

Joined Apr 4, 2008
144
By the way, has any other mac user found that after downloading MacrocASM it crashes whenever you try to open it? I tried deleting it and reinstalling it, it still didn't work, but I never deleted the preferences file because I couldn't find. I AM SO EXCITED TO START PROGRAMMING MCU I really want to thank you guys for helping me and making this more interesting than I would ever realize.

After a couple hours of google searches I found this site:

http://www.diylife.com/2008/02/15/program-a-pic-microcontroller/

I was looking at the JMD design. Since I do not have a computer with the RS232, I guess I could just get a standard RS232 to USB on ebay, right? Then I just make the necessary connections to the PIC and I should be good to program, right? I mean at least at my beginning stage anyway. I could use some soldering practice anyway despite my years of burns I still can't do that right. The only thing that concerned me was that limitation that warned of it's low power, anybody have a suggestion to step that up a bit so I can use with my "most laptops" Or do you think this lack of power might be just low enough to fit perfectly with the 18F PICs which use 12.5 volts or even the 24/32 which require 6? Thanks
 
Last edited:

Arm_n_Legs

Joined Mar 7, 2007
186
One processor can only do one things at a time. However you time slice the process. Alternatively, use the external interrupts for the key instead of polling.

No programmer is needed for that partial circuit i showed you. The design is based on In-System-Programming. Download the program into the MCU via a USB cable connected to the PC.
 

hgmjr

Joined Jan 28, 2005
9,027
Oh wow, that's a really cool function thanks!!!!!

What if I wanted to hold two keys at once? How would I get two parts of the code to work at once, like 1 part that is generating the sound from one key already being held and then still looping the check to see if any other key is being pressed.

That diagram really helps, but it is a chip still attached to the programmer, right? After I take it out of the programmer, the circuit won't be that complicated, right?
You may want to take a look at programming a Finite State Machine to perform your multiple tasks.

hgmjr
 
Last edited:

Thread Starter

MusicTech

Joined Apr 4, 2008
144
armnlegs, I was kinda confused about that. Some of the stuff got cut off at the top and bottom, and I don't know where it goes. Also, I am unfamiliar with some of the chips. What are the switches for anyway?

Thanks for the state machines concept.
 
Top