• 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: 如何顯示包含小數之數值顯示於LCD上
#2
新會員
新會員


查看用戶資訊
看你要小數點幾位
如果要2位就是先把變數 x100
/100存到int就是整數部分
%100就是小數部分
中間再送出一個小數點~~

有更快的方法嗎?

發表於: 2009/9/18 19:37
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


如何顯示包含小數之數值顯示於LCD上
#1
新會員
新會員


查看用戶資訊
請問各位先進,小弟要將含有小數的值顯示在LCD上,請問要如何修改,謝謝!

程式碼如下,可以顯示整數,但小數部份無法show出,請各位指教

----------------------------------------------------------------------


#include <p18f452.h> //包含PIC18F452的HEADER檔內容
#include "p18F_LCD.h" //將p18F_LCD.h函數庫檔內容輸入
#include "stdlib.h"

#define Fcy 4000000

char LCD_MSG1[]="IC PRACTICE"; //宣告字串於DATA Memory中
char LCD_MSG2[]="FREQUENCY: 0 "; //宣告字串於Data Memory中
unsigned int ASCII_Buf[16]; //用於傳輸至LCD上所使用的BUFFER
double speed;


//宣告集合變數以便處理二位元組變數資料
union {
unsigned int lt;
unsigned char bt[2];
}EDGE_N;

int Int_flag; //設定旗標確定是否有進中斷
unsigned int frequency;
unsigned int FreCount;

void InitializeTMR3(void); //TIMER3的初始設定副程式
void InitializeIC(void);

void isr_high(void); //宣告中斷副程式

void main(void)
{
InitializeTMR3( );
InitializeIC( );

INTCONbits.GIEH=1; // 將高優先中斷設定為"Enable"
PIR1bits.CCP1IF = 0; // Clear the interrupt flag
IPR1bits.CCP1IP = 1; // Set high priority
PIE1bits.CCP1IE = 1; // Enable CCP1 interrupt
RCONbits.IPEN=1; // 高低優先致能設定為"Enable"
Int_flag = 0;

OpenLCD( );
LCD_Set_Cursor(0,0); //使用Set_Cursor( ),設定游標於(0,0)
putsLCD(LCD_MSG1); //將存在Data Memory的字串,使用putrsLCD()輸出至LCD上
LCD_Set_Cursor(1,0); //使用Set_Cursor( ),設定游標於(0,0)
putsLCD(LCD_MSG2); //將存在Data Memory的字串,使用putrsLCD()輸出至LCD上


T3CONbits.TMR3ON = 1; // Start Timer3


while(1)
{
while(!Int_flag); // Get two input signal edge
PIE1bits.CCP1IE = 0; // Disable Interrupt of CCP1
Int_flag = 0;

FreCount = EDGE_N.lt;
frequency = Fcy / FreCount ;
frequency=frequency*4;
speed=frequency*0.0032;
PIE1bits.CCP1IE = 1; // Ensable Interrupt of CCP1
//double
itoa ( speed , ASCII_Buf ); // 利用

putcLCD(' '); //Claer Screen
putcLCD(' '); //Claer Screen
putcLCD(' '); //Claer Screen
putcLCD(' '); //Claer Screen
putcLCD(' '); //Claer Screen
putcLCD(' '); //Claer Screen



LCD_Set_Cursor(1,10) ; // Set LCD cursor 於 (1,10)
putsLCD(ASCII_Buf) ; // 傳送資料至LCD上

}

}

void InitializeIC(void)
{

TRISCbits.TRISC2 = 1; //設定CCP1為輸入 RC2 as input

CCP1CON=0b00000101; //Set capture every rising edge
//TMR3設為同步,Input Capture前除設為4
//可被量測的最小頻率 = 244.14Hz
//可被量測的最大頻率 = 16MHz


}

void InitializeTMR3(void)
{
T3CON = 0b11011000; //預除依定要設定為同步

PIE2bits.TMR3IE = 0; //DISable timer interrupt
}

#pragma code isrhighcode = 0x08 //高優先中斷位置
void isr_high_direct(void)
{
_asm //begin in-line assembly
goto isr_high //go to isr_high function
_endasm //end in-line assembly
}
#pragma code

#pragma interrupt isr_high // Function: isr_high(void)
void isr_high(void) //進入中斷程式
{

EDGE_N.bt[0] = CCPR1L;
EDGE_N.bt[1] = CCPR1H;
Int_flag = 1; // 設定軟體中斷旗標
PIR1bits.CCP1IF = 0; //清除中斷旗標
TMR3H = 0;
TMR3L = 0;
}
#pragma code

發表於: 2009/9/18 16:57
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... ]

教育訓練中心

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