完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,下面的代码仅仅是为了在PIC16F18856的RB2上产生一个方波输出。这样我们就可以测试RB2驱动的OPTO的输出是否有足够快的上升/下降时间。它是用XC8C和MPLAB X编写的。它建立了OK,但是你知道我如何设置这个定时器吗?Aymis(3)命令?另外,你认为我正确地设置了寄存器吗?我们不能测试,直到我们在星期一的董事会,但我们需要它准备好。
以上来自于百度翻译 以下为原文 Hello, The following code is simply meant to produce a square wave output on RB2 of PIC16F18856. This is so we can test if the output of the opto that RB2 drives into has a quick enough rise/fall time. It is written in XC8 C and MPLAB X. It builds OK but do you know how i set up the timer for the __delay_ms(3) command? Also, do you think ive set up the registers correctly. We cant test it till we get the boards in on Monday, but we need it ready. //This code simply puts out a square wave on RB2 //Period = 3ms //PIC16F18856 //XC8 compiler //MPLAB X V3.61 // PIC16F18856 Configuration Bit Settings // 'C' source line config statements // CONFIG1 #pragma config FEXTOSC = OFF // External Oscillator mode selection bits (Oscillator not enabled) #pragma config RSTOSC = EXT1X // Power-up default value for COSC bits (EXTOSC operating per FEXTOSC bits) #pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2) #pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (FSCM timer disabled) // CONFIG2 #pragma config MCLRE = OFF // Master Clear Enable bit (MCLR pin function is port defined function) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config LPBOREN = OFF // Low-Power BOR enable bit (ULPBOR disabled) #pragma config BOREN = OFF // Brown-out reset enable bits (Brown-out reset disabled) #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices) #pragma config ZCD = ON // Zero-cross detect disable (Zero-cross detect circuit is always enabled) #pragma config PPS1WAY = OFF // Peripheral Pin Select one-way control (The PPSLOCK bit can be set and cleared repeatedly by software) #pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable bit (Stack Overflow or Underflow will not cause a reset) // CONFIG3 #pragma config WDTCPS = WDTCPS_31// WDT Period Select bits (Divider ratio 1:65536; software control of WDTPS) #pragma config WDTE = OFF // WDT operating mode (WDT Disabled, SWDTEN is ignored) #pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required) #pragma config WDTCCS = SC // WDT input clock selector (Software Control) // CONFIG4 #pragma config WRT = OFF // UserNVM self-write protection bits (Write protection off) #pragma config SCANE = not_available// Scanner Enable bit (Scanner module is not available for use) #pragma config LVP = OFF // Low Voltage Programming Enable bit (High Voltage on MCLR/Vpp must be used for programming) // CONFIG5 #pragma config CP = OFF // UserNVM Program memory code protection bit (Program Memory code protection disabled) #pragma config CPD = OFF // DataNVM code protection bit (Data EEPROM code protection disabled) // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. #include #include #define _XTAL_FREQ 4000000 uint8_t count; void main(void) { //Setup ports TRISA = 0x30; //ADC INS TRISB = 0x08; //ZCD & DALIRX TRISC = 0x0C; //SELECT ANSELA = 0x00; //ADC INs ANSELB = 0x00; ANSELC = 0x00; WPUA = 0x00; ODCONA = 0x00; SLRCONA = 0x00; INLVLA = 0x00; //ST? CCDPA = 0x00; CCDNA = 0x00; WPUB = 0x00; ODCONB = 0x00; SLRCONB = 0x00; INLVLB = 0x00; //ST? CCDPB = 0x00; CCDNB = 0x00; WPUC = 0x00; ODCONC = 0x00; SLRCONC = 0x00; INLVLC = 0x00; //ST? CCDPC = 0x00; CCDNC = 0x00; INTCON = 0x00; CM1CON0 = 0x00; CM1CON1 = 0x00; CM2CON0 = 0x00; CM2CON1 = 0x00; PWM6CON = 0x00; PWM7CON = 0x00; ZCDCON = 0x00; //Initialize ports LATAbits.LATA0 = 0; LATAbits.LATA1 = 0; LATAbits.LATA2 = 0; LATAbits.LATA3 = 0; //LATAbits.LATA4 = 0; temp sensor input //LATAbits.LATA5 = 0; light sensor input LATAbits.LATA6 = 0; LATAbits.LATA7 = 0; //LATBbits.LATB0 = 0; zero crossing input LATBbits.LATB1 = 0; LATBbits.LATB2 = 0; //dali TX pin //LATBbits.LATB3 = 0; dali RX pin LATBbits.LATB4 = 0; LATBbits.LATB5 = 0; LATBbits.LATB6 = 0; LATBbits.LATB7 = 0; LATCbits.LATC0 = 0; LATCbits.LATC1 = 0; //LATCbits.LATC2 = 0; pulldown resistor //LATCbits.LATC3 = 0; pulldown resistor LATCbits.LATC4 = 0; LATCbits.LATC5 = 0; LATCbits.LATC6 = 0; LATCbits.LATC7 = 0; //5 second delay for (count=1;count<=50;count++) { __delay_ms(100); } while(1){ LATBbits.LATB2 = 0; __delay_ms(3); LATBbits.LATB2 = 1; __delay_ms(3); } return; } |
|
相关推荐
4个回答
|
|
Y-DELAYHYMS不使用计时器,它只计算指令周期。它只取决于您正确地定义了XXTALFILE FRQQ,只是告诉编译器您的时钟频率,它不控制它。为什么FFF围绕所有的位设置?你可以得到同样的效果:
以上来自于百度翻译 以下为原文 __delay_ms does not use a timer, it just counts instruction cycles. It just depends upon you correctly defining _XTAL_FREQ That just tells the compiler your clock frequency, it does NOT control it. //Initialize ports LATAbits.LATA0 = 0; LATAbits.LATA1 = 0; LATAbits.LATA2 = 0; LATAbits.LATA3 = 0; //LATAbits.LATA4 = 0; temp sensor input //LATAbits.LATA5 = 0; light sensor input LATAbits.LATA6 = 0; LATAbits.LATA7 = 0; //LATBbits.LATB0 = 0; zero crossing input LATBbits.LATB1 = 0; LATBbits.LATB2 = 0; //dali TX pin //LATBbits.LATB3 = 0; dali RX pin LATBbits.LATB4 = 0; LATBbits.LATB5 = 0; LATBbits.LATB6 = 0; LATBbits.LATB7 = 0; LATCbits.LATC0 = 0; LATCbits.LATC1 = 0; //LATCbits.LATC2 = 0; pulldown resistor //LATCbits.LATC3 = 0; pulldown resistor LATCbits.LATC4 = 0; LATCbits.LATC5 = 0; LATCbits.LATC6 = 0; LATCbits.LATC7 = 0; Why faff around with all that bit setting? You can get exactly the same effect with: LATA = 0; LATB = 0; LATC = 0; |
|
|
|
谢谢,在PIC12F509中,我记得我必须设置选项寄存器,否则,Y-YelayySMS()函数将无法工作。这与需要正确设置Time0有关,以便可以适当地计算延迟。看起来奇怪的是PIC12F509需要这个,但是PIC16F18856不需要它吗?
以上来自于百度翻译 以下为原文 Thanks, in the PIC12F509, i remember i had to set up the OPTION register or else the __delay_ms() function would not work. It was something to do with needing the TIMER0 to be set up properly so that the delays could be properly calculated. Seems strange that the PIC12F509 needs this but the PIC16F18856 doesnt need it? |
|
|
|
不需要硬件。它是编译器,并且在我记忆中一直在HTC XX8上工作。
以上来自于百度翻译 以下为原文 Nothing to with hardware. It's the compiler and has worked this way on htc thru xc8 as far back as I remember |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5178 浏览 9 评论
2003 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3177 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
737浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
635浏览 0评论
533浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 15:09 , Processed in 1.554993 second(s), Total 84, Slave 68 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号