1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Vi-Điều-Khiển-1

95 552 7

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 95
Dung lượng 1,32 MB

Nội dung

#pragma config OSC=HS#pragma config WDT=OFF #pragma config MCLRE=ON Delay10KTCYx50; while!sw2; x++; }PORTB=x%8... #include #pragma config OSC=HS #pragma config WDT=OFF #pragma config MCL

Trang 1

1.1. Lập trình điều khiển vào ra (20 câu)

Cho sơ đồ nguyên

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

LED6 LED5

LED5 LED6 RA0/AN0/C1IN-

2 RA1/AN1/C2IN- 3

RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26

RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30

RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1PIC18F4520

PIC18F4520

8 MHZ

C1 22p

C2 22p

RB7 LED4 RB6

LED3 RB5

LED2 RB4

LED1 RC1

LED5 RC2

LED6

#include<p18f4520.h>

#include<delays.h>

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

if(sw1==0)PORTB=0xff;

Trang 3

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

LED6 LED5

LED5 LED6 RA0/AN0/C1IN-

2 RA1/AN1/C2IN- 3

RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26

RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30

RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1PIC18F4520

PIC18F4520

8 MHZ C1

22p

C2 22p

RB7 LED4 RB6

LED3

RB5

LED2 RB4

LED1 RC1

LED5 RC2

LED6

==================================================

#include<p18f4520.h>

#include<delays.h>

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define sw1 PORTBbits.RB0

#define sw2 PORTBbits.RB1

#define sw3 PORTBbits.RB2

#define sw4 PORTBbits.RB3

#define led1 PORTBbits.RB4

#define led2 PORTBbits.RB5

#define led3 PORTBbits.RB6

#define led4 PORTBbits.RB7void main(void)

{

ADCON1=0x0f;

TRISB=0x0f;

while(1){

if(sw1==0)

Trang 4

led2=0;

}

if(sw3==0){ led3=1;

Delay10KTCYx(10);

led3=0;

}

if(sw4==0){ led4=1;

Delay10KTCYx(10);

led4=0;

}}}

Câu 1.3: (6 điểm)

Trang 5

Cho sơ đồ nguyên

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

if(sw4==0)PORTB=0xf0;

if(sw1==0|sw2==0|sw3==0)PORTB=0x00;

}}

Câu 1.4: (6 điểm)

Trang 6

Cho sơ đồ nguyên

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define sw2 PORTBbits.RB1

#define sw3 PORTBbits.RB2

#define sw4 PORTBbits.RB3

#define led1 PORTBbits.RB4

#define led2 PORTBbits.RB5

#define led3 PORTBbits.RB6

#define led4 PORTBbits.RB7

void main(void){

ADCON1=0x0f;

TRISB=0x0f;

while(1){

if(sw3==0){

led3=1;

led4=1;

}if(sw4==0)

Trang 7

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

Trang 8

#include<p18f4520.h>

#include<delays.h>

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

if(sw3==0)led3=1;

if (sw2==0)led3=0;

}}///////////////////////////////////////////////////////////////////////////////////////////////

Bài 1.5.2 tương tự như bài 1.5.1 nhé

Câu 1.5.2: (6 điểm)

Trang 9

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

Trang 10

Cho sơ đồ nguyên

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#define led1 PORTBbits.RB4

#define led2 PORTBbits.RB5

#define led3 PORTBbits.RB6

#define led4 PORTBbits.RB7

for(i=0;i<4;i++){

PORTB=m[i];

Delay10KTCYx(50);

}else

PORTB=0;

}}

Trang 11

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

LED6 LED5

LED5 LED6 RA0/AN0/C1IN-

2 RA1/AN1/C2IN- 3

RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26

RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30

RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1PIC18F4520

PIC18F4520

8 MHZ C1

22p

C2 22p

RB7 LED4 RB6

LED3 RB5

LED2 RB4

LED1 RC1

LED5 RC2

LED6

===============================================

#include<p18f4520.h>

#include<delays.h>

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define sw1 PORTBbits.RB0

#define sw2 PORTBbits.RB1

#define sw3 PORTBbits.RB2

#define sw4 PORTBbits.RB3

#define led1 PORTBbits.RB4

#define led2 PORTBbits.RB5

#define led3 PORTBbits.RB6

#define led4 PORTBbits.RB7void main(void)

{ int i;

ADCON1=0x0f;

Trang 12

PORTC=0;

Delay10KTCYx(50);

}else{PORTB=0;

PORTC=0;

}if(sw4==1){

PORTB=0x80;

PORTC=0;

Delay10KTCYx(50);

}else{PORTB=0;

PORTC=0;

}

if(sw4==1){

PORTC=0x02;

PORTB=0;

Trang 13

}}}

