Re: about printf and ccs-c
|
||||
---|---|---|---|---|
新會員
|
有人有 Embedded C Programming and the Microchip PIC by Richard H. Barnett 吗??
我已经找到第一本了 ........
發表於: 2006/11/6 16:05
|
|||
|
Re: about printf and ccs-c
|
||||
---|---|---|---|---|
新會員
|
谢谢mechwu,我按着您的提示做,可以看到输出,但是输出全是乱码,我的com port, baud rate 设置为:com 1, 115200.请教怎么解决.谢谢.
乱码如下: B<’a˜Â¼Ra¼Òa£”Y뉔үүv¼ÒR C 8$$<5$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$<$aB<$aB<aY//B<<<<<< <<<<<<<<<<<<<B<R$/$//B B<Y///////////// //////////////////////////////////////// //FB<+B<++R£/$//B<%B%BB<BYYYYYYYYYYYYYYY YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY F<KN"B<KKR#/$/////////////////////////// /////////////////////////////+aKaB<KaY// //////////////////////////////////////// //////////////FB<R$B<RR$5$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F&"B<&B<&QG///////////////////////////// //////////////////////////R<RB<$5$$FQ8/
發表於: 2006/10/30 15:21
|
|||
|
Re: about printf and ccs-c
|
||||
---|---|---|---|---|
資深會員
|
參照:
PIC 的程式要先啟用 UART,才能使用 printf() #use rs232( baud = 115200, xmit = PIN_C6, rcv = PIN_C7 ) 然後,你必須要有一台終端機 ... 接線如下 PIC 的 UART 的 TX / RX 線 (通常是 RC6 與 RC7) 接到 RS232 準位轉換器 (通常用 MAX232 這顆 IC) ,將 PIC 的 0V / 5V 的 TTL/CMOS 信號轉換為 +/- 9V 的 RS232 信號,然後,將 MAX232 的線接到 PC 的 COM port (或 USB / RS232 轉換器),然後, 啟動 PC 的終端機程式 (通常是 Hyperterminal, hypertrm.exe,或是 CCS 提供的 C:\Program Files\PICC\siow.exe) 然後,設定好 com port, baud rate 等參數,然後,就可以在 PC 的螢幕上看到輸出啦 先看看你的實驗板上有沒有 MAX232 這顆 IC 吧
發表於: 2006/10/30 12:37
|
|||
|
Re: about printf and ccs-c
|
||||
---|---|---|---|---|
新會員
|
如何讀取 16 位元的 TIMER1 的數值?有三種讀法,其中已上面那篇的習慣的寫法會百中錯一,很難發現,就算你用線上調試也一樣! #include <16F877.H> #use delay(clock = 20000000) #use rs232( baud = 115200, xmit = PIN_C6, rcv = PIN_C7 ) #define TMR1 *(int16 *)(0x0E) // 定義 TMR1 為位於 0x0E 的 16 bit 變數 #define TMR1L *(int8 *)(0x0E) // 若寫成 *(0x0E) 的話,變成 8 bit ! #define TMR1H *(int8 *)(0x0F) long Timer_1; #byte Timer_1 = 0x0E #byte Timer_1_L = 0x0E #byte Timer_1_H = 0x0F #bit A4 = 0x05.4 #bit TRISA4 = 0x85.4 #org 0x0800 void main() { int16 t_1, t_2, t_3; int8 i = 0; setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 ); // 1.6 usec per count TRISA4 = 0; while(1) { A4 = 1; // 用示波器看 pin_RA4 的信號,要加提昇電阻! t_1 = TMR1; // 這種寫法會有 隨機的 錯誤! 小心喔! t_2 = Timer_1; t_3 = get_timer1(); A4 = 0; if ( ((t_2-t_1)>3) || ((t_3-t_1)>3) || ((t_3-t_2)>3) ) // 抓到蟲啦 { printf ( "i, t_1, t_2, t_3 = %3u 0x%04LX 0x%04LX 0x%04LX\r\n", ++i, t_1, t_2, t_3 ); t_1 = TMR1; // 這次絕對不會錯! t_2 = Timer_1; t_3 = get_timer1(); printf ( "i, t_1, t_2, t_3 = %3u 0x%04LX 0x%04LX 0x%04LX\r\n\n", i, t_1, t_2, t_3 ); } } } 小弟的一點經驗,希望能讓 CCS 新手快樂向前行 祝 順心 ~~~~~~~~~~~~~~~~~~~~~~~ 以上是转贴,希望对关于timer1读写有帮助 我的问题是,我怎么能看到printf输出---- printf ( "i, t_1, t_2, t_3 = %3u 0x%04LX 0x%04LX 0x%04LX\r\n\n", i, t_1, t_2, t_3 ); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 我查阅了ccsc相关资料.......供参考 PRINTF( ) FPRINTF( ) -------------------------------------------------------------------------------- Syntax: printf (string) or printf (cstring, values...) or printf (fname, cstring, values...) fprintf (stream, cstring, values...) Parameters: String is a constant string or an array of characters null terminated. Values is a list of variables separated by commas, fname is a function name to be used for outputting (default is putc is none is specified). Stream is a stream identifier (a constant byte) Returns: undefined Function: Outputs a string of characters to either the standard RS-232 pins (first two forms) or to a specified function. Formatting is in accordance with the string argument. When variables are used this string must be a constant. The % character is used within the string to indicate a variable value is to be formatted and output. Longs in the printf may be 16 or 32 bit. A %% will output a single %. Formatting rules for the % follows. If fprintf() is used then the specified stream is used where printf() defaults to STDOUT (the last USE RS232). Format: The format takes the generic form %nt. n is optional and may be 1-9 to specify how many characters are to be outputted, or 01-09 to indicate leading zeros, or 1.1 to 9.9 for floating point and %w output. t is the type and may be one of the following: c Character s String or character u Unsigned int d Signed int Lu Long unsigned int Ld Long signed int x Hex int (lower case) X Hex int (upper case) Lx Hex long int (lower case) LX Hex long int (upper case) f Float with truncated decimal g Float with rounded decimal e Float in exponential format w Unsigned int with decimal place inserted. Specify two numbers for n. The first is a total field width. The second is the desired number of decimal places. Example formats: Specifier Value=0x12 Value=0xfe %03u 018 254 %u 18 254 %2u 18 * %5 18 254 %d 18 -2 %x 12 fe %X 12 FE %4X 0012 00FE %3.1w 1.8 25.4 * Result is undefined - Assume garbage. Availability: All Devices Requires: #use rs232 (unless fname is used) Examples: byte x,y,z; printf("HiThere"); printf("RTCCValue=>%2x\n\r",get_rtcc()); printf("%2u %X %4X\n\r",x,y,z); printf(LCD_PUTC, "n=%u",n);
發表於: 2006/10/27 16:36
|
|||
|
Re: about printf and ccs-c
|
||||
---|---|---|---|---|
版主
|
吳老師,
謝謝您的說明,感激不盡。
發表於: 2006/10/27 9:46
|
|||
|
Re: about printf and ccs-c
|
||||
---|---|---|---|---|
資深會員
|
CCS 最令人感動的就是這些 功能強大,高彈性的 fprintf, sprintf 啦,
printf (), printf (cstring, values...) printf (fname, cstring, values...) fprintf (stream, cstring, values...) sprintf(string, cstring, values...); PIC12, PIC16, PIC18 都可以用,呵呵 還可以自行創造些 printf( lcd_putc, ... ) 之類的好東西,只要有 lcd_putc ( char c ) 就可以直接送去 LCD,把函數 lcd_putc 當成檔案來用!呵呵 ----------------- Syntax: sprintf(string, cstring, values...); Syntax: printf (string) or printf (cstring, values...) or printf (fname, cstring, values...) fprintf (stream, cstring, values...) Syntax: sprintf(string, cstring, values...); Parameters: string is an array of characters. cstring is a constant string or an array of characters null terminated. Values are a list of variables separated by commas.
發表於: 2006/10/27 2:13
|
|||
|
Re: about printf and ccs-c
|
||||
---|---|---|---|---|
版主
|
我不知道CCS是否有類似SPRINTF( ) 的函數可以print到 RAM 裏。 ㄧ般在這種微控制器的 printf( ) 大都指向 UART , 無法像 PC 示指向銀幕的。
發表於: 2006/10/26 15:28
|
|||
|
Re: about printf and ccs-c
|
||||
---|---|---|---|---|
新會員
|
我知道是在終端機,但是我是指输出到屏幕,我在哪个窗口可以看到?.......
谢谢你的回复!
發表於: 2006/10/26 13:48
|
|||
|
Re: about printf and ccs-c
|
||||
---|---|---|---|---|
資深會員
|
1.通常是終端機。
2.CCS C看原廠附的手冊就夠了。
發表於: 2006/10/26 13:11
|
|||
不要問我哪裡來,我只是個流浪天涯的工程師
|
||||
|