- Đây là ảnh mô phỏng protues.
- Đây là code chương trình.
#include <stdio.h>
#include <stdlib.h>
#define _XTAL_FREQ 8000000 // if 4Mhz is XT
#include <xc.h>
// 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)
void main(void)
{
TRISA = 0XFF;
TRISB = 0X00;
PORTB = 0X00;
while(1)
{
if(RA0==1)
{
__delay_ms(100);
while(RA0==1)
{
RB7=1;
}
}
if(RA1==0)
__delay_ms(100);
while(RA1==0)
{
RB7=0;
}
}
}
EmoticonEmoticon