- Ảnh mô phỏng protues.
- Đây là code chương trình.
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 8000000
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS 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)
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)
{
TRISB = 0X00;
PORTB = 0X00;
TRISAbits.TRISA0 = 0;
TRISAbits.TRISA1 = 0;
TRISAbits.TRISA2 = 0;
TRISAbits.TRISA3 = 0;
while(1)
{
// xuat so 2 len led 7seg
PORTB = 0X5B;
PORTAbits.RA0 = 0;
__delay_ms(4);
PORTAbits.RA0 = 1;
// xuat so 0 len led 7 seg
PORTB = 0X3F;
PORTAbits.RA1 = 0;
__delay_ms(4);
PORTAbits.RA1 = 1;
// xuat so 1 len led 7seg
PORTB = 0X06;
PORTAbits.RA2 = 0;
__delay_ms(4);
PORTAbits.RA2 = 1;
// xuat so 5 len led 7 seg
PORTB = 0X6D;
PORTAbits.RA3 = 0;
__delay_ms(4);
PORTAbits.RA3 = 1;
}
}
EmoticonEmoticon