完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,我有UNIO/O EEPROM 11AA010和PIF 18F420的问题。我使用了AN C(“UNIO PIC18.H”和“UNIO PIC协议C”。编译器是XC8 V1.42。我已经成功地写了EEPROM上的字节,我可以阅读它(除了F我正在尝试读取一些值……)。无论我能写一个单词并读它,或者程序都在等待标记(PrI1BIT.CCP1IF=0){};在输入位或OutPoTBIT函数上或者在EEPROM上没有写/读。也许我有一个计时器和延迟的问题,但我不确定:代码如下还有主节目:谢谢你的帮助,克里斯
以上来自于百度翻译 以下为原文 Hello, I have a problem with the UNIO/O EEPROM 11AA010 and a PIF 18f4520. I have used the AN in C ("UNIO PIC18.h" and "UNIO PIC Protocol.c". The compiler is XC8 v1.42. I have written with succeed a bytes on the EEPROM and I am abble to read it (Except f I am trying to read some values...). Howeever I can write a word and read it, either the program is waiting for the flag while (PIR1bits.CCP1IF == 0) {}; on the Inputbit or Outputbit function or nothing can be written/readen on the eeprom. Maybe I have a problem with the timer and the delays but I am not sure : The code is the following : /******************************************************************** * * Software License Agreement * * Microchip Technology Inc. (Microchip) licenses this software to * you solely for use with Microchip microcontrollers and Microchip * serial EEPROM products. The software is owned by Microchip and/or * its licensors, and is protected under applicable copyright laws. * All rights reserved. * * SOFTWARE IS PROVIDED "AS IS." MICROCHIP AND ITS LICENSOR EXPRESSLY * DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR * NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP AND ITS LICENSORS BE * LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL * DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), * ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS. * ******************************************************************** * * Filename: UNIO PIC18.h * Processor: PIC18F25J10 * Compiler: MPLAB C18 3.20 or higher * Assembler: MPASMWIN 5.20 or higher * Linker: MPLINK 4.20 or higher * Date: April 30, 2008 * File Version: 1.0 * * Author: Chris Parris * Company: Microchip Technology Inc. * *******************************************************************/ #ifndef __UNIO_PIC18_H #define __UNIO_PIC18_H /** C O N S T A N T D E F I N I T I O N S ************************/ #define STARTHDR 0x55 // Define STARTHDR as 0x55 #define SAK 1 // Define SAK as 1 #define NOSAK 0 // Define NOSAK as 0 #define MAK 1 // Define MAK as 1 #define NOMAK 0 // Define NOMAK as 0 #define DEVICE_ADDR 0xA0 // Define DEVICE_ADDR as 0xA0 //#define DEVICE_ADDR 0xA1 // Define DEVICE_ADDR as 0xA1 #define PAGESIZE 16 // 16-byte page size for 11XXXXX /** B U S F R E Q U E N C Y C A L C U L A T I O N **************/ #define BUSFREQ 75000 // Set desired bus frequency to 75 kHz #define FCY 16000000 // Set instruction frequency to 10 MHz //Modifié en 16 MHz #define HALF_PERIOD ((FCY/(2*BUSFREQ))-1)// Timer period calculation /** C O M M A N D D E F I N I T I O N S **************************/ #define WREN 0b10010110 // WREN command #define WRDI 0b10010001 // WRDI command #define WRITE 0b01101100 // WRITE command #define READ 0b00000011 // READ command #define WRSR 0b01101110 // WRSR command #define RDSR 0b00000101 // RDSR command #define ERAL 0b01101101 // ERAL command #define SETAL 0b01100111 // SETAL command /** I / O P I N D E F I N I T I O N S **************************/ #define SCIO PORTBbits.RB4 // Serial clock, input/output pin, PORTB pin 4 #define SCIOTRIS TRISBbits.TRISB4 // SCIO direction bit /** T Y P E D E F S ************************************************/ typedef union _FLAGS { unsigned char _byte; struct { unsigned sendMAK:1; unsigned checkSAK:1; }; } FLAGS; typedef union _STATUSREG { unsigned char _byte; struct { unsigned WIP:1; unsigned WEL:1; unsigned BP0:1; unsigned BP1:1; }; } STATUSREG; typedef union _BYTE { unsigned char _byte; struct { unsigned b0:1; unsigned b1:1; unsigned b2:1; unsigned b3:1; unsigned b4:1; unsigned b5:1; unsigned b6:1; unsigned b7:1; }; } BYTE_one; typedef union _WORD { unsigned int _word; struct { unsigned char byte0; unsigned char byte1; }; struct { BYTE_one Byte0; BYTE_one Byte1; }; struct { BYTE_one LowB; BYTE_one HighB; }; struct { unsigned char v[2]; }; } WORD_one; #define LSB(a) ((a).v[0]) #define MSB(a) ((a).v[1]) /** P R O T O T Y P E S ********************************************/ void ByteWrite(WORD_one); // Byte Write function void ByteRead(WORD_one); // Byte Read function void PageWrite(WORD_one,unsigned char); // Page Write function void SeqRead(WORD_one,unsigned char); // Sequential Read function STATUSREG ReadStatusReg(void); // Read Status Register function void WriteStatusReg(STATUSREG); // Write Status Register function void WriteEnable(void); // Write Enable function void WriteDisable(void); // Write Disable function void WIP_Poll(void); // WIP polling function void StandbyPulse(void); // Generate Standby Pulse extern near unsigned char pageBuffer[PAGESIZE]; // 16-byte page buffer #endif and the main program: #include "UNIO PIC18.h" #include #define _XTAL_FREQ 16000000 /** P R O T O T Y P E S ************************************************/ void init(void); // Init. function // PIC18F4520 Configuration Bit Settings // 'C' source line config statements // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. // CONFIG1H #pragma config OSC = INTIO7 // Oscillator Selection bits (Internal oscillator block, CLKO function on RA6, port function on RA7) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled) #pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled) // CONFIG2L #pragma config PWRT = ON // Power-up Timer Enable bit (PWRT enabled) #pragma config BOREN = SBORDIS // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled)) #pragma config BORV = 1 // Brown Out Reset Voltage bits () // CONFIG2H #pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit)) #pragma config WDTPS = 128 // Watchdog Timer Postscale Select bits (1:128) // CONFIG3H #pragma config CCP2MX = PORTC // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1) #pragma config PBADEN = OFF // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset) #pragma config LPT1OSC = OFF // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation) #pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled) // CONFIG4L #pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset) #pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled) #pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode)) // CONFIG5L #pragma config CP0 = OFF // Code Protection bit (Block 0 (000800-001FFFh) not code-protected) #pragma config CP1 = OFF // Code Protection bit (Block 1 (002000-003FFFh) not code-protected) #pragma config CP2 = OFF // Code Protection bit (Block 2 (004000-005FFFh) not code-protected) #pragma config CP3 = OFF // Code Protection bit (Block 3 (006000-007FFFh) not code-protected) // CONFIG5H #pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected) #pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected) // CONFIG6L #pragma config WRT0 = OFF // Write Protection bit (Block 0 (000800-001FFFh) not write-protected) #pragma config WRT1 = OFF // Write Protection bit (Block 1 (002000-003FFFh) not write-protected) #pragma config WRT2 = OFF // Write Protection bit (Block 2 (004000-005FFFh) not write-protected) #pragma config WRT3 = OFF // Write Protection bit (Block 3 (006000-007FFFh) not write-protected) // CONFIG6H #pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected) #pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block (000000-0007FFh) not write-protected) #pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected) // CONFIG7L #pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks) #pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks) #pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks) #pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks) // CONFIG7H #pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) not protected from table reads executed in other blocks) //const unsigned char stopText[][20] = {"Quitter ?","OK: START","Annuler: STOP",}; //const char stopPos[3] = {0x80,0x94,0xD4}; //D4 //94 // //const unsigned char canceledText[][20] = {"Traitement","Annulé",}; //const char canceledPos[3] = {0xC5,0x9B,}; //D4 //94 // //const unsigned char startText[][20] = {"Pause",}; //const char startPos[3] = {0x87,}; // //const unsigned char endText[][20] = {"Fin de traitement",}; //const char endPos[3] = {0xC1,}; const unsigned char startTextBlink[][20] = {" ",}; char arr[16]; int main(void) { unsigned char setting=0; // while(1) // { initialisation_microcontroleur(); // Initialisation du microcontroleur. //Test EEPROM UNI/O static unsigned char i; // Loop counter static WORD_one address; // Address value init(); // Initialize PIC pageBuffer[0] = 0xCC; // Initialize first data byte address._word = 0x133; // Set address to 0x133 ByteWrite(address); // Write 1 byte of data at 0x133 pageBuffer[0] = 0xFF; ByteRead(address); // Read 1 byte of data at 0x133 for (i = 0; i < PAGESIZE; i++) // Initialize data array { pageBuffer = i; } address._word = 0x150; // Set address to 0x150 PageWrite(address, PAGESIZE); // Write 1 page of data starting at 0x150 for (i = 0; i < PAGESIZE; i++) // Initialize data array { pageBuffer = 0xFF; } SeqRead(address, PAGESIZE); // Read 1 page of data starting at 0x150 while(1){}; } void init(void) { // Initialize PLL OSCTUNEbits.PLLEN = 1; // Enable PLL //Delay100TCYx(200); // Delay for max 2 ms PLL lock time __delay_ms(2); // Initialize I/O ADCON1 = 0x0F; // Configure digital I/O SCIO = 0; // Set SCIO to drive low SCIOTRIS = 0; // Configure SCIO to output Nop(); // Delay to ensure minimum pulse width of 200 ns SCIO = 1; // Bring SCIO high to release from POR // Initialize Timer1 T1CON = 0b10000000; // Configure Timer1, 1:1 prescalar, 16-bit CCPR1H = 0x00; // Clear CCPR1H CCPR1L = HALF_PERIOD; // Load HALF_PERIOD into CCPR1L TMR1H = 0x00; // Clear TMR1H TMR1L = 0x00; // Clear TMR1L // Initialize CCP1 CCP1CON = 0b00001011; // Configure special event trigger StandbyPulse(); // Generate Standby Pulse } // end init(void) Thank you for your help, Kris Attachment(s) UNIO PIC18 Protocol.c (24.09 KB) - downloaded 50 times |
|
相关推荐
2个回答
|
|
X-ReF:http://www. McCys.com…/M1007500。
以上来自于百度翻译 以下为原文 x-ref: http://www.microchip.com/.../m1007500.aspx#1007500 |
|
|
|
你好,谢谢你CinziaG把我的帖子交叉链接。我想我发现了问题所在。这是由于延迟和半周期时间与总线频率有关。对于MCU 18 MHz,我将总线频率设置在50 MHz和16 MHz的频率上,希望能对其他用户有所帮助!克里斯
以上来自于百度翻译 以下为原文 Hello, Thank you CinziaG to cross link my posts. I think I have found the problem. It's due to the delays and the HALF PERIOD time in relation with the bus frequency. For the mcu 18 MHz, I set the Bus frequency on 50 MHz and the frequency on 16 MHz. I hope it will help other users ! Kris |
|
|
|
只有小组成员才能发言,加入小组>>
4825 浏览 9 评论
1831 浏览 8 评论
1749 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
2957 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2061 浏览 5 评论
462浏览 1评论
1111浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
364浏览 0评论
264浏览 0评论
LAN9252使用SQI通信,进行数字复位后读BYTE_TEST异常
1800浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-4-27 06:43 , Processed in 1.063252 second(s), Total 74, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号