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 8336569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:01:56+00:00 2026-06-09T04:01:56+00:00

I’m trying to understand this code : #include <pic.h> #include delay.h #define brisi_flag timer_flag=0

  • 0

I’m trying to understand this code:

#include <pic.h>
#include  "delay.h"

#define brisi_flag timer_flag=0

unsigned char timer;
unsigned char impuls;
unsigned char ton_koji_ne_svira;
static bit disable @ (unsigned)&PORTA*8+4;
static bit izlaz @ (unsigned)&PORTA*8+1;
static bit izlaz_inv @ (unsigned)&PORTA*8+0;
static unsigned char stanja @ 0x2e;
static bit stanje_izlaza @ (unsigned)&stanja*8+1;
static bit  timer_flag @ (unsigned)&INTCON*8+2; 

void
DelayMs_2(unsigned char cnt)
{
    unsigned char   i;
    do { asm("CLRWDT");
      if(ton_1)
         return;
        i = 4;
        do {
            DelayUs(250);
        } while(--i);
    } while(--cnt);
}

void
DelayMs(unsigned char cnt)
{
    unsigned char   i;
    do { asm("CLRWDT");
        i = 4;
        do {
            DelayUs(250);
        } while(--i);
    } while(--cnt);
}

void ton_1_2(unsigned char onaj_drugi_ton)
{
     izlaz=0;
     izlaz_inv=1;
     stanje_izlaza=0;
     TMR0=timer; 
ton_1_2_start:
     brisi_flag;
     disable=0;
ton_1_2_sviranje:
     while(timer_flag==0)
          {
        if((TMR0-timer)>=impuls)
             {izlaz=0;
              izlaz_inv=0;
             }
          }
     brisi_flag;
     TMR0=timer;
     if(stanje_izlaza==0)
        izlaz_inv=1;
     else   
        izlaz=1;
     stanje_izlaza=stanje_izlaza+1;   
     if((PORTA&0x0c)==onaj_drugi_ton)
        return;
     asm("CLRWDT");
     goto ton_1_2_sviranje;                 
}

void main()
{
    CMCON=0x07;//portA su normalni ulazi (za 16F628A)
    TRISA=0x0c;
    TRISB=0xff;
     disable=1;
    OPTION=0x81;   //WDT na 18 msec, preset TMR0 sa 4   

    izlaz=0;
    izlaz_inv=0;

    timer=107;
        impuls=0x1d;

    ton_1_2(ton_koji_ne_svira);
}

This program generates 800 Hz sound on speaker. I don’t understand how to calculate frequency (it must be something with variables impuls and timer ). This code is for PIC16F628A, it has external oscillator set at 4Mhz.

  • 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-09T04:01:57+00:00Added an answer on June 9, 2026 at 4:01 am

    Here is how I understand the code.

    The timer starts at 107. As the timer interrupt triggers on overflow the period is 256-107 = 149 ticks. During each period, the outputs are turned off after IMPULS=29 ticks. Hence you have a 29/149=19% duty cycle. In addition, the pulses alternate between two pins.

    OPTION=0x81 sets a 1:4 prescaler for the timer. Hence if the clock runs at 4MHz (period 0.25µs), the timer ticks at 1MHz (period 1µs). Thus a period of 149 ticks should equal 149µs and correspond to a frequency of 6711Hz. Adding the time it takes to start the timer each time the actual frequency is slightly lower.

    Are you sure the frequency is 800Hz ? Did you measure it ? Maybe the processor is really running at 500Hz, or there is a global 1:8 prescaler somewhere.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

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.