Mikrocontroller und Digitale Elektronik
›
Thread
Lauflicht mit PIC16F886
RS
R. S.
(frederenke)
OP
22.09.2012 19:38
#2844282
Hallo zusammen,
ich mache meine ersten Versuche mit PIC 's und komme grade bei einem
einfachen Problem nicht weiter.
Ich will ein simples Lauflicht an PORTB eines PIC16F886 realisieren.
Alles klappt soweit, jedoch will die LED an PORTB,0 nicht leuchten.
Was mache ich falsch?
Zur Beschaltung eine kleine vereinfachte "Skizze" (alle Portb Ports sind
beschaltet wie RB4)
Vielen Dank!
1 list p = 16 f886 ; list directive to define processor
2 #include <p16f886.inc> ; processor specific variable definitions
3
4 __CONFIG _CONFIG1 , _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
5 __CONFIG _CONFIG2 , _WRT_OFF & _BOR21V
6
7
8
9
10 ; ***** VARIABLE DEFINITIONS ------ aus der PIC Beispieldatei
11 w_temp EQU 0x7D ; variable used for context saving
12 status_temp EQU 0x7E ; variable used for context saving
13 pclath_temp EQU 0x7F ; variable used for context saving
14 ; Variables :
15 d0 equ 0x20
16 d1 equ 0x21
17 d2 equ 0x22
18 PORTB_SHDW equ 0x23
19
20 ORG 0x000 ; processor reset vector
21 goto beginn
22
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ORG 0x004 ; interrupt vector location
25
26 movwf w_temp ; save off current W register contents
27 movf STATUS , w ; move status register into W register
28 movwf status_temp ; save off contents of STATUS register
29 movf PCLATH , w ; move pclath register into w register
30 movwf pclath_temp ; save off contents of PCLATH register
31
32 movf pclath_temp , w ; retrieve copy of PCLATH register
33 movwf PCLATH ; restore pre - isr PCLATH register contents
34 movf status_temp , w ; retrieve copy of STATUS register
35 movwf STATUS ; restore pre - isr STATUS register contents
36 swapf w_temp , f
37 swapf w_temp , w ; restore pre - isr W register contents
38 retfie ; return from interrupt
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 beginn
41 bcf INTCON , GIE
42 BTFSC INTCON , GIE
43 GOTO $ - 2
44 bsf STATUS , RP0 ; Registerseite 1
45 movlw b ' 00000000 ' ; Port B als Ausgang definieren
46 movwf TRISB
47 bcf STATUS , RP0 ; Registerseite 0
48 clrf PORTB_SHDW
49 bsf PORTB_SHDW , 0
50 call write_portb
51 movlw 0x40
52 call delay
53 bcf PORTB_SHDW , 0
54 bsf PORTB_SHDW , 1
55 call write_portb
56 movlw 0x40
57 call delay
58 bcf PORTB_SHDW , 1
59 bsf PORTB_SHDW , 2
60 call write_portb
61 movlw 0x40
62 call delay
63 bcf PORTB_SHDW , 2
64 bsf PORTB_SHDW , 3
65 call write_portb
66 movlw 0x40
67 call delay
68 bcf PORTB_SHDW , 3
69 bsf PORTB_SHDW , 4
70 call write_portb
71 movlw 0x40
72 call delay
73 bcf PORTB_SHDW , 4
74 bsf PORTB_SHDW , 5
75 call write_portb
76 movlw 0x40
77 call delay
78 bcf PORTB_SHDW , 5
79 bsf PORTB_SHDW , 6
80 call write_portb
81 movlw 0x40
82 call delay
83 bcf PORTB_SHDW , 6
84 bsf PORTB_SHDW , 7
85 call write_portb
86 movlw 0x40
87 call delay
88 bcf PORTB_SHDW , 7
89 goto beginn ; go to beginning of program
90
91 write_portb
92 movwf w_temp
93 movf PORTB_SHDW , 0
94 movwf PORTB
95 RETLW w_temp
96
97 ; *************************************************************
98 ; Calls the delay_1ms W times
99 ; *************************************************************
100 delay
101 movwf d0
102 dly_loop
103 call delay_1ms
104 decfsz d0 , F
105 goto dly_loop
106 return
107
108
109 ; *************************************************************
110 ; 1 ms delay .
111 ; Modify this to match your processor speed .
112 ; http : //www.piclist.org/techref/piclist/codegen/delay.htm
113 ; *************************************************************
114 delay_1ms
115 movlw 0xF3 ; 2498 cycles
116 movwf d1
117 movlw 0x02
118 movwf d2
119 Delay_0
120 decfsz d1 , f
121 goto $ + 2
122 decfsz d2 , f
123 goto Delay_0
124 goto $ + 1 ; 2 cycles
125 return ; 4 cycles ( including call )
126
127 ; example of preloading EEPROM locations
128
129 ORG 0x2100
130 DE 5 , 4 , 3 , 2 , 1
131
132 END ; directive ' end of program '
TS
Thosrten S. (whitejack)
Gast
22.09.2012 19:48
#2844291
HI,
vorweg:
schau dir mal
rrf und rlf an.
Laut Program müsste es eigentlich gehen.
Tausche mal die Leitung die von Port B 0 Pin an den Transistor geht mit
der vom PORT B 1 und schau mal ob die LED dann leuchtet...
TS
RS
R. S.
(frederenke)
OP
22.09.2012 19:49
#2844292
PROBLEM GELÖST:
Der Pic ist kaputt. Mit einem anderen geht es!
Danke Thorsten für deine Hilfe
TS
Thosrten S. (whitejack)
Gast
22.09.2012 19:57
#2844297
ok,
wie gesagt, schau dir mal rrf und rlf an.
du setzt bit 0 und in einer schleife lässt du es immer einen weiter
routieren bis es "weg" ist, wenn das Register leer ist, kannst du das im
Statusregister (Zerobit) abfragen und neu setzen
-j2 bsf PORTB_SHDW,0
_j1 call write_portb
call delay
rlf PORTB_SHDW,f
btfss STATUS,Z
goto _j1
goto _j2
so ungefähr müsste es gehen... ist Jahre her das ich das gemacht habe...
↑ Nach oben
← Zurück zu Mikrocontroller und Digitale Elektronik
Antwort schreiben
Eine eigene Frage?
Dieser Thread ist über 14 Jahre alt.
Stell sie in einem eigenen Thread – dort lesen mehr Leute mit, und sie wird öfter und schneller beantwortet.
Neuen Thread starten
Eine Lösung, Ergänzung oder Rückmeldung zu diesem Thread? Dann antworte hier.