Re: PIC10LF320 燒錄完成卻沒有動作
|
||||
---|---|---|---|---|
新會員
|
另外請教我用以下寫法編譯OK
#define LED_W PORTAbits.PORTA1 //PWM #define LED_Y PORTAbits.PORTA0 #define SW PORTAbits.PORTA3 但是使用下面的寫法卻出現錯誤訊息, #define LED_W RA1 //PWM #define LED_Y RA0 #define SW RA3 ,錯誤訊息是: "PIC10LF320-Pickit_4.c:26: error: (192) undefined identifier "RA1" PIC10LF320-Pickit_4.c:27: error: (192) undefined identifier "RA0" PIC10LF320-Pickit_4.c:28: error: (192) undefined identifier "RA3"" 請問為甚麼呢?
發表於: 2020/6/11 15:01
|
|||
|
PIC10LF320 燒錄完成卻沒有動作
|
||||
---|---|---|---|---|
新會員
|
使用IC:PIC10LF320 6PIN
編譯器及軟體:PICkit4、MPLAB X IDE v3.35、HI-TECH PICC V9.83 需求:使用PIC10LF320達到3組LED之間的模式切換,其中RA3為輸入PIN,判斷輸入HI or LO,用RA0、RA1為輸出來決定兩組LED亮 OR 滅,以下是程式的部分,程式於另一顆PIC16F1503驗證過沒問題,因此懷疑是PIC10LF320設定或是沒有確實將程式燒錄進去所造成,再請前輩幫忙找問題,thx! ============================================================================================================== /* MCU : PIC10LF320 */ #include<pic.h> __CONFIG(WDTE_OFF&PWRTE_ON&MCLRE_ON&CP_OFF&BOREN_OFF&LVP_OFF); #define LED_W PORTAbits.PORTA1 //PWM #define LED_Y PORTAbits.PORTA0 #define SW PORTAbits.PORTA3 volatile unsigned int ms=0; volatile unsigned char step=0; volatile unsigned char debounce=60; void system_initial(void) { OSCCON = 0b01100000; INTCONbits.GIE = 1; INTCONbits.PEIE = 1; TRISA = 0b00001000; ANSELA = 0b00000000; LED_W = 0; LED_Y = 0; SW = 0; } void PWM_Init(void) { PWM2CON = 0b00000000; //Clear PWM2CON PR2 = 0b10100110; //Configure the Timer2 period - decimal 166 PWM2CON = 0b11000000; //Enable PWM Module, Module Output PWM2DCH = 0b00000000; //Clear duty cycle registers PWM2DCL = 0b00000000; TMR2IF = 0; //Clear the timer 2 interrupt flag T2CON = 0b00000001; //Set prescaler to 1 TMR2ON = 1; //Enable timer 2 PWM2DCH = 0b00010000; //Pulse Width:33.5μs, Duty = 10% PWM2DCL = 0b00000011; } void TIMER0_Init(void) { OPTION_REGbits.T0CS = 0; OPTION_REGbits.PSA = 0; OPTION_REGbits.PS = 0b010; INTCONbits.TMR0IE = 1; INTCONbits.TMR0IF = 0; } void interrupt SystemISR(void) { if(TMR0IF && TMR0IE); { TMR0IF = 0; ms++; } } void main(void) { system_initial(); TIMER0_Init(); PWM_Init(); while(1) { switch(step) { case 0: { PWM2CON = 0b01000000; //Disable PWM Module if(SW==1) { LED_Y=0; step=1; } else { if(ms==50) LED_Y=1; if(ms==100) LED_Y=0; if(ms==150) LED_Y=1; if(ms==200) LED_Y=0; if(ms==500) ms=0; } break; } case 1: { if(SW==0) { LED_W=0; ms=0; step=0; } else { PWM2CON = 0b11000000; //Enable PWM Module } break; } } } }
發表於: 2020/6/11 14:52
|
|||
|