完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我用的是PIC18,这个93C46怎么些都不成功,一直卡在while(!(EEDI));,希望哪位大神可以解答下,感激不尽啊!
#pragma config RETEN = OFF // VREG Sleep Enable bit (Ultra low-power regulator is Disabled (Controlled by REGSLP bit)) #pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep) #pragma config SOSCSEL = DIG // SOSC Power Selection and mode Configuration bits (Digital (SCLKI) mode) #pragma config XINST = OFF // Extended Instruction Set (Disabled) // CONFIG1H #pragma config FOSC = HS1 // Oscillator (HS oscillator (Medium power, 4 MHz - 16 MHz)) #pragma config PLLCFG = OFF // PLL x4 Enable bit (Disabled) #pragma config FCMEN = ON // Fail-Safe Clock Monitor (Enabled) #pragma config IESO = ON // Internal External Oscillator Switch Over Mode (Enabled) // CONFIG2L #pragma config PWRTEN = ON // Power Up Timer (Enabled) #pragma config BOREN = ON // Brown Out Detect (Controlled with SBOREN bit) #pragma config BORV = 3 // Brown-out Reset Voltage bits (1.8V) #pragma config BORPWR = LOW // BORMV Power level (BORMV set to low power level) // CONFIG2H #pragma config WDTEN = OFF // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled) #pragma config WDTPS = 1048576 // Watchdog Postscaler (1:1048576) // CONFIG3H #pragma config CANMX = PORTB // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively) #pragma config T0CKMX = PORTB // Timer0 Clock Input Mux bit (Timer0 gets its clock input from the RB5/T0CKI pin on 64-pin packages) #pragma config T3CKMX = PORTG // Timer3 Clock Input Mux bit (Timer3 gets its clock input from the RG2/T3CKI pin on 64-pin packages) #pragma config MSSPMSK = MSK7 // MSSP address masking (7 Bit address masking mode) #pragma config MCLRE = ON // Master Clear Enable (MCLR Enabled, RE3 Disabled) // CONFIG4L #pragma config STVREN = ON // Stack Overflow Reset (Enabled) #pragma config BBSIZ = BB2K // Boot Block Size (2K word Boot Block size) // CONFIG5L #pragma config CP0 = OFF // Code Protect 00800-03FFF (Disabled) #pragma config CP1 = OFF // Code Protect 04000-07FFF (Disabled) #pragma config CP2 = OFF // Code Protect 08000-0BFFF (Disabled) #pragma config CP3 = OFF // Code Protect 0C000-0FFFF (Disabled) // CONFIG5H #pragma config CPB = OFF // Code Protect Boot (Disabled) #pragma config CPD = OFF // Data EE Read Protect (Disabled) // CONFIG6L #pragma config WRT0 = OFF // Table Write Protect 00800-03FFF (Disabled) #pragma config WRT1 = OFF // Table Write Protect 04000-07FFF (Disabled) #pragma config WRT2 = OFF // Table Write Protect 08000-0BFFF (Disabled) #pragma config WRT3 = OFF // Table Write Protect 0C000-0FFFF (Disabled) // CONFIG6H #pragma config WRTC = OFF // Config. Write Protect (Disabled) #pragma config WRTB = OFF // Table Write Protect Boot (Disabled) #pragma config WRTD = OFF // Data EE Write Protect (Disabled) // CONFIG7L #pragma config EBTR0 = OFF // Table Read Protect 00800-03FFF (Disabled) #pragma config EBTR1 = OFF // Table Read Protect 04000-07FFF (Disabled) #pragma config EBTR2 = OFF // Table Read Protect 08000-0BFFF (Disabled) #pragma config EBTR3 = OFF // Table Read Protect 0C000-0FFFF (Disabled) // CONFIG7H #pragma config EBTRB = OFF // Table Read Protect Boot (Disabled) /* * File: main.c * Author: Administrator * * Created on July 18, 2017, 8:14 AM */ #include #include"1.h" void EEdelay(unsigned int time)//延迟 { unsigned char i=0; for(i=time;i>0;i--) { NOP(); // NOP(); } } void EEPortInit() { MDCONbits.MDEN=0; PADCFG1bits.RDPU=1; CM1CONbits.CON=0; ANCON1bits.ANSEL11=0; ANCON1bits.ANSEL12=0; ANCON1bits.ANSEL13=0; ANCON1bits.ANSEL14=0; ANCON1bits.ANSEL8=0; ANCON0bits.ANSEL3=0; TRISFbits.TRISF6=0; TRISFbits.TRISF7=0; TRISDbits.TRISD0=0; TRISDbits.TRISD1=1; PORTFbits.RF6=0; PORTFbits.RF7=0; PORTDbits.RD0=0; PORTDbits.RD1=0; } unsigned char ReadDate(unsigned char Adder)//读 { unsigned char i,date=0; //EEDI_M=BTSRMODE; TRISDbits.TRISD1=1; EECS=1; EEDO=1; EECLK=0; // EEdelay(1); EECLK=1; //EEdelay(1); EEDO=1; EECLK=0; // EEdelay(1); EECLK=1; //EEdelay(1); EEDO=0; EECLK=0; //EEdelay(1); EECLK=1; // EEdelay(1); // EECLK=0;//先发送开始位和操作码110 for(i=0;i<7;i++) //发送七位地址 { Adder<<=1; if((Adder&0x80)==0x80) EEDO=1; else EEDO=0; EECLK=0; //EEdelay(1); EECLK=1; //EEdelay(1); } for(i=0;i<8;i++) //发送八位数据 { date<<=1; //EECLK=1; EECLK=0; EEdelay(1); EECLK=1; EEdelay(1); if(EEDI) date|=0x01; else date&=(~0x01); } EECS=0; return(date); } void WriteDate(unsigned char Adder,unsigned char date)//写数据 { volatile unsigned char i,j=0; //EEDI_M=BTSMODE; INTCONbits.GIE=0; // WriteEnable();//写使能 //EraseAllData(Adder); // EEDO=0; EECS=1; EEDO=1; EECLK=0; EEdelay(4); EECLK=1; EEdelay(4); EEDO=0; EECLK=0; EEdelay(4); EECLK=1; EEdelay(4); EEDO=1; EECLK=0; EEdelay(4); EECLK=1; EEdelay(4); //先发送开始位和写操作码101 for(i=0;i<7;i++) //发送七位地址 { Adder<<=1; if((Adder&0x80)==0x80) EEDO=1; else EEDO=0; EECLK=0; EEdelay(4); EECLK=1; EEdelay(4); } for(i=0;i<8;i++) //发送八位数据 { if((date&0x80)==0x80) EEDO=1; else EEDO=0; EECLK=0; EEdelay(4); EECLK=1; EEdelay(4); date<<=1; } EECS=0; NOP(); NOP(); EECS=1; while(!EEDI); EECS=0; // WriteDenable();//写禁止 INTCONbits.GIE=1; } void WriteEnable() //写使能 { volatile unsigned char i,adder; //EEDO=0; EECS=1; //NOP(); EEDO=1; EECLK=0; // EEdelay(1); EECLK=1; //EEdelay(1); EEDO=0; EECLK=0; //EEdelay(1); EECLK=1; //EEdelay(1); EEDO=0; EECLK=0; // EEdelay(1); EECLK=1; //EEdelay(1); //写使能开始位 和操作码100 // delay(20); adder=0x60; for(i=0;i<7;i++)//发送七位地址11XXXXX { adder<<=1; if((adder&0x80)==0x80) EEDO=1; else EEDO=0; EECLK=0; //EEdelay(1); EECLK=1; //EEdelay(1); } EECS=0; } void WriteDenable()//写禁止 { volatile unsigned char i,adder; //EEDO=0; EECS=1; EEDO=1; EECLK=0; // EEdelay(1); EECLK=1; // EEdelay(1); EEDO=0; EECLK=0; // EEdelay(1); EECLK=1; // EEdelay(2); EEDO=0; EECLK=0; //EEdelay(1); EECLK=1; // EEdelay(1); //开始位和操作码100 adder=0x00; for(i=0;i<7;i++)//发送七位地址00XXXXX { adder<<=1; if((adder&0x80)==0x80) EEDO=1; else EEDO=0; EECLK=0; // EEdelay(1); EECLK=1; //EEdelay(1); } EECS=0; } void EraseAllData() { unsigned char i=0,Adder1; EECS=1; EEDO=1; EECLK=0; EEdelay(4); EECLK=1; EEdelay(4); EEDO=0; EECLK=0; EEdelay(4); EECLK=1; EEdelay(4); EEDO=0; EECLK=0; EEdelay(4); EECLK=1; EEdelay(4); Adder1=0x40; for(i=0;i<7;i++) { Adder1<<=1; if((Adder1&0x80)==0x80) EEDO=1; else EEDO=0; EECLK=0; EEdelay(4); EECLK=1; EEdelay(4); } EECS=0; NOP(); NOP(); EECS=1; while(!(EEDI)); EECS=0; } uchar Time; void main(void) { EEPortInit(); Time=ReadDate(0x00); while(1) { WriteEnable(); EraseAllData(); WriteDate(0x00,Time); WriteDenable(); } } 头文件是 #define EECS RF6 #define EECLK RF7 #define EEDI RD0 #define EEDO RD1 |
|
相关推荐
2 个讨论
|
|
只有小组成员才能发言,加入小组>>
求解外围电路实现的是4脚给持续低电平复位并正常工作,高电平不工作的原因
2076 浏览 1 评论
3471 浏览 3 评论
PIC1946程序有一个变量在运行过程中恢复初始值其他变量保持不变
2329 浏览 2 评论
2753 浏览 0 评论
PIC16F1825的RC5引脚,在主程序中操作无效,在中断中可以改变是为什么?
4010 浏览 5 评论
953浏览 0评论
用XC8编译PIC18F25K80时提示下面Error,求怎么解决这个问题
6338浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-20 09:40 , Processed in 0.557340 second(s), Total 45, Slave 39 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号