|
From: Scott H. <sh...@da...> - 2001-01-23 21:00:14
|
Hello all.. I'm trying to edit the serial390 routines to make them modular,
where I can utilize the other serial port if necessary. I've gotten a lot
of code working, but I'm trying to clean it up now. I have a lot of
functions like:
if(port==1)
SBUF1 = blah;
else if(port==0
SBUF0 = blah;
I'm trying to come up with a way now that I can basically have a pointers to
the sfrs and sbits. I've experimented around with the following code, but
it doesn't seem to work the way I thought it would. Is what I'm trying to
do possible with sdcc? Or, is there a recommended way of achieving the same
thing?
typedef struct
{
sfr SCON; // serial control
sbit RI;
sbit TI;
sbit RB8;
sbit TB8;
sbit REN;
sbit SM2;
sbit SM1;
sbit SM0;
sbit FE; // depending on SMOD0
sfr SBUF; // serial 0 data buffer
sfr CON; // power control
sfr TL; // timer 0 lsb
sfr TH; // timer 0 msb
}
_COMstruct;
struct _COM0
{
sfr at 0x98 SCON0; // serial 0 control
sbit at 0x98 RI_0;
sbit at 0x99 TI_0;
sbit at 0x9a RB8_0;
sbit at 0x9b TB8_0;
sbit at 0x9c REN_0;
sbit at 0x9d SM2_0;
sbit at 0x9e SM1_0;
sbit at 0x9f SM0_0;
sbit at 0x9f FE_0; // depending on SMOD0
sfr at 0x99 SBUF0; // serial 0 data buffer
sfr at 0x87 PCON; // power control
sfr at 0x8a TL0; // timer 0 lsb
sfr at 0x8c TH0; // timer 0 msb
}
COM0;
struct _COM1
{
sfr at 0xc0 SCON1; // serial 1 control
sbit at 0xc0 RI_1;
sbit at 0xc1 TI_1;
sbit at 0xc2 RB8_1;
sbit at 0xc3 TB8_1;
sbit at 0xc4 REN_1;
sbit at 0xc5 SM2_1;
sbit at 0xc6 SM1_1;
sbit at 0xc7 SM0_1;
sbit at 0xc7 FE_1; // depending on SMOD0
sfr at 0xc1 SBUF1; // serial 1 data buffer
sfr at 0xd8 WDCON; // watch dog
sfr at 0x8b TL1; // timer 1 msb
sfr at 0x8d TH1; // timer 1 msb
}
COM1;
typedef _COMstruct* COM;
COM ports[2] = { (COM)&COM0, (COM)&COM1 };
--
Scott Hughes - sh...@da...
Engineer, Auto Information
Dallas Semiconductor
|