完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
你好,请问你知道为什么我的PIC12F509的C代码(XC8)不工作吗?它所要做的是读取GP5上的方波电压输入,然后将GP4从高变为低,反之亦然,每秒GP5低。然而,GP4总是保持低位。你知道为什么吗?它建立成功但不工作
以上来自于百度翻译 以下为原文 Hello, Please do you know why my C code (XC8) for PIC12F509 doesnt work? All its supposed to do is read a square wave voltage input on GP5, and then change GP4 from high to low and vice versa, every second low-going of GP5. However, GP4 is always just staying low. Do you kow why? It builds successfully but doesn’t work /* * File: jitter.c * Author: * * Created on 8 sept 2017, 23:55 */ //this code jitters //This uses PIC12F509 //MPLAB X IDE //XC8 C compiler (free) #define _XTAL_FREQ 4000000 #include #include // #pragma config OSC = IntRC // Oscillator Selection bits (external 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 // GP3/MCLR Pin Function Select bit (GP3/MCLR pin function is MCLR) //I have not set the MCLR pin as an input because it will be noise susceptible. //Therefore i set MCLR up as reset, but i will never use it as reset..but will //simply tie the pin top Vdd on the PCB. //Declare functions which set up the microcontroller //void disable_interrupts(void); //How do this? //void disable_pullups(void); //How do this? // TRIS = 0x18; //Declare variables uint8_t count; void main(void) { GP0 = 0; GP1 = 0; GP2 = 0; GP4 = 0; GP5 = 0; OPTION = 0xD7; TRISGPIO = 0x20; GP4 = 0; //5 second delay for (count=1;count<=50;count++) { __delay_ms(100); } while(GP5 == 0) ; while(GP5 == 1) ; //STATUS LOW FIRST //When it gets to this point, the STATUS input has just gone low __delay_us(500); GP4 = 0; //FET OFF while(1){ while(GP5 == 0) ; //See out the rest of low STATUS while(GP5 == 1) ; //See out the high STATUS while(GP5 == 0) ; //See out the low STATUS while(GP5 == 1) ; //See out the high STATUS //STATUS LOW SECOND __delay_us(500); GP4 = 1; //FET ON while(GP5 == 0) ; //See out the rest of low STATUS while(GP5 == 1) ; //See out the high STATUS while(GP5 == 0) ; //See out the low STATUS while(GP5 == 1) ; //See out the high STATUS __delay_us(500); GP4 = 0; } while(1){;} return; } |
|
相关推荐
2个回答
|
|
不要试图同时解决两个问题,你能简单地让GP4在没有GP5测试的情况下闪现吗?
以上来自于百度翻译 以下为原文 Don't try to solve two problems at once. Can you simply get GP4 to flash without the GP5 tests? |
|
|
|
选项=0xD7;假设哪些位被设置而不是一些随机数。
以上来自于百度翻译 以下为原文 OPTION = 0xD7; Say what bits are set rather than some random number. |
|
|
|
只有小组成员才能发言,加入小组>>
5155 浏览 9 评论
1995 浏览 8 评论
1924 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3168 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2221 浏览 5 评论
721浏览 1评论
605浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
492浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
619浏览 0评论
518浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-18 09:24 , Processed in 1.258324 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号