ik volg een tutorial over het programeren van een 16f84a microcontroller, hier te vinden.
Maar ik kom er nog niet helemaal uit, ik heb geprobeerd een programma te schrijven waardoor een led normaal aan is, maar wanneer je een knop indrukt moet hij weer uit gaan, totdat je hem loslaat, dan hoort hij weer aan te gaan.
Ik heb nu dit ervoor geschreven:
;**********************************************************************
; This file is a basic code template for assembly code generation *
; on the PIC16F84A. 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 (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P16F84A.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************
list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
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
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
main
;****Set up the port****
bsf STATUS,5 ;Switch to Bank 1
movlw 01h ;Set the Port A pins:
movwf TRISA ;bit 1to output, bit 0 to input.
bcf STATUS,5 ;Switch back to Bank 0
Checkswitch
BTFSC PORTA,0
call Ledoff
Checkswitch2
BTFSS PORTA,0
call Ledon
goto Checkswitch
Ledon
ledaan movlw 02h ;Turn the LED on by first putting
movwf PORTA ;it into the w register and then ;on the port
return
Ledoff
leduit movlw 00h ;Turn the LED on by first putting
movwf PORTA ;it into the w register and then ;on the port
return
END ; directive 'end of program'
Ik heb het zo aangesloten:

Het schema kan lijkt mij al niet knoppen, doordat de pic geen stroom kan krijgen als de schakelaar uit staat, maar ik heb geen idee hoe je dit goed zou moeten aansluiten. Verder snapte ik ook niet helemaal op welke pin ik nu de schakelaar moest aansluiten (de ook niet echt trouwens), als iemand mij zou kunnen uitleggen hoe dit werkt zou ik dat heel fijn vinden
Maar ik kom er nog niet helemaal uit, ik heb geprobeerd een programma te schrijven waardoor een led normaal aan is, maar wanneer je een knop indrukt moet hij weer uit gaan, totdat je hem loslaat, dan hoort hij weer aan te gaan.
Ik heb nu dit ervoor geschreven:
;**********************************************************************
; This file is a basic code template for assembly code generation *
; on the PIC16F84A. 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 (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P16F84A.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************
list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
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
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
main
;****Set up the port****
bsf STATUS,5 ;Switch to Bank 1
movlw 01h ;Set the Port A pins:
movwf TRISA ;bit 1to output, bit 0 to input.
bcf STATUS,5 ;Switch back to Bank 0
Checkswitch
BTFSC PORTA,0
call Ledoff
Checkswitch2
BTFSS PORTA,0
call Ledon
goto Checkswitch
Ledon
ledaan movlw 02h ;Turn the LED on by first putting
movwf PORTA ;it into the w register and then ;on the port
return
Ledoff
leduit movlw 00h ;Turn the LED on by first putting
movwf PORTA ;it into the w register and then ;on the port
return
END ; directive 'end of program'
Ik heb het zo aangesloten:

Het schema kan lijkt mij al niet knoppen, doordat de pic geen stroom kan krijgen als de schakelaar uit staat, maar ik heb geen idee hoe je dit goed zou moeten aansluiten. Verder snapte ik ook niet helemaal op welke pin ik nu de schakelaar moest aansluiten (de ook niet echt trouwens), als iemand mij zou kunnen uitleggen hoe dit werkt zou ik dat heel fijn vinden
[ Voor 3% gewijzigd door huub8 op 01-03-2010 18:34 ]