完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,我在PIC18F14K50上使用EEPROM有问题。我想输入0x01到0x00地址eeprom。然后,我希望从UART得到这个结果。我只得到“eeprom数据是0”。如果您有什么想法解决这个问题,请告诉我。我期待着您的回音。
以上来自于百度翻译 以下为原文 Hello, I have a problem to use EEPROM on PIC18F14K50. I want to input 0x01 to 0x00 address eeprom. Then, I hope get this result from UART. I get only "eeprom data is 0". If you have any idea to solve this problem, please tell me. I'm looking forward to hearing from you. #include #include #include #include #include #define _XTAL_FREQ 48000000 #define SPI_CS LATCbits.LATC6 #pragma config CPUDIV = NOCLKDIV #pragma config USBDIV = OFF #pragma config FOSC = HS #pragma config PLLEN = ON #pragma config FCMEN = OFF #pragma config IESO = OFF #pragma config PWRTEN = OFF #pragma config BOREN = OFF #pragma config BORV = 30 #pragma config WDTEN = OFF #pragma config WDTPS = 32768 #pragma config MCLRE = OFF #pragma config HFOFST = OFF #pragma config STVREN = ON #pragma config LVP = OFF #pragma config XINST = OFF #pragma config BBSIZ = OFF #pragma config CP0 = OFF #pragma config CP1 = OFF #pragma config CPB = OFF #pragma config WRT0 = OFF #pragma config WRT1 = OFF #pragma config WRTB = OFF #pragma config WRTC = OFF #pragma config EBTR0 = OFF #pragma config EBTR1 = OFF #pragma config EBTRB = OFF __EEPROM_DATA(3,0,0,0,0,0,0,0); void putch(unsigned char ch) { while (!TXIF); TXREG = ch; } void DelayMs(int dlyms) { while (dlyms--) { __delay_ms(1); } } void main(void) { char data; unsigned char var, wcnt, EEadd; OSCCON = 0b00000000; ANSEL = 0b00000000; // ???? ANSELH = 0b00000000; LATC = 0; // PortC???????????? SPI_CS = 1; // SPI_CS??????? TRISCbits.TRISC6 = 0; // SPI_CS?????? TRISCbits.TRISC7 = 0; // SPISDO?????? TRISBbits.TRISB6 = 0; // SPISCK?????? SSPSTAT = 0b11000000; // FOSC_4, MODE_00, SMPEND SSPCON1 = 0b00110001; TRISBbits.TRISB5 = 1; ANSELHbits.ANS11 = 0; RCSTA = 0b10010000; TXSTA = 0b00100100; BAUDCON = 0b00001000; SPBRGH = 1249 / 256; SPBRG = 1249 % 256; __delay_ms(10); //T2CON = 0b00000100; // timer2 PS_1/1 POST_1/1 //PR2 = 249; // Timer2 PR?? int i = 0; wcnt = 0; EEadd = 0; eeprom_write(0x00, 0x01); while (1) { // ??????? data = eeprom_read(EEadd); printf("eeprom data is %cn", data); DelayMs(1000); i++; } // ???????? } |
|
相关推荐
7个回答
|
|
|
|
|
|
1.37只是最新版本之前的一个。它不包括外围库,如果您在docs文件夹中阅读Readme_XC8.htm文件,您会看到这些库。包含它们的最后一个版本是1.34。您可以获得它们,但是如前所述,这是一个单独的下载。
以上来自于百度翻译 以下为原文 1.37 is only one before the latest version. It does NOT include the peripheral libraries, which you would see if you read the Readme_XC8.htm file in the docs folder. The last version to include them was 1.34. You can get them, but as already stated, it is a seperate download. |
|
|
|
@qhb谢谢你的回答。我下载了v1.37XC8并使用它。但是,我无法正确地获取数据。我在项目的Properties上选择了XC8 v1.37并运行我的程序。我试着运行稍微修改过的程序。此源代码如下。>/**文件:newmain.c*Author:newmain.c*newmain.c*Author:kashiharaakira**创建于2016年8月31日,2016年8月31日,8:35PM**//\8:早8:35PM*/包含<*xc.h>包括<<<&xc.h>包括
以上来自于百度翻译 以下为原文 @qhb Thank you for your answer. I downloaded v1.37 XC8 and use it. However, I was not able to get data correctly. I selected XC8 v1.37 on Properties of my project and run my program. I try to run my program which is changed a little. this source code is the following. > /* * File: newmain.c * Author: kashiharaakira * * Created on August 31, 2016, 8:35 PM */ #include #include #include #include #include #define _XTAL_FREQ 48000000 #define SPI_CS LATCbits.LATC6 #pragma config CPUDIV = NOCLKDIV #pragma config USBDIV = OFF #pragma config FOSC = HS #pragma config PLLEN = ON #pragma config FCMEN = OFF #pragma config IESO = OFF #pragma config PWRTEN = OFF #pragma config BOREN = OFF #pragma config BORV = 30 #pragma config WDTEN = OFF #pragma config WDTPS = 32768 #pragma config MCLRE = OFF #pragma config HFOFST = OFF #pragma config STVREN = ON #pragma config LVP = OFF #pragma config XINST = OFF #pragma config BBSIZ = OFF #pragma config CP0 = OFF #pragma config CP1 = OFF #pragma config CPB = OFF #pragma config WRT0 = OFF #pragma config WRT1 = OFF #pragma config WRTB = OFF #pragma config WRTC = OFF #pragma config EBTR0 = OFF #pragma config EBTR1 = OFF #pragma config EBTRB = OFF void putch(unsigned char ch) { while (!TXIF); TXREG = ch; } void DelayMs(int dlyms) { while (dlyms--) { __delay_ms(1); } } int main(void) { OSCCON = 0b00000000; unsigned char value = 0x09; unsigned char address = 0xE5; eeprom_write(address, value); __delay_ms(5); TRISC = 0; TRISBbits.TRISB5 = 1; ANSELHbits.ANS11 = 0; RCSTA = 0b10010000; TXSTA = 0b00100100; BAUDCON = 0b00001000; SPBRGH = 1249 / 256; SPBRG = 1249 % 256; __delay_ms(10); while (1) { unsigned readValue = eeprom_read(address); printf("eeprom_read is %cn", readValue); DelayMs(1000); } } < This result is the following. eeprom_read is . I'm looking forward to hearing from you. |
|
|
|
如果这是你已经使用的版本,你为什么又下载它?“外围库”是从您下载编译器的同一个网页上单独下载的。这些内容都在我建议您阅读的自述文件中进行了解释。您使用的格式说明符是错误的。它将试图显示一个不可打印的字符。尝试“%d”或“%x”,而不是“%c”。
以上来自于百度翻译 以下为原文 Why did you download it again, if that is the version you were already using? The "peripheral libraries" are a seperate download, from the same web page where you download the compiler. This is all explained in the readme file I advised you to read. You're using the wrong format specifier there. It will be trying to show a non-printable character. Try "%d" or "%x" instead of "%c". |
|
|
|
|
|
|
|
谢谢你的回复。我写错了。我下载了v1.34XC8并尝试了。但是,我没能正确地获得数据。我试图在从%c更改为%d之后获得数据,但是我得到了以下结果。eeprom_read是0我选择v1.34XC8作为项目文件的属性。这个操作正确吗?DarioGIs,我真的应该尝试使用GPIO吗?
以上来自于百度翻译 以下为原文 Hello Thank you for your reply. @qhb I'm sorry. I take a mistake to write here. I download v1.34 XC8 and try it. However, I was not able to get correctly data. I tried to get data after changing from %c to %d but I get the following. eeprom_read is 0 I selected v1.34 XC8 on properties of my project file. This operation is correctly? @DarioG Is it true that I should try to output used GPIO? |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5243 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3208 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2258 浏览 5 评论
779浏览 1评论
672浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
598浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
680浏览 0评论
578浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 12:56 , Processed in 1.589876 second(s), Total 89, Slave 73 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号