Đếm từ 0 - 9 XC8

10:03:00 PM
- Led 7 seg được ứng dụng nhiều trong các mạch điện tử. Nên trong bài này mình sẽ là Project đếm từ 0 - 9 sử dụng pic16f877a và led 7 seg Cathot chung.

- Ảnh mô phỏng protues.

0 - 9 pic16f877a xc8

- Đây là code.

#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _XTAL_FREQ 4000000
// CONFIG
#pragma config FOSC = XT        // Oscillator Selection bits (HS 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)

unsigned char  const SEGMENT_MAP[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
char digit=0;

void hienthi(void);

void main(void) {
     TRISB = 0x00;           //Set PortB to all outputs
     PORTB = 0X00;
     while(1)
     {
         __delay_ms(100);
         hienthi();
     }
}
void hienthi(void)
{
     
        PORTB = (SEGMENT_MAP[digit]);
        digit++;
        if(digit > 9 )
        {
             digit = 0;
        }
}

- Link download Project.
http://www.mediafire.com/download/7fkwrd0pfz6g171/0_-_9.rar

Share this

Related Posts

Previous
Next Post »