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

論壇索引


Board index » All Posts (ken.wu)




PIC16F18325 RA5設為輸出沒反應
#1
新會員
新會員


請教版大及各路高手,我用的IC是PIC16F18325,使用MPLAB X IDE V5.45及PICKIT4進行燒錄,預計將RA1及RA5分別控制2串LED,但只有RA1有輸出,RA5直接用示波器量測都沒輸出訊號,code如下,再請幫忙看一下是定義哪邊有遺漏嗎?
--------------------------------------------------------------------------------------------------------------------------------------------------------
#include

#pragma config RSTOSC = HFINT32
#pragma config WDTE = ON
#pragma config PWRTE = ON
#pragma config CP = OFF
#pragma config BOREN = OFF
#pragma config LVP = OFF
#pragma config MCLRE = OFF

#define LED_B RA1
#define RH_LED_B RA5

volatile unsigned int milliseconds = 0;

void system_initial(void)
{
OSCCON1bits.NOSC = 0b110;
OSCFRQbits.HFFRQ = 0b0100;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
PMD2bits.ADCMD = 1;
TRISA = 0b00001100;
ANSELA = 0b00000000;
WDTCON = 0b00000011;

LED_B=0;
RH_LED_B=0;
}

void TIMER2_Init(void)
{
PR2 = 0b01111101;
T2CONbits.T2CKPS = 0b10;
T2CONbits.T2OUTPS = 0b0000;
T2CONbits.TMR2ON = 1;
PIE1bits.TMR2IE = 1;
PIR1bits.TMR2IF = 0;
}

void __interrupt() SystemISR(void)
{
while(!TMR2IF&&!TMR2IE);
TMR2IF = 0;
milliseconds++;
}

int main(void)
{
system_initial();
TIMER2_Init();

while(1)
{
CLRWDT();

if(milliseconds==50)
{
LED_B=1;
RH_LED_B=1;
}

if(milliseconds==100)
{
LED_B=0;
RH_LED_B=0;
milliseconds=0;
}
}
}

發表於: 2021/3/5 11:09
頂部


Re: PIC10LF322 ROM使用
#2
新會員
新會員


謝謝板大~我先研究看看~有問題再請你多指教。

發表於: 2021/1/8 8:56
頂部


PIC10LF322 ROM使用
#3
新會員
新會員


請問,我現在有需求要將資料放在ROM裡面,每次開機後先讀取資料,進行模式判斷後再跑主程式,且會在IC運作中更改放在ROM裡面的資料並儲存供下次使用,資料預計是0~9的數字給主程式判斷使用哪個模式,那麼PIC10LF322 的Program Memory Flash (words)及High Endurance Flash (bytes),哪個適合我使用呢?要怎麼使用?
還是需要有EEPROM的IC才能這樣使用呢?

發表於: 2021/1/7 9:45
頂部


Re: XC8T v1.0 教材的程式編譯顯示錯誤
#4
新會員
新會員


謝謝板主,已解決。

發表於: 2021/1/7 9:34
頂部


XC8T v1.0 教材的程式編譯顯示錯誤
#5
新會員
新會員


如題,在研究XC8T v1.0 教材裡的PIC16F1939 FSRH:FSRL ROM指標練習時,將教材裡的檔案開啟直接進行編譯,卻發生以下錯誤訊息,請問是我哪邊沒有設定好嗎?使用MPLAB X IDE v5.35,再請幫忙解答,thx!

1. 教材內容,如下
------------------------------------------------
#include

// ************ 設定 PIC16F1937 Configuration Bits ******

// PIC16F1939 Configuration Bit Settings

// 'C' source line config statements

#include

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG1
#pragma config FOSC = ECH // Oscillator Selection (ECH, External Clock, High Power Mode (4-32 MHz): device clock supplied to CLKIN pin)
#pragma config WDTE = ON // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#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 = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)

// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config VCAPEN = OFF // Voltage Regulator Capacitor Enable (All VCAP pin functionality is disabled)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)

const unsigned char Lookup_Table[ ] = {0xA0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 80, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 80, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 89, 80, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
0xAA, 0xAB};

unsigned char Input_Buffer[320] @0x21;
const unsigned char *near ROMPTR = Lookup_Table;
unsigned char *near RAMPTR = Input_Buffer; // PTR 指標位址設在 Access Memory
near unsigned int j; // 變數 j 放在 Access Memory

void main(void)
{
for (j = 0; j <= 302; j++)*RAMPTR++ = *ROMPTR++;

while (1);
}
--------------------------------------------------------

