完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好:我是C世界的新成员(特别是XC8)。我试图做一个在rs-232下传输的例子。下面我举了整个例子,但是我有两个主要问题:1)最基本的问题:1.A)TXREG2='D';//GOOD。发送一个“D”字符。1。b)无符号char A= De';txReG2= a;//坏传输0xb5字符(为什么?)也许TxReg不是无符号字符?2)最复杂的,定义我自己的硬币,就是挂微币的印刷品,非常感谢您的帮助。
以上来自于百度翻译 以下为原文 Hi everyone: I an new on C world (specially on XC8). I am trying to do a same example that transmit under rs-232. bellow i put the entire example, but i have 2 main problems: 1) the most basic: 1.A)TXREG2='D'; //GOOD. Transmit a 'D" characer. 1.B) unsigned char a='D'; TXREG2=a; //BAD transmit 0xb5 character (why? maybe TXREG is not unsigned char?) 2)The most complex, defining my own putch, printf hangup the micro; #define _XTAL_FREQ 4000000 #include #include //copied from http://www.microchip.com/forums/m777582.aspx //#include // PIC18F66J15 Configuration Bit Settings // CONFIG1L #pragma config WDTEN = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on SWDTEN bit)) #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit (Reset on stack overflow/underflow enabled) #pragma config XINST = ON // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode enabled) // CONFIG1H #pragma config CP0 = OFF // Code Protection bit (Program memory is not code-protected) // CONFIG2L #pragma config FOSC = HSPLL // Oscillator Selection bits (EC oscillator, PLL enabled and under software control, CLK function on OSC2) #pragma config FOSC2 = ON // Default/Reset System Clock Select bit (Clock selected by FOSC1:FOSC0 as system clock is enabled when OSCCON<1:0> = 00) #pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor enabled) #pragma config IESO = ON // Two-Speed Start-up (Internal/External Oscillator Switchover) Control bit (Two-Speed Start-up enabled) // CONFIG2H #pragma config WDTPS = 32768 // Watchdog Timer Postscaler Select bits (1:32768) // CONFIG3L // CONFIG3H #pragma config CCP2MX = DEFAULT // ECCP2 MUX bit (ECCP2/P2A is multiplexed with RC1) //// this send character routine is called by all the C library put/print routines void putch(unsigned char chr){ while (TX2IF == 0) continue; // wait until TXREG is not busy TXREG2 = chr; // send character } // //----------------------------------------------------------------------------- void init(void) { TRISB = 0b00000000; // all outputs TRISG = 0b00000100; // all outputs, except RX on RC7 // //init USART SPBRG2 = 25; // 9600 baud with 4MHz clock. Table 12-5 in datasheet BAUDCON2 = 0b00000000; // SCKP=0, BRG16=0, WUE=0, ABDEN=0 TXSTA2 = 0b00100100; // 8-bit, tx-enb, asynch, BRGH=1 RCSTA2 = 0b10010000; // SPEN=1, CREN=1, addr-det disabled. } // //-----------------------------------------------------------------------------void delay_ms(int dly){ unsigned int a; for(a=0;a } } // //----------------------------------------------------------------------------- void main(void) { unsigned char a=0x40; int cnt=0; OSCCON = 0b00000010; // set internal clock to 8MHz // OSCTUNE = 0b01000000; OSCTUNE = 0b00000000; init(); LATB3=0; //LED1 LATB2=0; //LED2 LATB1=0; //LED3 do{ LATB1=1; //ON led3 delay_ms(100); // printf("Hello world/r/n"); // Hangup MCU // printf(putch,"Hello world/r/n"); // Hangup MCU // sprintf(putch,"Hello world/r/n"); // Hangup MCU // a=0x44; // . // TXREG2=a; // / dont care A value allways transmit 0xb5 1011 0101 // if(cnt>5){ // // putch('P'); // // cnt=0; // Allways transmit "M" character // }else{ // / // putch('D'); // / // } // / if(cnt>5){ // . TXREG2=0x50; // work Transmit "P" character cnt=0; // . }else{ // / TXREG2='D'; // / work Transmit "D" character } // / // while (TX2IF == 0) continue; //do not hangup LATB1=0; //OFF led3 delay_ms(100); cnt++; } while (1); //loop forever } Any help will be greatly appreciated. |
|
相关推荐
3个回答
|
|
将#pragma config XINST=ON//Extended.ctionSetEnablebit(启用了指令集扩展和索引寻址模式)更改为#pragma config XINST=OFF//Extended.ctionSetEnablebit(禁用了指令集扩展和索引寻址模式)。不要抱怨,不要使用XC8扩展模式PIC18。
以上来自于百度翻译 以下为原文 Change #pragma config XINST = ON // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode enabled) to #pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled) I am surprised the compiler is not complaining about that. Do NOT use PIC18 extended mode with XC8. |
|
|
|
对!!!!现在工作!解决办法是,QHB说:#pragma config XINST=OFFiSENOW很多:-Hello world/r/n+-Hello world/r/n+-Hello world/r/n+-Hello world/r/n+grin:谢谢你们两个都帮了大忙。
以上来自于百度翻译 以下为原文 YES !!! Now works !! The solution was that the QHB say: #pragma config XINST = OFF i SEE NOW a lot of: -Hello world/r/n+ -Hello world/r/n+ -Hello world/r/n+ grin: thanks you both are really helpfull |
|
|
|
最后的XC8(1.40?)无论如何应该给你一个警告…
以上来自于百度翻译 以下为原文 last XC8 (1.40?) should have given you a warning anyway... |
|
|
|
只有小组成员才能发言,加入小组>>
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)不匹配。是什么原因
636浏览 0评论
533浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 18:47 , Processed in 1.508774 second(s), Total 80, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号