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

論壇索引


Board index » All Posts (Jing_Su)




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


可修改為 "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)

發表於: 2021/6/23 13:42
頂部


PIC16 Interrup
#2
新會員
新會員


第一次使用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;

}
}
}

發表於: 2021/6/23 10:07
頂部






:::

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... ]

教育訓練中心

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