- Đây là ảnh
mô phỏng protues.
- Đâ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)
#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 SANGHET (void);
void TATHET (void);
void XENKE (void);
void SANGNUA (void);
void main (void)
{
GPIO_init();
while(1)
{
SANGHET();
__delay_ms(500);
TATHET();
__delay_ms(500);
XENKE();
__delay_ms(500);
SANGNUA();
__delay_ms(500);
}
}
void GPIO_init(void)
{
TRISB = 0X00;
PORTB = 0X00;
}
void SANGHET (void)
{
PORTB = 0XFF;
}
void TATHET (void)
{
PORTB = 0X00;
}
void XENKE (void)
{
PORTB = 0XAA;
__delay_ms(500);
PORTB = 0X55;
}
void SANGNUA (void)
{
PORTB = 0X0F;
__delay_ms(500);
PORTB = 0XF0;
}
- Đây là video mô phỏng.
EmoticonEmoticon