Browsing this Thread:
1 Anonymous Users
|
Re: 如何顯示包含小數之數值顯示於LCD上
|
|
新會員
Joined
: 2009/9/6 22:39 最後登入時間
: 2009/9/25 0:21
Group:
註冊會員
Level : 2 HP : 0 / 25 MP : 3 / 1100 EXP : 0
|
看你要小數點幾位 如果要2位就是先把變數 x100 /100存到int就是整數部分 %100就是小數部分 中間再送出一個小數點~~
有更快的方法嗎?
發表於: 2009/9/18 19:37
|
|
|
如何顯示包含小數之數值顯示於LCD上
|
|
新會員
Joined
: 2007/3/16 10:38 最後登入時間
: 2010/5/8 19:48
Group:
註冊會員
Level : 3 HP : 0 / 52 MP : 6 / 2679 EXP : 9
|
請問各位先進,小弟要將含有小數的值顯示在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
|
|
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.