Hallo, ich fange gerade erst mit der Mikrocontrollerprogrammierung an. Hierzu verwende ich Assembler und einen PIC16F887. Ich möchte einzelne Portpins ins Arbeitsregister speichern/kopieren. Biser kann ich nur ganze Ports auslesen also zum Beispiel MOVF PORTA,w ----> kopiert das ganze PORTA ins Arbeitsregister. Wenn das zum Beispiel einfache Schalter sind. Wie kann ich dann z.b. die ersten drei Portpins einlesen, um sie dann einzeln weiterzugeben bzw auszugeben. Bin noch ein Anfänger und würde mich über eure Hilfe sehr freuen! Vielen Dank im Voraus Grüße Dani
:
Bearbeitet durch User
Tja, einfach geht nur ein MOVF für ganze Bytes und ein BTFSC für einzelne Bits. 3 Bits einlesen - das musst du mit ANDWF und RLF zusammenbasteln.
Schau dir mal die Übersicht TABLE 15-2: PIC16F882/883/884/886/887 INSTRUCTION SET und da die BIT-ORIENTED FILE REGISTER OPERATIONS an Hier ein sinnloses) Beispiel zum Ansteuern einer LED mit einem Taster:
1 | #define nBTN_ENC PORTB,RB1,ACCESS ;Input Pin for Button (low-active) |
2 | #define BTN_ENC_TRI TRISB,TRISB1,ACCESS |
3 | #define nLED_1 LATB,LATB2,ACCESS ;Output Pin for LED (low active) |
4 | #define LED_1_TRI TRISB,TRISB2,ACCESS |
5 | ... |
6 | |
7 | Main ; main code |
8 | btfss nBTN_ENC ; button not activated ? |
9 | bcf nLED_1 ; ? skip switch on |
10 | btfsc nBTN_ENC ; button activated ? |
11 | bsf nLED_1 ; ? skip swich off |
12 | bra Main |
(das Beispiel war für einen PIC18)
Myke Predko - PICMicro Microcontroller Pocket Reference: Here is a fast way to save specific bits from one register into another. movf Source, w xorwf Destination, w andlw B'xxxxxxxx' ; Replace "x" with "1" to Copy the Bit xorwf Destination, f
sagen wir einmal ich habe einen Port mit Tastern invertiert (weil low aktiv) ins Arbeitsregister w eingelesen. nun möchte ich über den Befehl BTFSC einzelne Pins an verschiedenen Ports ausgeben. ich habe mir das so vorgestellt: COMF PORTC, w ; invertiertes Einlesen der Schalter ins w-Register MOVWF zelle1 ; Kopieren vom w-Register in die zelle1 BTFSC zelle1, 0 ; Abfragen, ob zelle1 bit 0 high oder low ist? BSF PORTA, 0 ; Led an Port A pin 0 ausgeben Leider funtkioniert das nicht...mit dem Buildvorgang von MBLAP ich denke der Fehler liegt irgendwo beim thema mit dem register usw.. bitte um hilfe weiß nicht mehr was ich noch probieren soll
Dann benutze diesen Code: ;********************************************************************** ; This file is a basic code template for object module code * ; generation on the PIC16F877A. This file contains the * ; basic code building blocks to build upon. * ; * ; Refer to the MPASM User's Guide for additional information on * ; features of the assembler and linker (Document DS33014). * ; * ; Refer to the respective PIC data sheet for additional * ; information on the instruction set. * ; * ;********************************************************************** ; * ; Filename: MAIN.ASM * ; Date: * ; File Version: * ; * ; Author: * ; Company: * ; * ; * ;********************************************************************** ; * ; Files required: p16f877a.INC * ; 16f877a_g.lkr * ; * ; * ;********************************************************************** ; * ; Notes: * ; * ; * ; * ; * ;********************************************************************** LIST r=dec ; list directive to set the default radix list p=16F877A ; list directive to define processor #include "p16f877a.inc" ; processor specific variable definitions ; ; Defines and macros to help with ; bank selection ; #define BANK0 (h'000') #define BANK1 (h'080') #define BANK2 (h'100') #define BANK3 (h'180') ; '__CONFIG' directive is used to embed configuration word within .asm file. ; The lables following the directive are located in the respective .inc file. ; See data sheet for additional information on configuration word settings. __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF ;***** VARIABLE DEFINITIONS MAIN_DATA udata count res 1 delay_low res 1 delay_high res 1 ; example of using Shared Uninitialized Data Section INT_DATA UDATA_SHR w_temp RES 1 ; variable used for context saving status_temp RES 1 ; variable used for context saving pclath_temp RES 1 ; variable used for context saving ;********************************************************************** CODE org 0x000 ; processor reset vector RESET_VECTOR: nop ; ICD2 needs this goto start ; go to beginning of program INT_VECTOR: org 0x004 ; interrupt vector location INTERRUPT: movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register movf PCLATH,W movwf pclath_temp ; isr code can go here or be located as a call subroutine elsewhere movf pclath_temp,W movwf PCLATH movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt start: ; ; Turn off all analog inputs ; and make all pins available ; for digital I/O. ; banksel BANK1 movlw b'00000110' ; Set all ADC inputs for digital I/O movwf (ADCON1 ^ BANK1) ; movlw b'00000000' ; Turn off Comparator voltage reference movwf (CVRCON ^ BANK1) movlw 0x07 ; turn off Comparators movwf (CMCON ^ BANK1) banksel BANK0 clrf (ADCON0 ^ BANK0) ; Turn off ADC ; ; Set ports for digital output ; movlw b'00000000' movwf PORTA movlw b'00000000' movwf PORTB movlw b'00000000' movwf PORTC movlw b'00000000' movwf PORTD movlw b'00000000' movwf PORTE banksel BANK1 movlw b'00000000' movwf (TRISA ^ BANK1) movlw b'00000000' movwf (TRISB ^ BANK1) movlw b'00000000' movwf (TRISC ^ BANK1) movlw b'00000000' movwf (TRISD ^ BANK1) movlw b'00000000' movwf (TRISE ^ BANK1) banksel BANK0 clrf count clrf delay_low clrf delay_high ; remaining code goes here ; ; Make the LEDs on the LAB-X1 count ; main_loop: incf count,F movfw count movwf PORTD ; ; Pause between counts so humans ; can see the lights changing. ; delay_loop: incfsz delay_low goto delay_loop incfsz delay_high goto delay_loop goto main_loop END
Dani PIC schrieb im Beitrag #3918797: > Leider funtkioniert das nicht...mit dem Buildvorgang von MBLAP Ist das der gesamte Code? Mit welcher Fehlermeldung wird das Builden abgebrochen?
habe es so wie es dasteht zum laufen gebracht in einer neuen datei. weiß leider auch nicht woran es lag.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.