Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7990845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:07:35+00:00 2026-06-04T13:07:35+00:00

I have a project to program a microcontroller PIC18F, I have to connect a

  • 0

I have a project to program a microcontroller PIC18F, I have to connect a switching circuit to the microcontroller board, this switching circuit has an electric lock and a buzzer to be connected to it.

The lock is initially powered. It is supposed that when I send ‘1’, the buzzer will be powered with a square wave and the lock will be powered off. When it receives ‘0’, the buzzer will be switched off without powering the lock again. When it receives ‘2’ the lock should be powered but if the buzzer was unpowered before, it should not be powered again.

My confusion is in the last part. When I send ‘2’ via the hyperterminal, and I sent ‘0’ before it, the buzzer is powered again.

Here is the code,

void buzzertest();
char uart_rd;
int buzzer;
void main() {
TRISB=0X00;
PORTB=0x00;
RB5_bit = 0xFF;                  //lock  open
UART1_Init(9600);               // Initialize UART module at 9600 bps
while (1) {                     // Endless loop
 if (UART1_Data_Ready())       // If data is received,
 {
    buzzer=1;
    uart_rd = UART1_Read();     // read the received data,
    if(uart_rd =='1') {
       RB5_bit = 0x00;  //lock closed
       buzzertest();
     }
     if(uart_rd =='0' ){   //disable buzzer
        RB1_bit = 0x00;   //buzzer
        buzzer=0;
       }//end if
      buzzer=0;

      if(uart_rd =='2'){   //disable lock
        RB5_bit=0xFF;
        if(buzzer!=1){
            buzzertest();
         }
       }//end if
     } //end outer if
    } //end while
}//end main
void buzzertest(){
 while(1){
  RB1_bit = 0xFF;  //buzzer
  Delay_ms(1000);
  RB1_bit = 0x00; //buzzer
  Delay_ms(1000);
  if (UART1_Data_Ready())
  break;
 }//end while loop
}

Can please anyone help me solving this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:07:36+00:00Added an answer on June 4, 2026 at 1:07 pm

    You’re setting buzzer to 0 outside the if(uart_rd='0') block. So when you come to the if(uart_rd='2') block, buzzer is always 0 and so the if(buzzer!=1) block is always called.

    Have you tried stepping through this with a debugger? It would show up this kind of thing easily. You could also change those if blocks either to a switch statement or a series of if / else if statements to avoid these sorts of issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project where I am required to fix this program that has
I have a school project to program multilayer perceptron that classify data into three
I have a project to create a program, which prevents the user from escaping
I have a setup project that installs my app to the typical program files
I am working on Erlang robotic project. I have made a wallfollower robot program
My Project Setup I have the following project setup: \program.jar \images\logo.png In my code,
I have project which includes external jar file in it, I followed this link
I'm working on an i/o project where I have a microcontroller that communicates with
We have a project, and the professor asked us to print the program codes
Im sure this will be a simple one but have a project that started

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.