Title: Water
1?ata????t?? STATUS ?ata????t?? STATUS
bit 7 IRP Bit ep?????? pe?????? µ??µ?? (Bank) ??a t?? ?µµes? d?e????s??d?t?s? 1 Bank2, Bank3 0 Bank0, Bank1
bit 6-5 RP1RP0 Bit ep?????? pe?????? µ??µ?? (Bank) ??a t?? ?µes? d?e????s??d?t?s? 11 Bank3 10 Bank2 01 Bank1 00 Bank0
bit 4 TO Bit ??de???? ?pe??e???s?? WDT 1 ??de??? efa?µ???? t??f?d?s?a?, e?t??es?? e?t???? clrwdt ? sleep 0 ?pe??e???s? Watchdog Timer
bit 3 PD Bit ??de???? ?at?stas?? ?aµ???? ?ata????s?? ?s???? 1 ?et? ap? efa?µ??? t??f?d?s?a? ? ap? e?t??es? e?t???? clrwdt 0 ??de??? e?t??es?? e?t???? sleep
bit 2 Z S?µa?a µ?de??sµ?? 1 ?? ap?t??esµa µ?a? a???µ?t???? ? ??????? ?e?t?????a? e??a? µ?d?? 0 ?? ap?t??esµa µ?a? a???µ?t???? ? ??????? ?e?t?????a? de? e??a? µ?d??
bit 1 DC ??at??µe?? ? da?e??? ??at??µe?? ap? ta 4 bits ?aµ???? t???? 1 ?p???e? ??at??µe?? ap? ta 4 bits ?aµ???? t???? 0 ?e? ?p???e? ??at??µe?? ap? ta 4 bits ?aµ???? t????
bit 0 C ??at??µe?? 1 ??at??µe?? p?? p????pte? ap? t? bit ?????te??? t???? 0 ?e? p????pte? ??at??µe?? S?µ. St?? afa??es? ?s??e? a???ß?? t? a?t??et?. ?ta? ?p???e? da?e??? ??at??µe?? t?te C0 e?? ?ta? de? ?p???e? t?te C1
2???t?? µ??µ?? PIC16F887
3KATA?O????S ??????S/G?????S ???S?S
?? ?ata????t?? e?d???? ???s?? (Special Function
Registers SFRs) e??a? ?ata????t?? ?? ?p????
?a???????? e?d???? ?e?t?????e? t??
µ????e?e??t?. ?? ?ata????t?? e?d???? ???s?? p??
????? a?afe??e? µ???? t??a e??a? ? STATUS, o FSR
?a? o INDF. ?? SFRs a??? ?a? ?? ?ata????t??
?e????? ???s?? (General Purpose Registers GPRs)
e??a? ?a?t???af?µ???? st? µ??µ? t?? µ????e?e??t?.
? ???t?? µ??µ?? ?p?? ??e? a?afe??e? pe???aµß??e?
t?sse??? ?µ?de? ?? ?p??e? e??a? ?? Bank0, Bank1,
Bank2 ?a? Bank3. G?a ?a ???eta? s?st? p??sp??as?
se ??p???? ?ata????t? t?? RAM ?a p??pe?, e?t??
ap? t?? a?af??? st? ???µa t?? ?ata????t? se
??p??a e?t???, ?a de?????? ta Bank bits t??
?ata????t? STATUS st? s?st? Bank. ?a Bank bits
e??a? to bit5 (RP0) ?a? t? bit6 (RP1).
4Bank bits ?ata????t? STATUS
?? RP10, RP00 t?te se ???e a?af??? st? RAM
???eta? p??sp??as? st? Bank0. ?? RP10, RP01
t?te se ???e a?af??? st? RAM ???eta? p??sp??as?
st? Bank1. ?? RP11, RP00 t?te se ???e a?af???
st? RAM ???eta? p??sp??as? st? Bank2. ?? RP11,
RP01 t?te se ???e a?af??? st? RAM ???eta?
p??sp??as? st? Bank3. ?p?????? ?ata????t?? p??
ß??s???ta? se ep??a??pt?µe?e? ??se?? µ??µ?? ?a?
st?? t?sse??? Bank t?? µ????e?e??t?. ??t?? ??
?ata????t?? ?a µp????? ?a ?????? p??sp??as?
?p??ad?p?te st??µ?, ?p??d?p?te de?????? ta Bank
bits. ?a??de??µa t?t???? ?ata????t?? ap?te???? ??
STATUS (?ata????t?? ?at?stas??), FSR (?ata????t??
de??t??), INTCON (?ata????t?? d?a??p??).
5???S????S? S? ???F???????S BANK
Reg1 equ h'020' Bank0 Reg2 equ
h'0A0' Bank1 Reg3 equ h'120'
Bank2 Reg4 equ h'1A0' Bank3 bcf
STATUS,RP0 bcf STATUS,RP1 ltRP1gtltRP0gt 00
(Bank0) movlw d'10' movwf Reg1 Reg1 lt
d'10' bsf STATUS,RP0 bcf STATUS,RP1
ltRP1gtltRP0gt 01 (Bank1) movlw d'20' movwf Reg2
Reg2 lt d'20' bcf STATUS,RP0 bsf STATUS,RP1
ltRP1gtltRP0gt 10 (Bank2) movlw d'30' movwf Reg3
Reg1 lt d'30'
6????????S? ??F???O? ??S??O?/????O?
? PIC16F887 d?a??te? p??te ???e? e?s?d?? e??d??
??a ep????????a µe e??te????? s?s?e???. ?? ???e?
a?t?? e??a? T??a A 6 bit (RA0 ?? RA6) T??a
B 8 bit (RB0 ?? RB7) T??a C 8 bit (RC0 ??
RC7) T??a D 8 bit (RD0 ?? RD7) T??a E 4 bit
(RE0 ?? RE3) St??? a???d??te? t?? ?????
p???p?????ta? ta s?µata t?? d??f????
pe??fe?e?a??? ?????µ?t?? t?? µ????e?e??t?.
7????????S? ??F???O? ??S??O?/????O?
???e ???a d?a?e????eta? ap? d?? ?ata????t??. ?
???a ? d?a?e????eta? ap? t??? ?ata????t?? TRISA
?a? PORTA. ? ???a B d?a?e????eta? ap? t???
?ata????t?? TRISB ?a? PORTB. ? ???a C
d?a?e????eta? ap? t??? ?ata????t?? TRISC ?a?
PORTC. ? ???a D d?a?e????eta? ap? t???
?ata????t?? TRISD ?a? PORTD. ? ???a E
d?a?e????eta? ap? t??? ?ata????t?? TRISE ?a?
PORTE. ???e ?ata????t?? TRISx ?a? PORTx (xA, B,
C, D, E) ??e? e???? t?sa bit ?s??? a???d??te?
??e? ? a?t?st???? ???a. ? ???e ?ata????t?? TRISx
?a?????e? t?? ???e a???d??t? t?? a?t?st?????
???a? a? ?a ap?te?e? ??f?a?? e?s?d? ? ??f?a??
???d?. ???ad?, a? ??a bit t?? TRISx e??a? '0'
t?te ? a?t?st????? a???d??t?? t?? ???a? x
ap?te?e? ??f?a?? ???d?. ?? ??a bit t?? TRISx
e??a? '1' t?te ? a?t?st????? a???d??t?? t?? ???a?
x ap?te?e? ??f?a?? e?s?d?. G?a pa??de??µa a?
TRISBb'00110011' t?te a?t? s?µa??e? ?t? RB0
e?s?d??, RB1 e?s?d??, RB2 ???d??, RB3
???d?? RB4 e?s?d??, RB5 e?s?d??, RB6 ???d??,
RB7 ???d??
8????????S? ??F???O? ??S??O?/????O?
? ???e ?ata????t?? PORTx (xA, B, C, D, E)
?a?????e? t?? ???e a???d??t? t?? a?t?st?????
???a? a? ?a ß??s?eta? st? ?????? '0' ? st? ??????
'1' ??a t?? pe??pt?s? p?? ? a?t?st?????
?ata????t?? TRISx ??e? ???se? t?? a???d??t? ??
???d?. ???ad? a? ??a bit t?? PORTx e??a? '0' t?te
? a?t?st????? a???d??t?? t?? ???a? x ?a e??a? st?
?????? '0' (?e??s?) st?? pe??pt?s? p?? t?
a?t?st???? bit t?? ?ata????t? TRISx e??a?
???µ?sµ??? st? ?????? '0'. ?? ??a bit t?? PORTx
e??a? '1' t?te ? a?t?st????? a???d??t?? t?? ???a?
x ?a e??a? st? ?????? '1' (t?s? t??f?d?s?a?) st??
pe??pt?s? p?? t? a?t?st???? bit t?? ?ata????t?
TRISx e??a? ???µ?sµ??? st? ?????? '0'. G?a
pa??de??µa a? TRISBb'00000000' ?a?
PORTBb'11110000' t?te a?t? s?µa??e? ?t? ???? ??
a???d??te? t?? ???a? PORTB e??a? ???d??
?a? RB0'0', RB1'0', RB2'0', RB3'0', RB4'1',
RB5'1', RB6'1', RB7'1'
9???????G?? ????????S?S ??F???O? ?/?
1. ?a ?a????sete t??? 8 a???d??te? t?? ???a? D
t?? PIC16F887 ?? e??d??? ?a? ?a ?d???sete t???
RD0, RD3, RD5 ?a? RD7 st? ?????? '1' e?? t???
?p????p??? st? ?????? '0'. St? s????e?a ?a
?d???sete t?? a???d??t? RD0 st? ?????? '0' ?a?
t?? RD1 st? ?????? '1'. bsf STATUS, RP0 RP0 lt
'1' bcf STATUS, RP1 RP1 lt '0' ???µ?saµe ta
Bank bits ?a de?????? st?? Bank1 af?? ?????µe
?a ?????µe p??sp??as? st?? TRISD clrf TRISD
TRISD lt b'00000000' (???? ???d??) bcf STATUS,
RP0 RP0 lt '0' ???µ?saµe ta Bank bits ?a
de?????? st?? Bank0 af?? ?????µe ?a ?????µe
p??sp??as? st?? PORTD movlw b'10101001' movwf
PORTD PORTD lt b'10101001' bcf PORTD,RD0
RD0 lt '0'(PORTD lt b'10101000') bsf PORTD,RD1
RD1 lt '1'(PORTD lt b'10101010')
10???????G?? ????????S?S ??F???O? ?/?
2. ?a ?a????sete t??? a???d??te? RC0, RC1, RC2
?a? RC3 ?? e??d??? ?a? ?a t??? ?d???sete st?
?????? '1'. ?? a???d??te? RC4, RC5, RC6 ?a? RC7
de? ????????µe a? ap?te???? e?s?d??? ? e??d???
?p?te se ???e pe??pt?s? ?a µ?? a??????e? ?
?at?stas? t???. 1?? t??p?? bsf STATUS,RP0 bcf
STATUS,RP1 Bank1 ??a p??sp??as? st??
TRISC movlw b'11110000' andwf TRISC,f TRISC lt
b'UUUU0000',UUnchanged bcf STATUS,RP0 Bank0
??a p??sp??as? st?? PORTC movlw b'00001111' iorwf
PORTC,f PORTC lt b'UUUU1111',UUnchanged
11???????G?? ????????S?S ??F???O? ?/?
2o? t??p?? bsf STATUS,RP0 bcf STATUS,RP1 Bank1
??a p??sp??as? st?? TRISC bcf TRISC,RC0 TRISC
lt b'UUUUUUU0' bcf TRISC,RC1 TRISC lt
b'UUUUUU00' bcf TRISC,RC2 TRISC lt
b'UUUUU000' bcf TRISC,RC3 TRISC lt
b'UUUU0000' bcf STATUS,RP0 Bank0 ??a p??sp??as?
st?? PORTC bsf PORTC,RC0 RC0lt0, PORTC lt
b'UUUUUUU1' bsf PORTC,RC1 RC1lt0, PORTC lt
b'UUUUUU11' bsf PORTC,RC2 RC2lt0, PORTC lt
b'UUUUU111' bsf PORTC,RC3 RC3lt0, PORTC lt
b'UUUU1111'
12???????G?? ????????S?S ??F???O? ?/?
3. ?a ?a????sete t?? a???d??t? RD7 ?? ??f?a??
e?s?d? ?a? t?? a???d??t? RD0 ?? ??f?a?? ???d?. ??
st?? e?s?d? RD7 s??d?eta? s?µa p?? t?? ?d??e? st?
?????? '0' t?te t? RD0 ?a ?d????e? ep?s?? st?
?????? '0'. ?? st?? e?s?d? RD7 s??d?eta? s?µa p??
t?? ?d??e? st? ?????? '1' t?te t? RD0 ?a ?d????e?
ep?s?? st? ?????? '1'. bsf STATUS,RP0 bcf
STATUS,RP1 Bank1 bsf TRISD,RD7
TRISDltb'1UUUUUUU',U Unchanged bcf TRISD,RD0
TRISDltb'1UUUUUU0',U Unchanged bcf STATUS,RP0
Bank0 LOOP btfss PORTD,7 ?? RD71 pa???aµ??
ep?µ.e?t???? bcf PORTD,0 PORTDltb'0XXXXXX0',X
Unknown btfsc PORTD,7 ?? RD70 pa???aµ??
ep?µ.e?t???? bsf PORTD,0 PORTDltb'1XXXXXX1',X
Unknown goto LOOP
13S????S????G?? ????O?
?? ??f?a??? ???d?? t?? µ????e?e??t? µp????? ?a
???s?µ?p??????? ??a ?a d?s??µe e?t????
e?????s??/pa?s??, ??a ?a p?a?µat?p???s??µe
ep????????a µe ???e? s?s?e???, ??a ?a
d?µ??????s??µe s?µata e?????? ??p. ?pt???
µp????µe ?a d??µe t?? ?at?stas? µ?a? e??d?? a?
s??d?s??µe µ?a d??d? LED. ?ta? RB4'0' t?te
ILED0A (? d??d?? LED de? e?p?µpe? f??). ?ta?
RB4'1' t?te ? d??d?? e?p?µpe? f?? ?a? t? ?e?µa
e??a?
14S????S????G?? ??S??O?
?? ??f?a??? e?s?d?? µp????? ?a ???s?µ?p???????
??a ?a d?s??µe e??te???? ??p??e? e?t???? st?
µ????e?e??t?. ??a e??te???? e?t??? µp??e? ?a
d??e? µe t? ???s?µ?p???s? e??? d?a??pt? t?p??
pushbutton. ?ta? ? d?a??pt?? S1 e??a? pat?µ????
t?te eµfa???eta? d??aµ??? ?e??s?? st?? a???d??t?
RB4 ?p?te ?p??ad?p?te a?????s? ?a d??e? ??
ap?t??esµa ?????? '0'. ?ta? ? d?a??pt?? S1 de?
e??a? pat?µ???? t?te epe?d? ? a???d??t?? e?s?d??
pa???s???e? µe???? s???et? a?t?stas? ?a
eµfa???eta? st? RB4 t? d??aµ??? t?? 5V ?p?te
?p??ad?p?te a?????s? ?a d??e? ?? ap?t??esµa
?????? '1'.
15????O?????? ??????? ????????G???
?? pa?a??t? ?????µa ???p??e? t? 3? pa??de??µa
??d??a ??a t? d?a?e???s? e?s?d??/e??d??. St??
a???d??t? RD7 s??d?eta? o d?a??pt?? S1 ??a
a?????s? ??f?a??? e?s?d??. St?? a???d??t? RD0
s??d?eta? ? d??d?? LED1 ??a ?pt??? ??e??? t??
??f?a??? e??d??.
? a???d??t?? RE3 ???s?µ?p??e?ta? ?? Master Clear
(MCLR) ?a? ??e? t?p??et??e? µ?a pull-up a?t?stas?
?a? ??a? d?a??pt??. ?at??ta? t? d?a??pt? ????µe
RESET e?? af????t?? t?? ????µe ?a??????
?e?t?????a. ? µ????e?e??t?? ??a ?a ?e?t?????se?
ep?s?? ??e???eta? ??p???? ta?a?t?t? ?????sµ??.
?d? de? ?p???e? s??dedeµ???? e??te?????
ta?a?t?t?? ?a? ???s?µ?p??e?ta? ? es?te?????
ta?a?t?t?? p?? d?a??te? ? PIC16F887.