Câu 1.8: (6 điểm)

Trang 14

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

LED6 LED5

LED5 LED6 RA0/AN0/C1IN-

2 RA1/AN1/C2IN- 3

RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26

RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30

RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1PIC18F4520

PIC18F4520

8 MHZ

C1 22p

C2 22p

RB7 LED4

RB6

LED3

RB5

LED2 RB4

LED1 RC1

LED5 RC2

LED6

================================================

#include<p18f4520.h>

#include<delays.h>

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define sw1 PORTBbits.RB0

#define sw2 PORTBbits.RB1

#define sw3 PORTBbits.RB2

#define sw4 PORTBbits.RB3

#define led1 PORTBbits.RB4

#define led2 PORTBbits.RB5

#define led3 PORTBbits.RB6

#define led4 PORTBbits.RB7

#define led5 PORTCbits.RC1

#define led6 PORTCbits.RC2

void main(void){ unsigned char i;

ADCON1=0x0f;

TRISB=0x0f;

Trang 15

}if(i==4){PORTB=0xf0;

PORTC=0x00;

}if(i==5){PORTB=0xf0;

PORTC=0x02;

}if(i==6){PORTB=0xf0;

PORTC=0x06;

}}}

Câu 1.9: (6 điểm)

Trang 16

Cho sơ đồ nguyên lý

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

if(sw2==0){

Delay10KTCYx(50);

while(!sw2);

x++;

}PORTB=x<<4;

}}

Câu 1.10: (6 điểm)

Trang 17

Cho sơ đồ nguyên

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define sw3 PORTBbits.RB2

#define led1 PORTBbits.RB4

#define led2 PORTBbits.RB5

#define led3 PORTBbits.RB6

#define led4 PORTBbits.RB7

unsigned char x;

{ADCON1=0x0f;

TRISB=0x0f;

while(1){

if(sw3==0){

Delay10KTCYx(50);

while(!sw3);

x++;

if(x%5==1)

Trang 18

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

LED6 LED5

LED5 LED6 RA0/AN0/C1IN-

2 RA1/AN1/C2IN- 3

RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26

RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30

RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1PIC18F4520

PIC18F4520

8 MHZ

C1 22p

C2 22p

RB7 LED4

RB6

LED3

RB5

LED2 RB4

LED1 RC1

LED5 RC2

Trang 19

#define sw4 PORTBbits.RB3

#define led1 PORTBbits.RB4

#define led2 PORTBbits.RB5

#define led3 PORTBbits.RB6

#define led4 PORTBbits.RB7

#define led5 PORTCbits.RC1

#define led6 PORTCbits.RC2

led1=0;led2=0;led3=0;

led4=1;led5=1;led6=1;

}

if (sw4==0){

PORTB=0x00;

PORTC=0x00;

}}}

Câu 1.12: (6 điểm)

Trang 20

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

LED6 LED5

LED5 LED6 RA0/AN0/C1IN-

2 RA1/AN1/C2IN- 3

RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26

RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30

RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1PIC18F4520

PIC18F4520

8 MHZ

C1 22p

C2 22p

RB7 LED4

RB6

LED3

RB5

LED2 RB4

LED1 RC1

LED5 RC2

LED6

==============================================

#include<p18f4520.h>

#include<delays.h>

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define sw1 PORTBbits.RB0

#define sw2 PORTBbits.RB1

#define sw3 PORTBbits.RB2

#define sw4 PORTBbits.RB3

#define led1 PORTBbits.RB4

#define led2 PORTBbits.RB5

#define led3 PORTBbits.RB6

#define led4 PORTBbits.RB7

#define led5 PORTCbits.RC1

#define led6 PORTCbits.RC2void main(void)

{ADCON1=0x0f;

TRISB=0x0f;

TRISC=0x00;

Trang 21

PORTC=0x00;

}}}

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

Trang 22

#pragma config WDT=OFF

#pragma config MCLRE=ON

if(sw1==0)led1=1;

if(sw2==0|sw3==0|sw4==0)led1=0;

}}

Câu 1.14: (6 điểm)

Trang 23

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

LED6 LED5

LED5 LED6 RA0/AN0/C1IN-

2 RA1/AN1/C2IN- 3

RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26

RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30

RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1PIC18F4520

PIC18F4520

8 MHZ

C1 22p

C2 22p

RB7 LED4

RB6

LED3

RB5

LED2 RB4

LED1 RC1

LED5 RC2

LED6

============================================

#include<p18f4520.h>

#include<delays.h>

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define sw1 PORTBbits.RB0

#define sw2 PORTBbits.RB1

#define sw3 PORTBbits.RB2

#define sw4 PORTBbits.RB3

#define led1 PORTBbits.RB4

