Example: Input Pin Testing
Example: Input Pin Testing
Example: Input Pin Testing
#include <16f877.h> #fuses HS,nowdt #use delay (clock=20000000) void main(){ output_c(0); output_d(0); set_tris_c(0xff); set_tris_b(0x00); while (1){ if (input(pin_C1)==1) {output_high (pin_D1);} if (input(pin_C1)==0) {output_low(pin_D1);} }}
U1
2
R1
10k
13 14 1 2 3 4 5 6 7 8 9 10
X1
C2
22p
CRYSTAL
C1
22p
RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/AN4/SS RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RE0/AN5/RD RC2/CCP1 RE1/AN6/WR RC3/SCK/SCL RE2/AN7/CS RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT RD0/PSP0 RD1/PSP1 RD2/PSP2 RD3/PSP3 RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7 PIC16F877
33 34 35 36 37 38 39 40 15 16 17 18 23 24 25 26 19 20 21 22 27 28 29 30
SW1
SW-SPDT
D1
LED-GREEN
U1 X1
13 14 1 2 3 4 5 6 7 OSC1/CLKIN OSC2/CLKOUT MCLR/Vpp/THV RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD 33 34 35 36 37 38 39 40 15 16 17 18 23 24 25 26 19 20 21 22 27 28 29 30
CRYSTAL
C1
22p
C2
22p
8 9 10
RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/AN4/SS RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RE0/AN5/RD RC2/CCP1 RE1/AN6/WR RC3/SCK/SCL RE2/AN7/CS RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT RD0/PSP0 RD1/PSP1 RD2/PSP2 RD3/PSP3 RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7 PIC16F877
7-segment display
5
DIGITS TO D I S P L AY
D I S P L AY S E G M E N TS
dp 0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 0
a 1 0 1 1 0 1 1 1 1 1
b 1 1 1 1 1 0 0 1 1 1
c 1 1 0 1 1 1 1 1 1 1
d 1 0 1 1 0 1 1 0 1 1
e 1 0 1 0 0 0 1 0 1 0
f 1 0 0 0 1 1 1 0 1 1
g 0 0 1 1 1 1 1 0 1 1
7-segment display
main(){ set_tris_c(0x00); while(1){ output_c(0X7E);// display 0 on 7-segment display device delay_ms(1000); output_c(0X0C);// display 1 on 7-segment display device delay_ms(1000); output_c(0XB6);// display 2 on 7-segment display device delay_ms(1000); output_c(0X9E);// display 3 on 7-segment display device delay_ms(1000); output_c(0XCC);// display 4 on 7-segment display device delay_ms(1000); output_c(0XDA);// display 5 on 7-segment display device delay_ms(1000); output_c(0XFA);// display 6 on 7-segment display device delay_ms(1000); output_c(0X0E);// display 7 on 7-segment display device delay_ms(1000); output_c(0XFE);// display 8 on 7-segment display device delay_ms(1000); output_c(0XCE);// display 9 on 7-segment display device delay_ms(1000);}}
U1 X1
13 14 1 2 3 4 5 6 7 OSC1/CLKIN OSC2/CLKOUT MCLR/Vpp/THV RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD 33 34 35 36 37 38 39 40 15 16 17 18 23 24 25 26 19 20 21 22 27 28 29 30
CRYSTAL
C1
22p
C2
22p
8 9 10
RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/AN4/SS RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RE0/AN5/RD RC2/CCP1 RE1/AN6/WR RC3/SCK/SCL RE2/AN7/CS RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT RD0/PSP0 RD1/PSP1 RD2/PSP2 RD3/PSP3 RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7 PIC16F877
LCD DISPLAY
9
A liquid crystal display (LCD) is a thin, flat electronic visual display that uses the light modulating properties of liquid crystal(LCs). For more information see http://en.wikipedia.org/wiki/Liquid_crystal_display This component is specifically manufactured to be used with microcontrollers, which means that it cannot be activated by standard IC circuits
LCD Screen
10
An LCD screen can display two lines with 16 characters each. Every character consists of 5x8 or 5x11 dot matrix. a 5x8 character display which is most commonly used.
11
RS
0 1
Control of operating
R/W
0 1
7 8 9 Data / commands 10 11 12 13 14
D0 D1 D2 D3 D4 D5 D6 D7
Along one side of the small printed board of the LCD display there are pins that enable it to be connected to the microcontroller. There are in total of 14 pins marked with numbers (16 if there is a backlight). Their function is described in the table bellow:
// LCD pins D0-D3 are not used and PIC D3 is not used.
+5
14
U1 X1
13 14 1 2 3 4 5 6 7 OSC1/CLKIN OSC2/CLKOUT MCLR/Vpp/THV RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD 33 34 35 36 37 38 39 40 15 16 17 18 23 24 25 26 19 20 21 22 27 28 29 30
+5
LCD1
LM016L
CRYSTAL
C2
1nF
1nF
8 9 10
54%
C1
RA0/AN0 RA1/AN1 RA2/AN2/VREFRA3/AN3/VREF+ RA4/T0CKI RA5/AN4/SS RC0/T1OSO/T1CKI RC1/T1OSI/CCP2 RE0/AN5/RD RC2/CCP1 RE1/AN6/WR RC3/SCK/SCL RE2/AN7/CS RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT
VSS V DD VEE
RS RW E 4 5 6
RV1
1 2 3 1k 7 8 9 10 11 12 13 14
D0 D1 D2 D3 D4 D5 D6 D7