完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,我还在用PIC16F1574构建一个传感器设备,需要异步串行通信。TX通过PPS路由到端口C4,RX连接到端口C5。在我的代码中,AM使用内部寄存器16MHz使用配置寄存器和OSCOCN寄存器,并且我们完全延迟了1秒。可以使用ANSELC的模拟模式。当我们使用PIN码时,代码工作得很好,但是我们甚至连一个字符都无法传输。下面是相关代码:如果你们有想法的话,请帮助我们。
以上来自于百度翻译 以下为原文 Hello, I'm also building a sensor device with a PIC16F1574, requiring asynchronous serial communication. TX is routed to Port C4 through PPS, and RX is connected to Port C5.In my code iam using Internal Oscillator 16mhz using Config register and OSCCON Register, and we get a Delay of 1 sec perfectly.disable the Analog mode using ANSELC. code works fine when we use the Pin out,but we haven't been able to transmit even one character. Here's the relevant code:#pragma config FOSC = INTOSC // Oscillator Selection Bits (ECH, External Clock, High Power Mode (4-32 MHz); device clock supplied to CLKIN pin) #pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled) #pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled) #pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR) #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled) #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled) #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin) // CONFIG2 #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off) #pragma config PPS1WAY = OFF // PPSLOCK bit One-Way Set Enable bit (PPSLOCKED Bit Can Be Cleared & Set Repeatedly) #pragma config PLLEN = ON // PLL Enable (4x PLL ENabled) #pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will not cause a Reset) #pragma config BORV =LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.) #pragma config LPBOREN = OFF // Low Power Brown-out Reset enable bit (LPBOR is disabled) #pragma config LVP = ON #include #define _XTAL_FREQ 16000000 unsigned char data='a'; void main(void) { OSCCON=0x7A;// Config the Internal Frequency to 16 mhz TRISC=0x20; WPUC=0X00; ANSELC= 0X00; RC4PPS= 0X09; BAUDCON=0X00; SPBRGL= 0X19; TXSTA=0X20; RCSTA=0X78; PIE1 |=(1< while(1) { PORTC=0X01;__delay_ms(1000); PORTC=0X00;__delay_ms(1000); while(!PIR1bits.TXIF); //while(!TXIF); TXREG = data; } } please help us if you guys have an idea. Thanks in advance, |
|
相关推荐
3个回答
|
|
我看到了两个错误。(1)Pe1==(1 & lt;lt;tXy);当你想轮询一点时,不要启用中断。如果你有,你会被锁在连续中断中。(2)RCSTA=0x78;0x78=0B01111000,ISSPEN=0=OFRX9=1=OnSREN=1=OnCREN=1=ONADEN=1=on(底部三位是只读的,所以不管你给他们写什么)。所以,除了CREN之外的每一个设置都是错误的。JOR问题是SPON关闭,所以您的串口根本没有启用。对于正常操作,您需要设置SPEN和CREN,所以尝试写0B10010000(0x90)。
以上来自于百度翻译 以下为原文 I see two mistakes. [1] PIE1 |=(1< You got away with this because you didn't set the GIE bit. If you had, you would have been locked into continuous interrupts. [2] RCSTA=0X78; 0x78 = 0b01111000 That is SPEN = 0 = off RX9 = 1 = on SREN = 1 = on CREN = 1 = on ADDEN = 1 = on (The bottom three bits are read-only, so it doesn't matter what you write to them). So, every setting except CREN is wrong. The major problem is the SPEN is off, so your serial port is not enabled at all. For normal operation, you need to set SPEN and CREN on, so try writing 0b10010000 (0x90) instead. |
|
|
|
以上是一个很好的论点,因为没有代码块满是“神奇数字”,没有注释,而不是:
以上来自于百度翻译 以下为原文 The above is a good argument for not having blocks of code full of "magic numbers" and no comments. Rather than: RC4PPS= 0X09; BAUDCON=0X00; SPBRGL= 0X19; TXSTA=0X20; RCSTA=0X78; RC4PPS= 0X09; // Connect RC4 to "TX/CK" BAUDCON=0b00000000; //SCKP=0 (TX true), BRG16=0, ABDEN=0 SPBRGL= 25; // 9600 baud @ 16MHz when BRGH=0 and BRG16=0 TXSTA=0b00100000; // TXEN=1 RCSTA=0b10010000; // SPEN=1, CREN=1 |
|
|
|
甚至更好(在我看来)甚至可能被称为“自我记录”!苏珊
以上来自于百度翻译 以下为原文 ...or even better (in my opinion) TXSTAbits.TXEN = 1; Might even be called 'self documenting'! Susan |
|
|
|
只有小组成员才能发言,加入小组>>
5178 浏览 9 评论
2003 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3177 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
738浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
636浏览 0评论
533浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 22:55 , Processed in 1.430870 second(s), Total 83, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号