完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,这对我来说可能是一个简单的错误,但是我已经花了好几天时间尝试在Pic12f509上编写最简单的代码。现在我不是一个完全新手,我已经成功地从零知识编程了Atmel产品Attiny 13 Attiny 85 Atmega328,以便在几分钟内闪烁一个led。曾经有过MPLAB回避过我。我无法让模拟器工作,也无法正确地编程芯片。我试过Oshonsoft的优秀模拟器,实际上可以让模拟器工作,但是对于编写真正的芯片,没有办法。所以,在我创建代码之后,我编译它并生成十六进制输出。我没有使用pickit devic。e我有一个程序员,成功地对Atmel.、Eproms和许多TL866设备进行了编程。有人能告诉我我做错了什么吗?如果你愿意,可以嘲笑我吗?下面的代码是一个超级简化,只是为了让事情发生。/**File:auto_eddy_main.c*Author:mario**创建于2016年5月1日,2010年5月1日,10:21PM*/////包括<_&stdio.h>//包括<_&stdio.h>///\包括<_< pic.h>///\包括
以上来自于百度翻译 以下为原文 Hi, this is probably a simple error on my part but I have struggled for days trying the simplest of code on the Pic12f509. Now I am not a total new comer, I have successfully programmed Atmel products Attiny 13 Attiny 85 Atmega328 from Zero knowledge to blink a led in a matter of minutes. The PIC however with MPLAB has eluded me. I cannot get the simulator to work nor can I program a chip correctly. I have tried Oshonsoft's excellent simulator and can actually make the simulation work but as for programming a real chip , no go. So, after I create the code I compile it and a Hex output is produced. I am not using a pickit device I have a programmer that successfully programs Atmel Products , Eproms and many many devices the TL866. Can any body tell me what I am doing wrong and laugh at me if you like. This code below is a super simplification just to try to get something to happen. /* * File: auto_eddy_main.c * Author: mario * * Created on 1 May 2016, 10:21 PM */ //#include //#include //include // PIC12C509 Configuration Bit Settings // 'C' source line config statements // CONFIG #pragma config OSC = IntRC // Oscillator selection bits (internal RC oscillator) #pragma config WDT = OFF // Watchdog timer enable bit (WDT disabled) #pragma config CP = OFF // Code protection bit (Code protection off) #pragma config MCLRE = OFF // MCLR enable bit (MCLR tied to VDD, (Internally)) // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. #include // Pin Assignments #define OutGP1 GPIObits.GP1 #define LED GPIObits.GP2 // Output to Led #define Switch GPIObits.GP0 // Output to Switch Matrix #define SCL GPIObits.GP5 // Input to Digital Pot #define SDA GPIObits.GP4 // Input to Digital Pot #define Sensor GPIObits.GP3 // Output from Eddy current Sensor IC #define _XTAL_FREQ 4000000 int main() { //OPTION = 0x02; //Set option register Bit 7 Wake up on pin change enabled,Bit 6 enable weak pullups //Bit 5 Timer0 transition on internal clock, Bit 4 Timer0 positive edge triggered, //Bit 3 Prescaler assigned to Timer0, Bits 2 - 0 all zeros set prescaler value 1:2 TRISGPIO = 0b001000; //Set GP0,1,2,4,5 as output GP3 as input while(1) { if (Switch = 0) LED = 1; OutGP1 =0; } } Your help greatly appreciated. |
|
相关推荐
9个回答
|
|
摆脱:恢复:你使用的这个无名程序员是什么?你知道它是否正确地配置了配置比特?有可能它没有保存位置0x3FF的校准字。如果已经擦除,那么C代码将锁定,除非在项目设置中关闭“校准时钟”选项。
以上来自于百度翻译 以下为原文 Get rid of: #include and reinstate: include What is this unnamed programmer that you are using? Do you know if it programs the CONFIG bits correctly? Chances are it has NOT preserved the calibration word at location 0x3FF. If that has been wiped, then the C code will lock up unless you turn off the "calibrate clock" option in the project settings. |
|
|
|
谢谢您的回复。程序员是Minipro TL866cs。它实际上将校准字保留在0x3ff处,在编程之前读完校准字后将其复制回PIC。我已经试过包括
以上来自于百度翻译 以下为原文 Thank you for the response. The programmer is a Minipro TL866cs. It does actually preserve the calibration word at 0x3ff, it copies it back to the PIC after reading it before programming. I have already tried include Other than that my code is simple enough right? |
|
|
|
|
|
|
|
谢谢Mbedder的建议。但是这对模拟和实际芯片没有影响。不管我对输入引脚做什么,即强制它高或低,输出基本不变,如果我测量它的输出在3.68V。电源电压是5.05V。我试过sev。艾莱依芯片。
以上来自于百度翻译 以下为原文 Thank you Mbedder for the suggestion. However this made no difference to the simulation nor to the real chip. No matter what I do to the input pin i.e. force it high or low the output does not change, basically if I measure the output its sitting at 3.68V. The supply voltage is 5.05V. I have tried several chips. |
|
|
|
如果你的开关输入在GP0上,那么你的TrISGPIO应该是0B00 00 1001。
以上来自于百度翻译 以下为原文 TRISGPIO = 0b001000; If your switch input is on GP0, then your TRISGPIO should be 0b00001001 |
|
|
|
经验法则:总是读取来自POXX的输入,并将输出写入到LATX。如果需要读取设置输出的内容,请阅读LATx。
以上来自于百度翻译 以下为原文 Rule of thumb: Always read inputs from PORTx and write outputs to LATx. If you need to read what you set an output to, read LATx. |
|
|
|
|
|
|
|
1。根据需要初始化所有输出为1或0。2。您正在使用条件的输出的逻辑状态:if(Switch=0)//这应该是:if(Switch==0)LED=1;//这将打开GP2。没有代码使它退回Outgp1=0;//这将通过循环每次执行。这是有条件的。添加{和}
以上来自于百度翻译 以下为原文 1. You should initialize all outputs to 1 or 0 as needed. 2. You are using the logic state of an output in your conditional: if (Switch = 0) // This should be: if (Switch==0) LED = 1; // This will turn on GP2. There is no code to turn it back off OutGP1 =0; // This will execute every time through the loop. It is outside the conditional. Add { and } |
|
|
|
嗨,这个怎么样,我甚至只是看看MPLAB中的SFR,然后一步一步地完成代码,我甚至不能让GPIO遵循第一个GPIO=0b001011。当我改变刺激时,它跳转到if语句后面的正确的if部分,但是GPIO=对..int main(void){//OP.=0b0000000;//Set选项寄存器位7唤醒启用了pin更改,位6启用了弱上拉//位5Timer0转换三值时钟,位4定时器0正边触发,//位3定时器分配给定时器0,位2-0所有零设置定时器值1:2TRISGPIO=0b001000;//将GP0,1,2,4,5设置为输出GP3作为输入GPIO=0b001111;而(1){if(SensorGP3==0){//LEDGP2=0;//OutGP1=0;GPIO=0b000000;}其他{LeDGP2=1;Outgp1=1;}}返回0;}
以上来自于百度翻译 以下为原文 Hi, what about this, I even just look at the SFR's in MPLAB and step through the code and I cant even get the GPIO to follow the First GPIO=0b001011. It jumps to the correct If part after the if statement when I change the stimulus but the GPIO = has no effect on the GPIO pins in the simulation. int main(void) { //OPTION = 0b0000000; //Set option register Bit 7 Wake up on pin change enabled,Bit 6 enable weak pullups //Bit 5 Timer0 transition on internal clock, Bit 4 Timer0 positive edge triggered, //Bit 3 Prescaler assigned to Timer0, Bits 2 - 0 all zeros set prescaler value 1:2 TRISGPIO = 0b001000; //Set GP0,1,2,4,5 as output GP3 as input GPIO = 0b001111; while(1) { if (SensorGP3 == 0) { //LEDGP2 = 0; //OutGP1 = 0; GPIO = 0b000000; } else { LEDGP2 = 1; OutGP1 = 1; } } return 0; } |
|
|
|
只有小组成员才能发言,加入小组>>
5231 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3200 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
771浏览 1评论
659浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
588浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
669浏览 0评论
571浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-19 08:24 , Processed in 1.504333 second(s), Total 91, Slave 75 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号