• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: 請問用C18要怎麼把浮點數轉換成字串呢?
#9
初級會員
初級會員


查看用戶資訊
我這樣寫會出Warning?
---------------------------
#include <stdio.h>

float result = 0 ;
char temp[16];

sprintf (temp,"%f", result);

Warning [2066] type qualifier mismatch in assignment
---------------------------
問題出在那裡?
謝謝^^

發表於: 2009/12/2 14:14
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問用C18要怎麼把浮點數轉換成字串呢?
#8
資深會員
資深會員


查看用戶資訊
看看要不要用HI-TECH的PICC-18,C18我覺得有些難度…

HI-TECH的PICC-18可以讓您選擇是不是要使用float,很方便,至少我現在還沒有遇到問題.

C30是給16Bits MCU用的Compiler,如果您的MCU是18系列的話,那看了手冊也沒用。

我的用法是(HI-TECH PICC18):

extern void lcd_puts(char *s);

void main(void)
{
char buff[17];
float v = 1.234

sprintf(buff, "%02.3f", v);//將v 轉成字串
lcd_puts(buff);//將字串交給LCD顯示

}

發表於: 2009/11/16 15:39
我相信解決問題的方法不只一種,所以我在回答同好的問題時或者提出與主題不同的方案,
請不要以此做為攻擊的目標,畢竟我也只是想和大家討論如何解決問題而已…
解決問題最重要,.....
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問用C18要怎麼把浮點數轉換成字串呢?
#7
資深會員
資深會員


查看用戶資訊
給z2490438, minki兩位:
版主 Ryang,已經講出答案了使用sprintf.

Include: stdio.h
Prototype
int sprintf (char *buf, const rom char *fmt, ...);

Code Example#include <stdio.h>
void main (void)
{
    
int val 0xA12;
    
char buf[20];
    
sprintf (buf"%#010x"val);
    
/* buf will contain the string "0x00000a12"
}

基本上sprintf可以使用的東西,都跟printf一樣.
sprintf (buf, "%#010x", val);   //輸出給buf
printf ("%#010x", val);           // 輸出至stdout
改一下val的data type,及sprintf輸出的型態,就是你要的了.

sprintf, printf都是ANSI C中有的.只要google一下就可找到一堆應用.

發表於: 2009/11/16 10:45
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問用C18要怎麼把浮點數轉換成字串呢?
#6
初級會員
初級會員


查看用戶資訊
請問C30 ibearies User's Guide參考資料在哪裡呢?
我浮點數運算法都是用除的..
所以算到9位數真的很痛苦,然後再判斷小數點
程式一大串,都快不知道怎麼寫了

發表於: 2009/11/16 8:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問用C18要怎麼把浮點數轉換成字串呢?
#5
初級會員
初級會員


查看用戶資訊
那...現在有辦法在C18上把浮點數轉換成字串嗎...?

發表於: 2009/11/15 22:19
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問用C18要怎麼把浮點數轉換成字串呢?
#4
版主
版主


查看用戶資訊
用 sprintf( ) 函數,將輸出的結果送到 RAM 裡。所以可以將要列印的浮點字串送到RAM後再轉送到LCD module 上。
楊細用法參考 C30 ibearies User's Guide。

發表於: 2007/8/20 16:45
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問用C18要怎麼把浮點數轉換成字串呢?
#3
中級會員
中級會員


查看用戶資訊
謝謝Ryang的回覆~
再請問一下C30的printf()函數
要怎麼使用呢?
我要把浮點數轉成字串秀在LCD上。
putrsLCD();//秀字串的Function



發表於: 2007/8/18 11:26
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問用C18要怎麼把浮點數轉換成字串呢?
#2
版主
版主


查看用戶資訊
C18 只提供 ltoa( ) 的函數,目前並沒有 ftoa( ) 的函數支援,且 C18 的 printf ( ) 也不支援浮點數的列印。浮點數轉成ASCII 是很不簡單的功能,目前只有 C30 的 printf( ) 函數有支援。

發表於: 2007/8/17 17:52
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請問用C18要怎麼把浮點數轉換成字串呢?
#1
中級會員
中級會員


查看用戶資訊
在做資料處理時遇到這個問題
請問一下有適合的function可以用嗎?
還是有哪位兄台有處理過,可以教教我嗎?
謝謝大家~

發表於: 2007/8/17 10:37
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------