BÀI 1 : CHỚP TẮT LED PIC16F84A XC8

4:41:00 AM
- Ảnh sơ đồ mô phỏng trên protues.
blink led pic16f84a xc8
- Đây là code chương trình.
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 4000000
// CONFIG
#pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF       // Watchdog Timer (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (Power-up Timer is disabled)
#pragma config CP = OFF         // Code Protection bit (Code protection disabled)

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;
}
- Link download project : Click here

Share this

Related Posts

Previous
Next Post »