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


Browsing this Thread:   1 Anonymous Users




« 1 (2)


Re: 如何改成 左移完右移 重覆此動作!
#8
版主
版主


查看用戶資訊
MPLAB IDE 下選擇 Project --> Project Options --> Project

將 H 檔的路徑加進去 (c:\mcc18\h\),如下圖。

Attach file:



jpg  (0.00 KB)


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


Re: 如何改成 左移完右移 重覆此動作!
#7
新會員
新會員


查看用戶資訊
Ryang 妳教我的中斷程式 BUILD ALL後

出現 以下 [1027] 錯誤~~~ 要怎麼解決~~

昨天花2小時 還是解決不暸 ~@@

Fri Sep 25 12:15:12 2009
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\pic18\123\123.mcs".
Clean: Done.
Executing: "C:\MCC18\bin\mcc18.exe" -p=18F4520 "123.C" -fo="123.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\pic18\123\123.C:9:Error [1027] unable to locate 'p18f4520.h'
C:\pic18\123\123.C:10:Error [1027] unable to locate 'timers.h'
C:\pic18\123\123.C:11:Error [1027] unable to locate 'delays.h'
MPLAB C18 v3.22 (feature limited)
Copyright 2000-2008 Microchip Technology Inc.
This version of MPLAB C18 does not support the extended mode
and will not perform all optimizations. To purchase a full
copy of MPLAB C18, please contact your local distributor or
visit buy.microchip.com.

Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\pic18\123\123.mcp' failed.
Language tool versions: mplink.exe v4.30.01, mcc18.exe v3.22
Preprocessor symbol `__DEBUG' is defined.
Fri Sep 25 12:15:13 2009
----------------------------------------------------------------------
BUILD FAILED

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


Re: 如何改成 左移完右移 重覆此動作!
#6
版主
版主


查看用戶資訊
這就是使用 Timer2 霹靂燈的程式。8個 LED 接在 PORTD上。使用 APP001 EVM Board
PIR1bits.TMR2IF=0;            // Clear Timer2 interrupt Flag

    
if (Long_Count <= 12Long_Count++;      // 8mS * 12 = 96mS Timer2 的中斷每8mS中斷一次,中斷12次後為96mS
    
else                    // 96mS 計時已到準備移動 LED
    
{    
        
Long_Count=0;            // 96mS 歸零

        
if (Direct_LED==0x00)        // 檢查向右 或 向左轉旗號 ; 為 0 向左轉
        
{
             
PORTD<<=1;        // LED left shift
            
Dir_Count++;
            if (
Dir_Count==7)     // End of LED position? 總共轉了七次嗎?
            
{
                
Dir_Count=0;    // 是的, 將轉了七次的計數器歸零
                
Direct_LED=0x1// 設定下一次開始為向右轉
            
}
        }
        else
        {
            
PORTD>>=1;        // LED right shift
            
Dir_Count++;
            if (
Dir_Count==7
            {
                
Dir_Count=0;
                
Direct_LED=0x00//設定下一次開始為向左轉
            
}
        }
    }

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


Re: 如何改成 左移完右移 重覆此動作!
#5
資深會員
資深會員


查看用戶資訊
照你程式寫法的話

可以多設一個變數來決定現在是要左移(變數=0)還是右移(變數=1)

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


Re: 如何改成 左移完右移 重覆此動作!
#4
新會員
新會員


查看用戶資訊
blainehs 或 Ryang
能敎我 改成 左移跑完 右移 <--重複 嗎???

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


Re: 請教 PIC18 左移的程式 如何改成 霹靂燈
#3
版主
版主


查看用戶資訊
給你一個使用 Timer2 中斷的範例:
W401 教育訓練裡的練習 5-2
//***************************************************
//*                                                     *
//*                 Exercise 5-2                        *
//* MPLAB C18 WOrkshop Exercise for High-priority   *
//* Setting with C code.                            *
//*                                                    *
//***************************************************

#include <p18f452.h>
#include <timers.h>
#include <delays.h>

void isr_high(void);

volatile unsigned char Long_Count ;
volatile unsigned char Direct_LED ;
volatile unsigned char Dir_Count ;

void main(void)
{
        
TRISD=0x00;                    // Set output port for LED driver
        
PORTD=0b00000001;            // Set b0 of LED is On

        
RCONbits.IPEN=1;            // Enable Interrupt Priority bit
        
IPR1bits.TMR2IP=1;            // Set Timer2 for High Priority
        
INTCONbits.GIEH=1;            // Enable High Priority Interrupt

    /***********************************/
    /*        Interrupt Time       */         
    /*(1/(16Mhz/4)) (16*10*(199+1)) = 8mS */
    /***********************************/
        
OpenTimer2 (    TIMER_INT_ON        // Turn On the Timer2 with Interrupt
                
T2_PS_1_16
                
T2_POST_1_10);

        
PR2 199;

        
Long_Count=0;
        
Direct_LED=0;
        
Dir_Count=0;

        while(
1);                // Loop Here!
}

//************************************************
//*       #pragma Interrupt Declarations         *
//*                                                 *
//* Function: isr_high_direct                    *
//*   - Direct execution to the actual           *
//*     high-priority interrupt code.            *
//************************************************
#pragma code isrhighcode = 0x0008

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

//************************************************
//* Function: isr_high(void)                     *     
//*   High priority interrupt will               *
//*   - Received a serial data from RS-232       *
//*     Save the received data to buffer Rec_Data*                  
//************************************************
#pragma interrupt isr_high 

void isr_high(void)
{
    
PIR1bits.TMR2IF=0;            // Clear Timer2 interrupt Flag

    
if (Long_Count <= 12Long_Count++;      // 8mS * 12 = 96mS
    
else
    {    
        
Long_Count=0;            // Time is 96mS, do the function

        
if (Direct_LED==0x00)        // Right or Left shift
        
{
             
PORTD<<=1;        // LED left shift
            
Dir_Count++;
            if (
Dir_Count==7)     // End of LED position?
            
{
                
Dir_Count=0;    // Yes, set flag of right shift
                
Direct_LED=0x1;
            }
        }
        else
        {
            
PORTD>>=1;        // LED right shift
            
Dir_Count++;
            if (
Dir_Count==7
            {
                
Dir_Count=0;
                
Direct_LED=0x00;
            }
        }
    }        
}                                
#pragma code

發表於: 2009/9/24 10:06
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教 PIC18 左移的程式 如何改成 霹靂燈
#2
新會員
新會員


查看用戶資訊
把這一段:
delay_ms(200); // 延遲200ms
if(PORTD<128) // PORTD<128,向左移動
PORTD=(PORTD<<1);
else // PORTD>=128,回歸至RD0
PORTD=0X01;

改成這樣: (請自行宣告 int i=0;)
for(i=0;i<8;i++) delay_ms(200), PORTD=(PORTD<<1); // PORTD,向左移動
for(i=0;i<8;i++) delay_ms(200), PORTD=(PORTD>>1); // PORTD,向右移動

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


請教 PIC18 左移的程式 如何改成 霹靂燈
#1
新會員
新會員


查看用戶資訊
我想讓他 跑完左移 再從右邊跑回來 ~~重複這樣~~

PIC18F4520

想半天 ~~一直修改失敗 請前輩救我~~感激不盡!!!



//**********************************************************
//* Ex6_2_shift.c
//**********************************************************
#include <p18f4520.h> // 微控制器硬體名稱宣告
#include <delays.h> // 納入時間延遲函式庫函式原型名稱定義

#define OSC_CLOCK 10

void delay_ms(long A) {
//This function is only good for OSC_CLOCK higher than 4MHz
long i;
int us2TCY;
us2TCY=(10*OSC_CLOCK)>>2; // >>2相當於除以4
for(i=0;i<A;i++) Delay100TCYx(us2TCY);
}

void main (void) {

PORTD = 0x01; // 將PORTD設定點亮LED0
TRISD = 0; // 將TRISD設為0,PORTD設定為輸出
while (1) { // 無窮迴圈
delay_ms(200); // 延遲200ms
if(PORTD<128) // PORTD<128,向左移動
PORTD=(PORTD<<1);
else // PORTD>=128,回歸至RD0
PORTD=0X01;
}
}

發表於: 2009/9/24 1:38
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... ]

教育訓練中心

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