• slider image 331
  • slider image 332
  • slider image 333
  • slider image 334
  • slider image 335
  • slider image 336
:::


Browsing this Thread:   1 Anonymous Users






Re: PIC16 Interrup
#5
資深會員
資深會員


查看用戶資訊
我在使用 XC8 寫 PIC16F 的時候也遇到這個問題,一開始我也是如同 XC8 講義 Page 116 那樣宣告中斷函數:
void interrupt ISR(void){

}

結果也是出現樓主的錯誤訊息一直編譯不通過,後來去 Google 發現這兩個帖子:
https://bbs.21ic.com/icview-2546270-1-1.html
https://bbs.csdn.net/topics/392505791

把 void interrupt 中斷名(void) 改為 void __interrupt() 中斷名(void),下劃線是兩個,於是我的中斷函數改成這樣子:
void __interrupt() ISR(void){

}

這樣就編譯通過了,為什麼要這樣子宣告才行,是 XC8 講義寫錯了嗎?有人知道原因嗎?

Attach file:



jpg  PIC16F中斷函數.jpg (112.31 KB)
2310_60dd82224b539.jpg 1245X890 px

發表於: 7/1 16:52
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC16 Interrup
#4
版主
版主


查看用戶資訊
請在main( ) 函數外加入 void interrupt ISR(void) ; 的原型函數宣告。
要使用
#include <xc8.h>

發表於: 6/24 13:05

Edited by Ryang on 2021年07月02日 14:37:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC16 Interrup
#3
新會員
新會員


查看用戶資訊
可修改為 "void interrupt ISR(void) " 則會產生以下錯誤

是否哪邊的link 並未完成呢?

