static unsigned char control OPTION @ 0x00;
static volatile unsigned char control TRIS @ 0x06;
/* STATUS bits */
static bit GPWUF @ (unsigned)&STATUS*8+7;
static bit PA0 @ (unsigned)&STATUS*8+5;
static bit TO @ (unsigned)&STATUS*8+4;
static bit PD @ (unsigned)&STATUS*8+3;
static bit ZERO @ (unsigned)&STATUS*8+2;
static bit DC @ (unsigned)&STATUS*8+1;
static bit CARRY @ (unsigned)&STATUS*8+0;
/*----------------------------------------------------
Function : Delay
Input : unsigned int (counter)
Output : None
Description : Delay routine
if counter=1 delay 35us , if counter=10 delay 134us,
if counter=100 delay 1.12ms,
These delay is base on internal 4MHz
------------------------------------------------------*/
void Delay(unsigned int counter)
{
while(counter>0) counter--;
}
/*----------------------------------------------------
Function : Pulse
Input : None
Output : None
Description : Send a pulse (10) to Serial Data Clock(CLK)
------------------------------------------------------*/
void Pulse(void)
{
CLK = 1;
Delay(25);
CLK = 0;
}
/*----------------------------------------------------
Function : StartBit
Input : None
Output : None
Description :
1. Set Chip Select(CS) = 1 (high)
2. Set a Start Bit(1) to Serial Data Input(DI)
------------------------------------------------------*/
void StartBit(void)
{
CS = 1;
DI = 1;
Pulse();
}
/* Main routine */
void main(void)
{
unsigned char addr;
unsigned int rx_buf;
InitPIC();
/* Read a word then +1 and write back to 93LC46 */
for (addr = 0; addr < 10; addr++)
{
rx_buf = Read93LC46(addr);
rx_buf = rx_buf+1;
Write93LC46(addr, rx_buf);
}