Truncated match.
PICList
Thread
'Moving to C'
1997\10\14@082907
by
mike
|
Hi,
I have finally succumbed and decided to start using C on PIC projects.
I have some limited C knowledge (writing windows DLLs in order to
make VB3 maths run faster and a bit of code maintenance), but nothing
related to using C for embedded applications or small processors.
In an up-comimg project, I have a requirement to count the number of
pulses on an input pin. The pulses will be about 100us wide and can
come in with periods from 5ms to several days between them.
If I were writing this in assembler I may code the pulse detection
part something like:
( assume pulses are on RA0 )
wait4lo
btfsc Port_A, 0
goto wait4lo
goto $+1 ; add some de-glitching
goto $+1
btfsc Port_A, 0
goto wait4lo
wait4hi
btfss Port_A, 0
goto wait4hi
goto $+1 ; add some de-glitching
goto $+1
btfss Port_A, 0
goto wait4hi
...
do the counting and any other stuff here
...
goto wait4lo
How would something like this be coded in C?
Regards,
Mike Watson
1997\10\14@091323
by
Clyde Smith-Stubbs
|
On Tue, Oct 14, 1997 at 01:09:29PM +0000, Mike Watson wrote:
> I have finally succumbed and decided to start using C on PIC projects.
...
> In an up-comimg project, I have a requirement to count the number of
> pulses on an input pin. The pulses will be about 100us wide and can
> come in with periods from 5ms to several days between them.
...
> How would something like this be coded in C?
Pretty much the same as in assembler. Like this (tweak the DELAY counts
to ensure reliable detection with noise rejection):
#include <pic.h>
static volatile bit PulseIn @ (unsigned)&PORTA*8+0; // bit0 in port
A
static unsigned int pulsecount; // pulse
accumulator
#define DELAY(n) {unsigned char i = n ; do ; while(--i);}
main()
{
for(;;) {
// wait for a verified low level on the input
while(PulseIn == 1)
continue;
DELAY(5); // wait a bit (or 5)
if(PulseIn == 1)
continue; // just noise - ignore it
// wait for a verified high level on the input
for(;;) {
while(PulseIn == 0)
continue;
DELAY(5); // wait a bit (or 5)
if(PulseIn == 1)
break; // not just noise - it's ok
}
pulsecount++; // increment count or whatever
}
}
--
Clyde Smith-Stubbs | HI-TECH Software
Email: spam_OUTclydeTakeThisOuT
htsoft.com | Phone Fax
WWW: http://www.htsoft.com/ | USA: (408) 490 2885 (408) 490 2885
PGP: finger .....clydeKILLspam
@spam@htsoft.com | AUS: +61 7 3354 2411 +61 7 3354 2422
---------------------------------------------------------------------------
ANSI C for the PIC! Now shipping! See http://www.htsoft.com for more info.
1997\10\14@140655
by
Steven J Tucker
Anyone have any new information about when the Scenix SX devkit will
be available from Parallax? I see that Scenix posted an incomplete
data sheet, but nothing else new.
Also, I heard the SX will be able to read its own program memory during
execution, which is supposed to aid in lookups and table branching. Is
this true?
Thanks
Steve
1997\10\14@182102
by
Eric van Es
Mike Watson wrote:
> Hi,
>
> I have finally succumbed and decided to start using C on PIC projects.
>
> How would something like this be coded in C?
>
> Regards,
>
> Mike Watson
And while we are at it would some one explain how to go about creating and
reading a lookup table?
Please? Rwetty pwease?
--
Eric van Es | Cape Town, South Africa
vanes
KILLspamilink.nis.za | http://www.nis.za/~vanes
LOOKING FOR TEMPORARY / HOLIDAY ACCOMODATION?
http://www.nis.za/~vanes/accom.htm
1997\10\14@225405
by
Clyde Smith-Stubbs
|
On Wed, Oct 15, 1997 at 12:17:40AM +0200, Eric van Es wrote:
> And while we are at it would some one explain how to go about creating and
> reading a lookup table?
Sure, but what kind of lookup table? When programming a PIC in assembler,
a "lookup table" usually refers to a retlw table that is necessary to
use ROM for storing any kind of data - when using a C compiler this will
get done for you, e.g. the following array is used in a 7 segment display
routine to translate digits into 7 segment patterns; you don't have to
worry about how to implement it - the compiler does it.
static const unsigned char digits[10] =
{
0x5F, /* 0 */
0x06,
0x3B,
0x2F, /* 3 */
0x66,
0x6D,
0x7D,
0x07, /* 7 */
0x7F,
0x6F,
};
Using this later - segcnt is a segment mask:
PORTB |= segcnt & digits[curval % 10];
--
Clyde Smith-Stubbs | HI-TECH Software
Email: .....clydeKILLspam
.....htsoft.com | Phone Fax
WWW: http://www.htsoft.com/ | USA: (408) 490 2885 (408) 490 2885
PGP: finger EraseMEclydespam_OUT
TakeThisOuThtsoft.com | AUS: +61 7 3354 2411 +61 7 3354 2422
---------------------------------------------------------------------------
ANSI C for the PIC! Now shipping! See http://www.htsoft.com for more info.
1997\10\14@225405
by
Clyde Smith-Stubbs
|
On Wed, Oct 15, 1997 at 12:17:40AM +0200, Eric van Es wrote:
> And while we are at it would some one explain how to go about creating and
> reading a lookup table?
Sure, but what kind of lookup table? When programming a PIC in assembler,
a "lookup table" usually refers to a retlw table that is necessary to
use ROM for storing any kind of data - when using a C compiler this will
get done for you, e.g. the following array is used in a 7 segment display
routine to translate digits into 7 segment patterns; you don't have to
worry about how to implement it - the compiler does it.
static const unsigned char digits[10] =
{
0x5F, /* 0 */
0x06,
0x3B,
0x2F, /* 3 */
0x66,
0x6D,
0x7D,
0x07, /* 7 */
0x7F,
0x6F,
};
Using this later - segcnt is a segment mask:
PORTB |= segcnt & digits[curval % 10];
--
Clyde Smith-Stubbs | HI-TECH Software
Email: clyde
spam_OUThtsoft.com | Phone Fax
WWW: http://www.htsoft.com/ | USA: (408) 490 2885 (408) 490 2885
PGP: finger @spam@clydeKILLspam
htsoft.com | AUS: +61 7 3354 2411 +61 7 3354 2422
---------------------------------------------------------------------------
ANSI C for the PIC! Now shipping! See http://www.htsoft.com for more info.
More... (looser matching)
- Last day of these posts
- In 1997
, 1998 only
- Today
- New search...