完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,伙计们,我在UFART端口的配置方面有一些问题,在16F/LF88。如果我配置的微到8 MHz(内联)和波特率为19200,UART工作正常。但是如果我将它配置为4 MHz(内联)ANS相同的19200。(与外部的4兆赫CRISTAL相同)。我不能与其他微控制器,甚至是我使用的ARDUINO MIGA作为控制点。此时我只发送0x55 H作为控制字符。可能我错过了一些勘误表吗?Cyrd.*********配置文件***********SPBRG值是从设备数据表8 MHz和19200 BaD.ValuInUTUARTH(){ BRGH=1;SPBRG=0x19;//-0&-0x19-8 MHz;Syc=0;SPIN=1;TrISB2=1;TrISB5=1;CREN=1;TXEN=101〕的表。1;} 4个字节和19200个字节。{BRGH=1;SPBRG=0x0C;// 12 -Gt;0x0C;4 MHz同步=0;TrISB2=1;TrISB5=1;CREN=1;TXEN=1;} ***********读写函数是直形的MCC…:***********无效写Wr.CuuluART(char C){(1=PiR1BIT.TXIF){} TXR。EG= C;} char ReCARARUART(){同时()!如果(1=rcStest.Orr){//EUSAT错误}重启RcStest.SPCN=0;RcStest.SPEN=1;}返回RCREG;} *****************-----------TX----------发送一行“u”给LCDValb主(空){无符号char;;(i);;(i),(1){Ra0^=1;0;a & lt;16;ax+);} -Delay-Ms(1000);}-------------------------只是空格(空隙){无符号char a,计数,RES,循环;iNITUARTH();计数=0;Ra0=0;RB0=0;RB1=0;循环=0;而(1){R0^=1;DO RB0^=1;RES=RECHCHA。RuART(0x55);如果(RE==0x55)计数+Read;Read EnguluART(Res);}(计数和lt;16);循环+++;计数=0;γ-DelayyMS(1000);Rf(循环和lt;4){RB1=1;}否则{RB1= 0;循环=0;}}} PIC初始化*********初始化(如果需要空隙)({OSCCon=0B01111000;TrISB= 0);B900100100;//RX-RB2*********TX-RB5 TrISA=0B90000;PORTA=0B90000;PORTB= 0B90000;安塞尔=0B90000;ADCON0= 0B90000;ADCON1= 0B90000;};
以上来自于百度翻译 以下为原文 Hi Guys, I'm having some issues with the configuration of UART port in a couple of 16f/lf88. If I configure the micro to 8 MHZ (INTRC) and a baud rate of 19200 the UART works Correctly. But if I configure it to 4 MHZ (INTRC) ans the same 19200. (same happens with external 4 MHz cristal). I can't communicate with the other microcontroller or even an arduino mega I'm using as control point. At this time I'm just sending 0x55h as control char. Maybe I missed some errata? Any Insight would be much appreciated. Cheers. ********** Configuration files *************** SPBRG values are table on page 101 from device datasheet 8 MHz and 19200 baud. void initUARTH(){ BRGH = 1; SPBRG = 0x19; //25 -> 0x19 --- 8 MHz ; SYNC = 0; SPEN = 1; TRISB2 = 1; TRISB5 = 1; CREN = 1; TXEN = 1; } 4 MHz and 19200 baud. void initUARTH(){ BRGH = 1; SPBRG = 0x0c; //12 -> 0X0c --- 4 MHz SYNC = 0; SPEN = 1; TRISB2 = 1; TRISB5 = 1; CREN = 1; TXEN = 1; } ******************* Read Write functions are straight form MCC....: ************** void writeCharUART(char c){ while(0 == PIR1bits.TXIF){} TXREG = c; } char readCharUART(){ while(!PIR1bits.RCIF){} if(1 == RCSTAbits.OERR){ // EUSART error - restart RCSTAbits.SPEN = 0; RCSTAbits.SPEN = 1; } return RCREG; } *********Code****************** --------------TX------------- Send one line of "U" for LCD void main(void){ unsigned char a; init(); initUARTH(); while(1){ RA0 ^= 1; for (a = 0; a <16 ; a++){ writeCharUART(0x55); } __delay_ms(1000); } } ------------------RX------------------- Just ticking some leds.... void main(void){ unsigned char a, count, res, cycle; init(); initUARTH(); count = 0; RA0 = 0; RB0 = 0; RB1 = 0; cycle = 0; while(1){ RA0 ^= 1; do{ RB0 ^= 1; res= readCharUART(0x55); if (res == 0x55) count++; writeCharUART(res); } while (count < 16); cycle++; count = 0; __delay_ms(1000); RB0 = 0; if (cycle < 4){ RB1 = 1; } else { RB1 = 0; cycle = 0; } } } ****** PIC INITIALIZATION ************ Initialization if need void init(){ OSCCON = 0b01111000; TRISB = 0b00100100; // RX - RB2 *********** TX- RB5 TRISA = 0b00000000; PORTA = 0b00000000; PORTB = 0b00000000; ANSEL = 0b00000000; ADCON0 = 0b00000000; ADCON1 = 0b00000000; while(!OSCCONbits.IOFS); } |
|
相关推荐
2个回答
|
|
解决…抱歉浪费你的时间……欢呼…微笑:
以上来自于百度翻译 以下为原文 Solved... Sorry for wasting your time guys... Cheers...Smile: |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5248 浏览 9 评论
2036 浏览 8 评论
1956 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3217 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2264 浏览 5 评论
786浏览 1评论
677浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
603浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
684浏览 0评论
581浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-27 04:47 , Processed in 1.092989 second(s), Total 79, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号