2. 錯誤訊息,如下
--------------------------------------------------------
Program Lookup Table FSR.c:54:32: error: expected ';' after top level declarator
unsigned char Input_Buffer[320] @0x21;
^
;
Program Lookup Table FSR.c:55:26: error: expected ';' after top level declarator
const unsigned char *near ROMPTR = Lookup_Table;
^
;
Program Lookup Table FSR.c:56:16: error: redefinition of 'near' with a different type: 'unsigned char *' vs 'const unsigned char *'
unsigned char *near RAMPTR = Input_Buffer; // PTR }]b Access Memory
^
Program Lookup Table FSR.c:55:22: note: previous definition is here
const unsigned char *near ROMPTR = Lookup_Table;
^
Program Lookup Table FSR.c:56:20: error: expected ';' after top level declarator
unsigned char *near RAMPTR = Input_Buffer; // PTR }]b Access Memory
^
;
Program Lookup Table FSR.c:57:1: error: unknown type name 'near'
near unsigned int j; // j b Access Memory
^
Program Lookup Table FSR.c:57:6: error: expected identifier or '('
near unsigned int j; // j b Access Memory
^
Program Lookup Table FSR.c:61:10: error: use of undeclared identifier 'j'
for (j = 0; j <= 302; j++)*RAMPTR++ = *ROMPTR++;
^
Program Lookup Table FSR.c:61:17: error: use of undeclared identifier 'j'
for (j = 0; j <= 302; j++)*RAMPTR++ = *ROMPTR++;
^
Program Lookup Table FSR.c:61:27: error: use of undeclared identifier 'j'
for (j = 0; j <= 302; j++)*RAMPTR++ = *ROMPTR++;
^
Program Lookup Table FSR.c:61:32: error: use of undeclared identifier 'RAMPTR'
for (j = 0; j <= 302; j++)*RAMPTR++ = *ROMPTR++;
^
Program Lookup Table FSR.c:61:44: error: use of undeclared identifier 'ROMPTR'
for (j = 0; j <= 302; j++)*RAMPTR++ = *ROMPTR++;
^
11 errors generated.

發表於: 2020/12/31 14:26
頂部


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


另外請教我用以下寫法編譯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 燒錄完成卻沒有動作
#7
新會員
新會員


使用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
頂部


PIC16F1503 timer 計數中斷 與 外部中斷無法同時使用
#8
新會員
新會員


請教前輩,我原本有使用timer1設定每1ms中斷一次當做時間計算給LED1使用,後來我要增加另一個LED2(PWM控制點燈),所以打算用外部中斷功能,可以用彈跳開關做為兩各LED的切換,但加入中斷後,按彈跳開關都沒有反應,我是設定負緣觸發的時候產生中斷,示波器量測確實有負緣信號產生,但卻沒有進行切換,請問是我的設定哪邊有問題嗎?
以下是我的程式code,請不吝指教,

=========================================================================
#include<pic.h>

__CONFIG(FOSC_INTOSC&WDTE_OFF&PWRTE_ON&MCLRE_OFF&CP_OFF&BOREN_OFF);

#define LED1 RC2
#define LED2 RC1 //PWM

volatile unsigned int ms=0;
volatile unsigned char step=0;
volatile unsigned char SW=0;

void system_initial(void)
{
OSCCONbits.IRCF = 0b1110; //內部振盪器頻率設為8MHz
OSCCONbits.SCS = 0b11; //內部振盪器模塊
INTCONbits.GIE = 1; //允許所有有效中斷
INTCONbits.PEIE = 1; //允許所有有效外設中斷
INTCONbits.INTE = 1; //允許INT外部中斷
TRISA = 0b00000100; //RA2 input
TRISC = 0b00000000;
ANSELA = 0b00000000; //RA0~RA4 Digital I/O
ANSELC = 0b00000000; //RC0~RC3 Digital I/O
LED1 = 0;
LED2 = 0;
}

void PWM_Init(void)
{
PWM4CON = 0b00000000; //Clear PWM2CON
PR2 = 0b10100110; //Configure the Timer2 period - decimal 166
PWM4CON = 0b11000000; //Enable PWM Module, Module Output
PWM4DCH = 0b00000000; //Clear duty cycle registers
PWM4DCL = 0b00000000;
TMR2IF = 0; //Clear the timer 2 interrupt flag
T2CON = 0b00000001; //Set prescaler to 4
TMR2ON = 1; //Enable timer 2
PWM4DCH = 0b00010000; //Pulse Width:33.5μs, Duty = 10%
PWM4DCL = 0b00000011;
}

void INT_Init(void)
{
OPTION_REGbits.INTEDG = 0; //下降沿中斷
INTF = 0; //Clear INTF
}

void TIMER1_Init(void)
{
TMR1H=0xFF;
TMR1L=0x06;
T1CONbits.T1CKPS = 0b11;
T1CONbits.TMR1CS = 0b00;
PIE1bits.TMR1IE = 1;
T1CONbits.TMR1ON = 1;
PIR1bits.TMR1IF = 0;
}

void interrupt SystemISR(void)
{
if(TMR1IF && TMR1IE)
{
TMR1IF = 0;
TMR1H = 0xFF;
TMR1L = 0x06;
ms++;
}

if(INTF && INTE)
{
INTF = 0; //Clear INTF
SW = 1;
}
}

void main(void)
{
system_initial();
TIMER1_Init();
PWM_Init();

while(1)
{
switch(step)
{
case 0:
{
PWM4CON = 0b01000000; //disable PWM Module
LED2=0;

if(SW==1)
{
LED1=0;
step=1;
}

if(ms==60)
LED1=1;

if(ms==120)
LED1=0;

if(ms==180)
LED1=1;

if(ms==240)
LED1=0;

if(ms==1000)
ms=0;

break;
}

case 1: //LED2 PWM mode
{
if(SW==1)
{
ms=0;
step=0;
}

LED1=0;
PWM4CON = 0b11000000; //Enable PWM Module

break;
}
}
}
}

發表於: 2020/5/21 16:18
頂部


Re: PIC16F1503 timer 計數 每秒開+每秒關LED 循環
新會員
新會員



發表於: 2019/12/17 15:18
頂部



(1) 2 »



:::

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

教育訓練中心

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