完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
之前做过PIC16的串口,PIC18K20的DEMO软件也看过,然后觉得在K40上面应该不会太困难 谁知道,,,第一次使用PIC18F65K40,用USART5模块... 一个普通的测试发送 用示波器测量没有任何波形,但是while(!TXSTA5bits.TRMT); 在debug却可以通 过......请各位帮帮忙 给点意见...... 硬件上IO口除了上拉电阻没有接任何其他东西. 感谢各位了!!!!!!!!!!!! // CONFIG1L #pragma config FEXTOSC = OFF // External Oscillator mode Selection bits (Oscillator not enabled) #pragma config RSTOSC = HFINTOSC_64MHZ// Power-up default value for COSC bits (HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1) // CONFIG1H #pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled) #pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed) #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled) // CONFIG2L #pragma config MCLRE = INTMCLR // Master Clear Enable bit (If LVP = 0, MCLR pin function is port defined function; If LVP =1, RG5 pin fuction is MCLR) #pragma config PWRTE = OFF // Power-up Timer Enable bit (Power up timer disabled) #pragma config LPBOREN = OFF // Low-power BOR enable bit (ULPBOR disabled) #pragma config BOREN = SBORDIS // Brown-out Reset Enable bits (Brown-out Reset enabled , SBOREN bit is ignored) // CONFIG2H #pragma config BORV = VBOR_2P45 // Brown Out Reset Voltage selection bits (Brown-out Reset Voltage (VBOR) set to 2.45V) #pragma config ZCD = OFF // ZCD Disable bit (ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON) #pragma config PPS1WAY = ON // PPSLOCK bit One-Way Set Enable bit (PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle) #pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset) #pragma config DEBUG = OFF // Debugger Enable bit (Background debugger disabled) #pragma config XINST = OFF // Extended Instruction Set Enable bit (Extended Instruction Set and Indexed Addressing Mode disabled) // CONFIG3L #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) // CONFIG3H #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) // CONFIG4L #pragma config WRT0 = OFF // Write Protection Block 0 (Block 0 (000800-001FFFh) not write-protected) #pragma config WRT1 = OFF // Write Protection Block 1 (Block 1 (002000-003FFFh) not write-protected) #pragma config WRT2 = OFF // Write Protection Block 2 (Block 2 (004000-005FFFh) not write-protected) #pragma config WRT3 = OFF // Write Protection Block 3 (Block 3 (006000-007FFFh) not write-protected) // CONFIG4H #pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-30000Bh) not write-protected) #pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected) #pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected) #pragma config SCANE = ON // Scanner Enable bit (Scanner module is available for use, SCANMD bit can control the module) #pragma config LVP = ON // Low Voltage Programming Enable bit (Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored) // CONFIG5L #pragma config CP = OFF // UserNVM Program Memory Code Protection bit (UserNVM code protection disabled) #pragma config CPD = OFF // DataNVM Memory Code Protection bit (DataNVM code protection disabled) // CONFIG5H // CONFIG6L #pragma config EBTR0 = OFF // Table Read Protection Block 0 (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks) #pragma config EBTR1 = OFF // Table Read Protection Block 1 (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks) #pragma config EBTR2 = OFF // Table Read Protection Block 2 (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks) #pragma config EBTR3 = OFF // Table Read Protection Block 3 (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks) // CONFIG6H #pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)
void main(void) {
PORT_init(); Open5USART();
while(1) {
while(!TXSTA5bits.TRMT); TX5REG = 0X55;
}
return; }
void PORT_init(void) {
ANSELE = 0X00;
PORTE = 0xFF; TRISE = 0x00;
}
void Open5USART(void) { TRISEbits.TRISE2 = 0; TRISEbits.TRISE3 = 1; RX5PPS = 0X23; TX5PPS = 0X22; UART5MD = 0; TXSTA5bits.CSRC = 0; TXSTA5bits.TX9 = 0; TXSTA5bits.TXEN = 1; // Enable transmitter TXSTA5bits.SYNC = 0; TXSTA5bits.BRGH = 1; RCSTA5bits.RX9 = 0; RCSTA5bits.CREN = 0; RCSTA5bits.SPEN = 1; // Enable receiver BAUDCON5bits.BRG16 = 1; BAUDCON5bits.SCKP = 0; SP5BRG = 1665; // HFINTOSC with HFFRQ = 64 MHz 9600 PIE4bits.RC5IE = 0; // Interrupt on receipt PIE4bits.TX5IE = 0; // Interrupt on transmission } |
|
相关推荐
5个回答
|
|
|
|
|
|
只用过PIC18F45K40,串口时没碰到过这个问题:
1.但是如果在debug可以的话,1.可以通过TX5PPS RxyPPS把发送引脚配置到其他空的IO引脚试试 2.可以参考https://bbs.elecfans.com/jishu_1391570_1_1.html 3.可以加延时 while(1) { while(!TXSTA5bits.TRMT); TX5REG = 0X55; 延时1S } 4.我是用的发送中断,从来没用过while(!TXSTA5bits.TRMT),这样太占资源了吧,9600的波特率,发送一个字节需要等待1ms |
|
|
|
|
|
|
|
|
|
|
|
get!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
只有小组成员才能发言,加入小组>>
求解外围电路实现的是4脚给持续低电平复位并正常工作,高电平不工作的原因
1928 浏览 1 评论
2995 浏览 3 评论
PIC1946程序有一个变量在运行过程中恢复初始值其他变量保持不变
2184 浏览 2 评论
2564 浏览 0 评论
PIC16F1825的RC5引脚,在主程序中操作无效,在中断中可以改变是为什么?
3694 浏览 5 评论
644浏览 0评论
用XC8编译PIC18F25K80时提示下面Error,求怎么解决这个问题
2985浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-4-23 21:12 , Processed in 0.418493 second(s), Total 51, Slave 45 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号