用HI-TECH C写的使用PIC12C508读写93LC4

用hi-tech c写的使用pic12c508读写93lc46范例程式
/************************************************************
* processer : microchip pic12c508 *
* compiler : hi-tech picc 8.00 pl2 *
* writer : jason kuo *
* description : it can read/write 93lc46 (64 x 16-bit organization) *
*************************************************************/
static volatile unsigned char rtcc @ 0x01;
static volatile unsigned char tmr0 @ 0x01;
static volatile unsigned char pcl @ 0x02;
static volatile unsigned char status @ 0x03;
static unsigned char fsr @ 0x04;
static volatile unsigned char osccal @ 0x05;
static volatile unsigned char gpio @ 0x06;
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;
/* option bits */
#define gpwu (1<<7)
#define gppu (1<<6)
#define t0cs (1<<5)
#define t0se (1<<4)
#define psa (1<<3)
#define ps2 (1<<2)
#define ps1 (1<<1)
#define ps0 (1<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();
}
/*----------------------------------------------------
function : ewen
input : none
output : none
description : erase/write enable
------------------------------------------------------*/
void ewen(void)
{
unsigned char i,temp;
startbit(); /* 1 */
temp = 0x80; /* 0011xxxx ,(opcode:00, address:11xxxx) */
for(i=0; i>= 1;
}
cs = 0;
}
/*----------------------------------------------------
function : ewds
input : none
output : none
description : erase/write disable
------------------------------------------------------*/
void ewds(void)
{
unsigned char i;
startbit(); /* 1 */
di = 0; /* 0000xxxx, (opcode:00, address:00xxxx) */
for(i=0; i= 1;
}
temp = 0x8000; /* dddddddddddddddd(16bits data)*/
for(i=0; i>= 1;
}
cs = 0;
ewds();
}
/*----------------------------------------------------
function : read93lc46
input : unsigned char offset address
output : unsigned int
description : read 16bits data from 93lc46 offset address
------------------------------------------------------*/
unsigned int read93lc46(unsigned char offset_addr)
{
unsigned char addr, i, temp;
unsigned int rx_data;
startbit(); /* 1 */
offset_addr = offset_addr&0x3f; /* 6bits address */
addr = offset_addr + 0x80; /* 10aaaaaa ,(opcode:10, address:aaaaaa) */
temp = 0x80;
for(i=0; i>= 1;
}
rx_data = 0x0000; /* dddddddddddddddd(16bits data)*/
for(i=0; i<16; i++) {
pulse();
if(do)
rx_data |= 0x0001;
if(i < 15)
rx_data <<= 1;
}
cs = 0;
return(rx_data);
}
void initpic(void)
{
option = (gpwu | gppu | ps2 | ps1 | ps0);
tris = 0x10;
cs = 0;
clk = 0;
di = 0;
}
/* 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);
}
}

OPPOR11什么时候上市:OPPOR11已生产?OPPOR11、OPPOR11Plus谍照曝光多个版本可选,明日发布?
采用TL494芯片实现电动跑步机的开关电源设计
视觉ADAS解决方案大比拼,准备好为你爱车雇一个保镖了吗?
中国芯借势AI+IoT智能化浪潮把握全球嵌入式机遇的分析
8月新机汇总:诺基亚8、华硕ZenFone4、三星Note8和LG V30配置售价曝光,诺基亚8最值得期待?
用HI-TECH C写的使用PIC12C508读写93LC4
英特尔推新品牌计划 云计算入局添战力
基于生成式人工智能的工业软件自主创新路径分析
具有最低电压噪声的放大器
贝尔公司已正式开始推广V-22倾转旋翼机的VIP版
EDN China "LED技术论坛"邀
应用种子低温低湿储藏柜需要注意的事项有哪些
和大家分享5款专业度高、品质优良的手持机设计
什么是线性恒流驱动IC?浅淡高压线性恒流驱动芯片优缺点
苹果的产品从iPhone到Apple Watch 是如何一直实现后发制人的?
激光焊接机出光弱该怎么解决?
RFID行业未来发展趋势是怎样的
电视厂商大战CES 2019 8K时代已然向我们走来
Konqueror/embedded向ARM-Linux平台
IOT技术的5大验证和挑战