• slider image 442
  • slider image 477
  • slider image 479
  • slider image 480
  • slider image 481
  • slider image 482
:::


Browsing this Thread:   1 Anonymous Users






Re: PIC10LF320 燒錄完成卻沒有動作
#3
版主
版主


查看用戶資訊
HI-TECH PICC V9.83 是舊的編譯器,建議使用新的編譯器 XC8。

RA0 等位元定址要看 p10f320.h 檔裡是否有定義?
尋找一下: C:\Program Files (x86)\Microchip\xc8\v1.45\include
C:\Program Files (x86)\Microchip\xc8\v2.05\pic\include


extern volatile __bit                   RA0                 @ (((unsigned) &PORTA)*8) + 0;
#define                                 RA0_bit             BANKMASK(PORTA), 0
extern volatile __bit                   RA1                 @ (((unsigned) &PORTA)*8) + 1;
#define                                 RA1_bit             BANKMASK(PORTA), 1
extern volatile __bit                   RA2                 @ (((unsigned) &PORTA)*8) + 2;
#define                                 RA2_bit             BANKMASK(PORTA), 2

發表於: 2020/6/12 11:05
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC10LF320 燒錄完成卻沒有動作
#2
新會員
新會員


查看用戶資訊
另外請教我用以下寫法編譯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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


PIC10LF320 燒錄完成卻沒有動作
#1
新會員
新會員


查看用戶資訊
使用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
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... ]

教育訓練中心

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