Chapter 4 PIC IO Programming
Chapter 4 PIC IO Programming
LED
7-Segment LED
2
Function
bsf
fileReg, bit
bcf
fileReg, bit
btg
fileReg, bit
Example: btfss
e.g., Write a program to (a) keep
monitoring RB2 bit until it becomes high
(b) When RB2 becomes high, write 45H
to Port C
bsf TRISB, 2; set RB2 as input
clrf TRISC; set Port C as output
movlw 0x45
Again: btfss PORTB, 2
bra Again
movwf PORTC
10
Example: btfss
e.g., Write a program to check RB2.
If RB2 = 0, send the letter N to Port D
If RB2 = 1, send the letter Y to Port D
bsf TRISB, 2; set RB2 as input
clrf TRISD; set Port D as output
Again: btfss PORTB, 2
bra Over
movlw AY
movwf PORTD
bra Again
Over: movlw AN
movwf PORTD
bra Again
11
Example: btfsc
e.g., Perform the same function using
btfsc
bsf TRISB, 2; set RB2 as input
clrf TRISD; set Port D as output
Again: btfsc PORTB, 2
bra Over
movlw AN
movwf PORTD
bra Again
Over: movlw AY
movwf PORTD
bra Again
12
Common Cathode
Active high
Common Anode
Active low
13
Logic 1 turns on a
segment.
Example: To display
digit 1, all segments
except b and c should
be off.
Byte 00000110 = 06 will
display digit 1.
15
16
3 components of a loop
20
21
call SVN_SEG
23
24
When K5 is pressed
10 1
1 1
10
01
1
1
25
1 1
01 1
10
01
01
10
26
0111 DetectColOutput = 1
1011 DetectColOutput = 2
1101 DetectColOutput = 3
1110 DetectColOutput = 4
1111 No button is pressed, DetectColOutput = 0
4.Two cases: