โปรแกรมรับค่าจากขา B0 เพื่อเริ่มทำงานให้ PWM ออกทางขา B3 แล้วรับค่ามาวัดความถี่ของสัญญาณที่ขา A3 และ A4 ค่ะ

#include <16F627A.h>
#define CLOCK_SP 16000000 // Clock Speed(Hz)
// Device Specification
#fuses HS, NOLVP, WDT, NOPROTECT
#use delay (clock=CLOCK_SP)
#use fast_io(A)
#use fast_io(B)
#define use_portb_lcd
#include
void Frequency_TwoS(void){
float Period_Tx,Period_Rx;
//float Period_Diff0;
while(!input(PIN_A3));
delay_us(1);
while(input(PIN_A3)); //Wait for signal to go high
set_timer1(0);
delay_us(1);
while(!input(PIN_A3));
delay_us(1);
while(input(PIN_A3));
Period_Tx = get_timer1();
delay_us(1);
delay_us(1);
while(!input(PIN_A4));
delay_us(1);
while(input(PIN_A4)); //Wait for signal to go high
set_timer1(0);
delay_us(1);
while(!input(PIN_A4));
delay_us(1);
while(input(PIN_A4));
Period_Rx = get_timer1();
delay_us(1);
//Period_Diff0 = (Period_Tx - Period_Rx);
//Period_Diff0 = 1/(Period_Diff0);
printf(lcd_putc,"\\fT:%4.2f R:%4.2f",Period_Tx,Period_Rx);
//printf(lcd_putc,"\\fDiff_Period:%4.2f us",Period_Diff0);
}
//-------------------------------------
//---------------------------------
void OpenTimer (void)
{
int16 McE;
setup_timer_2(T2_DIV_BY_16,249,1);
setup_ccp1(ccp_pwm);
McE =500;
set_pwm1_duty(McE); // Output PIN B3
enable_interrupts(INT_TIMER2);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); //Prescaler are 1,2,4,8 and
// count to 2^16 = 65536
enable_interrupts(INT_TIMER1);
}
//---------------------------------
void main() {
//-------------------------------------------------
set_tris_a(0B11111000);
set_tris_b(0B00000000); // 0000 0000 Portd is Output
//-------------------------------------------------
enable_interrupts(global);
enable_interrupts(INT_EXT);
ext_int_edge(H_TO_L);
lcd_init();
switch ( restart_cause() )
{
case WDT_TIMEOUT:
{
printf(lcd_putc,"\\fWatchdog timeout!");
break;
}
case NORMAL_POWER_UP:
{
output_high(PIN_A0);
break;
}
}
setup_wdt(WDT_2304MS);
while(TRUE)
{
restart_wdt();
if (input(PIN_B0))
{
output_toggle(PIN_A2);
OpenTimer();
Frequency_TwoS();
if (!input(PIN_B0))
{
setup_timer_2(T2_DISABLED,0,1);
disable_interrupts(GLOBAL);
}
}
//printf(lcd_putc,"\\nEverything\'s ok!");
//delay_ms(10);
}
}

คือว่า พอ Run แล้วใช้ Rom ไป 88%
ถ้าใช้งาน Period_Diff0 = (Period_Tx - Period_Rx); จะขึ้น Out of ROM, A segment or the program is too large
แล้วถ้าหนูเอา #include และการ printf ออก ลอง Run ดูปรากฏว่าใช้ ROM เพียง 23%
แล้วถ้าเปิดการใช้งาน Period_Diff0 = (Period_Tx - Period_Rx); ลอง Run ดูปรากฏว่าใช้ ROM ไป 57%
จากนั้นเปิด Period_Diff0 = 1/(Period_Diff0); ลอง Run ดูปรากฏว่าใช้ ROM ไป 79%
แค่คำนวณอย่างเดียวก็ 79% แล้วอ่ะ ยังไม่ได้แสดงผลเลยค่ะ นึกขึ้นมาได้ว่าพี่ ๆ เคยแนะนำให้ใช้คำสั่ง sprintf แต่หนูใช้ไม่เป็น ต้องกำหนดให้ออก LCD ด้วย เลยโง่เลยงานนี้
รบกวนพี่สอนได้ไหมคะ อย่าสอนโหดนักนะคะ เดี๋ยวต้นหอมโดนด่าแล้วจะนอนไม่หลับ สงสารหนูนิดนึ่งนะคะ
http://rapidshare.com/files/133554397/Pantip.rar.html 
แก้ไขเมื่อ 31 ก.ค. 51 14:22:10