Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIC USART even parity
#6
To bas rijetko zatreba, ali ipak zatreba... Datum na ovom fajlu, koji iskopah sa svog diska, je iz 2004. god. Smile
Ovo je najbrzi nacin za brojanje bitova, a kad se izbroje, samo treba setovati taj parity bit, na osnovu rezultata tog brojanja, tj. njegovog bita 0, i sve radi uredno... Imate slanje sa 9 bita i setovanim parity bitom.

================================================

#include <pic.h>

/*

Freely distributable in this original form.
Any questions or comments? shane@keyghost.com
Updates to FAQ available from http://www.keyghost.com/htpic

Bit counter by Ratko Tomic, modified for PIC micro by Shane Tolmie
*/

unsigned char bit_count(unsigned int x)
{
unsigned char n=0;
/*
** The loop will execute once for each bit of x set, this is in average
** twice as fast as the shift/test method.
*/
if (x) do
n++;
while (0!=(x=x & (x-1)));
return (n);
}

unsigned int n;
unsigned char c;

void main(void)
{

n=0;
while (n<0xFFFE)
{
n++; //put a break point here and watch c and n!
printf("n=%d, c=%c\n", n, c);
c=bit_count(n);

}
}
===============================================
Reply


Messages In This Thread
PIC USART even parity - by dlalkovic - 03-26-2021, 05:12 PM
RE: PIC USART even parity - by vojinilic - 03-26-2021, 05:38 PM
RE: PIC USART even parity - by dlalkovic - 03-26-2021, 06:02 PM
RE: PIC USART even parity - by dlalkovic - 03-31-2021, 06:19 PM
RE: PIC USART even parity - by vojinilic - 03-31-2021, 08:57 PM
RE: PIC USART even parity - by ognjan - 04-01-2021, 09:47 AM
RE: PIC USART even parity - by vojinilic - 04-01-2021, 11:29 AM
RE: PIC USART even parity - by Macola - 04-01-2021, 11:56 AM
RE: PIC USART even parity - by vojinilic - 04-01-2021, 12:36 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)