CLEAN SUCCESSFUL (total time: 2ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'D:/MPLAB/RT11001 FI/PIC16LF1829/Code Examples/interrupt.X'
make -f nbproject/Makefile-default.mk dist/default/production/interrupt.X.production.hex
make[2]: Entering directory 'D:/MPLAB/RT11001 FI/PIC16LF1829/Code Examples/interrupt.X'
"C:\Program Files\Microchip\xc8\v2.32\bin\xc8-cc.exe" -mcpu=16F1829 -c -mdfp="C:/Program Files/Microchip/MPLABX/v5.50/packs/Microchip/PIC12-16F1xxx_DFP/1.2.63/xc8" -fno-short-double -fno-short-float -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx32 -Wl,--data-init -mno-keep-startup -mno-osccal -mno-resetbits -mno-save-resetbits -mno-download -mno-stackcall -std=c99 -gdwarf-3 -mstack=compiled:auto:auto -o build/default/production/_ext/1472/interrupt.p1 ../interrupt.c
../interrupt.c:109:6: error: variable has incomplete type 'void'
void interrupt ISR(void) {
^
../interrupt.c:109:15: error: expected ';' after top level declarator
void interrupt ISR(void) {
^
;
2 errors generated.
(908) exit status = 1
nbproject/Makefile-default.mk:107: recipe for target 'build/default/production/_ext/1472/interrupt.p1' failed
make[2]: Leaving directory 'D:/MPLAB/RT11001 FI/PIC16LF1829/Code Examples/interrupt.X'
nbproject/Makefile-default.mk:91: recipe for target '.build-conf' failed
make[1]: Leaving directory 'D:/MPLAB/RT11001 FI/PIC16LF1829/Code Examples/interrupt.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make[2]: *** [build/default/production/_ext/1472/interrupt.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 962ms)

發表於: 6/23 13:42
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC16 Interrup
#2
版主
版主


查看用戶資訊
XC8 底下的 PIC16F 及 PIC18F 的中斷函數有特定的語法,建議可以到教育訓練光碟下下載 "XC8" 及 "PIC101" 的教材來研讀。

試著將底下的中斷宣告 "void interruptISR(void) {"
修改成 void interrupt ISR(void) { 如附圖所示:

教育訓練光碟網址:
http://www.microchip.com.tw/RTC/RTC_DVD/

在" 8-Bits MCU 相關課程" 下,下載底下的課程:
1. PIC101 X IDE & MCC& XC8 基礎課程
2. XC8T v1.0

Attach file:



jpg  擷取.JPG (75.26 KB)
16_60d2a25463f26.jpg 788X546 px

發表於: 6/23 10:54
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


PIC16 Interrup
#1
新會員
新會員


查看用戶資訊
第一次使用PIC,官網下載範例中斷程式,編譯後卻得到"未呼叫中斷副程式"、請問要如何修正? # used PIC16F1829
以下是該程式

#include // Including XC8 compiler library

#define _XTAL_FREQ 500000 //Used by the XC8 delay_ms(x) macro

#define DOWN 0
#define UP 1

#define SWITCH PORTAbits.RA2

#define LED_RIGHT 1
#define LED_LEFT 0

#define PULL_UPS //if this is uncommented, the trace under JP5 can be cut
//with no affect on the output
//config bits that are part-specific for the PIC16F1829
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = OFF // PLL Enable (4x PLL disabled)
#pragma config STVREN = OFF // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will not cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)

/* -------------------LATC-----------------
* Bit#: -7---6---5---4---3---2---1---0---
* LED: ---------------|DS4|DS3|DS2|DS1|-
*-----------------------------------------
*/

unsigned char _direction; //a global variable
void main(void) {
//general init
OSCCON = 0b00111000; //500KHz clock speed
TRISC = 0; //PortC are outputs
LATC = 0; //PortC in OFF state

LATCbits.LATC3 = 1; //DS4 is lit //RC3 output=1
_direction = LED_RIGHT; //start with LEDs rotating from right to left

//setup switch (SW1)
TRISAbits.TRISA2 = 1; //switch as input //RA2 are Input pin
ANSELAbits.ANSA2 = 0; //digital switch //ADC Func Off

//by using the internal resistors, you can save cost by eleminating an external pull-up/down resistor
#ifdef PULL_UPS
WPUA2 = 1; //enable the weak pull-up for the PortA
nWPUEN = 0; //enable the global weak pull-up bit
#endif
//setup TIMER0 as the delay
//1:256 prescaler for a delay of: (insruction-cycle * 256-counts)*prescaler = ((8uS * 256)*256) =~ 524mS
OPTION_REG = 0b00000111; //setup TIMER0 // Prescaler Rate Select bits = 0b111 = 256
INTCONbits.TMR0IE = 1; //enable the TMR0 rollover interrupt

//setup interrupt on change for the switch
INTCONbits.IOCIE = 1; //enable interrupt on change global
IOCANbits.IOCAN2 = 1; //when SW1 is pressed, enter the ISR

INTCONbits.GIE = 1; //enable global interupts


while (1) {
continue; //can spend rest of time doing something critical here
}
}

void interruptISR(void) {

if (IOCAF) { //SW1 was just pressed //INTERRUPT-ON-CHANGE PORTA FLAG REGISTER
IOCAF = 0; //must clear the flag in software
__delay_ms(5); //debounce by waiting and seeing if still held down
if (SWITCH == DOWN) {
_direction ^= 1; //change directions
}
}

if (INTCONbits.T0IF) { // When Timer 0 rolls over, rotate the LED
INTCONbits.T0IF = 0; //T0IF : Timer0 Overflow Interrupt Flag bit

if (_direction == LED_RIGHT) {
LATC >>= 1; //rotate right
if (STATUSbits.C == 1) //when the last LED is lit, restart the pattern
//STATUS: STATUS REGISTER ; C= 1 : A carry-out from the Most Significant bit of the result occurred
LATCbits.LATC3 = 1;
} else{
LATC <<= 1; //rotate left
if (LATCbits.LATC4 == 1) //when the last LED is lit, restart the pattern
LATCbits.LATC0 = 1;

}
}
}

發表於: 6/23 10:07
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://mu.microchip.com/page/tmu
http://www.microchip.com.tw/modules/tadnews/page.php?ncsn=2&nsn=41
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
https://page.microchip.com/APAC-PrefCenters-TW.html
https://www.youtube.com/user/MicrochipTechnology
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
https://www.microchip.com/development-tools/
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/
[ more... ]

教育訓練中心

課程 - 台北教育訓練中心
課程 - 新竹教育訓練中心
課程 - 高雄教育訓練中心
教育訓練中心介紹
購買 - 實驗工具
臺灣實驗板介紹與資源