RP Store Tìm linh kiện theo mã, gửi BOM nhận báo giá Gửi BOM

LẬp trÌnh pic16f877a trÊn mplab xc8

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • lam3ngon
    Nhập môn đệ tử
    • Mar 2015
    • 1

    #1

    LẬp trÌnh pic16f877a trÊn mplab xc8

    BÀI 1 : CHỚP TẮT LED PIC16F877A XC8
    - Đây là code chương trình.
    #include <stdio.h>
    #include <stdlib.h>
    #define _XTAL_FREQ 4000000
    #include <xc.h>
    // CONFIG
    #pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
    #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
    #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
    #pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
    #pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
    #pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
    #pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
    #pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
    void GPIO_init (void);
    void Anode (void);
    void Cathode (void);
    void main (void)
    {
    GPIO_init();
    while(1)
    {
    __delay_ms(100);
    Anode();
    Cathode();
    __delay_ms(100);
    }
    }
    void GPIO_init(void)
    {
    TRISBbits.TRISB0 = 0; // RB0 LÀ OUTPUT
    TRISBbits.TRISB7 = 0; // RB7 LÀ OUTPUT
    PORTBbits.RB0 = 1; // OFF LED RB0
    PORTBbits.RB7 = 0; // OFF LED RB7
    }
    void Anode (void)
    {
    PORTBbits.RB0 = 0;
    __delay_ms(500);
    PORTBbits.RB0 = 1;
    }
    void Cathode (void)
    {
    PORTBbits.RB7 = 1;
    __delay_ms(500);
    PORTBbits.RB7 = 0;
    }
    Ảnh mô phỏng và project các bạn download tại file đính kèm bên dưới hoặc vào link sau download http://xcvn.blogspot.com/2015/11/cho...f877a-xc8.html
    Attached Files
Working...