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

4:58:00 AM
- Ảnh mô phỏng protues.
blink led pic16f628a
- Đâ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: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF      // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is digital input, MCLR internally tied to VDD)
#pragma config BOREN = OFF      // Brown-out Detect Enable bit (BOD disabled)
#pragma config LVP = OFF        // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EE Memory Code Protection bit (Data memory code protection off)
#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;
}

- Link download project : Click here

Share this

Related Posts

Previous
Next Post »