Mccct

668 Words May 3rd, 2014 3 Pages
(E) On Speaker
The beep sound is produced by the frequency of the electric signals.
The following shows a way to generate a tone of certain frequency using C program statements.

#include <p18f4520.h>
#include <delays.h> void main ()
{
char i = 0; //declarations
ADCON1 = 0x0f;
TRISE = 11100000;
PORTE = 0; for (i=0;i<500;i++)
{
PORTEbits.RE2 = ~PORTEbits.RE2 // toggled wave
Delay10TCYx(10); //?????
PORTEbits.RE2 = 0;
Delay10TCYx(1);
} for (i=0;i<250;i++)
{
PORTEbits.RE2 = 1;
Delay10TCYx(1);
PORTEbits.RE2 = 0;
Delay10TCYx(4);
}

Here is a way to generate a tone of certain frequency continuously for a certain duration using C program statements.

//------------------- speaker_freq_dur.c
…show more content…
There are two parts; duty cycle and frequency. The duty cycle shows the percentage of the amount of time the signal is in a high (on) state over the total time it takes to complete one cycle. The frequency describes how fast the PWM completes a cycle.
The following is a way to run the motor using C program statements

#include #define L293D_A P2_0 //Positive of motor
#define L293D_B P2_1 //Negative of motor
#define L293D_E P2_2 //Enable of L293D
// Function Prototypes void rotate_f(void); //Forward run funtion void rotate_b(void); //Backward run function void breaks(void); //Motor stop function void delay(void); //Some delay void main(){ //Our main function while(1){ //Infinite loop rotate_f(); //Run forward delay(); //Some delay breaks(); //Stop delay (); //Some delay rotate_b(); //Run Backwards delay(); //Some delay breaks(); //Stop delay(); //Some delay } //Do this infinitely
}
void rotate_f(){
L293D_A = 1; //Make positive of motor 1
L293D_B = 0; //Make negative of motor 0
L293D_E = 1; //Enable L293D
}
void rotate_b(){
L293D_A = 0; //Make positive of motor 0
L293D_B = 1; //Make negative of motor 1
L293D_E = 1; //Enable L293D
}
void breaks(){
L293D_A

More about Mccct