dsPIC30F4013에 대한 LEB 깜박임 및 UART 통신의 코드 예
dsPIC30F4013용 LED Blinking 및 UART 통신 샘플 코드를 공유합니다.
이 코드는 내부 시계와 함께 작동합니다.
1Hz 간격으로 LED를 점멸하고 UART 통신을 통해 "S"를 전달합니다.
회로
사진(브레드보드 프로토타이핑)
배선 테이블
dsPIC30F4013
주변 장치(LED 또는 FT232 )
Vdd
3V3(FT232)
대
접지(FT232)
핀25(U1TX)
RXD(FT232)
핀26(U1RX)
TXD(FT232)
핀27
양극(LED)
소스 코드
// FOSC
#pragma config FOSFPR = FRC_PLL4 // Oscillator (Internal Fast RC (No change to Primary Osc Mode bits))
#pragma config FCKSMEN = CSW_FSCM_OFF // Clock Switching and Monitor (Sw Disabled, Mon Disabled)
// FWDT
#pragma config FWPSB = WDTPSB_16 // WDT Prescaler B (1:16)
#pragma config FWPSA = WDTPSA_512 // WDT Prescaler A (1:512)
#pragma config WDT = WDT_OFF // Watchdog Timer (Disabled)
// FBORPOR
#pragma config FPWRT = PWRT_64 // POR Timer Value (64ms)
#pragma config BODENV = BORV27 // Brown Out Voltage (2.7V)
#pragma config BOREN = PBOR_ON // PBOR Enable (Enabled)
#pragma config MCLRE = MCLR_DIS // Master Clear Enable (Enabled)
// FGS
#pragma config GWRP = GWRP_OFF // General Code Segment Write Protect (Disabled)
#pragma config GCP = CODE_PROT_OFF // General Segment Code Protection (Disabled)
// FICD
#pragma config ICS = ICS_PGD // Comm Channel Select (Use PGC/EMUC and PGD/EMUD)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
unsigned int counter = 0; // Initialize counter
int main() {
/* OSCCON oscillator setting register */
OSCCONbits.CF = 0; // Not detected clock failure
OSCCONbits.COSC = 0b111; // PLL oscillator which was defined FOSFPR
OSCCONbits.LOCK = 1; // PLL is in lock
OSCCONbits.LPOSCEN = 0; // Secondary oscillator is disabled
OSCCONbits.NOSC = 0b111; // New PLL oscillator which was defined
OSCCONbits.OSWEN = 0; // Switch is completed
OSCCONbits.POST = 0; // Postscaler does not alter clock
/* IO Setting */
TRISA = 0; // Digital out
TRISB = 0; // Digital out
TRISC = 0; // Digital out
TRISD = 0; // Digital out
TRISF = 0; // Digital out
TRISFbits.TRISF2 = 1; // RX pin setting
TRISFbits.TRISF3 = 0; // TX pin setting
TRISBbits.TRISB0 = 1; // Analog in
TRISBbits.TRISB1 = 1; // Analog in
TRISBbits.TRISB2 = 1; // Analog in
TRISBbits.TRISB3 = 1; // Analog in
TRISBbits.TRISB4 = 1; // Analog in
TRISBbits.TRISB5 = 1; // Analog in
TRISBbits.TRISB8 = 1; // Analog in
TRISBbits.TRISB9 = 1; // Analog in
TRISBbits.TRISB10 = 1; // Analog in
TRISBbits.TRISB11 = 1; // Analog in
TRISBbits.TRISB12 = 1; // Analog in
/*Timer Setting Register(ADC Sampling Time Management)*/
T1CONbits.TON = 0; //Timer OFF. タイマーOFF.
T1CONbits.TCS = 0; //Use internal Clock. 内部クロックを使用.
T1CONbits.TGATE = 0; //Gate time accumulate is off.ゲートタイム累積無効.
T1CONbits.TSIDL = 0; //Continue on IDLE mode. アイドルモードでタイマ継続.
T1CONbits.TSYNC = 0; //NONE. 無視(TCS = 0のとき)
T1CONbits.TCKPS = 0b11; //prescaler 256
/*Interrupt Setting*/
PR1 = 28; //700Hz
IPC0bits.T1IP = 5; //Interrupt priority is 5. 優先順位5, 高いほうが優先順位が高い.
IEC0bits.T1IE = 1; //Timer 1 interrupt is enable. タイマ1割り込みON.
IFS0bits.T1IF = 0; //Timer 1 Interrupt flag is off. タイマ1割り込みフラグ0。
T1CONbits.TON = 1; //Timer ON
/* UART Setting */
U1MODEbits.UARTEN = 1; //UART disabled
U1MODEbits.USIDL = 0; //Run UART on IDLE mode
U1MODEbits.ALTIO = 0; //Alternate pin is enabled
U1MODEbits.WAKE = 0; //Wakeup is disabled
U1MODEbits.LPBACK = 0; //Loopback mode is disabled
U1MODEbits.ABAUD = 1; //U1RX to Capture
U1MODEbits.PDSEL = 0; //No parity 8-bit
U1MODEbits.STSEL = 0; //1STOP bit
U1STAbits.UTXISEL = 1; //When buffer is empty
U1STAbits.UTXBRK = 0; //Transfer break is normal mode
U1STAbits.URXISEL = 0b00; //When accepting any character, interrupt is occured
U1STAbits.ADDEN = 0; //Address detector is disabled
U1STAbits.OERR = 0; //Not Overrun (First write only)
U1BRG = 49;
U1MODEbits.UARTEN = 1; //UART disabled
U1STAbits.UTXEN = 1; //UART TX is enabled.
PORTFbits.RF5 = 1; // Invert bit
while(1);
}
int flagLED = 0;
int counterLED = 0;
void __attribute__((interrupt, shadow, auto_psv)) _T1Interrupt(void) {
IFS0bits.T1IF = 0; // Flag is low
counterLED++;
if(counterLED >= 1000) {
printf("S\n");
if (flagLED == 0) flagLED = 1;
else flagLED = 0;
PORTFbits.RF5 = flagLED;
counterLED = 0;
}
}
데모
이 원본 기사는 내가 쓴 다음과 같습니다. 이 기사는 일본어에서 영어로 번역되었습니다.
dsPIC30F4013으로 L치카와 UART 통신을 하는
zenn.dev
Reference
이 문제에 관하여(dsPIC30F4013에 대한 LEB 깜박임 및 UART 통신의 코드 예), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://dev.to/akirakashihara/code-example-of-leb-blinking-and-uart-communication-for-dspic30f4013-53g9
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
// FOSC
#pragma config FOSFPR = FRC_PLL4 // Oscillator (Internal Fast RC (No change to Primary Osc Mode bits))
#pragma config FCKSMEN = CSW_FSCM_OFF // Clock Switching and Monitor (Sw Disabled, Mon Disabled)
// FWDT
#pragma config FWPSB = WDTPSB_16 // WDT Prescaler B (1:16)
#pragma config FWPSA = WDTPSA_512 // WDT Prescaler A (1:512)
#pragma config WDT = WDT_OFF // Watchdog Timer (Disabled)
// FBORPOR
#pragma config FPWRT = PWRT_64 // POR Timer Value (64ms)
#pragma config BODENV = BORV27 // Brown Out Voltage (2.7V)
#pragma config BOREN = PBOR_ON // PBOR Enable (Enabled)
#pragma config MCLRE = MCLR_DIS // Master Clear Enable (Enabled)
// FGS
#pragma config GWRP = GWRP_OFF // General Code Segment Write Protect (Disabled)
#pragma config GCP = CODE_PROT_OFF // General Segment Code Protection (Disabled)
// FICD
#pragma config ICS = ICS_PGD // Comm Channel Select (Use PGC/EMUC and PGD/EMUD)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
unsigned int counter = 0; // Initialize counter
int main() {
/* OSCCON oscillator setting register */
OSCCONbits.CF = 0; // Not detected clock failure
OSCCONbits.COSC = 0b111; // PLL oscillator which was defined FOSFPR
OSCCONbits.LOCK = 1; // PLL is in lock
OSCCONbits.LPOSCEN = 0; // Secondary oscillator is disabled
OSCCONbits.NOSC = 0b111; // New PLL oscillator which was defined
OSCCONbits.OSWEN = 0; // Switch is completed
OSCCONbits.POST = 0; // Postscaler does not alter clock
/* IO Setting */
TRISA = 0; // Digital out
TRISB = 0; // Digital out
TRISC = 0; // Digital out
TRISD = 0; // Digital out
TRISF = 0; // Digital out
TRISFbits.TRISF2 = 1; // RX pin setting
TRISFbits.TRISF3 = 0; // TX pin setting
TRISBbits.TRISB0 = 1; // Analog in
TRISBbits.TRISB1 = 1; // Analog in
TRISBbits.TRISB2 = 1; // Analog in
TRISBbits.TRISB3 = 1; // Analog in
TRISBbits.TRISB4 = 1; // Analog in
TRISBbits.TRISB5 = 1; // Analog in
TRISBbits.TRISB8 = 1; // Analog in
TRISBbits.TRISB9 = 1; // Analog in
TRISBbits.TRISB10 = 1; // Analog in
TRISBbits.TRISB11 = 1; // Analog in
TRISBbits.TRISB12 = 1; // Analog in
/*Timer Setting Register(ADC Sampling Time Management)*/
T1CONbits.TON = 0; //Timer OFF. タイマーOFF.
T1CONbits.TCS = 0; //Use internal Clock. 内部クロックを使用.
T1CONbits.TGATE = 0; //Gate time accumulate is off.ゲートタイム累積無効.
T1CONbits.TSIDL = 0; //Continue on IDLE mode. アイドルモードでタイマ継続.
T1CONbits.TSYNC = 0; //NONE. 無視(TCS = 0のとき)
T1CONbits.TCKPS = 0b11; //prescaler 256
/*Interrupt Setting*/
PR1 = 28; //700Hz
IPC0bits.T1IP = 5; //Interrupt priority is 5. 優先順位5, 高いほうが優先順位が高い.
IEC0bits.T1IE = 1; //Timer 1 interrupt is enable. タイマ1割り込みON.
IFS0bits.T1IF = 0; //Timer 1 Interrupt flag is off. タイマ1割り込みフラグ0。
T1CONbits.TON = 1; //Timer ON
/* UART Setting */
U1MODEbits.UARTEN = 1; //UART disabled
U1MODEbits.USIDL = 0; //Run UART on IDLE mode
U1MODEbits.ALTIO = 0; //Alternate pin is enabled
U1MODEbits.WAKE = 0; //Wakeup is disabled
U1MODEbits.LPBACK = 0; //Loopback mode is disabled
U1MODEbits.ABAUD = 1; //U1RX to Capture
U1MODEbits.PDSEL = 0; //No parity 8-bit
U1MODEbits.STSEL = 0; //1STOP bit
U1STAbits.UTXISEL = 1; //When buffer is empty
U1STAbits.UTXBRK = 0; //Transfer break is normal mode
U1STAbits.URXISEL = 0b00; //When accepting any character, interrupt is occured
U1STAbits.ADDEN = 0; //Address detector is disabled
U1STAbits.OERR = 0; //Not Overrun (First write only)
U1BRG = 49;
U1MODEbits.UARTEN = 1; //UART disabled
U1STAbits.UTXEN = 1; //UART TX is enabled.
PORTFbits.RF5 = 1; // Invert bit
while(1);
}
int flagLED = 0;
int counterLED = 0;
void __attribute__((interrupt, shadow, auto_psv)) _T1Interrupt(void) {
IFS0bits.T1IF = 0; // Flag is low
counterLED++;
if(counterLED >= 1000) {
printf("S\n");
if (flagLED == 0) flagLED = 1;
else flagLED = 0;
PORTFbits.RF5 = flagLED;
counterLED = 0;
}
}
데모
이 원본 기사는 내가 쓴 다음과 같습니다. 이 기사는 일본어에서 영어로 번역되었습니다.
dsPIC30F4013으로 L치카와 UART 통신을 하는
zenn.dev
Reference
이 문제에 관하여(dsPIC30F4013에 대한 LEB 깜박임 및 UART 통신의 코드 예), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://dev.to/akirakashihara/code-example-of-leb-blinking-and-uart-communication-for-dspic30f4013-53g9
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(dsPIC30F4013에 대한 LEB 깜박임 및 UART 통신의 코드 예), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/akirakashihara/code-example-of-leb-blinking-and-uart-communication-for-dspic30f4013-53g9텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)