Project
(Listing 5, continued)
//Don't change anything else
#define SCALER
#define ITIME
#if BRATE > 1200
#defineDLY 3
#defineTX_OHEAD 13
#else
#defineDLY 9
#define TX_OHEAD
#endif
#define RX_OHEAD 12
#define DELAY(ohead)
10000000
4*SCALER/XTAL
// Instruction cycle time
// cycles per null loop
// overhead cycles per loop
// cycles per null loop
14
// receiver overhead per loop
(((SCALER/BRATE)-(ohead*ITIME))/(DLY*ITIME))
static bit TxData @ (unsigned)&SERIAL_PORT*8+TX_PIN;
static bit RxData @ (unsigned)&SERIAL_PORT*8+RX_PIN;
#define INIT_PORT SERIAL_TRIS = 1<<RX_PIN
tion
// Map TxData to pin
// Map RxData to pin
// set up I/O direc-
void putch(char c)
{
unsigned char bitno;
#if BRATE > 1200
unsigned char dly;
#else
unsigned int dly;
#endif
INIT_PORT;
TxData = 0; // start bit
bitno = 12;
do
{
dly = DELAY(TX_OHEAD);// wait one bit time
do // waiting in delay loop
while(--dly);
if(c & 1)
TxData = 1;
if(!(c & 1))
TxData = 0;
c = (c >> 1) | 0x80;
}while(--bitno);
NOP();
}
char getch(void)
{
unsigned char c, bitno;
#if BRATE > 1200
unsigned char dly;
#else
unsigned int dly;
#endif
for(;;)
{
while(RxData)
continue;
dly = DELAY(3)/2;
do
while(--dly);
if(RxData)
continue;
bitno = 8;
c = 0;
// wait for start bit
// waiting in delay loop
// twas just noise
(continued)
out of the PIC10F206 serial
port. Once I encounter a
null, I know that I have sent
the entire string and I send a
carriage return and line feed
combination. A simple delay
loop is executed and the bit-bang serial process sends
another NUTS & VOLTS
message.
Good Things in
Small Packages
F
o
r
E
l
e
c
t
r
o
n
i
c
s
NUTS & VOLTS
E
v
e
r
y
t
h
i
n
g
Okay, let’s begin our
descent and land this thing.
As you have seen, lots of
useful things can be done
with a tiny PIC10F206, its
four I/O lines, and a good C
compiler like the HI-TECH
PICC C compiler. The air
is really clear at 23,000
feet. You have seen for
yourself that using a C
compiler with a tiny PIC
like the PIC10F206 is not
necessarily a bad thing.
Whether you code in
assembler or C, the
PIC10F20X series of micro-controllers is a blast to work
with. I’m sure you’ll want to
try your hand at some tiny
applications, as well. So, I’ll
make all of the Little Bits
code in the listings available
for download from the Nuts
& Volts FTP server (www.
nutsvolts.com).
For those of you who
want to melt some solder
around a PIC10F206,
either the Wahl Iso Tip
portable soldering iron
with a 7566-100 micro tip
or a Metcal Soldering
Station with a SSC-645A
soldering element is perfect for the task. If you
don’t want to roll your own
Little Bits, you can get a kit
of parts or an assembled
Little Bits unit from EDTP
Electronics (www.edtp.
com). NV
48
JANUARY 2005