www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]用HI-TECH C寫(xiě)的使用PIC12C508讀寫(xiě)93LC46范例程式/************************************************************ * Processer : Microchip PIC12C508 * * Compiler : Hi-TECH PICC 8.00 PL2 *

HI-TECH C寫(xiě)的使用PIC12C508讀寫(xiě)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;
}
 

/*----------------------------------------------------
 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<8; i++) {
        if(0x30 & temp)
            DI = 1;
        else
            DI = 0;
        Pulse();
        temp >>= 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<8; i++)
        Pulse();

    CS = 0;
}

/*----------------------------------------------------
 Function : Write93LC46          
 Input : unsigned char Offset Address, unsigned int tx_data       
 Output : None          
 Description :  Write 16bits data in to 93LC46 Offset Address
 ------------------------------------------------------*/     
void Write93LC46(unsigned char Offset_Addr, unsigned int tx_data)
{
    unsigned char Addr, i;
    unsigned int temp;

    EWEN();

    StartBit();                  /* 1 */
    Offset_Addr=Offset_Addr&0x3F; /* 6bits address */
    Addr = Offset_Addr + 0x40;          /* 01AAAAAA ,(opcode:01, address:AAAAAA) */
    temp = 0x0080;
    for(i=0; i<8; i++) {
        if(Addr & temp)
            DI = 1;
        else
            DI = 0;
        Pulse();
        temp >>= 1;
    }

    temp = 0x8000;                      /* DDDDDDDDDDDDDDDD(16bits data)*/
    for(i=0; i<16; i++) {
        if(tx_data & temp)
            DI = 1;
        else
            DI = 0;
        Pulse();
        temp >>= 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<8; i++) {
        if(Addr & temp)
            DI = 1;
        else
            DI = 0;
        Pulse();
        temp >>= 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);
 }

}

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

在這篇文章中,小編將為大家?guī)?lái)單片機(jī)的相關(guān)報(bào)道。如果你對(duì)本文即將要講解的內(nèi)容存在一定興趣,不妨繼續(xù)往下閱讀哦。

關(guān)鍵字: 單片機(jī) AVR PIC

北京2025年8月6日 /美通社/ -- 亞馬遜云科技宣布,Anthropic最新一代模型Claude Opus 4.1與Claude Sonnet 4,現(xiàn)已在Amazon Bedrock全面上線。這批新型雙模推理模型支...

關(guān)鍵字: 模型 PIC 亞馬遜 CK

北京 2025年5月23日 /美通社/ -- 亞馬遜云科技宣布在Amazon Bedrock中推出Anthropic的最新一代模型Claude Opus 4和Claude Sonnet 4。這兩款全新混合推理模型能夠根...

關(guān)鍵字: PIC 亞馬遜 模型 TI

Claude 3.7 Sonnet混合推理模型,解鎖"深度思維",優(yōu)化編碼及計(jì)算機(jī)應(yīng)用能力 北京2025年2月25日 /美通社/ -- 亞馬遜云科技宣布,人工智能安全與研究公司Anthropic迄今...

關(guān)鍵字: NET PIC 亞馬遜 模型

北京2024年11月23日 /美通社/ -- 亞馬遜宣布與Anthropic持續(xù)深化戰(zhàn)略合作。Anthropic選擇亞馬遜云科技為模型訓(xùn)練首要合作伙伴,并計(jì)劃使用Amazon Trainium和Amazon I...

關(guān)鍵字: PIC 亞馬遜 AN NI

倫敦2024年10月24日 /美通社/ -- 根據(jù)最新的GSMA "2024年移動(dòng)互聯(lián)網(wǎng)連接狀況" 報(bào)告,全球43%的人口(相當(dāng)于34.5億人)...

關(guān)鍵字: 移動(dòng)互聯(lián)網(wǎng) GSMA BSP 讀寫(xiě)

深圳2024年8月22日 /美通社/ -- 對(duì)于消費(fèi)級(jí)SSD來(lái)說(shuō),性能一直是用戶最為關(guān)注的重要指標(biāo)之一。高性能不僅是提升數(shù)據(jù)處理速度的關(guān)鍵,更是支撐AI模型訓(xùn)練、大數(shù)據(jù)分析及高負(fù)載應(yīng)用的基礎(chǔ),尤其是在AI應(yīng)用加速落地背景...

關(guān)鍵字: SSD 測(cè)試 讀寫(xiě) IO

在嵌入式系統(tǒng)開(kāi)發(fā)中,時(shí)間戳的獲取是一項(xiàng)基礎(chǔ)而關(guān)鍵的功能。時(shí)間戳,即表示某一瞬間的時(shí)間點(diǎn)的唯一標(biāo)識(shí),通常以自某一固定時(shí)間點(diǎn)(如Unix紀(jì)元,即1970年1月1日00:00:00 UTC)以來(lái)的秒數(shù)或毫秒數(shù)表示。它不僅在日志...

關(guān)鍵字: 嵌入式系統(tǒng)開(kāi)發(fā) C代碼 時(shí)間戳 Unix

北京2023年9月5日 /美通社/ -- 浪潮云海在2023年5月正式發(fā)布新一代InCloud Rail G7系列超融合一體機(jī),其內(nèi)置的InCloud dSAN超融合存儲(chǔ)組件,基于新一代的硬件平臺(tái)設(shè)計(jì),支持全棧RDMA協(xié)...

關(guān)鍵字: IO 讀寫(xiě) 軟件 測(cè)試

什么是PIC中斷程序呢?形象的生活比喻就比如你現(xiàn)在這在看我的文章,突然你的朋友喊你一起去烤地瓜,這時(shí)候你就中斷了看文章和朋友烤地瓜去了,烤完地瓜之后你又回來(lái)看文章??镜毓线@件事就好比中斷程序,他中斷了你看文章這件事。在程...

關(guān)鍵字: PIC 中斷 標(biāo)志位
關(guān)閉