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)
/* osccal bits */
static volatile bit cal3 @ (unsigned)&osccal*8+7;
static volatile bit cal2 @ (unsigned)&osccal*8+6;
static volatile bit cal1 @ (unsigned)&osccal*8+5;
static volatile bit cal0 @ (unsigned)&osccal*8+4;
static volatile bit gp5 @ (unsigned)&gpio*8+5;
static volatile bit gp4 @ (unsigned)&gpio*8+4;
static volatile bit gp3 @ (unsigned)&gpio*8+3;
static volatile bit gp2 @ (unsigned)&gpio*8+2;
static volatile bit gp1 @ (unsigned)&gpio*8+1;
static volatile bit gp0 @ (unsigned)&gpio*8+0;
#define config_addr 0xfff
/* code protection */
#define mclren 0xffff // memory clear enable
#define mclrdis 0xffef // memory clear disable
/*watchdog*/
#define wdten 0xffff // watchdog timer enable
#define wdtdis 0xfffb // watchdog timer disable
/* code protection */
#define protect 0xfff7 // protect the program code
#define unprotect 0xffff // do not protect the program code
/*osc configurations*/
#define extrc 0xffff // external resistor/capacitor
#define intrc 0xfffe // internal
#define xt 0xfffd // crystal/resonator
#define lp 0xfffc // low power crystal/resonator
/* 93lc46 i/o pin define */
#define cs gp0 //chip select
#define clk gp1 //serial data clock
#define di gp2 //serial data input
#define do gp4 //serial data output
void delay(unsigned int counter);
void pulse(void);
void startbit(void);
void ewen(void);
void ewds(void);
extern void write93lc46(unsigned char offset_addr, unsigned int tx_data);
extern unsigned int read93lc46(unsigned char offset_addr);
void initpic(void);
#define clrwdt() asm(“ clrwdt”)
#define sleep() asm(“ sleep”)
#define ___mkstr1(x) #x
#define ___mkstr(x) ___mkstr1(x)
#define __config(x) asm(“tpsect config,class=config,delta=2”);
asm(“tglobaltconfig_word”);
asm(“config_word”);
asm(“tdw ”___mkstr(x))
#define __idloc(w) asm(“tpsect idloc,class=idloc,delta=2”);
asm(“tglobaltidloc_word”);
asm(“idloc_word”);
asm(“tirpct__arg,” ___mkstr(w));
asm(“tdw 0&__arg&h”);
asm(“tendm”)
__config(mclrdis & wdtdis & extrc & protect);
/*----------------------------------------------------
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;
}

如何选择优质的液晶拼接屏,有哪些参考因素
PCB焊盘露金边的原因及影响
HDGK-8智能高压开关机械特性测试仪断口接线说明
什么是3D NAND闪存?
如何杜绝信息设备维修泄密隐患
PIC12C508读写93LC46范例程式
什么是车规级,车规级的介绍(四)
基于GLM-6B对话模型的实体属性抽取项目实现解析
KC智能寻迹小车
智慧城市:智能交通系统中的激光雷达案例
旁路电容、去耦电容、滤波电容的作用分别是什么
数字温湿度传感器DHT11的主要特点及引脚说明
自制Word2Vec图书推荐系统,帮你找到最想看的书!
比特币已有85%被挖出剩下的15%会在未来100年内被慢慢释放
Redmi7&Note7Pro上手 到底香不香
厘清信号完整性分析所用到的测试码型及其应用
高通骁龙636和835的差别有多大
单相半波整流电路原讲解
玩游戏什么蓝牙耳机好?英雄联盟手游耳机分享
2019年“床垫第一股”喜临门迎来业绩增长,发布“智慧选床系统”