#define led2 PORTBbits.RB5

#define led3 PORTBbits.RB6

#define led4 PORTBbits.RB7

#define led5 PORTCbits.RC1

#define led6 PORTCbits.RC2void main(void)

{ADCON1=0x0f;

TRISB=0x0f;

TRISC=0x00;

Trang 24

PORTC=0x00;;

}}}

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define sw4 PORTBbits.RB3

#define led4 PORTBbits.RB7void main(void)

Trang 25

}}

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

Trang 26

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

Delay10KTCYx(50);

while(!sw2);

x++;

}PORTB=x%8<<4;

}}

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

Trang 27

#include<p18f4520.h>

#include<delays.h>

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

if(sw2==0){

Delay10KTCYx(50);

while(!sw2);

x++;

}PORTB=x%4<<4;

}}

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

Trang 28

#include<p18f4520.h>

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define sw1 PORTBbits.RB0

#define sw2 PORTBbits.RB1

#define sw3 PORTBbits.RB2

#define led1 PORTBbits.RB4

#define led2 PORTBbits.RB5

#define led3 PORTBbits.RB6

Trang 29

Cho sơ đồ nguyên

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

Trang 30

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

if(sw2==0)led2=1;

if(sw3==0 & sw4==0)led2=0;

}}

Trang 31

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define xung PORTBbits.RB4

{TMR0L=256-250;

T0CONbits.TMR0ON=1;// bat timer0

Trang 32

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define xung PORTBbits.RB5

void main(void){

Trang 33

}}

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

Trang 34

#define xung PORTBbits.RB6

while(!INTCONbits.TMR0IF);// cho

co tran = 1

T0CONbits.TMR0ON=0;//tat timer0INTCONbits.TMR0IF=0;// 1 US DETHUC HIEN 1 LENH

xung=~xung;

}}

Câu 1.23: (6 điểm)

Trang 35

Cho sơ đồ nguyên

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define xung PORTBbits.RB7

TMR0L=(65536-62500)%256;T0CONbits.TMR0ON=1;// bat timer0

while(!INTCONbits.TMR0IF);// cho

co tran = 1

T0CONbits.TMR0ON=0;//tat timer0

Trang 36

INTCONbits.TMR0IF=0;// 1 US DE

THUC HIEN 1 LENH

xung=~xung;

}}

Câu 1.24: (6 điểm)

Trang 37

Cho sơ đồ nguyên

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define xung PORTCbits.RC0

TMR0L=256-250+6;

T0CONbits.TMR0ON=1;// bat timer0

while(!INTCONbits.TMR0IF);// cho

co tran = 1

T0CONbits.TMR0ON=0;//tat timer0INTCONbits.TMR0IF=0;// 1 US DETHUC HIEN 1 LENH

Trang 38

}

}

Câu 1.25: (6 điểm)

Trang 39

Cho sơ đồ nguyên

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

#pragma config OSC=HS

#pragma config WDT=OFF

#pragma config MCLRE=ON

#define led1 PORTBbits.RB4

#define led2 PORTBbits.RB5

if(INTCONbits.INT0IF==1)

INTCONbits.INT0IF=0;

led1=0;

for(i=0;i<10;i++){

Trang 40

KEY3 KEY2 KEY1

OSC2 OSC1

LED1

2

RA0/AN0/C1IN- 3

RA1/AN1/C2IN-RA2/AN2/C2IN+/VREF-/CVREF 4

RA3/AN3/C1IN+/VREF+

5 RA4/T0CKI/C1OUT 6

RA5/AN4/SS/HLVDIN/C2OUT 7

RA6/OSC2/CLKO 14

RA7/OSC1/CLKI 13

RB0/AN12/FLT0/INT0 33

RB1/AN10/INT1 34

RB2/AN8/INT2 35

RB3/AN9/CCP2A 36

RB4/KBI0/AN11 37

RB5/KBI1/PGM 38

RB6/KBI2/PGC 39

RB7/KBI3/PGD 40

RC0/T1OSO/T13CKI 15RC1/T1OSI/CCP2B 16RC2/CCP1/P1A 17RC3/SCK/SCL 18RC4/SDI/SDA 23RC5/SDO 24RC6/TX/CK 25RC7/RX/DT 26RD0/PSP0 19RD1/PSP1 20RD2/PSP2 21RD3/PSP3 22RD4/PSP4 27RD5/PSP5/P1B 28RD6/PSP6/P1C 29RD7/PSP7/P1D 30RE0/RD/AN5 8RE1/WR/AN6 9RE2/CS/AN7 10RE3/MCLR/VPP 1

PIC18F4520

PIC18F4520

8 MHZ C1

Ngày đăng: 21/06/2017, 16:34

w