BÀI 6 : HIỂN THỊ SỐ 2015 LÊN LED 7 ĐOẠN PIC16F887 XC8

10:48:00 PM
- Đây là ảnh mô phỏng protues.
hiển thị số 2015 lên 4 led 7 đoạn pic16f887 xc8
- Đây là code chương trình.
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 8000000

// CONFIG1
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF      // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config CPD = OFF        // Data Code Protection bit (Data memory code protection is disabled)
#pragma config BOREN = OFF      // Brown Out Reset Selection bits (BOR disabled)
#pragma config IESO = OFF       // Internal External Switchover bit (Internal/External Switchover mode is disabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
#pragma config LVP = OFF        // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming)

// CONFIG2
#pragma config BOR4V = BOR40V   // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
#pragma config WRT = OFF        // Flash Program Memory Self Write Enable bits (Write protection off)

const unsigned char Anode[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F};
const unsigned char Cathode[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90};
void main(void)
{
    TRISC = 0X00;
    PORTC = 0X00;
    TRISAbits.TRISA0 = 0;
    TRISAbits.TRISA1 = 0;
    TRISAbits.TRISA2 = 0;
    TRISAbits.TRISA3 = 0;
    while(1)
    {
        // xuat so 2 len led 7seg
        PORTC = 0XA4;
        PORTAbits.RA0 = 1;
        __delay_ms(4);
        PORTAbits.RA0 = 0;
        // xuat so 0 len led 7 seg
        PORTC = 0XC0;
        PORTAbits.RA1 = 1;
        __delay_ms(4);
        PORTAbits.RA1 = 0;
        // xuat so 1 len led 7seg
        PORTC = 0XF9;
        PORTAbits.RA2 = 1;
        __delay_ms(4);
        PORTAbits.RA2 = 0;
        // xuat so 5 len led 7 seg
        PORTC = 0X92;
        PORTAbits.RA3 = 1;
        __delay_ms(4);
        PORTAbits.RA3 = 0;
    }

}
- Link download project Click here

Share this

Related Posts

Previous
Next Post »