-
Der von dir gepostete Code sollte eigentlich folgendes machen
LED1 an -> Pause -> LED2 an, LED1 aus -> Pause -> Alles aus -> Pause -> Start
Kann es sein, dass dein PIC nicht stabil läuft. Löte mal einen 100nF Kondensator zwischen VDD und VSS und zwar so nahe wie möglich am PIC. Am besten direkt darunter zwischen den Pins. Oder hast du den Kondensator bereits und nur nicht im Schaltplan gezeichnet?
Gruß
Wolfgang
-
Mein LED Lauflicht funktioniert inzwischen. Allerdings hat sich jetzt ein neues Problem ergeben. Der PIC läuft nicht kontinuierlich durch, sondern startet das Programm nach einer bestimmten Zeit immer neu. Das erkenne ich daran, dass das Lauflicht nach einem Mal durchlaufen nur noch ein halbes Mal durchläuft und dann wieder von vorne anfängt.
Ich versorge den PIC mit 5V über ein USB-Kabel. Benutzen tue ich den internen Oszilator des PIC16F88. Zur Entstörung habe ich schon einen 100nF Kondensator zwischen VDD und VSS gehängt (direkt unter die Pins). Wie kann ich dieses Problem beheben?
Hier ist zur Sicherheit auch nochmal der Code:
Code:
#include P16f88.INC
;*****Set up the Constants****
STATUS equ 03h ;Address of the STATUS register
TRISA equ 85h ;Address of the tristate register for port A
PORTA equ 05h ;Address of Port A
TRISB equ 86h
PORTB equ 06h
OSCCON equ 8Fh
COUNT1 equ 20h ;First counter for our delay loops
COUNT2 equ 21h ;Second counter for our delay loops
;****Set up the port****
call Delay
bsf STATUS,RP0 ;Switch to Bank 1
movlw 10h ;Set the Port A pins
movwf TRISA
movlw 01h ;Set the Port B pins
movwf TRISB
movlw 2Eh
movwf OSCCON
clrf ANSEL
bcf STATUS,RP0 ;Switch back to Bank 0
movlw 00h ;
movwf PORTA
movlw 00h
movwf PORTB
;****Turn the 1st LED on****
Start movlw 04h ;Turn the Port A LEDs on by first putting it
movwf PORTA ;into the w register and then on the port
call Delay
btfsc PORTA,4 ;if RA4 is on, the next instruction is skipped
call Delay
;2nd LED
movlw 08h ;Turn the Port A LEDs on by first putting it
movwf PORTA ;into the w register and then on the port
call Delay
btfsc PORTA,4
call Delay
;3rd LED****
movlw 00h ;Turn the LEDs off by first putting it
movwf PORTA ;into the w register and then on the port
movlw 02h ;Turn LED on RB1 on
movwf PORTB
call Delay
btfsc PORTA,4
call Delay
;4th LED
movlw 04h
movwf PORTB
call Delay
btfsc PORTA,4
call Delay
;5th LED
movlw 10h
movwf PORTB
call Delay
btfsc PORTA,4
call Delay
;6th LED
movlw 20h
movwf PORTB
call Delay
btfsc PORTA,4
call Delay
;turn all off
movlw 00h
movwf PORTB
call Delay
btfsc PORTA,4
call Delay
;****Now go back to the start of the program
goto Start ;go back to Start and turn LEDs on again
;****Here is our Subroutine
Delay
movlw 30
movwf COUNT1 ;Load count1 with init value
movlw 10
movwf COUNT2 ;Load count2 with init value
Loop1 decfsz COUNT1,f ;This second loop keeps the LEDs
goto Loop1 ;turned off long enough for us to
decfsz COUNT2,f ;see it turned off
goto Loop1 ;
return
;****End of the program****
end ;Needed by some compilers, and also
;just in case we miss the goto instruction.
end ;Needed by some compilers, and also
;just in case we miss the goto instruction.
-
hast du den watchdogTimer deaktiviert???, der würde nach ablauf für ein reset des µC sorgen...
-
Ich denke, das ich das nicht getan habe. Kann mir jemand bitte sagen, wie das geht bzw. wie das zugehörige Register heißt, nachdem ich im Datenblatt suchen muss?
-
Ich würde mal an die 5V Leitung vom USB Anschluss noch mal so ca. 100µF hängen. Bei meiner Dockingstation z.b. hatte ich ansonsten eine Restwelligkeit von ca 0,5V bei 20khz. Kann schon sein das du ein deratiges Problem hast.
-
Ok, es war der Watchdogtimer. Gibt wohl ein paar Tricks die man als Anfänger lernen muss.
-
Ich weiß ja nicht genau was du benutzt, aber in MPLAB kann man auf jeden fall die Config-Werte in die *.asm datei schreiben.
z.B.
Code:
#include P16f88.INC
; Configuration festlegen
__CONFIG _CP_OFF & _DEBUG_OFF & _WDT_OFF & _PWRTE_ON & _EXTRC_IO
;*****Set up the Constants****
STATUS equ 03h ;Address of the STATUS register
TRISA equ 85h ;Address of the tristate register for port A
PORTA equ 05h ;Address of Port A
TRISB equ 86h
PORTB equ 06h
OSCCON equ 8Fh
COUNT1 equ 20h ;First counter for our delay loops
COUNT2 equ 21h ;Second counter for our delay loops
;****Set up the port****
call Delay
bsf STATUS,RP0 ;Switch to Bank 1
movlw 10h ;Set the Port A pins
movwf TRISA
movlw 01h ;Set the Port B pins
movwf TRISB
movlw 2Eh
movwf OSCCON
clrf ANSEL
bcf STATUS,RP0 ;Switch back to Bank 0
movlw 00h ;
movwf PORTA
movlw 00h
movwf PORTB
;****Turn the 1st LED on****
Start movlw 04h ;Turn the Port A LEDs on by first putting it
movwf PORTA ;into the w register and then on the port
call Delay
btfsc PORTA,4 ;if RA4 is on, the next instruction is skipped
call Delay
;2nd LED
movlw 08h ;Turn the Port A LEDs on by first putting it
movwf PORTA ;into the w register and then on the port
call Delay
btfsc PORTA,4
call Delay
;3rd LED****
movlw 00h ;Turn the LEDs off by first putting it
movwf PORTA ;into the w register and then on the port
movlw 02h ;Turn LED on RB1 on
movwf PORTB
call Delay
btfsc PORTA,4
call Delay
;4th LED
movlw 04h
movwf PORTB
call Delay
btfsc PORTA,4
call Delay
;5th LED
movlw 10h
movwf PORTB
call Delay
btfsc PORTA,4
call Delay
;6th LED
movlw 20h
movwf PORTB
call Delay
btfsc PORTA,4
call Delay
;turn all off
movlw 00h
movwf PORTB
call Delay
btfsc PORTA,4
call Delay
;****Now go back to the start of the program
goto Start ;go back to Start and turn LEDs on again
;****Here is our Subroutine
Delay
movlw 30
movwf COUNT1 ;Load count1 with init value
movlw 10
movwf COUNT2 ;Load count2 with init value
Loop1 decfsz COUNT1,f ;This second loop keeps the LEDs
goto Loop1 ;turned off long enough for us to
decfsz COUNT2,f ;see it turned off
goto Loop1 ;
return
;****End of the program****
end ;Needed by some compilers, and also
;just in case we miss the goto instruction.
end ;Needed by some compilers, and also
;just in case we miss the goto instruction.
Ich gebe dir jetzt abner keine garantie das die entsprechenden Config-Werte für deine Versuche die richtigen sind....
Alle Config-Befehle kannst du am Ende der p16f88.INC Nachlesen, wofür die stehen und was die bewirken steht im Datenblatt!
Wenn du ein Brennprogramm von Sprut benutzt kannst du die Config-Werte auch direkt im Brennprogramm einstellen, auf der seite www.sprut.de ist das mit der Configuration auch noch mal erklärt.
Ein 100µF Elko schadet natürlich nicht.
-
Ich bin selber noch Anfänger, und würde dir dieses Buch empfehlen:
PICs für Einsteiger
ISBN 3-7723-4994-3
Mir hat es viel geholfen und hat auch viele Anfängerfehler vermieden. Das Buch beschäftigt sich halt nur mit dem Controller 12F629 und 12F675, aber es ist eine gute Grundlage. Ich bin danach ohne Probleme gleich auf die 16Fxxx Reihe umgestiegen. Ich hab dass Buch beim Conrad bekommen
Und wegen dem Blinklicht: Dass wird in diesem Buch auch ausführlich beschrieben.
-