Design, build and debug a system based on the PIC16F1829 and the PICkit-3. Use y
ID: 2083021 • Letter: D
Question
Design, build and debug a system based on the PIC16F1829 and the PICkit-3. Use your assigned PICkit and buzzer to aid you with debugging. The system will use the potentiometer, switch and LEDs already on the board, with the addition of an active buzzer (CEP-2242). Connect the buzzer on the connector J1 so it is controlled by RA5 and RC5. Connect the long lead to RA5. The system should act as a simulation of a display for a metal detector. Use the potentiometer to provide a simulation of the intensity of the detector signal. The buzzer should emit beeps at a rate proportional to the simulated signal intensity, from one beep per second (for low intensity) up to continuous (for high intensity). Also, the LEDs should indicate the intensity by lighting zero, one, two, three or four LEDs like a bar display. Use the push button switch to enable and disable the buzzer and lights.Explanation / Answer
/* Here Im using MikroC Pro for PIC
Potentiometer voltage range : 0-5v
Five LEDs like a Bar Display
You must select internal oscillator through "Project Edit" Option because we are using low frequency for PWM
Connect the (Pull Up)switch between RB6 and GND */
unsigned int value;
unsigned short int beep;
void main()
{
TRISC4_bit=0; //I choose subsequent pins for Bar LEDs
TRISC3_bit=0;
TRISC6_bit=0;
TRISC7_bit=0;
TRISB7_bit=0;
TRISC5_bit=0; //We are connecting the Buzzer between RA5 and and RC5. So I choose RA5 as PWM output and RC5 a GND
TRISB6_bit=1; //Switch
while(1)
{
if (PORTC5_bit==0)
{
PORTC5_bit=0;
value=ADC_Read(3); //Reading the output of potentiometer at anlog channel number 3
beep=value/100; //Maximkum 10 beeps/sec.(10 bit ADC)
PWM2_Init(beep);
if(value<200)
{
PORTC4_bit=1;
PORTC3_bit=0;
PORTC6_bit=0;
PORTC7_bit=0;
PORTB7_bit=0;
}
else if(value<400)
{
PORTC4_bit=1;
PORTC3_bit=1;
PORTC6_bit=0;
PORTC7_bit=0;
PORTB7_bit=0;
}
else if(value<600)
{
PORTC4_bit=1;
PORTC3_bit=1;
PORTC6_bit=1;
PORTC7_bit=0;
PORTB7_bit=0;
}
else if(value<800)
{
PORTC4_bit=1;
PORTC3_bit=1;
PORTC6_bit=1;
PORTC7_bit=1;
PORTB7_bit=0;
}
else if(value<1000)
{
PORTC4_bit=1;
PORTC3_bit=1;
PORTC6_bit=1;
PORTC7_bit=1;
PORTB7_bit=1;
}
delay_ms(1000); //Delay 1 sec.
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.