Pic 16f84a

Moptio Messages postés 2 Date d'inscription mercredi 6 avril 2005 Statut Membre Dernière intervention 25 avril 2005 - 6 avril 2005 à 09:56
Moptio Messages postés 2 Date d'inscription mercredi 6 avril 2005 Statut Membre Dernière intervention 25 avril 2005 - 25 avril 2005 à 10:27
Bonjour,
Je commence la programmation des PICs et notamment du 16F84A en langage assembleur et ca ne marche pas.
Le but etait de me familiariser avec ce Pic, donc j'ai fait un programme qui allume la led reliée a RBO (Utilisation du PICDEM1). Aidez moi SVP
voila mon code:
list p=16F84A ; list directive to define processor
#include ; processor specific variable definitions
;PROCESSOR 16F84A
;RADIX HEX
;INCLUDE "P16F84A.INC"
__CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC
;_CONFIG 3FF1
; '__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 (examples)


; example of using Uninitialized Data Section
INT_VAR UDATA 0x0C
;w_temp RES 1 ; variable used for context saving
;status_temp RES 1 ; variable used for context saving


; example of using Overlayed Uninitialized Data Section
; in this example both variables are assigned the same GPR location by linker
G_DATA UDATA_OVR ; explicit address can be specified
flag RES 2 ; temporary variable (shared locations - G_DATA)


G_DATA UDATA_OVR
count RES 2 ; temporary variable (shared locations - G_DATA)






;**********************************************************************
RESET_VECTOR CODE 0x000 ; processor reset vector
; goto start ; go to beginning of program



;INT_VECTOR CODE 0x004 ; interrupt vector location
; 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



; isr code can go here or be located as a call subroutine elsewhere



; 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





MAIN CODE
;start


; nop ; code starts here (example)
; banksel flag ; example
; clrf flag ; example
; remaining code goes here


ORG 00 ; Vecteur de reset
GOTO START ; Renvoi a l'adresse EEPROM 05H


; INITIALISATION


START ORG 05 ;
CLRF PORTB
MOVLW b'00000000'
MOVWF TRISA
BCF STATUS,RP0


; PROGRAMME
LOOP BSF PORTB,0
BCF PORTB,0
GOTO LOOP









END ; directive 'end of program'

2 réponses

phenojeff Messages postés 87 Date d'inscription jeudi 10 octobre 2002 Statut Membre Dernière intervention 4 avril 2008
6 avril 2005 à 17:05
Allo tu commence pas simple j'espere que tu va trouvé celui la plus simple a comprendre

je ne sait pas comment tu a brancher ton pic a tu mit un Quartz avec ses condo

si oui celui la devrait marcher mais des petit detail de branchement ferait pas de mal pour comprendre a++

**********************************************************************
;
PROGRAMME D'ENTRAINEMENT
AU

*

; FONCTIONNEMENT DES
PICS.




*

; 16F84A Quartz 4Mhz





*

;**********************************************************************

;
*

; NOM:
LED-CLI
*

; Date:
09/02/2001
*

; Version:
1.0
*

; Circuit: Platine
d'essais
*

; Auteur:
JEFFPHENO
*

; Msn: pheno_webster@hotmail.com

*

;**********************************************************************

;
*

; Fichier requis:
P16F84A.inc
*

;
*

;**********************************************************************

;
*

; Notes: Ce petit programme permet de faire clignoter une led *

; sur le PORT RB0 à un intervale de fréquence de 1Hz *

;
*

;
*

;**********************************************************************





LIST
p=16F84A
; Définition de processeur

#include ; Définitions de variables



__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_OFF & _HS_OSC



; '__CONFIG' précise les paramètres encodés dans le processeur au moment de

; la programmation du processeur. Les définitions sont dans le fichier include.

; Voici les valeurs et leurs définitions :

; _CP_ON Code protection ON : impossible de relire

; _CP_OFF Code protection OFF

; _PWRTE_ON Timer reset sur power on en service

; _PWRTE_OFF Timer reset hors-service

; _WDT_ON Watch-dog en service

; _WDT_OFF Watch-dog hors service

; _LP_OSC Oscillateur quartz basse vitesse

; _XT_OSC Oscillateur quartz moyenne vitesse

; _HS_OSC Oscillateur quartz grande vitesse

; _RC_OSC Oscillateur à réseau RC



;*********************************************************************

;
ASSIGNATIONS
*

;*********************************************************************



OPTIONVAL EQU H'0000' ; Valeur registre option




INTERMASK EQU H'0000' ; Masque d'interruption


;*********************************************************************

;
DEFINE
*

;*********************************************************************



#DEFINE LED1 PORTB,0 ; LED1 sur RB0



;*********************************************************************

;
MACRO
*

;*********************************************************************



LEDON macro

bsf LED1

endm



LEDOFF macro

bcf LED1

endm



;*********************************************************************

;
DECLARATIONS DE
VARIABLES
*

;*********************************************************************



CBLOCK 0x00C ; début de la zone variables



cmpt1 : 1 ; compteur de boucles 1

cmpt2 : 1

cmpt3 : 1


ENDC
; Fin de la
zone




;**********************************************************************

;
DEMARRAGE SUR
RESET
*

;**********************************************************************



org 0x000 ; Adresse de départ après reset

goto init ; Adresse 0: initialiser



;*********************************************************************

;
INITIALISATIONS
*

;*********************************************************************



init

bsf STATUS,RP0 ; sélectionner banque 1

clrf EEADR ; permet de diminuer la consommation

movlw OPTIONVAL ; charger masque

movwf OPTION_REG ; initialiser registre option



; Effacer RAM

; ------------

movlw 0x0c ; initialisation pointeur

movwf FSR ; pointeur d'adressage indirec

init1

clrf INDF ; effacer ram

incf FSR,f ; pointer sur suivant

btfss
FSR,6 ; tester si fin zone
atteinte (>=40)

goto init1 ; non, boucler

btfss
FSR,4 ; tester si fin zone
atteinte (>=50)

goto init1 ; non, boucler



; initialisations spécifiques

; ---------------------------

movlw 0xFE

movwf TRISB ;RB0 en Sortie pour led



bcf STATUS,RP0 ; repasser banque 0

goto start ; sauter au programme principal



;*********************************************************************

;
SOUS-ROUTINE DE
TEMPORISATION
*

;*********************************************************************

;---------------------------------------------------------------------

; Cette sous-routine introduit un retard de 500.000 µs.

; Elle ne reçoit aucun paramètre et n'en retourne aucun

;---------------------------------------------------------------------

tempo



clrf cmpt2 ; effacer compteur2

boucle2

clrf cmpt1 ; effacer compteur1

boucle1

nop ; perdre 1 cycle

decfsz cmpt1 , f ; décrémenter compteur1

goto
boucle1 ; si pas 0,
boucler

decfsz cmpt2 , f ; si 0, décrémenter compteur 2

goto
boucle2 ; si cmpt2 pas 0,
recommencer boucle1

return ; retour de la sous-routine



;*********************************************************************

;
PROGRAMME
PRINCIPAL
*

;*********************************************************************



start

LEDON

call tempo ; appeler la tempo de 0.5s

LEDOFF

call tempo ; appeler la tempo de 0.5s



goto start ; boucler





END ; directive fin de programme
0
Moptio Messages postés 2 Date d'inscription mercredi 6 avril 2005 Statut Membre Dernière intervention 25 avril 2005
25 avril 2005 à 10:27
Merci pour la réponse
0
Rejoignez-nous