完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,您知道PIC12F509的代码为什么不能编译吗?它是用MPLAB X IDE编写的,使用XC8C编译器编写的。所有的代码都是在端口GP4上选择一个低到高的过渡,然后等待3毫秒,然后取端口GP2高。我现在被建筑错误弄得眼花缭乱。
以上来自于百度翻译 以下为原文 Hello, Do you know why this code for PIC12F509 will not compile? It is written in MPLAB X IDE and using XC8 C compiler. All the code does is pick out a low to high transition on PORT GP4 and then wait 3 ms, then take PORT GP2 high. I am festooned with build errors at the moment. /* * File: zapper.c * Author: * * Created on 03 June 2017, 23:55 */ //This code turns the product ON at the mains peak voltage //It does this by using the zero crossing detector input. //This uses PIC12F509 //MPLAB X IDE //XC8 C compiler (free) #define _XTAL_FREQ 4000000 #include #include #pragma config OSC = ExtRC // 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 = ON // 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. //Define output #define FETS LATBbits.RB2; //Define input #define zero_x PORTBbits.RB4; //Define actions #define ON LATBbits.RB2 = 1 /*Turn ON FETs*/ //Declare functions which set up the microcontroller void disable_interrupts(void); //How do this? void disable_pullups(void); //How do this? void setup_ports(void); void setup_ports(void) { TRISB = 0b00011000; return; } //Declare variables uint8_t count; void main(void) { setup_ports(); //10 second delay for (count=1;count<=100;count++) { __delayms(100); } here: if {zero_x = 1} {goto here;} here1: if {zero_x = 0} {goto here1;} //When it gets to this point, the zero crossing input has just gone high __delayms(3); //delay to get to the mains peak ON; //Turn ON FETs...at the mains peak while(1){;} return (); } |
|
相关推荐
8个回答
|
|
1。您没有发布生成错误。2、如果(ZooOxx=1)应该是====是一个赋值。=比较。3.那是什么样的混乱?当(ZooOxx==1)时,在C4中做同样的事情。禁用Iututs di.();5。上拉是WPUB位。
以上来自于百度翻译 以下为原文 1. You did not post the build errors. 2.if( Zero_x = 1) should be == = is an assignment. == is a compare. 3.what is that goto mess? while (zero_x == 1); does the same thing in C 4. Disable interupts di(); 5. The pull-ups are the WPUB bit |
|
|
|
|
|
|
|
和括号周围的“如果”条件而不是括号,拼写错误的γ-Delaymis…
以上来自于百度翻译 以下为原文 and braces around "if" conditions instead of parentheses, and misspelling of __delay_ms... |
|
|
|
我以为我看到了这样的东西,但让它去,以为我还在睡觉。
以上来自于百度翻译 以下为原文 I thought I saw something like that but let it go, thinking I was still asleep |
|
|
|
您好,谢谢,我现在把它建起来了,但是它不工作。请您检查一下它的引脚,打开和关闭*****************文件:ZAPER。C*作者:**创建于2017年6月03,23:55 *///这使用PIC12F509//MPLAB XIDID//XC8C编译器(免费)。E&L.X.H.&Gt;Stdit.H.G.T.PrimaMang-COMFIG OSC=内/ /振荡器选择位(内部RC振荡器)α-PrAPMA配置WTD= OF//看门狗定时器允许位(WDT禁用)α-PrAPMA配置Cp=O//码保护位(码保护关)α-PracMA配置MCLRE ON//GP3/ MCLR Pin FuNCSET选择位(GP3/MCLR PIN功能是MCLR)// I没有设置MCLR引脚作为输入,因为它将是噪声敏感的。/因此,我设置MCLR作为复位,但我将永远不使用它作为复位..但将/ /简单地拴在PCB上的引脚顶部VDD。/ /定义输出α定义FETs gp2//定义输入定义ZooOxx GP4/ /定义动作/ /声明功能,设置微控制器/空隙禁用中断(无效);/无效/不可用(无效);虚空设置端口(空隙);空隙设置端口(空隙){TrISGPIO=0B000 011000;/TrIS= 0x18;返回;} /声明变量/ /空隙主(空隙){StuuPuxPosits();而(1){Pp2=1;γ-DelayyMS(30);/ /延迟到达电源峰值GP2=0;γ-DelayyMS(30);}返回;}
以上来自于百度翻译 以下为原文 Hello, Thanks i have got it building now, but it doesnt work.please could you check.its just to pulse a pin on and off *********************** /* * File: zapper.c * Author: * * Created on 03 June 2017, 23:55 */ //This uses PIC12F509 //MPLAB X IDE //XC8 C compiler (free) #define _XTAL_FREQ 4000000 #include #include #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 = ON // 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. //Define output #define FETS GP2 //Define input #define zero_x GP4 //Define actions //Declare functions which set up the microcontroller //void disable_interrupts(void); //How do this? //void disable_pullups(void); //How do this? void setup_ports(void); void setup_ports(void) { TRISGPIO = 0b00011000; // TRIS = 0x18; return; } //Declare variables // void main(void) { setup_ports(); while(1){ GP2 = 1; __delay_ms(30); //delay to get to the mains peak GP2 = 0; __delay_ms(30); } return; } |
|
|
|
GP2与T0CKI共享功能,因此您必须将Time0设置为内部时钟。
以上来自于百度翻译 以下为原文 GP2 shares function with T0CKI, so you will have to setup Timer0 to internal clock. |
|
|
|
从XC8用户指南中,您必须一次写入所有的选项位,不能单独设置它们。
以上来自于百度翻译 以下为原文 From the XC8 User Guide OPTION= nGPWU | nGPPU | PSA; //GPWU disabled, GPPU disabled, T0 internal, Prescaler assigned to WDT Note, you have to write all the OPTION bits in one go, you can't set them individually. |
|
|
|
你的这个程序是有编译的出错的么,是什么错误呢
|
|
|
|
只有小组成员才能发言,加入小组>>
5234 浏览 9 评论
2026 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3201 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
771浏览 1评论
659浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
588浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
670浏览 0评论
571浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-20 07:32 , Processed in 1.375285 second(s), Total 91, Slave 75 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号